GGWEB/src/main/java/com/mca/sec/LoginSuccessHandler.java

66 lines
1.9 KiB
Java
Raw Normal View History

2022-02-15 07:38:58 +00:00
package com.mca.sec;
import java.io.IOException;
import java.time.LocalDateTime;
2022-02-15 07:38:58 +00:00
import javax.annotation.Resource;
2022-02-15 07:38:58 +00:00
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.mca.cmmn.service.LogService;
import com.mca.cmmn.vo.LogActions;
import com.mca.cmmn.vo.LogVO;
2022-02-15 07:38:58 +00:00
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;
@Resource(name="logService")
private LogService logService;
2022-02-15 07:38:58 +00:00
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException, ServletException {
// TODO Auto-generated method stub
LoginUserVO user = UserUtil.getMemberInfo();
if(user == null){
response.sendRedirect("/");
}else{
HttpSession session = request.getSession();
session.setAttribute("userVO", user);
LoginSuccessHandler loginSuccessHandler = new LoginSuccessHandler();
authentication.getAuthorities().forEach(authority ->{
loginSuccessHandler.roleName = authority.getAuthority();
});
LogVO logVO = new LogVO();
logVO.setLog(user.getUserid(), LogActions.LOGIN.getValue(), null, LocalDateTime.now());
logService.insertLog(logVO);
switch (loginSuccessHandler.roleName) {
case "ROLE_USER":
response.sendRedirect("/map/request");
return;
case "ROLE_ADMIN":
response.sendRedirect("/admin/dashBoard");
return;
case "ROLE_DISABLE":
response.sendRedirect("/login?fail");
return;
}
}
2022-02-15 07:38:58 +00:00
}
}