Skip to content

Commit

Permalink
Merge pull request #36 from dear-santa/feature/board-member
Browse files Browse the repository at this point in the history
fix: JWT 토큰 유효 기간 변경 및 내가 쓴 글 조회 mapper 수정
  • Loading branch information
sooyoungh authored Dec 14, 2023
2 parents ebd7b93 + 2badd3e commit 0d88d33
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/dearsanta/app/security/JwtInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/com/dearsanta/app/security/JwtTokenProvider.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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";

Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
42 changes: 25 additions & 17 deletions src/main/resources/com/dearsanta/app/mapper/BoardMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)
Expand Down

0 comments on commit 0d88d33

Please sign in to comment.