Skip to content

Commit ab96bfb

Browse files
authored
[Fix] 유저 권한 관련 문제 해결, ID/PW sign 엔드 포인트 수정 (#290)
* fix: userRole 문제 해결 * fix: sign 엔드 포인트 수정 - 필터에만 적용시키고 스웨거 api에는 올바르게 적용하지 않았기에 수정.
1 parent ef9c1b2 commit ab96bfb

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

src/main/java/com/somemore/global/auth/controller/SignController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
@RestController
1616
@RequiredArgsConstructor
17-
@RequestMapping("/api/center")
17+
@RequestMapping("/api")
1818
@Tag(name = "Sign API", description = "ID,PW 로그인, 로그아웃")
1919
public class SignController {
2020

@@ -30,7 +30,7 @@ public class SignController {
3030
*
3131
* 실제 로그인 절차는 필터에서 처리됩니다.
3232
*/
33-
@PostMapping("/sign-in")
33+
@PostMapping("/sign-in/id-pw")
3434
public ApiResponse<String> signIn(
3535
@RequestParam SignRequestDto signRequestDto
3636
) {

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)