Security шаблон

This commit is contained in:
L_DelOff
2023-03-01 23:46:16 +03:00
parent 74600740eb
commit 9eebb2bfff
14 changed files with 374 additions and 7 deletions

View File

@@ -0,0 +1,25 @@
package ru.ldeloff.hedgehogcloud.config;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Set;
@Component
public class AuthenticationSuccessUserHandler implements AuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
Set<String> roles = AuthorityUtils.authorityListToSet(authentication.getAuthorities());
if (roles.contains("ROLE_ADMIN")) {
response.sendRedirect("/admin");
} else {
response.sendRedirect("/user");
}
}
}