2022-02-15 07:38:58 +00:00
|
|
|
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")) {
|
2022-02-21 09:41:19 +00:00
|
|
|
response.sendRedirect("/admin/dashBoard");
|
2022-02-15 07:38:58 +00:00
|
|
|
return;
|
|
|
|
|
}else if(loginSuccessHandler.roleName.equals("ROLE_DISABLE")) {
|
|
|
|
|
response.sendRedirect("/login?fail");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
response.sendRedirect("/");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|