중간백업
This commit is contained in:
parent
0078c89323
commit
7bb1898ba4
@ -1,5 +1,11 @@
|
|||||||
package nlib.cmm;
|
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
@ -16,17 +22,56 @@ import nlib.restful.service.DataApiResVO;
|
|||||||
import nlib.security.SecUserVO;
|
import nlib.security.SecUserVO;
|
||||||
import nlib.user.service.NlibLoginVO;
|
import nlib.user.service.NlibLoginVO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* @Class Name : NlibCommonController.java
|
||||||
|
*
|
||||||
|
* @Description : 컨트롤러의 공통적인 기능을 제공하는 컨트롤러 상위 클래스
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @ ------------ -------- ---------------------------
|
||||||
|
* @ 수정일 수정자 수정내용
|
||||||
|
* @ ------------ -------- ---------------------------
|
||||||
|
* @ 2021. 7. 23. KNKIM 최초 생성
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author 이씨플라자 * DIGITALSHIP KNKIM
|
||||||
|
* @since 2021. 7. 23.
|
||||||
|
* @version 1.0
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class NlibCommonController {
|
public class NlibCommonController {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(BoardController.class);
|
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) {
|
public NlibLoginVO getNlibLoginVO(Authentication authentication) {
|
||||||
if(authentication == null) return null;
|
if(authentication == null) return null;
|
||||||
|
|
||||||
return (NlibLoginVO)authentication.getPrincipal();
|
return (NlibLoginVO)authentication.getPrincipal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 스프링 시큐리티 Authentication를 통해서 사용자로그인정보 SecUserVO를 리턴한다.
|
||||||
|
*
|
||||||
|
* @param authentication
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public SecUserVO getSecLoginVO(Authentication authentication) {
|
public SecUserVO getSecLoginVO(Authentication authentication) {
|
||||||
|
|
||||||
if(authentication == null) return null;
|
if(authentication == null) return null;
|
||||||
@ -34,10 +79,33 @@ public class NlibCommonController {
|
|||||||
return (SecUserVO)authentication.getPrincipal();
|
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<String> makeResponseEntityJson(DataApiResVO resVO) {
|
public ResponseEntity<String> makeResponseEntityJson(DataApiResVO resVO) {
|
||||||
@ -61,4 +129,27 @@ public class NlibCommonController {
|
|||||||
|
|
||||||
return ResponseEntity.ok().headers(headers).body(jsonStr);
|
return ResponseEntity.ok().headers(headers).body(jsonStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ResponseEntity<String> makeResponseEntityJson(List<HashMap<String,String>> list) {
|
||||||
|
|
||||||
|
// Convert Json
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
String jsonStr = null;
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.add(HttpHeaders.CONTENT_TYPE, "application/json; charset=UTF-8");
|
||||||
|
|
||||||
|
try {
|
||||||
|
jsonStr = mapper.writeValueAsString(list);
|
||||||
|
log.debug("RETURN DATA > json:" + jsonStr);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
ErrorMessage eMsg = new ErrorMessage("ERR_JSON_CONVERT", "응답객체를 JSON으로 변환 처리 중 오류가 발생하였습니다. : " + e.toString());
|
||||||
|
try { jsonStr = mapper.writeValueAsString(eMsg); } catch (JsonProcessingException ee) {}
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).headers(headers).body(jsonStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResponseEntity.ok().headers(headers).body(jsonStr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user