Remove unnecessary lambda blocks
Remove lambda blocks that aren't needed and replace instead with a simple expression. Issue gh-8945
This commit is contained in:
@@ -146,16 +146,14 @@ public final class DefaultReactiveOAuth2AuthorizedClientManager implements React
|
||||
.flatMap((serverWebExchange) -> Mono.justOrEmpty(authorizeRequest.getAuthorizedClient())
|
||||
.switchIfEmpty(Mono
|
||||
.defer(() -> loadAuthorizedClient(clientRegistrationId, principal, serverWebExchange)))
|
||||
.flatMap((authorizedClient) -> {
|
||||
// Re-authorize
|
||||
return authorizationContext(authorizeRequest, authorizedClient)
|
||||
.flatMap((authorizationContext) -> authorize(authorizationContext, principal,
|
||||
serverWebExchange))
|
||||
// Default to the existing authorizedClient if the
|
||||
// client was not re-authorized
|
||||
.defaultIfEmpty(authorizeRequest.getAuthorizedClient() != null
|
||||
? authorizeRequest.getAuthorizedClient() : authorizedClient);
|
||||
}).switchIfEmpty(Mono.defer(() ->
|
||||
.flatMap((authorizedClient) -> // Re-authorize
|
||||
authorizationContext(authorizeRequest, authorizedClient).flatMap(
|
||||
(authorizationContext) -> authorize(authorizationContext, principal, serverWebExchange))
|
||||
// Default to the existing authorizedClient if the
|
||||
// client was not re-authorized
|
||||
.defaultIfEmpty(authorizeRequest.getAuthorizedClient() != null
|
||||
? authorizeRequest.getAuthorizedClient() : authorizedClient))
|
||||
.switchIfEmpty(Mono.defer(() ->
|
||||
// Authorize
|
||||
this.clientRegistrationRepository.findByRegistrationId(clientRegistrationId)
|
||||
.switchIfEmpty(Mono.error(() -> new IllegalArgumentException(
|
||||
|
||||
@@ -565,20 +565,16 @@ public final class ServerOAuth2AuthorizedClientExchangeFilterFunction implements
|
||||
String clientRegistrationId = authorizeRequest.getClientRegistrationId();
|
||||
Authentication principal = authorizeRequest.getPrincipal();
|
||||
|
||||
return Mono.justOrEmpty(authorizeRequest.getAuthorizedClient())
|
||||
.switchIfEmpty(Mono.defer(() -> this.authorizedClientRepository
|
||||
.loadAuthorizedClient(clientRegistrationId, principal, null)))
|
||||
.flatMap((authorizedClient) -> {
|
||||
// Re-authorize
|
||||
return Mono
|
||||
.just(OAuth2AuthorizationContext.withAuthorizedClient(authorizedClient)
|
||||
.principal(principal).build())
|
||||
.flatMap((authorizationContext) -> authorize(authorizationContext, principal))
|
||||
// Default to the existing authorizedClient if the client
|
||||
// was not re-authorized
|
||||
.defaultIfEmpty(authorizeRequest.getAuthorizedClient() != null
|
||||
? authorizeRequest.getAuthorizedClient() : authorizedClient);
|
||||
}).switchIfEmpty(Mono.defer(() ->
|
||||
return Mono.justOrEmpty(authorizeRequest.getAuthorizedClient()).switchIfEmpty(Mono.defer(
|
||||
() -> this.authorizedClientRepository.loadAuthorizedClient(clientRegistrationId, principal, null)))
|
||||
.flatMap((authorizedClient) -> // Re-authorize
|
||||
Mono.just(OAuth2AuthorizationContext.withAuthorizedClient(authorizedClient).principal(principal)
|
||||
.build()).flatMap((authorizationContext) -> authorize(authorizationContext, principal))
|
||||
// Default to the existing authorizedClient if the client
|
||||
// was not re-authorized
|
||||
.defaultIfEmpty(authorizeRequest.getAuthorizedClient() != null
|
||||
? authorizeRequest.getAuthorizedClient() : authorizedClient))
|
||||
.switchIfEmpty(Mono.defer(() ->
|
||||
// Authorize
|
||||
this.clientRegistrationRepository.findByRegistrationId(clientRegistrationId)
|
||||
.switchIfEmpty(Mono.error(() -> new IllegalArgumentException(
|
||||
|
||||
@@ -85,10 +85,10 @@ public class OAuth2AuthorizationCodeAuthenticationProviderTests {
|
||||
OAuth2AuthorizationExchange authorizationExchange = new OAuth2AuthorizationExchange(this.authorizationRequest,
|
||||
authorizationResponse);
|
||||
|
||||
assertThatThrownBy(() -> {
|
||||
this.authenticationProvider.authenticate(
|
||||
new OAuth2AuthorizationCodeAuthenticationToken(this.clientRegistration, authorizationExchange));
|
||||
}).isInstanceOf(OAuth2AuthorizationException.class).hasMessageContaining(OAuth2ErrorCodes.INVALID_REQUEST);
|
||||
assertThatThrownBy(() -> this.authenticationProvider.authenticate(
|
||||
new OAuth2AuthorizationCodeAuthenticationToken(this.clientRegistration, authorizationExchange)))
|
||||
.isInstanceOf(OAuth2AuthorizationException.class)
|
||||
.hasMessageContaining(OAuth2ErrorCodes.INVALID_REQUEST);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -98,10 +98,10 @@ public class OAuth2AuthorizationCodeAuthenticationProviderTests {
|
||||
OAuth2AuthorizationExchange authorizationExchange = new OAuth2AuthorizationExchange(this.authorizationRequest,
|
||||
authorizationResponse);
|
||||
|
||||
assertThatThrownBy(() -> {
|
||||
this.authenticationProvider.authenticate(
|
||||
new OAuth2AuthorizationCodeAuthenticationToken(this.clientRegistration, authorizationExchange));
|
||||
}).isInstanceOf(OAuth2AuthorizationException.class).hasMessageContaining("invalid_state_parameter");
|
||||
assertThatThrownBy(() -> this.authenticationProvider.authenticate(
|
||||
new OAuth2AuthorizationCodeAuthenticationToken(this.clientRegistration, authorizationExchange)))
|
||||
.isInstanceOf(OAuth2AuthorizationException.class)
|
||||
.hasMessageContaining("invalid_state_parameter");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.catchThrowable;
|
||||
import static org.assertj.core.api.Assertions.assertThatObject;
|
||||
|
||||
/**
|
||||
* Tests for {@link ClaimAccessor}.
|
||||
@@ -142,12 +142,7 @@ public class ClaimAccessorTests {
|
||||
String expectedClaimValue = "true";
|
||||
String claimName = "boolean";
|
||||
this.claims.put(claimName, expectedClaimValue);
|
||||
|
||||
Throwable thrown = catchThrowable(() -> {
|
||||
boolean actualClaimValue = this.claimAccessor.getClaim(claimName);
|
||||
});
|
||||
|
||||
assertThat(thrown).isInstanceOf(ClassCastException.class);
|
||||
assertThatObject(this.claimAccessor.getClaim(claimName)).isNotInstanceOf(Boolean.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,16 +38,14 @@ public class HeaderBearerTokenResolverTests {
|
||||
|
||||
@Test
|
||||
public void constructorWhenHeaderNullThenThrowIllegalArgumentException() {
|
||||
assertThatCode(() -> {
|
||||
new HeaderBearerTokenResolver(null);
|
||||
}).isInstanceOf(IllegalArgumentException.class).hasMessage("header cannot be empty");
|
||||
assertThatCode(() -> new HeaderBearerTokenResolver(null)).isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("header cannot be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenHeaderEmptyThenThrowIllegalArgumentException() {
|
||||
assertThatCode(() -> {
|
||||
new HeaderBearerTokenResolver("");
|
||||
}).isInstanceOf(IllegalArgumentException.class).hasMessage("header cannot be empty");
|
||||
assertThatCode(() -> new HeaderBearerTokenResolver("")).isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("header cannot be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user