Skip to content

Commit

Permalink
refactor: token validation complete
Browse files Browse the repository at this point in the history
  • Loading branch information
singsangssong committed Oct 17, 2024
1 parent 09c7cd9 commit 9576760
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/main/java/kr/tgwing/tech/project/domain/Link.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class Link extends BaseEntity {
private String url;

private String description;

public void setProject(Project project) {
this.project = project;
}
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/kr/tgwing/tech/security/filter/JwtFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import kr.tgwing.tech.security.util.JwtUtil;
import kr.tgwing.tech.user.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.filter.OncePerRequestFilter;
Expand All @@ -35,7 +36,6 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
if (authorization == null || !authorization.startsWith("Bearer ")) {
log.info("token is null");
filterChain.doFilter(request, response);

return;
}

Expand All @@ -44,12 +44,17 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
//Bearer 부분 제거 후 순수 토큰만 획득
String token = authorization.split(" ")[1];

if ("/api/validate".equals(request.getRequestURI()) && "POST".equalsIgnoreCase(request.getMethod())) {
log.info("유효성 검사 토큰 요청 확인");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().write("token validation result: success!");
return;
}

//토큰 소멸 시간 검증
if (jwtUtil.isExpired(token)) {
log.info("token is useless...");
filterChain.doFilter(request, response);

return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/kr/tgwing/tech/security/util/JwtUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public JwtUtil(@Value(".${spring.jwt.secretKey}")String secret) {
secretKey = Keys.hmacShaKeyFor(secret.getBytes(StandardCharsets.UTF_8));
}


public String getStudentId(String token) {

return Jwts.parserBuilder().setSigningKey(secretKey).build().parseClaimsJws(token).getBody().getSubject();
Expand All @@ -37,6 +36,7 @@ public Boolean isExpired(String token) {
.getBody().getExpiration().before(new Date());
}


public String createJwt(String studentId, String profilePicture, String role, Long expiredTime) {
// name : token에 들어있는 것으로 사용함
// secretKey : 서명
Expand Down

0 comments on commit 9576760

Please sign in to comment.