重定向发生在,org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler
但插件扩展了此类org.codehaus.groovy.grails.plugins.springsecurity.AjaxAwareAuthenticationSuccessHandler
以支持 Ajax 登录。
如果您想根据角色自定义重定向位置,我会继承AjaxAwareAuthenticationSuccessHandler
并覆盖onAuthenticationSuccess()
. 您将有权访问身份验证,因此您可以检查授予的权限并根据这些权限确定去哪里。
然后在 resources.groovy 中用你的替换插件的 bean:
import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils
beans = {
authenticationSuccessHandler(MyAuthenticationSuccessHandler) {
def conf = SpringSecurityUtils.securityConfig
requestCache = ref('requestCache')
redirectStrategy = ref('redirectStrategy')
defaultTargetUrl = conf.successHandler.defaultTargetUrl
alwaysUseDefaultTargetUrl = conf.successHandler.alwaysUseDefault
targetUrlParameter = conf.successHandler.targetUrlParameter
ajaxSuccessUrl = conf.successHandler.ajaxSuccessUrl
useReferer = conf.successHandler.useReferer
}
}