-
Notifications
You must be signed in to change notification settings - Fork 0
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
[FEATURE] Security 관련 리팩토링 #21
Conversation
bongsh0112
commented
Oct 10, 2023
- CustomUserDetails 변경점 확인
- claim에 새로운 값 추가
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
바꿔줘 응애
@@ -56,6 +54,5 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti | |||
PasswordEncoder passwordEncoder() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
접근제어자 필요하지 않을까요?
if (header != null && header.startsWith(TOKEN_PREFIX)) { | ||
authToken = header.replace(TOKEN_PREFIX," "); | ||
try { | ||
username = this.jwtTokenProvider.getUsernameFromToken(authToken); | ||
CustomUserDetails userDetails = CustomUserDetails.of( | ||
jwtTokenProvider.getUserIdFromToken(authToken), | ||
jwtTokenProvider.getUserRoleFromToken(authToken), | ||
jwtTokenProvider.getUserNickNameFromToken(authToken) | ||
); | ||
|
||
SecurityContextHolder.getContext().setAuthentication( | ||
new UsernamePasswordAuthenticationToken(userDetails, "user", userDetails.getAuthorities()) | ||
); | ||
} catch (IllegalArgumentException ex) { | ||
log.info("fail get user id"); | ||
throw UserNotFoundException.EXCEPTION; | ||
} catch (ExpiredJwtException ex) { | ||
log.info("Token expired"); | ||
throw TokenNotFoundException.EXCEPTION; | ||
} catch (MalformedJwtException ex) { | ||
log.info("Invalid JWT !!"); | ||
throw InvalidTokenException.EXCEPTION; | ||
} catch (Exception e) { | ||
log.info("Unable to get JWT Token !!"); | ||
throw TokenException.EXCEPTION; | ||
} | ||
} else { | ||
log.info("JWT does not begin with Bearer !!"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (header != null && header.startsWith(TOKEN_PREFIX)) {
authToken = header.replace(TOKEN_PREFIX," ");
try {
CustomUserDetails userDetails = CustomUserDetails.of(
jwtTokenProvider.getUserIdFromToken(authToken),
jwtTokenProvider.getUserRoleFromToken(authToken),
jwtTokenProvider.getUserNickNameFromToken(authToken)
);
SecurityContextHolder.getContext().setAuthentication(
new UsernamePasswordAuthenticationToken(userDetails, "user", userDetails.getAuthorities())
);
} catch (IllegalArgumentException ex) {
throw UserNotFoundException.EXCEPTION;
} catch (ExpiredJwtException ex) {
throw TokenNotFoundException.EXCEPTION;
} catch (MalformedJwtException ex) {
throw InvalidTokenException.EXCEPTION;
} catch (Exception e) {
throw TokenException.EXCEPTION;
}
}
filterChain.doFilter(request, response);
이걸로도 끝낼 수 있지 않을까요?
@@ -15,7 +14,7 @@ | |||
import java.util.Map; | |||
import java.util.function.Function; | |||
|
|||
import static HookKiller.server.common.constants.StaticVariable.*; | |||
import static HookKiller.server.jwt.ClaimVal.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*는 하나하나 다 호출하는걸로 변경가능할까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 정말 잘해쒀요~