Skip to content

Commit

Permalink
Merge pull request #47 from GApple-T/redis
Browse files Browse the repository at this point in the history
πŸ”€::토큰 만료된 게 없을 λ•Œ λ°˜ν™˜λ˜λŠ” DTO μΆ”κ°€
  • Loading branch information
enbraining authored Dec 21, 2023
2 parents c32d7ea + 099ad23 commit 5bfcaf7
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,40 +103,30 @@ public ResponseEntity<AuthLogoutResponse> refresh(String headerAuthorization, St
}
String refresh = jwtProvider.resolveToken(headerRefresh);
String authorization = jwtProvider.resolveToken(headerAuthorization);
log.info("Access={}, Refresh={}", authorization, refresh);
log.info(SecurityContextHolder.getContext().getAuthentication().getAuthorities().toString());

boolean accessValidate = jwtProvider.validateToken(authorization);
boolean refreshValidate = jwtProvider.validateToken(refresh);

UUID savedId;
if(refreshValidate){
Authentication refreshToken = jwtProvider.getAuthentication(refresh);
log.info("Authorities={}", refreshToken.getAuthorities());
savedId = UUID.fromString(refreshToken.getName());
} else savedId = UUID.fromString(SecurityContextHolder.getContext().getAuthentication().getName());
log.info("savedId={}", savedId);

ValueOperations<String, String> stringValueOperations = stringRedisTemplate.opsForValue();
String token = stringValueOperations.get(savedId.toString());

log.info("savedToken={}", token);

if(refresh.equals(token)){
if(!accessValidate && !refreshValidate){
throw new RuntimeException();
} else if(!accessValidate){
Member member = memberRepository.findMemberById(savedId);

log.info(member.getId().toString());

String password = member.getPassword();

List<AccessRole> roles = new ArrayList<>();
roles.add(AccessRole.valueOf(member.getRole()));

log.info(roles.toString());

Authentication authentication =
new UsernamePasswordAuthenticationToken(savedId.toString(), password, roles);

Expand All @@ -146,20 +136,15 @@ public ResponseEntity<AuthLogoutResponse> refresh(String headerAuthorization, St

return ResponseEntity.ok(new AuthLogoutResponse(newAccessToken, null, "ok"));
} else if(!refreshValidate){
log.info("authorization={}", authorization);
Authentication authorizationToken = jwtProvider.getAuthentication(authorization); // 였λ₯˜ λ°œμƒμ§€
log.info("authorizationToken={}", authorizationToken);
UUID id = UUID.fromString(authorizationToken.getName());
log.info("id={}", id);
String newRefresh = jwtProvider.generateRefreshToken(authorizationToken);
log.info("newRefresh={}",newRefresh);

stringValueOperations.set(id.toString(), newRefresh);

return ResponseEntity.ok(new AuthLogoutResponse(null, newRefresh, "ok"));
} else {
log.info("ok");
return new ResponseEntity<>(HttpStatus.OK);
return ResponseEntity.ok().body(new AuthLogoutResponse(null, null, "ok"));
}
} else throw new RuntimeException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public String resolveToken(String token) {
}

public Authentication getAuthentication(String accessToken) {
log.info("createAuthorityList={}", getRole(accessToken));
return new UsernamePasswordAuthenticationToken(getUsername(accessToken), "", createAuthorityList(getRole(accessToken)));
}

Expand Down

0 comments on commit 5bfcaf7

Please sign in to comment.