-
Notifications
You must be signed in to change notification settings - Fork 6k
Implemented solution and tests for "OAuth2AuthorizedClientArgumentResolver should get new access token when expired and client_credentials #6609" #6839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5a94d18
ff0c229
a8e2b6b
01ab4e7
6b21b50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,7 +98,7 @@ public void setClientCredentialsTokenResponseClient( | |
} | ||
|
||
Mono<Request> createDefaultedRequest(String clientRegistrationId, | ||
Authentication authentication, ServerWebExchange exchange) { | ||
Authentication authentication, ServerWebExchange exchange) { | ||
Mono<Authentication> defaultedAuthentication = Mono.justOrEmpty(authentication) | ||
.switchIfEmpty(currentAuthentication()); | ||
|
||
|
@@ -124,14 +124,14 @@ Mono<OAuth2AuthorizedClient> loadAuthorizedClient(Request request) { | |
|
||
private Mono<OAuth2AuthorizedClient> authorizedClientNotLoaded(String clientRegistrationId, Authentication authentication, ServerWebExchange exchange) { | ||
return this.clientRegistrationRepository.findByRegistrationId(clientRegistrationId) | ||
.switchIfEmpty(Mono.error(() -> new IllegalArgumentException("Client Registration with id " + clientRegistrationId + " was not found"))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see any code changes here - just formatting changes. Am I missing something? |
||
.flatMap(clientRegistration -> { | ||
if (AuthorizationGrantType.CLIENT_CREDENTIALS.equals(clientRegistration.getAuthorizationGrantType())) { | ||
return clientCredentials(clientRegistration, authentication, exchange); | ||
} | ||
return Mono.error(() -> new ClientAuthorizationRequiredException(clientRegistrationId)); | ||
}); | ||
} | ||
.switchIfEmpty(Mono.error(() -> new IllegalArgumentException("Client Registration with id " + clientRegistrationId + " was not found"))) | ||
.flatMap(clientRegistration -> { | ||
if (AuthorizationGrantType.CLIENT_CREDENTIALS.equals(clientRegistration.getAuthorizationGrantType())) { | ||
return clientCredentials(clientRegistration, authentication, exchange); | ||
} | ||
return Mono.error(() -> new ClientAuthorizationRequiredException(clientRegistrationId)); | ||
}); | ||
} | ||
|
||
Mono<OAuth2AuthorizedClient> clientCredentials( | ||
ClientRegistration clientRegistration, Authentication authentication, ServerWebExchange exchange) { | ||
|
@@ -176,7 +176,7 @@ static class Request { | |
private final ServerWebExchange exchange; | ||
|
||
public Request(String clientRegistrationId, Authentication authentication, | ||
ServerWebExchange exchange) { | ||
ServerWebExchange exchange) { | ||
this.clientRegistrationId = clientRegistrationId; | ||
this.authentication = authentication; | ||
this.exchange = exchange; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,7 +98,7 @@ public void setClientCredentialsTokenResponseClient( | |
} | ||
|
||
Mono<Request> createDefaultedRequest(String clientRegistrationId, | ||
Authentication authentication, ServerWebExchange exchange) { | ||
Authentication authentication, ServerWebExchange exchange) { | ||
Mono<Authentication> defaultedAuthentication = Mono.justOrEmpty(authentication) | ||
.switchIfEmpty(currentAuthentication()); | ||
|
||
|
@@ -125,14 +125,14 @@ Mono<OAuth2AuthorizedClient> loadAuthorizedClient(Request request) { | |
|
||
private Mono<OAuth2AuthorizedClient> authorizedClientNotLoaded(String clientRegistrationId, Authentication authentication, ServerWebExchange exchange) { | ||
return this.clientRegistrationRepository.findByRegistrationId(clientRegistrationId) | ||
.switchIfEmpty(Mono.error(() -> new IllegalArgumentException("Client Registration with id " + clientRegistrationId + " was not found"))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see any code changes here - just formatting changes. Am I missing something? |
||
.flatMap(clientRegistration -> { | ||
if (AuthorizationGrantType.CLIENT_CREDENTIALS.equals(clientRegistration.getAuthorizationGrantType())) { | ||
return clientCredentials(clientRegistration, authentication, exchange); | ||
} | ||
return Mono.error(() -> new ClientAuthorizationRequiredException(clientRegistrationId)); | ||
}); | ||
} | ||
.switchIfEmpty(Mono.error(() -> new IllegalArgumentException("Client Registration with id " + clientRegistrationId + " was not found"))) | ||
.flatMap(clientRegistration -> { | ||
if (AuthorizationGrantType.CLIENT_CREDENTIALS.equals(clientRegistration.getAuthorizationGrantType())) { | ||
return clientCredentials(clientRegistration, authentication, exchange); | ||
} | ||
return Mono.error(() -> new ClientAuthorizationRequiredException(clientRegistrationId)); | ||
}); | ||
} | ||
|
||
private Mono<? extends OAuth2AuthorizedClient> clientCredentials( | ||
ClientRegistration clientRegistration, Authentication authentication, ServerWebExchange exchange) { | ||
|
@@ -177,7 +177,7 @@ static class Request { | |
private final ServerWebExchange exchange; | ||
|
||
public Request(String clientRegistrationId, Authentication authentication, | ||
ServerWebExchange exchange) { | ||
ServerWebExchange exchange) { | ||
this.clientRegistrationId = clientRegistrationId; | ||
this.authentication = authentication; | ||
this.exchange = exchange; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,9 +46,7 @@ | |
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; | ||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; | ||
import static org.mockito.ArgumentMatchers.any; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not be included since there are no code changes. |
||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.ArgumentMatchers.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on my explanation in this comment, we don't need any changes here as the current implementation does exactly what is required. Please reset the changes here.