2010-11-16 74 views
2

我在我的grails項目中集成了spring security core,然後是s2-quickstart。如何使用spring安全核心和grails處理登錄

所以我得到了所有基本的gsps,域控制器也。

所以我有一個用戶id ='我'和密碼(編碼)='密碼'數據庫內角色='ROLE_ADMIN'。

現在我對他們擁有的api類感到困惑。我需要在我的項目開始時顯示登錄頁面,如果用戶輸入正確的密碼,那麼它應該重定向到儀表板頁面。所以我寫了下面的一段代碼:

UrlMapping.groovy 
================= 
"/"(controller:"login", action:"auth") 

LoginController.groovy 
====================== 
class LoginController { 
def authenticationTrustResolver 
def springSecurityService 

def index = { 
     redirect(action: 'auth', params: params) 
} 
def auth = { 
     //Checking Licensing stuff 
     .... 
     .... 

} 
def signIn = { 
     if (params.username == null) 
      redirect(action: 'login') 
     def config = SpringSecurityUtils.securityConfig 
     if (springSecurityService.isLoggedIn()) { 
      def targetUri = "/dashboard/loadDashboard" 
      redirect(uri: targetUri) 
    } 
     else 
     { 
      println params.username 
      println params.password 

      //Don't know which class I should use here 
     } 
} 

auth.gsp inside (login directory) 
================================= 
<form action='login/signIn' method='POST' id='loginForm' class='cssform' autocomplete='off'> 
<label for='username'>Login ID</label> 
        <input type='text' class='text_' name='j_username' id='username' /> 
<label for='password'>Password</label> 
        <input type='password' class='text_' name='j_password' id='password' /> 
<input type='submit' value='Login' /> 

所以我不知道我應該怎麼傳遞給其的LoginController的簽到方法的其他部分內部類的用戶名和密碼。

任何幫助將高度讚賞...

回答

2

彈簧安全爲您完成所有。

只需航線用戶到儀表板

UrlMapping.groovy 
================= 
"/"(controller:"dashboard", action:"indexorwhatever") 

,並與@Secured註解註釋DashboardController

相關問題