jhleem / egov star

임종호 임종호 2022-02-15 @47

세션 타임아웃
Index: base3.10/src/main/java/egovframework/com/cmm/interceptor/AuthenticInterceptor.java =================================================================== --- base3.10/src/main/java/egovframework/com/cmm/interceptor/AuthenticInterceptor.java (revision 46) +++ base3.10/src/main/java/egovframework/com/cmm/interceptor/AuthenticInterceptor.java (revision 47) @@ -134,11 +134,12 @@ int authoCheck = menuService.selectAuthoUrlCheck(checkMenuVO); if( authoCheck == 0 && Boolean.FALSE.equals(EgovUserDetailsHelper.isRoleAdmin())) { ModelAndView modelAndView = new ModelAndView(); + int sessionTimeout = request.getSession().getMaxInactiveInterval() / 60; if (isAjax) { MappingJackson2JsonView view = new MappingJackson2JsonView(); AjaxWrapper aw = new AjaxWrapper(AjaxWrapper.FAIL); if (loginVO == null) { - aw.setResult("장기간(60분) 동안 미사용으로 로그아웃 되었습니다."); + aw.setResult("장기간(" + sessionTimeout + "분) 동안 미사용으로 로그아웃 되었습니다."); } else { aw.setResult("권한이 없습니다."); } @@ -153,7 +154,7 @@ // if ("A".equals(menuVO.getMenuGb())) { // returnUrl = contextPath + "/admin/index.do"; // } - view.addStaticAttribute("message", "장기간(30분) 동안 미사용으로 로그아웃 되었습니다."); + view.addStaticAttribute("message", "장기간(" + sessionTimeout + "분) 동안 미사용으로 로그아웃 되었습니다."); view.addStaticAttribute("returnUrl", returnUrl); } else { view.addStaticAttribute("message", "권한이 없습니다."); Index: base3.10/src/main/webapp/WEB-INF/tiles/layouts/defaultLayout.jsp =================================================================== --- base3.10/src/main/webapp/WEB-INF/tiles/layouts/defaultLayout.jsp (revision 46) +++ base3.10/src/main/webapp/WEB-INF/tiles/layouts/defaultLayout.jsp (revision 47) @@ -1,7 +1,6 @@ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%> -<c:set value="${sessionScope.FUNCTION_AUTHO}" var="functionAutho" /> <c:set value="${sessionScope.systemVO}" var="systemVO" /> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko" id="fouc"> Index: base3.10/src/main/webapp/WEB-INF/tiles/template/adminHeader.jsp =================================================================== --- base3.10/src/main/webapp/WEB-INF/tiles/template/adminHeader.jsp (revision 46) +++ base3.10/src/main/webapp/WEB-INF/tiles/template/adminHeader.jsp (revision 47) @@ -37,7 +37,7 @@ <link rel="stylesheet" href="<c:url value='/resource/jquery-ui-1.12.1/jquery-ui.min.css'/>"> <!-- 쿠키JS --> -<script type="text/javascript" src="<c:url value='/js/com/jquery.cookie.js'><c:param name="dt" value="${nowDate}"/></c:url>"></script> +<script type="text/javascript" src="<c:url value='/js/com/cookie.js'><c:param name="dt" value="${nowDate}"/></c:url>"></script> <script type="text/javascript"> $(document).ready(function() { Index: base3.10/src/main/webapp/WEB-INF/tiles/template/defaultFooter.jsp =================================================================== --- base3.10/src/main/webapp/WEB-INF/tiles/template/defaultFooter.jsp (revision 46) +++ base3.10/src/main/webapp/WEB-INF/tiles/template/defaultFooter.jsp (revision 47) @@ -53,12 +53,12 @@ <script type="text/javascript" src="<c:url value='/js/user/aos.js'><c:param name="dt" value="${nowDate}"/></c:url>"></script> <script src="<c:url value='/js/user/designJS.js'><c:param name="dt" value="${nowDate}"/></c:url>"></script> <script> -$(function() { + $(function() { AOS.init({ easing: 'ease-out-back', duration: 1000 }); //slide up animation -}) + }) // 사용자 권한가져오기 function fncGetAuthorCode() { Index: base3.10/src/main/webapp/WEB-INF/tiles/template/adminMenu.jsp =================================================================== --- base3.10/src/main/webapp/WEB-INF/tiles/template/adminMenu.jsp (revision 46) +++ base3.10/src/main/webapp/WEB-INF/tiles/template/adminMenu.jsp (revision 47) @@ -74,7 +74,7 @@ <c:when test="${loginVO != null}"> <li><span><b>${loginVO.name }</b></span> 님 환영합니다.</li> <li><spring:message code="comCmm.top.leftSessionTime"/> - <span id="leftTimeInfo">00:00:00</span><!-- 세션만료 남은시간 --></li> - <li><a id="clickInfo" class="btn02" href="#"><spring:message code="comCmm.top.incSessionTime"/></a><!-- 시간연장 --></li> + <li><a id="addSessionTerm" class="btn02" href="#"><spring:message code="comCmm.top.incSessionTime"/></a><!-- 시간연장 --></li> <li class="icon_home"><a href="<c:url value="/index.do"/>">home</a></li> <li class="icon_logout"><a href="<c:url value="/uat/uia/actionLogout.do"/>">logout</a></li> </c:when> @@ -152,23 +152,8 @@ </div> <script> +//세션만료 남은 시간 $(function() { -// function getCookie(cname) { -// var name = cname + "="; -// var decodedCookie = decodeURIComponent(document.cookie); -// var ca = decodedCookie.split(';'); -// for(var i = 0; i <ca.length; i++) { -// var c = ca[i]; -// while (c.charAt(0) == ' ') { -// c = c.substring(1); -// } -// if (c.indexOf(name) == 0) { -// return c.substring(name.length, c.length); -// } -// } -// return ""; -// } - function pad(n, width) { n = n + ''; return n.length >= width ? n : new Array(width - n.length + 1).join('0') + n; @@ -193,12 +178,9 @@ return; } objClickInfo = document.getElementById("clickInfo"); - //console.log(objLeftTime.textContent); latestTime = getCookie("egovLatestServerTime"); expireTime = getCookie("egovExpireSessionTime"); - //console.log("latestServerTime = "+latestTime); - //console.log("expireSessionTime = "+expireTime); elapsedTime = 0; firstLocalTime = (new Date()).getTime(); @@ -217,21 +199,15 @@ objClickInfo.text = '<spring:message code="comCmm.top.expiredSessionTime"/>'; //시간만료 stateExpiredTime = true; alert('<spring:message code="comCmm.top.expireSessionTimeInfo"/>');//로그인 세션시간이 만료 되었습니다. - // reload content main page -// $("#sessionInfo").hide(); location.href = logoutUrl; - //parent.frames["_content"].location.reload(); return; } var timeHour = Math.floor(timeRemaining/1000/60 / 60); var timeMin = Math.floor((timeRemaining/1000/60) % 60); var timeSec = Math.floor((timeRemaining/1000) % 60); - //objLeftTime.textContent = pad(timeHour,2) +":"+ pad(timeMin,2) +":"+ pad(timeSec,2); - //objLeftTime.outerText = pad(timeHour,2) +":"+ pad(timeMin,2) +":"+ pad(timeSec,2); objLeftTime.innerHTML = pad(timeHour,2) +":"+ pad(timeMin,2) +":"+ pad(timeSec,2); - //console.log("call showRemaining() = "+objLeftTime.innerHTML); } function reqTimeAjax() { @@ -249,22 +225,17 @@ //서버로부터 정상적으로 응답이 왔을 때 실행 latestTime = getCookie("egovLatestServerTime"); expireTime = getCookie("egovExpireSessionTime"); - //console.log("latestServerTime = "+latestTime); - //console.log("expireSessionTime = "+expireTime); init(); - //alert("정상수신 , data = "+data); }, error: function(err) { alert("err : "+err); - //서버로부터 응답이 정상적으로 처리되지 못햇을 때 실행 - //alert("오류발생 , error="+err.state()); } }); return false; } // 시간연장 이벤트 - $('#clickInfo').on('click', reqTimeAjax); + $('#addSessionTerm').on('click', reqTimeAjax); // 세션만료 초기화 init(); Index: base3.10/src/main/webapp/WEB-INF/tiles/template/defaultHeader.jsp =================================================================== --- base3.10/src/main/webapp/WEB-INF/tiles/template/defaultHeader.jsp (revision 46) +++ base3.10/src/main/webapp/WEB-INF/tiles/template/defaultHeader.jsp (revision 47) @@ -3,7 +3,6 @@ <%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <script type="text/javascript"> - //sessionStorage.setItem("contextpath", "${pageContext.request.contextPath}"); const CONTEXT_PATH = "${pageContext.request.contextPath}"; </script> @@ -52,7 +51,7 @@ <script type="text/javascript" src="<c:url value='/js/com/jquery.blockUI.js'><c:param name="dt" value="${nowDate}"/></c:url>" ></script> <!-- 쿠키JS --> -<script type="text/javascript" src="<c:url value='/js/com/jquery.cookie.js'><c:param name="dt" value="${nowDate}"/></c:url>"></script> +<script type="text/javascript" src="<c:url value='/js/com/cookie.js'><c:param name="dt" value="${nowDate}"/></c:url>"></script> <!-- 공통JS --> <script type="text/javascript" src="<c:url value='/js/com/common.js' ><c:param name="dt" value="${nowDate}"/></c:url>"></script> Index: base3.10/src/main/webapp/WEB-INF/tiles/template/defaultTopMenu.jsp =================================================================== --- base3.10/src/main/webapp/WEB-INF/tiles/template/defaultTopMenu.jsp (revision 46) +++ base3.10/src/main/webapp/WEB-INF/tiles/template/defaultTopMenu.jsp (revision 47) @@ -3,6 +3,7 @@ <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> <header class="header"> <div class="skip"> <a href="#contents" onclick="$('#contents').attr('tabindex', '-1').focus(); return false;">본문 바로가기</a> <a href="#gnb_wrap" onclick="$('#gnb_wrap').attr('tabindex', '-1').focus(); return false;">메뉴바로가기</a> </div> <div class="inner"> @@ -16,7 +17,11 @@ <ul class="header_right"> <c:choose> <c:when test="${loginVO != null}"> - <li><a href="javascript:void(0);">${loginVO.name } 님 환영합니다.</a></li> + <li> + <a href="javascript:void(0);">${loginVO.name } 님 환영합니다.</a> + <a href="javascsript:void(0)"><spring:message code="comCmm.top.leftSessionTime"/> - <span id="leftTimeInfo">00:00:00</span><!-- 세션만료 남은시간 --></a> + <a href="javascript:void(0);" id="addSessionTerm"><spring:message code="comCmm.top.incSessionTime"/><!-- 시간연장 --></a> + </li> <li><a href="<c:url value='/admin/index.do'/>" target="_blank" title="관리자 페이지 [새창열림]">admin</a></li> </c:when> <c:otherwise> @@ -32,4 +37,94 @@ <button type="button" class="total_search" title="통합검색" aria-haspopup="dialog" data-popup="search"><span class="icon-search"></span><em class="blind">통합검색</em></button> </div> </div> -</header> \ No newline at end of file +</header> +<script> +//세션만료 남은 시간 +$(function() { + function pad(n, width) { + n = n + ''; + return n.length >= width ? n : new Array(width - n.length + 1).join('0') + n; + } + + var objLeftTime; + var objClickInfo; + var latestTime; + var expireTime; + var timeInterval = 1000; // 1초 간격 호출 + var firstLocalTime = 0; + var elapsedLocalTime = 0; + var stateExpiredTime = false; + var logoutUrl = "<c:url value='/uat/uia/actionLogout.do'/>"; + var timer; + + function init() { + objLeftTime = document.getElementById("leftTimeInfo"); + + if (objLeftTime == null) { + console.log("'leftTimeInfo' ID is not exist!"); + return; + } + objClickInfo = document.getElementById("clickInfo"); + + latestTime = getCookie("egovLatestServerTime"); + expireTime = getCookie("egovExpireSessionTime"); + + elapsedTime = 0; + firstLocalTime = (new Date()).getTime(); + showRemaining(); + + timer = setInterval(showRemaining, timeInterval); // 1초 간격 호출 + } + + function showRemaining() { + elapsedLocalTime = (new Date()).getTime() - firstLocalTime; + + var timeRemaining = expireTime - latestTime - elapsedLocalTime; + if ( timeRemaining < timeInterval ) { + clearInterval(timer); + objLeftTime.innerHTML = "00:00:00"; + objClickInfo.text = '<spring:message code="comCmm.top.expiredSessionTime"/>'; //시간만료 + stateExpiredTime = true; + alert('<spring:message code="comCmm.top.expireSessionTimeInfo"/>');//로그인 세션시간이 만료 되었습니다. + + location.href = logoutUrl; + + return; + } + var timeHour = Math.floor(timeRemaining/1000/60 / 60); + var timeMin = Math.floor((timeRemaining/1000/60) % 60); + var timeSec = Math.floor((timeRemaining/1000) % 60); + objLeftTime.innerHTML = pad(timeHour,2) +":"+ pad(timeMin,2) +":"+ pad(timeSec,2); + } + + function reqTimeAjax() { + + if (stateExpiredTime==true) { + alert('<spring:message code="comCmm.top.cantIncSessionTime"/>');//시간을 연장할수 없습니다. + return; + } + + $.ajax({ + url:'${pageContext.request.contextPath}/uat/uia/refreshSessionTimeout.do', //request 보낼 서버의 경로 + type:'get', // 메소드(get, post, put 등) + data:{}, //보낼 데이터 + success: function(data) { + //서버로부터 정상적으로 응답이 왔을 때 실행 + latestTime = getCookie("egovLatestServerTime"); + expireTime = getCookie("egovExpireSessionTime"); + init(); + }, + error: function(err) { + alert("err : "+err); + } + }); + return false; + } + + // 시간연장 이벤트 + $('#addSessionTerm').on('click', reqTimeAjax); + + // 세션만료 초기화 + init(); +}); +</script> \ No newline at end of file Index: base3.10/src/main/webapp/js/com/cookie.js =================================================================== --- base3.10/src/main/webapp/js/com/cookie.js (revision 46) +++ base3.10/src/main/webapp/js/com/cookie.js (revision 47) @@ -42,4 +42,4 @@ var todayDate = new Date(); todayDate.setDate(todayDate.getDate() + expiredays); document.cookie = name + '=' + escape(value) + '; path=/; expires=' + todayDate.toGMTString() + ';'; -} +} \ No newline at end of file
Add a comment
List