JWT 저장소 Local Storage -> Cookie 전환

dev_token
kkw29 1 year 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.security.core.authority.SimpleGrantedAuthority;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import java.security.Key; import java.security.Key;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -21,10 +23,12 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
@Component @Component
public class TokenProvider { public class TokenProvider {
private final HttpServletResponse httpServletResponse;
private final Key key; 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); byte[] keyBytes = Decoders.BASE64.decode(secretKey);
this.key = Keys.hmacShaKeyFor(keyBytes); this.key = Keys.hmacShaKeyFor(keyBytes);
} }
@ -52,11 +56,27 @@ public class TokenProvider {
.signWith(key, SignatureAlgorithm.HS256) .signWith(key, SignatureAlgorithm.HS256)
.compact(); .compact();
return CinnamonToken.builder() CinnamonToken token = CinnamonToken.builder()
.grantType("Bearer") .grantType("Bearer")
.accessToken(accessToken) .accessToken(accessToken)
.refreshToken(refreshToken) .refreshToken(refreshToken)
.build(); .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 토큰을 복호화하여 토큰에 들어있는 정보를 꺼내는 메서드 // JWT 토큰을 복호화하여 토큰에 들어있는 정보를 꺼내는 메서드

@ -23,6 +23,7 @@ import org.springframework.ui.Model;
import org.springframework.util.FileCopyUtils; import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.*;
@ -52,8 +53,20 @@ public class MonitoringConsultingController {
private final ExcelService excelService; private final ExcelService excelService;
private final LogService logService; private final LogService logService;
private final HttpServletRequest httpServletRequest;
@GetMapping("/consulting/manage.do") @GetMapping("/consulting/manage.do")
public String ConsultingView(Model model){ 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"; return "/adm/rcp/monitoring/consulting";
} }

@ -23,9 +23,9 @@
</div> </div>
<header id="header"> <header id="header">
<%@ include file="/WEB-INF/jsp/adm/include/header.jsp"%> <%-- <%@ include file="/WEB-INF/jsp/adm/include/header.jsp"%>--%>
</header> </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> <script type="text/javascript" src="<c:url value='/aajs/consulting.js' />"></script>

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

Loading…
Cancel
Save