[英]How to redirect user to different pages after logout with Spring Security and Grails
I am new to Groovy and Grails. 我是Groovy和Grails的新手。 I have developed an application using the Spring Security plugin using a database requested request map.
我已经使用Spring Security插件通过数据库请求的请求映射开发了一个应用程序。 I want a custom redirection to the home pages after logout according to the roles.
我希望根据角色注销后自定义重定向到主页。
If the user is ROLE_ADMIN, after logout he would be redirected to his home page in views adminUser/Homepage.gsp 如果用户是ROLE_ADMIN,则注销后,他将被重定向到视图adminUser / Homepage.gsp中的主页。
If the user is ROLE_USER, after logout he would be redirected to his home page in views User/Homepage.gsp 如果用户是ROLE_USER,则注销后,他将在视图User / Homepage.gsp中重定向到他的主页。
I am not able to get any custom authentication redirection according to the user role. 我无法根据用户角色获得任何自定义身份验证重定向。
You have two options 你有两个选择
1) Create a custom logout method were you can logout user programmatically using SecurityContextHolder.clearContext()
then redirect user based on there ROLES 1)创建一个自定义注销方法,您可以使用
SecurityContextHolder.clearContext()
编程方式注销用户,然后根据那里的ROLES重定向用户
2) Create custom logout handler, follow this link https://grails-plugins.github.io/grails-spring-security-core/guide/logoutHandlers.html 2)创建自定义注销处理程序,单击此链接https://grails-plugins.github.io/grails-spring-security-core/guide/logoutHandlers.html
I am posting my solution thanks a lot for your help. 我正在发布我的解决方案,非常感谢您的帮助。 This approach is simple and easy you just need to call the logout method from your request variable from your logout controller.
这种方法既简单又容易,您只需要从注销控制器的请求变量中调用注销方法即可。
def roles = SpringSecurityUtils.getPrincipalAuthorities()
for (String role in roles) {
if (role.equals("ROLE_ADMIN")) {
request.logout()
redirect uri : "/admin/logoutPage"
}
else if (role.equals("ROLE_USER")) {
request.logout()
redirect uri : "/user/logoutPage"
}
else {
request.logout()
redirect uri : "/"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.