2017-04-13 80 views
0

Iam在我的grails 2.4.4應用程序中使用spring-security-core 2.0-RC5。最近我在我的應用程序中實現了以下過濾器,但問題在於SignupController請求即將到來時,由於springSecurityService注入(在註冊的情況下沒有驗證並且沒有會話)發生錯誤。將springSecurityService注入到導致錯誤的過濾器中

那麼我怎麼能注入springSecurityService在我的過濾器沒有趕上註冊請求。

import com.services.portal.ProfileService; 
 
import com.services.portal.SignupService; 
 
import com.services.portal.UserSessionService; 
 
import com.domain.auth.User; 
 
import com.services.portal.FormProcessService; 
 
import com.services.portal.ProfileService; 
 
import com.services.portal.SignupService; 
 
import com.services.portal.UserSessionService 
 

 
import grails.plugin.springsecurity.SpringSecurityService; 
 
import grails.plugin.springsecurity.annotation.Secured 
 
import grails.plugin.springsecurity.ui.AbstractS2UiController; 
 
import groovy.sql.Sql 
 

 

 

 
class AuthFilters { 
 
\t def springSecurityService 
 
\t def filters = { 
 
\t \t allExceptIndex(controller: 'login|signup|logout', invert: true) { 
 
\t \t \t before = { 
 
\t \t \t \t if(session["Username"] == null){ 
 
\t \t \t \t \t def Username = springSecurityService.getPrincipal().getUsername() 
 
\t \t \t \t \t session["Username"] = Username 
 
\t \t \t \t } 
 
\t \t \t \t if(session["UserId"] == null){ 
 
\t \t \t \t \t String userId = springSecurityService.getPrincipal().getId() 
 
\t \t \t \t \t session["UserId"] = userId 
 
\t \t \t \t } 
 
\t \t \t \t if(session["incomingIp"] == null){ 
 
\t \t \t \t \t def incomingIp = request.remoteHost 
 
\t \t \t \t \t session["incomingIp"] = incomingIp 
 
\t \t \t \t } 
 
\t \t \t \t if(session["currUserRole"] == null){ 
 
\t \t \t \t \t def roles = springSecurityService.getPrincipal().getAuthorities() 
 
\t \t \t \t \t roles = roles.toString().substring(1, roles.toString().length()-1) 
 
\t \t \t \t \t session["currUserRole"] = roles 
 
\t \t \t \t } 
 
\t \t \t } 
 

 
\t \t \t after = { Map model -> 
 
\t \t \t } 
 

 
\t \t \t afterView = { Exception e -> 
 
\t \t \t } 
 
\t \t } 
 
     } 
 
    }

回答

0

該處理的申請要求將其公開通過行動之前使用@Secured(['permitAll'])控制器。

+0

我已將@Secured(['permitAll'])註釋添加到註冊控制器 –

相關問題