Skip to content

Commit 267bd57

Browse files
committed
fix: userRole 문제 해결
1 parent ef9c1b2 commit 267bd57

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/main/java/com/somemore/global/auth/idpw/filter/IdPwAuthFilter.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,24 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
4444
@Override
4545
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authResult) {
4646
response.setStatus(HttpServletResponse.SC_OK);
47+
String userId = authResult.getName();
48+
String role = extractRole(authResult);
4749
EncodedToken accessToken =
4850
generateTokensOnLoginUseCase.saveRefreshTokenAndReturnAccessToken(
49-
UUID.fromString(authResult.getName()),
50-
UserRole.from(authResult.getAuthorities().stream()
51-
.findFirst()
52-
.map(GrantedAuthority::getAuthority)
53-
.orElseThrow(() -> new IllegalStateException("유저 권한 자체가 존재하지 않습니다."))));
51+
UUID.fromString(userId),
52+
UserRole.from(role));
5453

5554
response.setHeader("Authorization", accessToken.getValueWithPrefix());
5655
// cookieUseCase.setAccessToken(response, accessToken.value());
5756
}
5857

58+
private static String extractRole(Authentication authResult) {
59+
return authResult.getAuthorities().stream()
60+
.findFirst()
61+
.map(GrantedAuthority::getAuthority)
62+
.orElseThrow(() -> new IllegalStateException("유저 권한 자체가 존재하지 않습니다."));
63+
}
64+
5965
@Override
6066
protected void unsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException failed) throws IOException {
6167
ProblemDetail problemDetail = buildUnauthorizedProblemDetail(failed);

src/main/java/com/somemore/user/domain/UserRole.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static UserRole getOAuthUserDefaultRole() {
2424

2525
public static UserRole from(String role) {
2626
for (UserRole userRole : values()) {
27-
if (userRole.name().equals(role)) {
27+
if (role.contains(userRole.name())) {
2828
return userRole;
2929
}
3030
}

0 commit comments

Comments
 (0)