Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ”€::토큰 만료된 게 없을 λ•Œ λ°˜ν™˜λ˜λŠ” DTO μΆ”κ°€ #47

Merged
merged 2 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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