Using modern Java features
This commit is contained in:
committed by
Josh Cummings
parent
7e01ebdd92
commit
9b603b99ab
+1
-2
@@ -396,8 +396,7 @@ public class JdbcOAuth2AuthorizedClientService implements OAuth2AuthorizedClient
|
||||
|
||||
@Override
|
||||
protected void doSetValue(PreparedStatement ps, int parameterPosition, Object argValue) throws SQLException {
|
||||
if (argValue instanceof SqlParameterValue) {
|
||||
SqlParameterValue paramValue = (SqlParameterValue) argValue;
|
||||
if (argValue instanceof SqlParameterValue paramValue) {
|
||||
if (paramValue.getSqlType() == Types.BLOB) {
|
||||
if (paramValue.getValue() != null) {
|
||||
Assert.isInstanceOf(byte[].class, paramValue.getValue(),
|
||||
|
||||
+1
-2
@@ -110,9 +110,8 @@ public class RemoveAuthorizedClientOAuth2AuthorizationFailureHandler implements
|
||||
@Override
|
||||
public void onAuthorizationFailure(OAuth2AuthorizationException authorizationException, Authentication principal,
|
||||
Map<String, Object> attributes) {
|
||||
if (authorizationException instanceof ClientAuthorizationException
|
||||
if (authorizationException instanceof ClientAuthorizationException clientAuthorizationException
|
||||
&& hasRemovalErrorCode(authorizationException)) {
|
||||
ClientAuthorizationException clientAuthorizationException = (ClientAuthorizationException) authorizationException;
|
||||
this.delegate.removeAuthorizedClient(clientAuthorizationException.getClientRegistrationId(), principal,
|
||||
attributes);
|
||||
}
|
||||
|
||||
+1
-2
@@ -112,9 +112,8 @@ public class RemoveAuthorizedClientReactiveOAuth2AuthorizationFailureHandler
|
||||
@Override
|
||||
public Mono<Void> onAuthorizationFailure(OAuth2AuthorizationException authorizationException,
|
||||
Authentication principal, Map<String, Object> attributes) {
|
||||
if (authorizationException instanceof ClientAuthorizationException
|
||||
if (authorizationException instanceof ClientAuthorizationException clientAuthorizationException
|
||||
&& hasRemovalErrorCode(authorizationException)) {
|
||||
ClientAuthorizationException clientAuthorizationException = (ClientAuthorizationException) authorizationException;
|
||||
return this.delegate.removeAuthorizedClient(clientAuthorizationException.getClientRegistrationId(),
|
||||
principal, attributes);
|
||||
}
|
||||
|
||||
+2
-2
@@ -70,13 +70,13 @@ public class OAuth2AuthorizationCodeReactiveAuthenticationManagerTests {
|
||||
@Test
|
||||
public void authenticateWhenErrorThenOAuth2AuthorizationException() {
|
||||
this.authorizationResponse = TestOAuth2AuthorizationResponses.error();
|
||||
assertThatExceptionOfType(OAuth2AuthorizationException.class).isThrownBy(() -> authenticate());
|
||||
assertThatExceptionOfType(OAuth2AuthorizationException.class).isThrownBy(this::authenticate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void authenticateWhenStateNotEqualThenOAuth2AuthorizationException() {
|
||||
this.authorizationRequest.state("notequal");
|
||||
assertThatExceptionOfType(OAuth2AuthorizationException.class).isThrownBy(() -> authenticate());
|
||||
assertThatExceptionOfType(OAuth2AuthorizationException.class).isThrownBy(this::authenticate);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+10
-12
@@ -478,12 +478,11 @@ public class ClientRegistrationsTests {
|
||||
final Dispatcher dispatcher = new Dispatcher() {
|
||||
@Override
|
||||
public MockResponse dispatch(RecordedRequest request) {
|
||||
switch (request.getPath()) {
|
||||
case "/.well-known/oauth-authorization-server/issuer1":
|
||||
case "/.well-known/oauth-authorization-server/":
|
||||
return buildSuccessMockResponse(responseBody);
|
||||
}
|
||||
return new MockResponse().setResponseCode(404);
|
||||
return switch (request.getPath()) {
|
||||
case "/.well-known/oauth-authorization-server/issuer1", "/.well-known/oauth-authorization-server/" ->
|
||||
buildSuccessMockResponse(responseBody);
|
||||
default -> new MockResponse().setResponseCode(404);
|
||||
};
|
||||
}
|
||||
};
|
||||
this.server.setDispatcher(dispatcher);
|
||||
@@ -514,12 +513,11 @@ public class ClientRegistrationsTests {
|
||||
final Dispatcher dispatcher = new Dispatcher() {
|
||||
@Override
|
||||
public MockResponse dispatch(RecordedRequest request) {
|
||||
switch (request.getPath()) {
|
||||
case "/issuer1/.well-known/openid-configuration":
|
||||
case "/.well-known/openid-configuration/":
|
||||
return buildSuccessMockResponse(responseBody);
|
||||
}
|
||||
return new MockResponse().setResponseCode(404);
|
||||
return switch (request.getPath()) {
|
||||
case "/issuer1/.well-known/openid-configuration", "/.well-known/openid-configuration/" ->
|
||||
buildSuccessMockResponse(responseBody);
|
||||
default -> new MockResponse().setResponseCode(404);
|
||||
};
|
||||
}
|
||||
};
|
||||
this.server.setDispatcher(dispatcher);
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ final class ReactiveJwtDecoderProviderConfigurationUtils {
|
||||
}
|
||||
Assert.notEmpty(jwsAlgorithms, "Failed to find any algorithms from the JWK set");
|
||||
return jwsAlgorithms;
|
||||
}).onErrorMap(KeySourceException.class, (ex) -> new IllegalStateException(ex));
|
||||
}).onErrorMap(KeySourceException.class, IllegalStateException::new);
|
||||
}
|
||||
|
||||
static Mono<Map<String, Object>> getConfigurationForIssuerLocation(String issuer, WebClient web) {
|
||||
|
||||
+2
-2
@@ -61,10 +61,10 @@ class ReactiveRemoteJWKSource implements ReactiveJWKSource {
|
||||
public Mono<List<JWK>> get(JWKSelector jwkSelector) {
|
||||
// @formatter:off
|
||||
return this.cachedJWKSet.get()
|
||||
.switchIfEmpty(Mono.defer(() -> getJWKSet()))
|
||||
.switchIfEmpty(Mono.defer(this::getJWKSet))
|
||||
.flatMap((jwkSet) -> get(jwkSelector, jwkSet))
|
||||
.switchIfEmpty(Mono.defer(() -> getJWKSet()
|
||||
.map((jwkSet) -> jwkSelector.select(jwkSet)))
|
||||
.map(jwkSelector::select))
|
||||
);
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
+1
-2
@@ -101,10 +101,9 @@ public final class OpaqueTokenAuthenticationProvider implements AuthenticationPr
|
||||
*/
|
||||
@Override
|
||||
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
|
||||
if (!(authentication instanceof BearerTokenAuthenticationToken)) {
|
||||
if (!(authentication instanceof BearerTokenAuthenticationToken bearer)) {
|
||||
return null;
|
||||
}
|
||||
BearerTokenAuthenticationToken bearer = (BearerTokenAuthenticationToken) authentication;
|
||||
OAuth2AuthenticatedPrincipal principal = getOAuth2AuthenticatedPrincipal(bearer);
|
||||
Authentication result = this.authenticationConverter.convert(bearer.getToken(), principal);
|
||||
if (result == null) {
|
||||
|
||||
+1
-2
@@ -74,8 +74,7 @@ public final class BearerTokenAuthenticationEntryPoint implements Authentication
|
||||
if (StringUtils.hasText(error.getUri())) {
|
||||
parameters.put("error_uri", error.getUri());
|
||||
}
|
||||
if (error instanceof BearerTokenError) {
|
||||
BearerTokenError bearerTokenError = (BearerTokenError) error;
|
||||
if (error instanceof BearerTokenError bearerTokenError) {
|
||||
if (StringUtils.hasText(bearerTokenError.getScope())) {
|
||||
parameters.put("scope", bearerTokenError.getScope());
|
||||
}
|
||||
|
||||
+1
-2
@@ -82,8 +82,7 @@ public final class BearerTokenServerAuthenticationEntryPoint implements ServerAu
|
||||
if (StringUtils.hasText(error.getUri())) {
|
||||
parameters.put("error_uri", error.getUri());
|
||||
}
|
||||
if (error instanceof BearerTokenError) {
|
||||
BearerTokenError bearerTokenError = (BearerTokenError) error;
|
||||
if (error instanceof BearerTokenError bearerTokenError) {
|
||||
if (StringUtils.hasText(bearerTokenError.getScope())) {
|
||||
parameters.put("scope", bearerTokenError.getScope());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user