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

[FEATURE] Security 관련 리팩토링 #21

Merged
merged 8 commits into from
Oct 10, 2023
Merged

Conversation

bongsh0112
Copy link
Member

  • CustomUserDetails 변경점 확인
  • claim에 새로운 값 추가

Copy link
Member

@donsonioc2010 donsonioc2010 left a 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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

접근제어자 필요하지 않을까요?

Comment on lines 52 to 75
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 !!");
}
Copy link
Member

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.*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*는 하나하나 다 호출하는걸로 변경가능할까요?

@donsonioc2010 donsonioc2010 self-requested a review October 10, 2023 05:05
Copy link
Member

@donsonioc2010 donsonioc2010 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 정말 잘해쒀요~

@donsonioc2010 donsonioc2010 merged commit b7d8fe2 into dev Oct 10, 2023
1 check passed
@donsonioc2010 donsonioc2010 deleted the feat/4-security-login branch October 10, 2023 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants