|
|
@@ -1,5 +1,6 @@
|
|
|
package com.its.web.security;
|
|
|
|
|
|
+import com.its.web.dto.admin.PrincipalDetail;
|
|
|
import com.its.web.dto.admin.TbWwwMemberDto;
|
|
|
import com.its.web.mapper.its.admin.AdminMapper;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
@@ -16,7 +17,9 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
import java.io.IOException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
@Slf4j
|
|
|
@@ -29,8 +32,9 @@ public class WebLoginSuccessHandler implements AuthenticationSuccessHandler {
|
|
|
|
|
|
@Override
|
|
|
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
|
|
|
-
|
|
|
-// String currSysTime = ItsUtils.getSysTime();
|
|
|
+ SimpleDateFormat sdfDate = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
+ Date dtNow = new Date();
|
|
|
+ String currSysTime = sdfDate.format(dtNow);
|
|
|
// IP, 세션 ID
|
|
|
WebAuthenticationDetails details = (WebAuthenticationDetails)authentication.getDetails();
|
|
|
|
|
|
@@ -44,43 +48,28 @@ public class WebLoginSuccessHandler implements AuthenticationSuccessHandler {
|
|
|
log.info("login Roll: {}", auth.getAuthority());
|
|
|
}
|
|
|
|
|
|
- TbWwwMemberDto userInfr = (TbWwwMemberDto)authentication.getPrincipal();
|
|
|
-// String remoteIp = ItsUtils.getHttpServletRemoteIP(request);
|
|
|
-// TbUserCnncHs cnncHs = TbUserCnncHs.builder()
|
|
|
-// .operSystId(userInfr.getOperSystId())
|
|
|
-// .userId(userInfr.getUserId())
|
|
|
-// .loginHms(ItsUtils.getSysTime())
|
|
|
-// .logoutHms("")
|
|
|
-// .build();
|
|
|
-// this.cnncHsRepo.insertData(cnncHs.getOperSystId(), cnncHs.getLoginHms(), cnncHs.getUserId(), cnncHs.getLogoutHms());
|
|
|
-// log.info("Login History: {}, {}", cnncHs, remoteIp);
|
|
|
-//
|
|
|
-// userInfr.setLoginHms(cnncHs.getLoginHms());
|
|
|
-// userInfr.setLogoutHms("");
|
|
|
-//
|
|
|
-// String uri = WebConstants.DEFAULT_URI;
|
|
|
-// String domain = "/";
|
|
|
-//
|
|
|
-// HttpSession session = request.getSession(false); // 세션을 생성 하지 않음
|
|
|
-// if (session != null) {
|
|
|
-// log.info("Session[{}}] [{}], Login Authentication: User: {}, {}, {}, Login History: {}, {}",
|
|
|
-// session.getId(), currSysTime, userInfr.getUserId(), userInfr.getOperSystId(), userInfr.getLoginHms(), remoteIp, cnncHs.getLoginHms());
|
|
|
-// } else {
|
|
|
-// session = request.getSession(true); // 새로운 세션을 생성
|
|
|
-// session.setMaxInactiveInterval(WebConstants.MAX_INACTIVE_SESSION_TIMEOUT);
|
|
|
-// log.info("Session[{}] [{}], Login Authentication, Session Create: User: {}, {}, {}, {}, Login History: {}, {}",
|
|
|
-// session.getId(), currSysTime, userInfr.getUserId(), userInfr.getOperSystId(), userInfr.getLoginHms(), session.getMaxInactiveInterval(), remoteIp, cnncHs.getLoginHms());
|
|
|
-// }
|
|
|
-// session.setAttribute(WebConstants.USER_UUID, WebMvcConfig.encUserId(cnncHs.getUserId()));
|
|
|
-// session.setAttribute(WebConstants.USER_TIME, cnncHs.getLoginHms());
|
|
|
-// session.setAttribute(WebConstants.LOGIN_USER, userInfr);
|
|
|
-//
|
|
|
-// CookieUtils.setCookie(response, WebConstants.USER_UUID, WebMvcConfig.encUserId(cnncHs.getUserId()), 60*60, domain);
|
|
|
-// CookieUtils.setCookie(response, WebConstants.USER_TIME, cnncHs.getLoginHms(), 60*60, domain);
|
|
|
-// CookieUtils.setCookie(response, WebConstants.USER_OPER_SYST_ID, userInfr.getOperSystId(), 60*60, domain);
|
|
|
+ PrincipalDetail principal = (PrincipalDetail)authentication.getPrincipal();
|
|
|
+ TbWwwMemberDto userInfr = principal.getUser();
|
|
|
+
|
|
|
+ String remoteIp = this.getHttpServletRemoteIP(request);
|
|
|
+ log.info("Login History: {}, {}", currSysTime, remoteIp);
|
|
|
+
|
|
|
+ HttpSession session = request.getSession(false); // 세션을 생성 하지 않음
|
|
|
+ if (session != null) {
|
|
|
+ log.info("Session[{}}] [{}], Login Authentication: User: {}, {}, Login History: {}, {}",
|
|
|
+ session.getId(), currSysTime, userInfr.getEmail(), userInfr.getMemberNm(), remoteIp, currSysTime);
|
|
|
+ } else {
|
|
|
+ session = request.getSession(true); // 새로운 세션을 생성
|
|
|
+ session.setMaxInactiveInterval(60);
|
|
|
+ log.info("Session[{}] [{}], Login Authentication, Session Create: User: {}, {}, {}, Login History: {}, {}",
|
|
|
+ session.getId(), currSysTime, userInfr.getEmail(), userInfr.getMemberNm(), currSysTime, session.getMaxInactiveInterval(), remoteIp, currSysTime);
|
|
|
+ }
|
|
|
+ session.setAttribute("UUID", userInfr.getEmail());
|
|
|
+ session.setAttribute("TIME", currSysTime);
|
|
|
+ session.setAttribute("NAME", userInfr.getMemberNm());
|
|
|
|
|
|
-// clearAuthenticationAttributes(request);
|
|
|
-// response.sendRedirect(uri);
|
|
|
+ clearAuthenticationAttributes(request);
|
|
|
+ response.sendRedirect("/phits/main");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -97,4 +86,36 @@ public class WebLoginSuccessHandler implements AuthenticationSuccessHandler {
|
|
|
|
|
|
session.removeAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
|
|
|
}
|
|
|
+
|
|
|
+ public static String getHttpServletRemoteIP(HttpServletRequest request) {
|
|
|
+ if (request == null) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ String ipAddress = request.getHeader("X-FORWARDED-FOR");
|
|
|
+ // proxy 환경일 경우
|
|
|
+ if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
|
|
+ ipAddress = request.getHeader("Proxy-Client-IP");
|
|
|
+ }
|
|
|
+ // 웹로직 서버일 경우
|
|
|
+ if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
|
|
+ ipAddress = request.getHeader("WL-Proxy-Client-IP");
|
|
|
+ }
|
|
|
+ if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
|
|
+ ipAddress = request.getHeader("HTTP_CLIENT_IP");
|
|
|
+ }
|
|
|
+ if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
|
|
+ ipAddress = request.getHeader("HTTP_X_FORWARDED_FOR");
|
|
|
+ }
|
|
|
+ // 기타
|
|
|
+ if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
|
|
+ ipAddress = request.getRemoteAddr() ;
|
|
|
+ }
|
|
|
+ //-Djava.net.preferIPv4Stack=true
|
|
|
+ if (ipAddress.equals("0:0:0:0:0:0:0:1")) //==> ipv6 <== default
|
|
|
+ {
|
|
|
+ ipAddress = "127.0.0.1"; //==> localhost
|
|
|
+ }
|
|
|
+ return ipAddress;
|
|
|
+ }
|
|
|
}
|