JWT 저장소 Local Storage -> Cookie 전환

dev_token
kkw29 2 years ago
parent 1bb45ee9b2
commit d878f94a13

@ -11,6 +11,8 @@ import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.stereotype.Component;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import java.security.Key;
import java.util.Arrays;
import java.util.Collection;
@ -21,10 +23,12 @@ import java.util.stream.Collectors;
@Slf4j
@Component
public class TokenProvider {
private final HttpServletResponse httpServletResponse;
private final Key key;
public TokenProvider(@Value("${spring.jwt.secret}") String secretKey) {
public TokenProvider(@Value("${spring.jwt.secret}") String secretKey, HttpServletResponse httpServletResponse) {
this.httpServletResponse = httpServletResponse;
byte[] keyBytes = Decoders.BASE64.decode(secretKey);
this.key = Keys.hmacShaKeyFor(keyBytes);
}
@ -52,11 +56,27 @@ public class TokenProvider {
.signWith(key, SignatureAlgorithm.HS256)
.compact();
return CinnamonToken.builder()
.grantType("Bearer")
.accessToken(accessToken)
.refreshToken(refreshToken)
.build();
CinnamonToken token = CinnamonToken.builder()
.grantType("Bearer")
.accessToken(accessToken)
.refreshToken(refreshToken)
.build();
// create a cookie
Cookie cookie = new Cookie("JWT", token.toString());
// expires in 7 days
cookie.setMaxAge(7 * 24 * 60 * 60);
// optional properties
cookie.setSecure(true);
cookie.setHttpOnly(true);
cookie.setPath("/");
// add cookie to response
httpServletResponse.addCookie(cookie);
return token;
}
// JWT 토큰을 복호화하여 토큰에 들어있는 정보를 꺼내는 메서드

@ -23,6 +23,7 @@ import org.springframework.ui.Model;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
@ -52,8 +53,20 @@ public class MonitoringConsultingController {
private final ExcelService excelService;
private final LogService logService;
private final HttpServletRequest httpServletRequest;
@GetMapping("/consulting/manage.do")
public String ConsultingView(Model model){
Cookie[] cookies = httpServletRequest.getCookies(); // 모든 쿠키 가져오기
if(cookies != null){
for (Cookie c : cookies) {
String name = c.getName(); // 쿠키 이름 가져오기
String value = c.getValue(); // 쿠키 값 가져오기
log.info("###Cookie_Name : " + name);
log.info("###Cookie_Value : " + value);
}
}
return "/adm/rcp/monitoring/consulting";
}

@ -23,9 +23,9 @@
</div>
<header id="header">
<%@ include file="/WEB-INF/jsp/adm/include/header.jsp"%>
<%-- <%@ include file="/WEB-INF/jsp/adm/include/header.jsp"%>--%>
</header>
<c:import url="/adm/menu/getLnbMenu.do" />
<%-- <c:import url="/adm/menu/getLnbMenu.do" />--%>
<script type="text/javascript" src="<c:url value='/aajs/consulting.js' />"></script>

@ -825,41 +825,41 @@ var Consulting = {
}
$(document).ready(function () {
Consulting.init();
$('#oprMngCode').on('change', function() {
Consulting.setSearchData();
});
$('#addBookmarkBtn').on('click', function() {
var param = {
oprMngCode: $('#addOprMngCode').val(),
logType: Consulting.logTypeVal,
token: $('#tokenVal').val(),
talkSeq: Consulting.talkSeqVal,
talkText: $('#bookmarkText').text(),
bookmarkErrCode: $('#bookmarkErr').val()
}
Consulting.addBookmark(param);
});
$('#removeBookmarkBtn').on('click', function() {
var param = {
oprMngCode: $('#removeOprMngCode').val(),
measureType: $('#measureType').val(),
seq: $('#seqVal').val(),
measureInfo: $('#measureInfo').val()
}
Consulting.removeBookmark(param);
});
let telNo = document.getElementById('telNo');
telNo.addEventListener('keyup', event => Consulting.fncInputEnterKey(event));
let dnisNo = document.getElementById('dnisNo');
dnisNo.addEventListener('keyup', event => Consulting.fncInputEnterKey(event));
// Consulting.init();
//
// $('#oprMngCode').on('change', function() {
// Consulting.setSearchData();
// });
//
// $('#addBookmarkBtn').on('click', function() {
// var param = {
// oprMngCode: $('#addOprMngCode').val(),
// logType: Consulting.logTypeVal,
// token: $('#tokenVal').val(),
// talkSeq: Consulting.talkSeqVal,
// talkText: $('#bookmarkText').text(),
// bookmarkErrCode: $('#bookmarkErr').val()
// }
//
// Consulting.addBookmark(param);
// });
//
// $('#removeBookmarkBtn').on('click', function() {
// var param = {
// oprMngCode: $('#removeOprMngCode').val(),
// measureType: $('#measureType').val(),
// seq: $('#seqVal').val(),
// measureInfo: $('#measureInfo').val()
// }
//
// Consulting.removeBookmark(param);
// });
//
// let telNo = document.getElementById('telNo');
// telNo.addEventListener('keyup', event => Consulting.fncInputEnterKey(event));
//
// let dnisNo = document.getElementById('dnisNo');
// dnisNo.addEventListener('keyup', event => Consulting.fncInputEnterKey(event));
});
$(document).on("click", ".addedIco", function() {

Loading…
Cancel
Save