Issue gh-5776
This commit is contained in:
Joe Grandja 2018-09-12 11:57:53 -04:00
parent 8746e71b9a
commit ed9cd478ba
2 changed files with 5 additions and 8 deletions

View File

@ -19,7 +19,6 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.security.oauth2.client.registration.ClientRegistration; import org.springframework.security.oauth2.client.registration.ClientRegistration;
import org.springframework.security.oauth2.core.ClientAuthenticationMethod; import org.springframework.security.oauth2.core.ClientAuthenticationMethod;
import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse; import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse;
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames; import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -52,9 +51,7 @@ public class WebClientReactiveClientCredentialsTokenResponseClient implements Re
.build(); .build();
@Override @Override
public Mono<OAuth2AccessTokenResponse> getTokenResponse(OAuth2ClientCredentialsGrantRequest authorizationGrantRequest) public Mono<OAuth2AccessTokenResponse> getTokenResponse(OAuth2ClientCredentialsGrantRequest authorizationGrantRequest) {
throws OAuth2AuthenticationException {
return Mono.defer(() -> { return Mono.defer(() -> {
ClientRegistration clientRegistration = authorizationGrantRequest.getClientRegistration(); ClientRegistration clientRegistration = authorizationGrantRequest.getClientRegistration();

View File

@ -72,11 +72,11 @@ public class ServerOAuth2AuthorizationCodeAuthenticationTokenConverter
@Override @Override
public Mono<Authentication> convert(ServerWebExchange serverWebExchange) { public Mono<Authentication> convert(ServerWebExchange serverWebExchange) {
return this.authorizationRequestRepository.removeAuthorizationRequest(serverWebExchange) return this.authorizationRequestRepository.removeAuthorizationRequest(serverWebExchange)
.switchIfEmpty(oauth2AuthenticationException(AUTHORIZATION_REQUEST_NOT_FOUND_ERROR_CODE)) .switchIfEmpty(oauth2AuthorizationException(AUTHORIZATION_REQUEST_NOT_FOUND_ERROR_CODE))
.flatMap(authorizationRequest -> authenticationRequest(serverWebExchange, authorizationRequest)); .flatMap(authorizationRequest -> authenticationRequest(serverWebExchange, authorizationRequest));
} }
private <T> Mono<T> oauth2AuthenticationException(String errorCode) { private <T> Mono<T> oauth2AuthorizationException(String errorCode) {
return Mono.defer(() -> { return Mono.defer(() -> {
OAuth2Error oauth2Error = new OAuth2Error(errorCode); OAuth2Error oauth2Error = new OAuth2Error(errorCode);
return Mono.error(new OAuth2AuthorizationException(oauth2Error)); return Mono.error(new OAuth2AuthorizationException(oauth2Error));
@ -89,11 +89,11 @@ public class ServerOAuth2AuthorizationCodeAuthenticationTokenConverter
.flatMap(additionalParams -> { .flatMap(additionalParams -> {
String id = (String) additionalParams.get(OAuth2ParameterNames.REGISTRATION_ID); String id = (String) additionalParams.get(OAuth2ParameterNames.REGISTRATION_ID);
if (id == null) { if (id == null) {
return oauth2AuthenticationException(CLIENT_REGISTRATION_NOT_FOUND_ERROR_CODE); return oauth2AuthorizationException(CLIENT_REGISTRATION_NOT_FOUND_ERROR_CODE);
} }
return this.clientRegistrationRepository.findByRegistrationId(id); return this.clientRegistrationRepository.findByRegistrationId(id);
}) })
.switchIfEmpty(oauth2AuthenticationException(CLIENT_REGISTRATION_NOT_FOUND_ERROR_CODE)) .switchIfEmpty(oauth2AuthorizationException(CLIENT_REGISTRATION_NOT_FOUND_ERROR_CODE))
.map(clientRegistration -> { .map(clientRegistration -> {
OAuth2AuthorizationResponse authorizationResponse = convertResponse(exchange); OAuth2AuthorizationResponse authorizationResponse = convertResponse(exchange);
OAuth2AuthorizationCodeAuthenticationToken authenticationRequest = new OAuth2AuthorizationCodeAuthenticationToken( OAuth2AuthorizationCodeAuthenticationToken authenticationRequest = new OAuth2AuthorizationCodeAuthenticationToken(