diff --git a/src/main/java/nlib/cmm/web/NotificationController.java b/src/main/java/nlib/cmm/web/NotificationController.java index 6b638b74..c3d691b7 100644 --- a/src/main/java/nlib/cmm/web/NotificationController.java +++ b/src/main/java/nlib/cmm/web/NotificationController.java @@ -11,6 +11,7 @@ import javax.servlet.http.HttpSession; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.ResponseEntity; +import org.springframework.security.access.annotation.Secured; import org.springframework.security.core.Authentication; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -106,11 +107,13 @@ public class NotificationController extends NlibCommonController { * @param req * @return */ + @Secured("ROLE_USER") @RequestMapping(value="/cmm/listNotificationsAjax.do") public ResponseEntity listNotificationsAjax(HttpServletRequest req, - Authentication authentication, @RequestBody Map paramMap) throws Exception { + Authentication authentication, @RequestBody(required = false) Map paramMap) throws Exception { String mbInfoId = getMbInfoId(req); + if(paramMap == null) paramMap = new HashMap(); int pageIndex = StringUtil.toNumber(paramMap.get("pageIndex"), 1); int pageSize = StringUtil.toNumber(paramMap.get("pageSize"), DEFUALT_PAGE_SIZE); diff --git a/src/main/java/nlib/security/CustomRequestCache.java b/src/main/java/nlib/security/CustomRequestCache.java new file mode 100644 index 00000000..64ec938f --- /dev/null +++ b/src/main/java/nlib/security/CustomRequestCache.java @@ -0,0 +1,38 @@ +package nlib.security; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.security.web.savedrequest.HttpSessionRequestCache; + +/** + *
+ * @Class Name : CustomRequestCache.java
+ * 
+ * @Description : 스프링 시큐리티에 권한 실패시 HttpSessionRequestCache에 저장되는 정보 커스터마이징 
+ * 
+ * 
+ * @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
+ *
+ * 
+ * + * @ ------------ -------- --------------------------- + * @ 수정일 수정자 수정내용 + * @ ------------ -------- --------------------------- + * @ 2021. 11. 16. KNKIM 최초 생성 + * + * + * @author 이씨플라자 * DIGITALSHIP KNKIM + * @since 2021. 11. 16. + * @version 1.0 + * + */ +public class CustomRequestCache extends HttpSessionRequestCache { + + @Override + public void saveRequest(HttpServletRequest request, HttpServletResponse response) { + + // Ajax Reqeust 들도 캐쉬되도록 처리함 + super.saveRequest(request, response); + } +} \ No newline at end of file diff --git a/src/main/java/nlib/security/SpringSecurityConfig.java b/src/main/java/nlib/security/SpringSecurityConfig.java index 50cfa776..d0d89782 100644 --- a/src/main/java/nlib/security/SpringSecurityConfig.java +++ b/src/main/java/nlib/security/SpringSecurityConfig.java @@ -70,6 +70,7 @@ public class SpringSecurityConfig extends WebSecurityConfigurerAdapter { protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/**").permitAll() + .and().requestCache().requestCache(new CustomRequestCache()) .and().formLogin() .loginPage(NlibProperty.getString("login.url") + "?login=req") .permitAll() diff --git a/src/main/java/nlib/user/web/LoginController.java b/src/main/java/nlib/user/web/LoginController.java index 4e70544e..6656e0f5 100644 --- a/src/main/java/nlib/user/web/LoginController.java +++ b/src/main/java/nlib/user/web/LoginController.java @@ -12,6 +12,9 @@ import javax.servlet.http.HttpSession; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.security.web.savedrequest.HttpSessionRequestCache; import org.springframework.security.web.savedrequest.RequestCache; import org.springframework.security.web.savedrequest.SavedRequest; @@ -23,6 +26,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.mvc.support.RedirectAttributes; +import com.fasterxml.jackson.databind.ObjectMapper; + import egovframework.com.ext.oauth.service.OAuthConfig; import egovframework.com.ext.oauth.service.OAuthLogin; import egovframework.com.ext.oauth.service.OAuthUniversalUser; @@ -113,7 +118,11 @@ public class LoginController extends NlibCommonController { RequestCache cache = new HttpSessionRequestCache(); SavedRequest savedRequest = cache.getRequest(req, res); if (savedRequest != null) { - councilReturnUrl = savedRequest.getRedirectUrl(); + if(savedRequest.getRedirectUrl().contains("Ajax.do")) { + cache.removeRequest(req, res); + } else { + councilReturnUrl = savedRequest.getRedirectUrl(); + } log.debug("setCouncilInfo > HttpSessionRequestCache에서 획득 councilReturnUrl = " + councilReturnUrl); } @@ -210,6 +219,23 @@ public class LoginController extends NlibCommonController { return "redirect:" + redirect; } + /** + * Ajax 요청에 대한 권한 부재시 오류 처리 + * + * @param req + * @param res + * @return + * @throws Exception + */ + @RequestMapping(value= {"/login/responseDeniedAuth.do"}) + public ResponseEntity responseDeniedAuth(HttpServletRequest req, HttpServletResponse res) throws Exception { + HttpHeaders headers = new HttpHeaders(); + headers.add(HttpHeaders.CONTENT_TYPE, "application/json; charset=UTF-8"); + String errorStr = "로그인 후, 이용해 주시기 바랍니다."; + log.debug("responseDeniedAuth > errorStr=" + errorStr); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).headers(headers).body(errorStr); + } + /** * 로그인 정보 입력 화면을 출력한다. * @@ -233,6 +259,16 @@ public class LoginController extends NlibCommonController { Model model) throws Exception { String reqPath = req.getServletPath(); + + // Ajax 호출이면서 인증 오류에 따른 요청인 경우, Ajax용 RES 생성 함수로 전환 + if("req".equals(login)) { + RequestCache cache = new HttpSessionRequestCache(); + SavedRequest savedRequest = cache.getRequest(req, res); + if (savedRequest != null && savedRequest.getRedirectUrl().contains("Ajax.do")) { + cache.removeRequest(req, res); + return "redirect:/login/responseDeniedAuth.do"; + } + } // callType if(StringUtil.isEmpty(callType)) { diff --git a/src/main/webapp/WEB-INF/jsp/nlib/cmm/listNotifications.jsp b/src/main/webapp/WEB-INF/jsp/nlib/cmm/listNotifications.jsp index 4f92a559..bb8d782f 100644 --- a/src/main/webapp/WEB-INF/jsp/nlib/cmm/listNotifications.jsp +++ b/src/main/webapp/WEB-INF/jsp/nlib/cmm/listNotifications.jsp @@ -167,8 +167,8 @@ $( document ).ready(function() { pageLoad("fn_searchArticle", jsonObj.pagingPageIndex, jsonObj.pagingTotRecordCount, jsonObj.pagingStartPage, jsonObj.pagingEndPage, jsonObj.pagingLastPage); - }).fail(function (jqXHR, textStatus, errorThrown) { - alert("조회에 실패하였습니다. 관리자에게 문의 바랍니다."); + }).fail(function (request, textStatus, errorThrown) { + alert("조회에 실패하였습니다. \n" + gfn_removeQuotes(request.responseText)); }); } @@ -196,6 +196,7 @@ $( document ).ready(function() { 0

- 최근 한달동안 발송된 알림 내역만 보관됩니다.

+