在grails中我试图在登录到我的人控制器后引导用户。我试图在config.groovy中添加重定向但它不起作用。它仍然会将我重定向回登录页面。
我的config.grooovy
Spring安全部分位于
// Added by the Spring Security Core plugin:
grails.plugins.springsecurity.userLookup.userDomainClassName = 'grail4.User'
grails.plugins.springsecurity.userLookup.authorityJoinClassName = 'grail4.UserRole'
grails.plugins.springsecurity.authority.className = 'grail4.Role'
//grails.plugins.springsecurity.successHandler.defaultTargetUrl = 'https://www.yahoo.com'
grails.plugins.springsecurity.securityConfigType = SecurityConfigType.InterceptUrlMap
grails.plugins.springsecurity.successHandler.defaultTargetUrl = '/index'
grails.plugins.springsecurity.interceptUrlMap = [
'/people/*': ['IS_AUTHENTICATED_REMEMBERED'],
]
***grails.plugins.springsecurity.successHandler.defaultTargetUrl ="/people"***
输入正确的用户名密码后,如果我复制&粘贴网址。但是登录页面没有将其重定向到该页面。
答案 0 :(得分:0)
以下应该工作 -
grails.plugins.springsecurity.successHandler.defaultTargetUrl = '/people'
看起来用户未成功通过身份验证。您应该尝试注册spring security listener
在Config.groovy中
grails.plugins.springsecurity.useSecurityEventListener = true
实现安全监听器 -
class MySecurityEventListener implements ApplicationListener<ApplicationEvent> {
static Log logger = LogFactory.getLog(CGWSecurityEventListener.class);
public void onApplicationEvent(final ApplicationEvent e) {
if (e instanceof AbstractAuthenticationEvent) {
if (e instanceof AbstractAuthenticationFailureEvent) {
logger.warn(String.format("Authentication failure", ((AbstractAuthenticationFailureEvent) e).getAuthentication().principal),
((AbstractAuthenticationFailureEvent) e).getException());
}
else if (e instanceof AuthenticationSuccessEvent) {
logger.debug(String.format("user %s has been authenticated sucessfully", ((AuthenticationSuccessEvent) e).getAuthentication().principal))
}
}
}
}