Skip to content
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 @@ -14,7 +14,7 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/center")
@RequestMapping("/api")
@Tag(name = "Sign API", description = "ID,PW 로그인, 로그아웃")
public class SignController {

Expand All @@ -30,7 +30,7 @@ public class SignController {
*
* 실제 로그인 절차는 필터에서 처리됩니다.
*/
@PostMapping("/sign-in")
@PostMapping("/sign-in/id-pw")
public ApiResponse<String> signIn(
@RequestParam SignRequestDto signRequestDto
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,24 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
@Override
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authResult) {
response.setStatus(HttpServletResponse.SC_OK);
String userId = authResult.getName();
String role = extractRole(authResult);
EncodedToken accessToken =
generateTokensOnLoginUseCase.saveRefreshTokenAndReturnAccessToken(
UUID.fromString(authResult.getName()),
UserRole.from(authResult.getAuthorities().stream()
.findFirst()
.map(GrantedAuthority::getAuthority)
.orElseThrow(() -> new IllegalStateException("유저 권한 자체가 존재하지 않습니다."))));
UUID.fromString(userId),
UserRole.from(role));

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

private static String extractRole(Authentication authResult) {
return authResult.getAuthorities().stream()
.findFirst()
.map(GrantedAuthority::getAuthority)
.orElseThrow(() -> new IllegalStateException("유저 권한 자체가 존재하지 않습니다."));
}

@Override
protected void unsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException failed) throws IOException {
ProblemDetail problemDetail = buildUnauthorizedProblemDetail(failed);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/somemore/user/domain/UserRole.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static UserRole getOAuthUserDefaultRole() {

public static UserRole from(String role) {
for (UserRole userRole : values()) {
if (userRole.name().equals(role)) {
if (role.contains(userRole.name())) {
return userRole;
}
}
Expand Down
Loading