diff --git a/src/main/java/com/dearsanta/app/security/JwtInterceptor.java b/src/main/java/com/dearsanta/app/security/JwtInterceptor.java index e9de8a2..bfae798 100644 --- a/src/main/java/com/dearsanta/app/security/JwtInterceptor.java +++ b/src/main/java/com/dearsanta/app/security/JwtInterceptor.java @@ -33,7 +33,9 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons } public String getMemberIdByAccessToken(String accessToken) { + log.info("getMemberIdByAccessToken() accessToken : " + accessToken); String token = jwtTokenProvider.resolveBearerToken(accessToken); + log.info("resolveBearerToken() accessToken : " + token); Claims claims = jwtTokenProvider.getClaims(token); String memberId = claims.get("memberId").toString(); log.info("claims : " + claims + " memberId : " + memberId); diff --git a/src/main/java/com/dearsanta/app/security/JwtTokenProvider.java b/src/main/java/com/dearsanta/app/security/JwtTokenProvider.java index 90fc8a2..dda116d 100644 --- a/src/main/java/com/dearsanta/app/security/JwtTokenProvider.java +++ b/src/main/java/com/dearsanta/app/security/JwtTokenProvider.java @@ -1,10 +1,7 @@ package com.dearsanta.app.security; import com.dearsanta.app.security.dto.TokenDto; -import io.jsonwebtoken.Claims; -import io.jsonwebtoken.ExpiredJwtException; -import io.jsonwebtoken.Jwts; -import io.jsonwebtoken.MalformedJwtException; +import io.jsonwebtoken.*; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import io.jsonwebtoken.security.Keys; @@ -20,8 +17,8 @@ public class JwtTokenProvider { private String jwtIssuer = "dearsanta"; private String bearerHeader = "Bearer "; private String jwtSecretKey = "tm4zrpa3tlZzqsJzrsJzsnpDrpbzrp4zrk6TslrTqsIDsnpAtm4zrpa3tlZzqsJzrsJzsnpfvbnoperufgvjlsdnvkjhwfhDrpbzrp4zrk6TslrTqsID"; - private long accessTokenValidity = 1000000000; - private long refreshTokenValidity = 1000000000; + private long accessTokenValidity = 10 * 24 * 60 * 60 * 1000; + private long refreshTokenValidity = 10 * 24 * 60 * 60 * 1000; private SecretKey secretKey; private String MEMBER_ID = "memberId"; @@ -45,8 +42,9 @@ public String createBearerTokenWithValidity(String memberId, long tokenValidity) } private String createTokenWithValidity(String memberId, long tokenValidity){ - Date now = new Date(); - Date expirationAt = new Date(now.getTime() + tokenValidity); + Date now = new Date(System.currentTimeMillis()); + Date expirationAt = new Date(now.getTime() + accessTokenValidity); + log.info("createTokenWithValidity() : " + expirationAt); return Jwts.builder() .claim(MEMBER_ID, memberId) @@ -85,7 +83,7 @@ public String resolveBearerToken(String token) { if (token != null && token.startsWith(bearerHeader)) { return token.substring(bearerHeader.length()); } - throw new NoSuchElementException("토큰이 만료되었습니다."); + throw new NoSuchElementException("토큰 형식이 잘못되었습니다. " + token); } public Long getExpirationTime(String accessToken) { diff --git a/src/main/resources/com/dearsanta/app/mapper/BoardMapper.xml b/src/main/resources/com/dearsanta/app/mapper/BoardMapper.xml index c85d8d3..46da338 100644 --- a/src/main/resources/com/dearsanta/app/mapper/BoardMapper.xml +++ b/src/main/resources/com/dearsanta/app/mapper/BoardMapper.xml @@ -58,28 +58,36 @@ id, title, content, - created_date AS createdDate, - updated_date AS updatedDate, - member_id AS memberId, - img_url AS imgUrl, - like_count AS likeCount, - view_count AS viewCount, - reply_count AS replyCount + createdDate, + updatedDate, + memberId, + userNickname, + userImgUrl, + isMine, + imgUrl, + likeCount, + viewCount, + replyCount FROM ( SELECT /*+ INDEX_DESC(board ${criteria.sorted}) */ rownum AS rn, - id, - title, - content, - created_date, - updated_date, - member_id, - img_url, - like_count, - view_count, - reply_count + board.id AS id, + board.title AS title, + board.content AS content, + board.created_date AS createdDate, + board.updated_date AS updatedDate, + board.member_id AS memberId, + member.nickname AS userNickname, + member.img_url AS userImgUrl, + 0 AS isMine, + board.img_url AS imgUrl, + board.like_count AS likeCount, + board.view_count AS viewCount, + board.reply_count AS replyCount FROM board + LEFT JOIN member + ON board.member_id = member.id WHERE member_id = #{criteria.selectId, jdbcType=VARCHAR} AND rownum <= #{criteria.pageNum} * #{criteria.pageSize} )