|
@@ -0,0 +1,76 @@
|
|
|
+package com.its.op.security;
|
|
|
+
|
|
|
+import com.its.op.dto.its.LoginDto;
|
|
|
+import com.its.op.service.its.LoginService;
|
|
|
+import com.its.utils.ItsUtils;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpSession;
|
|
|
+import javax.servlet.http.HttpSessionEvent;
|
|
|
+import javax.servlet.http.HttpSessionListener;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Component
|
|
|
+//public class WebHttpSessionListener implements ApplicationListener<SessionDestroyedEvent> {
|
|
|
+// // 상용 웹서버에서 HttpSessionListener 작동 안될때
|
|
|
+// @Override
|
|
|
+// public void onApplicationEvent(SessionDestroyedEvent event) {
|
|
|
+// }
|
|
|
+//}
|
|
|
+public class WebHttpSessionListener implements HttpSessionListener {
|
|
|
+
|
|
|
+ private final LoginService service;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void sessionCreated(HttpSessionEvent httpSessionEvent) {
|
|
|
+ HttpSession session = httpSessionEvent.getSession();
|
|
|
+ SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ if (session != null) {
|
|
|
+ String creationTime = sdfDate.format(new Date(session.getCreationTime()));
|
|
|
+ String lastAccessTime = sdfDate.format(new Date(session.getLastAccessedTime()));
|
|
|
+ UserInfrVo userInfr = (UserInfrVo) session.getAttribute(WebConstants.LOGIN_USER);
|
|
|
+ if (userInfr != null) {
|
|
|
+ session.setMaxInactiveInterval(WebConstants.MAX_INACTIVE_SESSION_TIMEOUT);
|
|
|
+ log.info("Session Created: User: {}, {}", userInfr.getUserId(), userInfr.getOperSystId());
|
|
|
+ }
|
|
|
+ log.error("Session Created: {}, {}, {}", creationTime, lastAccessTime, session.getMaxInactiveInterval());
|
|
|
+ }
|
|
|
+ log.error("Session Created: {}", httpSessionEvent.getSession().getMaxInactiveInterval());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
|
|
|
+ HttpSession session = httpSessionEvent.getSession();
|
|
|
+ SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ if (session != null) {
|
|
|
+ String creationTime = sdfDate.format(new Date(session.getCreationTime()));
|
|
|
+ String lastAccessTime = sdfDate.format(new Date(session.getLastAccessedTime()));
|
|
|
+ UserInfrVo userInfr = (UserInfrVo) session.getAttribute(WebConstants.LOGIN_USER);
|
|
|
+ if (userInfr != null) {
|
|
|
+ if (StringUtils.isNotEmpty(userInfr.getUserId()) && StringUtils.isEmpty(userInfr.getLogoutHms())) {
|
|
|
+ LoginDto.LogoutReqDto req = LoginDto.LogoutReqDto.builder()
|
|
|
+ .user_id(WebMvcConfig.decUserId(userInfr.getUserId()))
|
|
|
+ .login_hms(userInfr.getLoginHms())
|
|
|
+ .build();
|
|
|
+ this.service.logout(req);
|
|
|
+ userInfr.setLogoutHms(ItsUtils.getSysTime());
|
|
|
+ log.info("logout history: {}", req);
|
|
|
+ }
|
|
|
+ log.info("Session Destroyed: User: {}, {}, {}, {}", userInfr.getUserId(), userInfr.getOperSystId(), userInfr.getLoginHms(), userInfr.getLogoutHms());
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ log.error("Session Destroyed: {}, {}, {}", creationTime, lastAccessTime, session.getMaxInactiveInterval());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ log.error("Session Destroyed: {}", httpSessionEvent);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|