48 lines
1.4 KiB
Java
48 lines
1.4 KiB
Java
|
|
package com.mca.sec;
|
||
|
|
|
||
|
|
import java.io.IOException;
|
||
|
|
|
||
|
|
import javax.servlet.ServletException;
|
||
|
|
import javax.servlet.http.HttpServletRequest;
|
||
|
|
import javax.servlet.http.HttpServletResponse;
|
||
|
|
import javax.servlet.http.HttpSession;
|
||
|
|
|
||
|
|
import org.springframework.security.core.Authentication;
|
||
|
|
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
||
|
|
|
||
|
|
import com.mca.sec.vo.LoginUserVO;
|
||
|
|
import com.mca.sec.UserUtil;
|
||
|
|
|
||
|
|
public class LoginSuccessHandler implements AuthenticationSuccessHandler{
|
||
|
|
private String roleName;
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
|
||
|
|
Authentication authentication) throws IOException, ServletException {
|
||
|
|
// TODO Auto-generated method stub
|
||
|
|
|
||
|
|
LoginUserVO user = UserUtil.getMemberInfo();
|
||
|
|
|
||
|
|
HttpSession session = request.getSession();
|
||
|
|
session.setAttribute("userVO", user);
|
||
|
|
|
||
|
|
LoginSuccessHandler loginSuccessHandler = new LoginSuccessHandler();
|
||
|
|
authentication.getAuthorities().forEach(authority ->{
|
||
|
|
loginSuccessHandler.roleName = authority.getAuthority();
|
||
|
|
});
|
||
|
|
|
||
|
|
if(loginSuccessHandler.roleName.equals("ROLE_USER")) {
|
||
|
|
response.sendRedirect("/map/request");
|
||
|
|
return;
|
||
|
|
}else if(loginSuccessHandler.roleName.equals("ROLE_ADMIN")) {
|
||
|
|
response.sendRedirect("/admin/request");
|
||
|
|
return;
|
||
|
|
}else if(loginSuccessHandler.roleName.equals("ROLE_DISABLE")) {
|
||
|
|
response.sendRedirect("/login?fail");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
response.sendRedirect("/");
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|