Skip to content

Commit

Permalink
optimize: security app token response when user not found or disable. (
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiveHao committed Jul 11, 2024
1 parent 5e3f545 commit fd0841a
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;
import run.ikaros.api.constant.OpenApiConst;
import run.ikaros.api.infra.exception.security.UserAuthenticationException;
import run.ikaros.api.infra.exception.user.UserNotFoundException;
import run.ikaros.server.endpoint.CoreEndpoint;
import run.ikaros.server.security.authentication.jwt.JwtApplyParam;
import run.ikaros.server.security.authentication.jwt.JwtAuthenticationProvider;
Expand Down Expand Up @@ -71,6 +73,8 @@ private Mono<ServerResponse> applyJwtToken(ServerRequest request) {
.flatMap(userDetailsService::findByUsername)
.map(UserDetails::getUsername)
.map(jwtAuthenticationProvider::generateToken)
.flatMap(token -> ServerResponse.ok().bodyValue(token));
.flatMap(token -> ServerResponse.ok().bodyValue(token))
.onErrorResume(UserNotFoundException.class,
e -> Mono.error(new UserAuthenticationException(e.getLocalizedMessage(), e)));
}
}

0 comments on commit fd0841a

Please sign in to comment.