forked from JoyChou93/java-sec-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomSuccessHandler.java
More file actions
46 lines (31 loc) · 1.09 KB
/
CustomSuccessHandler.java
File metadata and controls
46 lines (31 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.config;
import java.io.IOException;
import java.util.Set;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
@Configuration
public class CustomSuccessHandler implements AuthenticationSuccessHandler{
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException, ServletException {
// TODO Auto-generated method stub
Set<String> roles = AuthorityUtils.authorityListToSet(authentication.getAuthorities());
if(roles.contains("ROLE_ADMIN"))
{
response.sendRedirect("/admin/");
}
else if(roles.contains("ROLE_USER"))
{
response.sendRedirect("/user/");
}
else
{
response.sendRedirect("/signin");
}
}
}