AuthenticationSuccessHandlerを作成し、WebSecurityConfigで
@Autowired
private AuthenticationSuccessHandler AuthenticationSuccessHandler;
.successHandler(AuthenticationSuccessHandler)
にセットしたところROLE権限ごとにページ遷移しました。
java
1@Component
2public class AuthenticationSuccessHandler
3 implements org.springframework.security.web.authentication.AuthenticationSuccessHandler {
4
5 @Override
6 public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
7 Authentication authentication) throws IOException, ServletException {
8 Set<String> roles = AuthorityUtils.authorityListToSet(authentication.getAuthorities());
9
10 if (roles.contains("ADMIN")) {
11 response.sendRedirect(request.getContextPath() + "/admin");
12 }else if(roles.contains("USER")){
13 response.sendRedirect(request.getContextPath() + "/user");
14 }
15 }
16}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/03/22 06:28