source: src/main/java/com/example/salonbella/security/CustomSuccessHandler.java

Last change on this file was 74af394, checked in by makyjovanovsky <mjovanovski04@…>, 17 months ago

login/register with mail confirmation

  • Property mode set to 100644
File size: 1.0 KB
Line 
1package com.example.salonbella.security;
2
3import org.springframework.context.annotation.Configuration;
4import org.springframework.security.core.Authentication;
5import org.springframework.security.core.authority.AuthorityUtils;
6import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
7
8import javax.servlet.ServletException;
9import javax.servlet.http.HttpServletRequest;
10import javax.servlet.http.HttpServletResponse;
11import java.io.IOException;
12import java.util.Set;
13
14@Configuration
15public class CustomSuccessHandler implements AuthenticationSuccessHandler {
16
17 @Override
18 public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
19 Set<String> roles = AuthorityUtils.authorityListToSet(authentication.getAuthorities());
20
21 if (roles.contains("ROLE_ADMIN")) {
22 response.sendRedirect("/adminDashboard");
23 } else {
24 response.sendRedirect("/userDashboard");
25 }
26 }
27}
Note: See TracBrowser for help on using the repository browser.