shjung 2 rokov pred
rodič
commit
3d347d0826

+ 2 - 2
src/main/java/com/its/op/controller/ResourceMonitoringController.java

@@ -67,10 +67,10 @@ public class ResourceMonitoringController {
         List<WebsocketMonitoringDto> result = this.resourceMonitoringService.getWebsocketList();
         return ResponseEntity.ok(result);
     }
-    @ApiOperation(value = "웹소켓 디버그 조회", response = WebsocketMonitoringDto.class, responseContainer = "ArrayList")
+    @ApiOperation(value = "웹소켓 디버그 조회", response = String.class, responseContainer = "ArrayList")
     @GetMapping(path="/websocket/debug/{flag}", produces = MediaType.APPLICATION_JSON_VALUE)
     public ResponseEntity<String> getWebsocketDebug(
-            @ApiParam(name = "id", value = "디버그 설정(0 or 1", example = "0", required = true)
+            @ApiParam(name = "flag", value = "디버그 설정(0 or 1", example = "0", required = true)
             @PathVariable("flag") String flag
     ) {
         String result = this.resourceMonitoringService.getWebsocketDebug(flag);

+ 17 - 19
src/main/java/com/its/op/controller/its/LoginController.java

@@ -154,13 +154,23 @@ public class LoginController {
      */
     @RequestMapping(value = "/logout.do", method = {RequestMethod.GET, RequestMethod.POST})
     public ModelAndView logout(HttpServletRequest request, HttpServletResponse response) {
+
+        HttpSession session = request.getSession(false);
+        if (session != null) {
+            UserInfrVo userInfr = (UserInfrVo) session.getAttribute(WebConstants.LOGIN_USER);
+            if (userInfr != null) {
+                userInfr.setLogoutHms(ItsUtils.getSysTime());
+                log.info("logout User: {}, {}", userInfr.getUserId(), userInfr.getOperSystId());
+            }
+        }
+
         Cookie[] cookies = request.getCookies();
         String encUserId = "";
         String loginHms = "";
         if (cookies != null && cookies.length > 0) {
-            for (Cookie cookie : cookies) {
-                log.info("logout cookie: {}, {}", cookie.getName(), cookie.getValue());
-            }
+//            for (Cookie cookie : cookies) {
+//                log.info("Logout cookie: {}, {}", cookie.getName(), cookie.getValue());
+//            }
             encUserId = CookieUtils.getCookie(request, WebConstants.USER_UUID);
             loginHms = CookieUtils.getCookie(request, WebConstants.USER_TIME);
             expiredCookie(response, WebConstants.USER_UUID);
@@ -171,29 +181,17 @@ public class LoginController {
             LoginDto.LogoutReqDto req = LoginDto.LogoutReqDto.builder()
                     .user_id(WebMvcConfig.decUserId(userId))
                     .login_hms(loginHms)
+                    .user_id(session == null ? "xxx-xxx-xxx-xxx" : session.getId())
                     .build();
             this.service.logout(req);
-            log.info("logout history: {}", req);
+            log.info("Logout Request, Logout History Save: [{}], {}, {}", req.getSessionId(), req.getUserId(), req.getLoginHms());
         }
 
-//        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
-//        if (auth != null) {
-//            // 여기로 안들어오네... 나중에 확인.....
-//            log.error("Authentication: {}", auth.toString());
-//            expiredCookie(response, WebConstants.USER_UUID);
-//            expiredCookie(response, WebConstants.USER_TIME);
-//            //new SecurityContextLogoutHandler().logout(request, response, auth);
-//        }
-
-        HttpSession session = request.getSession(false);
+        // 로그아웃 이력 저장 후 세션 종료 시킴
         if (session != null) {
-            UserInfrVo userInfr = (UserInfrVo) session.getAttribute(WebConstants.LOGIN_USER);
-            if (userInfr != null) {
-                userInfr.setLogoutHms(ItsUtils.getSysTime());
-                log.info("logout User: {}, {}", userInfr.getUserId(), userInfr.getOperSystId());
-            }
             session.invalidate();   // session remove
         }
+
         new SecurityContextLogoutHandler().logout(request, response, SecurityContextHolder.getContext().getAuthentication());
         return new ModelAndView("redirect:" + WebConstants.LOGIN_PAGE_URI);
     }

+ 5 - 0
src/main/java/com/its/op/dto/its/LoginDto.java

@@ -95,6 +95,11 @@ public class LoginDto implements Serializable {
         @JsonProperty("login_hms")
         private String loginHms;
 
+        @ApiModelProperty("로그인 세션")  // N VARCHAR(64)
+        @JsonProperty("session_id")
+        @JsonIgnore
+        private String sessionId;
+
         @Builder
         public LogoutReqDto(String user_id, String login_hms) {
             this.userId = user_id;

+ 3 - 1
src/main/java/com/its/op/global/TbIfscManager.java

@@ -65,7 +65,9 @@ public class TbIfscManager extends AbstractTableManager<Long, TbIfsc> {
         this.isLoadTrafByServer = isLoadTrafByServer;
         this.loadTrafTm = SysUtils.getSysTimeMin();
         stopWatch.stop();
-        log.info("TbIfscManager.loadTraf: {}, isLoadTrafByServer[{}], isLoadTraf[{}], {} ms.", this.loadTrafTm, isLoadTrafByServer, isLoadTraf, stopWatch.getTotalTimeMillis());
+        if (isLoadTraf) {
+            log.info("TbIfscManager.loadTraf: {}, isLoadTrafByServer[{}], {} ms.", this.loadTrafTm, isLoadTrafByServer, stopWatch.getTotalTimeMillis());
+        }
     }
     private void findTraf() {
         this.trafList = this.trafRepo.findAll();

+ 1 - 1
src/main/java/com/its/op/global/TbLinkManager.java

@@ -69,7 +69,7 @@ public class TbLinkManager extends AbstractTableManager<Long, TbLink> {
         this.loadTrafTm = SysUtils.getSysTimeMin();
         stopWatch.stop();
         if (isLoadTraf) {
-            log.info("TbLinkManager.loadTraf: {}, isLoadTrafByServer[{}], isLoadTraf[{}], {} ms.", this.loadTrafTm, isLoadTrafByServer, isLoadTraf, stopWatch.getTotalTimeMillis());
+            log.info("TbLinkManager.loadTraf: {}, isLoadTrafByServer[{}], {} ms.", this.loadTrafTm, isLoadTrafByServer, stopWatch.getTotalTimeMillis());
         }
     }
     private void findTraf() {

+ 3 - 1
src/main/java/com/its/op/global/TbRoadManager.java

@@ -65,7 +65,9 @@ public class TbRoadManager extends AbstractTableManager<Long, TbRoad> {
         this.isLoadTrafByServer = isLoadTrafByServer;
         this.loadTrafTm = SysUtils.getSysTimeMin();
         stopWatch.stop();
-        log.info("TbRoadManager.loadTraf: {}, isLoadTrafByServer[{}], isLoadTraf[{}], {} ms.", this.loadTrafTm, isLoadTrafByServer, isLoadTraf, stopWatch.getTotalTimeMillis());
+        if (isLoadTraf) {
+            log.info("TbRoadManager.loadTraf: {}, isLoadTrafByServer[{}], {} ms.", this.loadTrafTm, isLoadTrafByServer, stopWatch.getTotalTimeMillis());
+        }
     }
     private void findTraf() {
         this.trafList = this.trafRepo.findAll();

+ 16 - 8
src/main/java/com/its/op/security/WebHttpSessionListener.java

@@ -29,23 +29,27 @@ public class WebHttpSessionListener implements HttpSessionListener {
 
     @Override
     public void sessionCreated(HttpSessionEvent httpSessionEvent) {
+        String currSysTime = ItsUtils.getSysTime();
         HttpSession session = httpSessionEvent.getSession();
         SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         if (session != null) {
+            session.setMaxInactiveInterval(WebConstants.MAX_INACTIVE_SESSION_TIMEOUT);
+
             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.info("Session[{}] [{}], Created: [{}, {}] User: {}, {}", session.getId(), currSysTime, creationTime, lastAccessTime, userInfr.getUserId(), userInfr.getOperSystId());
             }
-            log.info("Session Created: {}, {}, {}", creationTime, lastAccessTime, session.getMaxInactiveInterval());
+            log.info("Session[{}] [{}], Created: [{}, {}] User Not Found: {}", session.getId(), currSysTime, creationTime, lastAccessTime, session.getMaxInactiveInterval());
+        } else {
+            log.info("Session[NULL] [{}], Created: Not Found Session.", currSysTime);
         }
-        log.info("Session Created: {}", httpSessionEvent.getSession().getMaxInactiveInterval());
     }
 
     @Override
     public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
+        String currSysTime = ItsUtils.getSysTime();
         HttpSession session = httpSessionEvent.getSession();
         SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         if (session != null) {
@@ -60,16 +64,20 @@ public class WebHttpSessionListener implements HttpSessionListener {
                             .build();
                     this.service.logout(req);
                     userInfr.setLogoutHms(ItsUtils.getSysTime());
-                    log.info("logout history: {}", req);
+                    log.info("Session[{}] [{}], Destroyed: [{}, {}] User: {}, {}, {}, {}, Logout History: {}",
+                            session.getId(), currSysTime, creationTime, lastAccessTime, userInfr.getUserId(), userInfr.getOperSystId(), userInfr.getLoginHms(), userInfr.getLogoutHms(), req);
+                } else {
+                    log.info("Session[{}] [{}], Destroyed: [{}, {}] User: {}, {}, {}, {}, Logout History Already Save.",
+                            session.getId(), currSysTime, creationTime, lastAccessTime, userInfr.getUserId(), userInfr.getOperSystId(), userInfr.getLoginHms(), userInfr.getLogoutHms());
                 }
-                log.info("Session Destroyed: User: {}, {}, {}, {}", userInfr.getUserId(), userInfr.getOperSystId(), userInfr.getLoginHms(), userInfr.getLogoutHms());
             }
             else {
-                log.info("Session Destroyed: {}, {}, {}", creationTime, lastAccessTime, session.getMaxInactiveInterval());
+                log.info("Session[{}] [{}], Destroyed: [{}, {}] User Not Found: {}",
+                        session.getId(), currSysTime, creationTime, lastAccessTime, session.getMaxInactiveInterval());
             }
         }
         else {
-            log.info("Session Destroyed: {}", httpSessionEvent);
+            log.info("Session[NULL] [{}], Destroyed:  Not Found Session.", currSysTime);
         }
     }
 

+ 12 - 2
src/main/java/com/its/op/security/WebLoginSuccessHandler.java

@@ -31,6 +31,7 @@ public class WebLoginSuccessHandler implements AuthenticationSuccessHandler {
     @Override
     public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
 
+        String currSysTime = ItsUtils.getSysTime();
         // IP, 세션 ID
         WebAuthenticationDetails details = (WebAuthenticationDetails)authentication.getDetails();
 
@@ -53,7 +54,7 @@ public class WebLoginSuccessHandler implements AuthenticationSuccessHandler {
                 .logoutHms("")
                 .build();
         this.cnncHsRepo.insertData(cnncHs.getOperSystId(), cnncHs.getLoginHms(), cnncHs.getUserId(), cnncHs.getLogoutHms());
-        log.info("login history: {}, {}", cnncHs, remoteIp);
+        log.info("Login History: {}, {}", cnncHs, remoteIp);
 
         userInfr.setLoginHms(cnncHs.getLoginHms());
         userInfr.setLogoutHms("");
@@ -61,7 +62,16 @@ public class WebLoginSuccessHandler implements AuthenticationSuccessHandler {
         String uri = WebConstants.DEFAULT_URI;
         String domain = "/";
 
-        HttpSession session = request.getSession();
+        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);

+ 11 - 1
src/main/java/com/its/op/security/WebMvcConfig.java

@@ -21,7 +21,17 @@ public class WebMvcConfig implements WebMvcConfigurer {
 
         registry.addInterceptor(new ApiInterceptor())
                 .addPathPatterns("/api/**")                         // API Controller interceptors
-                .excludePathPatterns("/facility/**", "/wall/**", "/dashboard/**", "/api/resource/**", "/api/reload/**", "/api/test/**", "/manual/**")    // 해당 경로는 인터셉터가 가로채지 않는다.
+                .excludePathPatterns(
+                        "/application/facility/**",
+                        "/application/wall/**",
+                        "/application/dashboard/**",
+                        "/facility/**",
+                        "/wall/**",
+                        "/dashboard/**",
+                        "/api/resource/**",
+                        "/api/reload/**",
+                        "/api/test/**",
+                        "/manual/**")    // 해당 경로는 인터셉터가 가로채지 않는다.
                 ;
     }
 

+ 5 - 2
src/main/java/com/its/op/security/WebSecurityConfig.java

@@ -64,7 +64,10 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
         web.ignoring().antMatchers(HttpMethod.PUT, "/api/test/**");  // GET Method 는 모두 통과
         web.ignoring().antMatchers(HttpMethod.DELETE, "/api/test/**");  // GET Method 는 모두 통과
 
-        web.ignoring().antMatchers(HttpMethod.GET, "/manual/**");  // GET Method 는 모두 통과
+        web.ignoring().antMatchers(HttpMethod.GET, "/application/manual/**", "/manual/**");  // GET Method 는 모두 통과
+        web.ignoring().antMatchers(HttpMethod.GET, "/application/wall/**", "/wall/**");  // GET Method 는 모두 통과
+        web.ignoring().antMatchers(HttpMethod.GET, "/application/facility/**", "/facility/**");  // GET Method 는 모두 통과
+        web.ignoring().antMatchers(HttpMethod.GET, "/application/dashboard/**", "/dashboard/**");  // GET Method 는 모두 통과
 
     }
 
@@ -112,7 +115,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
                     .invalidateHttpSession(true)
                     .deleteCookies(WebConstants.JSESSIONID, WebConstants.USER_UUID, WebConstants.USER_TIME);
             http.sessionManagement()
-                    .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED)   // 스프링 시큐리티가 필요 시 생성 (default)
+                    .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED)//NEVER)//IF_REQUIRED)   // 스프링 시큐리티가 필요 시 생성 (default)
                     // 인증에 성공할 때 마다 세션 ID나 세션을 변경해서 발급해줌으로써
                     // 세션을 중간에서 가로채더라도 해당 세션이 유효하지 않게 하는 기능
                     .invalidSessionUrl(loginPage)    // 세션이 유효하지 않을 경우 이동 할 페이지

+ 3 - 3
src/main/java/com/its/op/service/ResourceMonitoringService.java

@@ -130,9 +130,9 @@ public class ResourceMonitoringService {
     }
 
     public String getWebsocketDebug(String flag) {
-        String before = this.itsWebSocketSessionManager.isDebug() ? "before: true" : "before: false";
+        boolean isBefore = this.itsWebSocketSessionManager.isDebug();
         this.itsWebSocketSessionManager.setDebug("1".equals(flag));
-        String after = this.itsWebSocketSessionManager.isDebug() ? "after: true" : "after: false";
-        return before + "\n" + after;
+        boolean isAfter = this.itsWebSocketSessionManager.isDebug();
+        return "{ \"before\": " + isBefore + ",\n\"after\": " + isAfter + "\n}";
     }
 }

+ 3 - 3
src/main/java/com/its/op/websocket/ItsWebSocketSessionManager.java

@@ -78,7 +78,7 @@ public class ItsWebSocketSessionManager {
         this.sessionMap.forEach((key, session) -> {
             session.sendMessage(command, message);
             if (this.isDebug) {
-                log.info("sendBroadcastMessage: {}, to: {}, {}", command, session.getSession().getRemoteAddress(), message);
+                log.info("sendBroadcastMessage: {}, to: {}, {}", command, session.getSession().getRemoteAddress(), message.getPayload());
             }
         });
         return this.sessionMap.size();
@@ -91,7 +91,7 @@ public class ItsWebSocketSessionManager {
                 session.sendMessage(command, message);
                 broadcastCount.getAndIncrement();
                 if (this.isDebug) {
-                    log.info("sendBroadcastSigPhaseMessage: {}, to: {}, {}", command, session.getSession().getRemoteAddress(), message);
+                    log.info("sendBroadcastSigPhaseMessage: {}, to: {}, {}", command, session.getSession().getRemoteAddress(), message.getPayload());
                 }
             }
         });
@@ -105,7 +105,7 @@ public class ItsWebSocketSessionManager {
                 session.sendMessage(command, message);
                 broadcastCount.getAndIncrement();
                 if (this.isDebug) {
-                    log.info("sendBroadcastUserMessage: {}, to: {}, {}", command, session.getSession().getRemoteAddress(), message);
+                    log.info("sendBroadcastUserMessage: {}, to: {}, {}", command, session.getSession().getRemoteAddress(), message.getPayload());
                 }
             }
         });