我在Spring Security的应用程序中完成了登录和注销
情况:
使用有效凭据登录后,我正在指导基于角色的页面。点击后退按钮后,它将带我登录屏幕。再次,如果我提供有效的凭据,它不会重定向到基于角色的页面,它只保留登录页面。
而且会议仍然没有失效..
如果我在浏览器中输入有效网址,显示有效页面以及之前记录的详细信息...
答案 0 :(得分:1)
答案 1 :(得分:0)
Collection<? extends GrantedAuthority> roleList = SecurityContextHolder
.getContext().getAuthentication().getAuthorities();
在登录方法中使用此方法,并检查用户是否具有您在spring-security文件中定义的角色(ROLE_USER或ROLE_ADMIN)。然后使用:
ModelAndView mav = new ModelAndView();
if (roleList.contains(new SimpleGrantedAuthority("ROLE_USER"))){
return mav.setViewName("redirect:/homepageafterlogin");
//it will automatically redirect to homepage if you hit the login url or
//press back button.
} else {
if (roleList.contains(new SimpleGrantedAuthority("ROLE_ANONYMOUS"))){
//means user is already not logged in then
return mav.setViewName("/signin.jsp");
}
}