Using modern Java features

This commit is contained in:
Krzysztof Krason
2023-01-20 16:45:41 +01:00
committed by Josh Cummings
parent 7e01ebdd92
commit 9b603b99ab
72 changed files with 206 additions and 402 deletions

View File

@@ -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(),

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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);