Last change
on this file since 4d7e387 was 4d7e387, checked in by makyjovanovsky <mjovanovski04@…>, 21 months ago |
commit 1
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Line | |
---|
1 | package com.example.salonbella.security;
|
---|
2 |
|
---|
3 | import org.springframework.context.annotation.Configuration;
|
---|
4 | import org.springframework.security.core.Authentication;
|
---|
5 | import org.springframework.security.core.authority.AuthorityUtils;
|
---|
6 | import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
---|
7 |
|
---|
8 | import javax.servlet.ServletException;
|
---|
9 | import javax.servlet.http.HttpServletRequest;
|
---|
10 | import javax.servlet.http.HttpServletResponse;
|
---|
11 | import java.io.IOException;
|
---|
12 | import java.util.Set;
|
---|
13 |
|
---|
14 | @Configuration
|
---|
15 | public 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.