Ajax 스프링 시큐리티 권한 처리 개선
This commit is contained in:
parent
d02f8c9066
commit
c7e3a6809d
@ -11,6 +11,7 @@ import javax.servlet.http.HttpSession;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.security.access.annotation.Secured;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
@ -106,11 +107,13 @@ public class NotificationController extends NlibCommonController {
|
|||||||
* @param req
|
* @param req
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@Secured("ROLE_USER")
|
||||||
@RequestMapping(value="/cmm/listNotificationsAjax.do")
|
@RequestMapping(value="/cmm/listNotificationsAjax.do")
|
||||||
public ResponseEntity<String> listNotificationsAjax(HttpServletRequest req,
|
public ResponseEntity<String> listNotificationsAjax(HttpServletRequest req,
|
||||||
Authentication authentication, @RequestBody Map<String, String> paramMap) throws Exception {
|
Authentication authentication, @RequestBody(required = false) Map<String, String> paramMap) throws Exception {
|
||||||
|
|
||||||
String mbInfoId = getMbInfoId(req);
|
String mbInfoId = getMbInfoId(req);
|
||||||
|
if(paramMap == null) paramMap = new HashMap<String, String>();
|
||||||
int pageIndex = StringUtil.toNumber(paramMap.get("pageIndex"), 1);
|
int pageIndex = StringUtil.toNumber(paramMap.get("pageIndex"), 1);
|
||||||
int pageSize = StringUtil.toNumber(paramMap.get("pageSize"), DEFUALT_PAGE_SIZE);
|
int pageSize = StringUtil.toNumber(paramMap.get("pageSize"), DEFUALT_PAGE_SIZE);
|
||||||
|
|
||||||
|
|||||||
38
src/main/java/nlib/security/CustomRequestCache.java
Normal file
38
src/main/java/nlib/security/CustomRequestCache.java
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package nlib.security;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.springframework.security.web.savedrequest.HttpSessionRequestCache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* @Class Name : CustomRequestCache.java
|
||||||
|
*
|
||||||
|
* @Description : 스프링 시큐리티에 권한 실패시 HttpSessionRequestCache에 저장되는 정보 커스터마이징
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @ ------------ -------- ---------------------------
|
||||||
|
* @ 수정일 수정자 수정내용
|
||||||
|
* @ ------------ -------- ---------------------------
|
||||||
|
* @ 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -70,6 +70,7 @@ public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
protected void configure(HttpSecurity http) throws Exception {
|
protected void configure(HttpSecurity http) throws Exception {
|
||||||
http.authorizeRequests()
|
http.authorizeRequests()
|
||||||
.antMatchers("/**").permitAll()
|
.antMatchers("/**").permitAll()
|
||||||
|
.and().requestCache().requestCache(new CustomRequestCache())
|
||||||
.and().formLogin()
|
.and().formLogin()
|
||||||
.loginPage(NlibProperty.getString("login.url") + "?login=req")
|
.loginPage(NlibProperty.getString("login.url") + "?login=req")
|
||||||
.permitAll()
|
.permitAll()
|
||||||
|
|||||||
@ -12,6 +12,9 @@ import javax.servlet.http.HttpSession;
|
|||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
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.HttpSessionRequestCache;
|
||||||
import org.springframework.security.web.savedrequest.RequestCache;
|
import org.springframework.security.web.savedrequest.RequestCache;
|
||||||
import org.springframework.security.web.savedrequest.SavedRequest;
|
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.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
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.OAuthConfig;
|
||||||
import egovframework.com.ext.oauth.service.OAuthLogin;
|
import egovframework.com.ext.oauth.service.OAuthLogin;
|
||||||
import egovframework.com.ext.oauth.service.OAuthUniversalUser;
|
import egovframework.com.ext.oauth.service.OAuthUniversalUser;
|
||||||
@ -113,7 +118,11 @@ public class LoginController extends NlibCommonController {
|
|||||||
RequestCache cache = new HttpSessionRequestCache();
|
RequestCache cache = new HttpSessionRequestCache();
|
||||||
SavedRequest savedRequest = cache.getRequest(req, res);
|
SavedRequest savedRequest = cache.getRequest(req, res);
|
||||||
if (savedRequest != null) {
|
if (savedRequest != null) {
|
||||||
|
if(savedRequest.getRedirectUrl().contains("Ajax.do")) {
|
||||||
|
cache.removeRequest(req, res);
|
||||||
|
} else {
|
||||||
councilReturnUrl = savedRequest.getRedirectUrl();
|
councilReturnUrl = savedRequest.getRedirectUrl();
|
||||||
|
}
|
||||||
log.debug("setCouncilInfo > HttpSessionRequestCache에서 획득 councilReturnUrl = " + councilReturnUrl);
|
log.debug("setCouncilInfo > HttpSessionRequestCache에서 획득 councilReturnUrl = " + councilReturnUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,6 +219,23 @@ public class LoginController extends NlibCommonController {
|
|||||||
return "redirect:" + redirect;
|
return "redirect:" + redirect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajax 요청에 대한 권한 부재시 오류 처리
|
||||||
|
*
|
||||||
|
* @param req
|
||||||
|
* @param res
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@RequestMapping(value= {"/login/responseDeniedAuth.do"})
|
||||||
|
public ResponseEntity<String> 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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 로그인 정보 입력 화면을 출력한다.
|
* 로그인 정보 입력 화면을 출력한다.
|
||||||
*
|
*
|
||||||
@ -234,6 +260,16 @@ public class LoginController extends NlibCommonController {
|
|||||||
|
|
||||||
String reqPath = req.getServletPath();
|
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
|
// callType
|
||||||
if(StringUtil.isEmpty(callType)) {
|
if(StringUtil.isEmpty(callType)) {
|
||||||
if(reqPath.startsWith("/login/member")) callType = OAuthLogin.CALL_TYPE_MEMBER;
|
if(reqPath.startsWith("/login/member")) callType = OAuthLogin.CALL_TYPE_MEMBER;
|
||||||
|
|||||||
@ -167,8 +167,8 @@ $( document ).ready(function() {
|
|||||||
|
|
||||||
pageLoad("fn_searchArticle", jsonObj.pagingPageIndex, jsonObj.pagingTotRecordCount, jsonObj.pagingStartPage, jsonObj.pagingEndPage, jsonObj.pagingLastPage);
|
pageLoad("fn_searchArticle", jsonObj.pagingPageIndex, jsonObj.pagingTotRecordCount, jsonObj.pagingStartPage, jsonObj.pagingEndPage, jsonObj.pagingLastPage);
|
||||||
|
|
||||||
}).fail(function (jqXHR, textStatus, errorThrown) {
|
}).fail(function (request, textStatus, errorThrown) {
|
||||||
alert("조회에 실패하였습니다. 관리자에게 문의 바랍니다.");
|
alert("조회에 실패하였습니다. \n" + gfn_removeQuotes(request.responseText));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,6 +196,7 @@ $( document ).ready(function() {
|
|||||||
<span class="count">총 <em name="itemsCount" id="itemsCount">0</em>건</span>
|
<span class="count">총 <em name="itemsCount" id="itemsCount">0</em>건</span>
|
||||||
<div class="text">
|
<div class="text">
|
||||||
<p>- 최근 한달동안 발송된 알림 내역만 보관됩니다.</p>
|
<p>- 최근 한달동안 발송된 알림 내역만 보관됩니다.</p>
|
||||||
|
<button type="button" name="btnSearch" id="btnSearch">새로고침</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user