diff --git a/src/main/java/nlib/cmm/NlibCommonController.java b/src/main/java/nlib/cmm/NlibCommonController.java index 55b5c029..0ec01804 100644 --- a/src/main/java/nlib/cmm/NlibCommonController.java +++ b/src/main/java/nlib/cmm/NlibCommonController.java @@ -1,5 +1,11 @@ package nlib.cmm; +import java.util.Base64; +import java.util.HashMap; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpHeaders; @@ -16,17 +22,56 @@ import nlib.restful.service.DataApiResVO; import nlib.security.SecUserVO; import nlib.user.service.NlibLoginVO; +/** + *
+ * @Class Name : NlibCommonController.java + * + * @Description : 컨트롤러의 공통적인 기능을 제공하는 컨트롤러 상위 클래스 + * + * + * @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021) + * + *+ * + * @ ------------ -------- --------------------------- + * @ 수정일 수정자 수정내용 + * @ ------------ -------- --------------------------- + * @ 2021. 7. 23. KNKIM 최초 생성 + * + * + * @author 이씨플라자 * DIGITALSHIP KNKIM + * @since 2021. 7. 23. + * @version 1.0 + * + */ public class NlibCommonController { private static final Logger log = LoggerFactory.getLogger(BoardController.class); - static final String ANONYMOUS_AUTH_KEY = "ANONYMOUS_AUTH_KEY_NONE"; + + + /** + * AuthKey 생성 시, 로그인하지 않은 사용자의 AuthKey 생성시 사용되는 접두어 + */ + static final String ANONYMOUS_AUTH_KEY_PREFIX = "GST-"; + /** + * 스프링 시큐리티 Authentication를 통해서 사용자로그인정보 NlibLoginVO를 리턴한다. + * + * @param authentication + * @return + */ public NlibLoginVO getNlibLoginVO(Authentication authentication) { if(authentication == null) return null; return (NlibLoginVO)authentication.getPrincipal(); } + /** + * 스프링 시큐리티 Authentication를 통해서 사용자로그인정보 SecUserVO를 리턴한다. + * + * @param authentication + * @return + */ public SecUserVO getSecLoginVO(Authentication authentication) { if(authentication == null) return null; @@ -34,10 +79,33 @@ public class NlibCommonController { return (SecUserVO)authentication.getPrincipal(); } - public String getAuthKey(Authentication authentication) { - if(authentication == null) return ANONYMOUS_AUTH_KEY; + /** + * 통합자료시스템 요청 시, 제공할 사용자정보 auth key 생성 + * - 로그인 한 경우 : 사용자ID를 BASE64로 인코딩한 값 + * - 로그인하지 않은 경우 : GST-세션ID + * + * @param request + * @param authentication + * @return + */ + public String createAuthKey(HttpServletRequest request, Authentication authentication) { - return ((NlibLoginVO)authentication.getPrincipal()).getAuthKey(); + String userId = null; + String authKey = null; + + if(authentication != null) { + userId = ((NlibLoginVO)authentication.getPrincipal()).getId(); + } + + if(nlib.util.StringUtil.isEmpty(userId)) { + authKey = ANONYMOUS_AUTH_KEY_PREFIX + request.getSession().getId(); + } else { + authKey = Base64.getEncoder().encodeToString(userId.getBytes()); + } + + log.debug("createAuthKey > " + authKey); + + return authKey; } public ResponseEntity