Make classes final where possible

Update classes that have private constructors so that they are also
declared final. In a few cases, inner-classes used private constructors
but were subclassed. These have now been changed to have package-private
constructors.

Issue gh-8945
This commit is contained in:
Phillip Webb
2020-07-24 19:03:31 -07:00
committed by Rob Winch
parent b5d499e2eb
commit 6894ff5d12
58 changed files with 229 additions and 226 deletions

View File

@@ -140,7 +140,7 @@ public final class OAuth2AuthorizationContext {
/**
* A builder for {@link OAuth2AuthorizationContext}.
*/
public static class Builder {
public static final class Builder {
private ClientRegistration clientRegistration;

View File

@@ -122,7 +122,7 @@ public final class OAuth2AuthorizeRequest {
/**
* A builder for {@link OAuth2AuthorizeRequest}.
*/
public static class Builder {
public static final class Builder {
private String clientRegistrationId;

View File

@@ -89,7 +89,7 @@ public final class OAuth2AuthorizedClientProviderBuilder {
/**
* A builder for the {@code authorization_code} grant.
*/
public class AuthorizationCodeGrantBuilder implements Builder {
public final class AuthorizationCodeGrantBuilder implements Builder {
private AuthorizationCodeGrantBuilder() {
}
@@ -131,7 +131,7 @@ public final class OAuth2AuthorizedClientProviderBuilder {
/**
* A builder for the {@code refresh_token} grant.
*/
public class RefreshTokenGrantBuilder implements Builder {
public final class RefreshTokenGrantBuilder implements Builder {
private OAuth2AccessTokenResponseClient<OAuth2RefreshTokenGrantRequest> accessTokenResponseClient;
@@ -226,7 +226,7 @@ public final class OAuth2AuthorizedClientProviderBuilder {
/**
* A builder for the {@code client_credentials} grant.
*/
public class ClientCredentialsGrantBuilder implements Builder {
public final class ClientCredentialsGrantBuilder implements Builder {
private OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> accessTokenResponseClient;
@@ -319,7 +319,7 @@ public final class OAuth2AuthorizedClientProviderBuilder {
/**
* A builder for the {@code password} grant.
*/
public class PasswordGrantBuilder implements Builder {
public final class PasswordGrantBuilder implements Builder {
private OAuth2AccessTokenResponseClient<OAuth2PasswordGrantRequest> accessTokenResponseClient;

View File

@@ -89,7 +89,7 @@ public final class ReactiveOAuth2AuthorizedClientProviderBuilder {
/**
* A builder for the {@code authorization_code} grant.
*/
public class AuthorizationCodeGrantBuilder implements Builder {
public final class AuthorizationCodeGrantBuilder implements Builder {
private AuthorizationCodeGrantBuilder() {
}
@@ -133,7 +133,7 @@ public final class ReactiveOAuth2AuthorizedClientProviderBuilder {
/**
* A builder for the {@code refresh_token} grant.
*/
public class RefreshTokenGrantBuilder implements Builder {
public final class RefreshTokenGrantBuilder implements Builder {
private ReactiveOAuth2AccessTokenResponseClient<OAuth2RefreshTokenGrantRequest> accessTokenResponseClient;
@@ -230,7 +230,7 @@ public final class ReactiveOAuth2AuthorizedClientProviderBuilder {
/**
* A builder for the {@code client_credentials} grant.
*/
public class ClientCredentialsGrantBuilder implements Builder {
public final class ClientCredentialsGrantBuilder implements Builder {
private ReactiveOAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> accessTokenResponseClient;
@@ -325,7 +325,7 @@ public final class ReactiveOAuth2AuthorizedClientProviderBuilder {
/**
* A builder for the {@code password} grant.
*/
public class PasswordGrantBuilder implements Builder {
public final class PasswordGrantBuilder implements Builder {
private ReactiveOAuth2AccessTokenResponseClient<OAuth2PasswordGrantRequest> accessTokenResponseClient;

View File

@@ -195,7 +195,7 @@ public final class ClientRegistration implements Serializable {
private Map<String, Object> configurationMetadata = Collections.emptyMap();
private ProviderDetails() {
ProviderDetails() {
}
/**
@@ -263,7 +263,7 @@ public final class ClientRegistration implements Serializable {
private String userNameAttributeName;
private UserInfoEndpoint() {
UserInfoEndpoint() {
}
/**
@@ -322,7 +322,7 @@ public final class ClientRegistration implements Serializable {
/**
* A builder for {@link ClientRegistration}.
*/
public static class Builder implements Serializable {
public static final class Builder implements Serializable {
private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;

View File

@@ -131,7 +131,7 @@ public final class ServerOAuth2AuthorizedClientExchangeFilterFunction implements
private final Mono<Authentication> currentAuthenticationMono = ReactiveSecurityContextHolder.getContext()
.map(SecurityContext::getAuthentication).defaultIfEmpty(ANONYMOUS_USER_TOKEN);
private final Mono<String> clientRegistrationIdMono = currentAuthenticationMono
private final Mono<String> clientRegistrationIdMono = this.currentAuthenticationMono
.filter(t -> this.defaultOAuth2AuthorizedClient && t instanceof OAuth2AuthenticationToken)
.cast(OAuth2AuthenticationToken.class).map(OAuth2AuthenticationToken::getAuthorizedClientRegistrationId);
@@ -472,7 +472,7 @@ public final class ServerOAuth2AuthorizedClientExchangeFilterFunction implements
private Mono<String> effectiveClientRegistrationId(ClientRequest request) {
return Mono.justOrEmpty(clientRegistrationId(request))
.switchIfEmpty(Mono.justOrEmpty(this.defaultClientRegistrationId))
.switchIfEmpty(clientRegistrationIdMono);
.switchIfEmpty(this.clientRegistrationIdMono);
}
/**
@@ -488,7 +488,7 @@ public final class ServerOAuth2AuthorizedClientExchangeFilterFunction implements
* {@link ServerWebExchange} that is active for the given request.
*/
private Mono<Optional<ServerWebExchange>> effectiveServerWebExchange(ClientRequest request) {
return Mono.justOrEmpty(serverWebExchange(request)).switchIfEmpty(currentServerWebExchangeMono)
return Mono.justOrEmpty(serverWebExchange(request)).switchIfEmpty(this.currentServerWebExchangeMono)
.map(Optional::of).defaultIfEmpty(Optional.empty());
}
@@ -534,7 +534,7 @@ public final class ServerOAuth2AuthorizedClientExchangeFilterFunction implements
this.clientResponseHandler = new AuthorizationFailureForwarder(authorizationFailureHandler);
}
private static class UnAuthenticatedReactiveOAuth2AuthorizedClientManager
private static final class UnAuthenticatedReactiveOAuth2AuthorizedClientManager
implements ReactiveOAuth2AuthorizedClientManager {
private final ReactiveClientRegistrationRepository clientRegistrationRepository;
@@ -628,7 +628,7 @@ public final class ServerOAuth2AuthorizedClientExchangeFilterFunction implements
*
* @since 5.3
*/
private class AuthorizationFailureForwarder implements ClientResponseHandler {
private final class AuthorizationFailureForwarder implements ClientResponseHandler {
/**
* A map of HTTP Status Code to OAuth 2.0 Error codes for HTTP status codes that
@@ -667,7 +667,9 @@ public final class ServerOAuth2AuthorizedClientExchangeFilterFunction implements
Mono<String> clientRegistrationId = effectiveClientRegistrationId(request);
return Mono.zip(currentAuthenticationMono, serverWebExchange, clientRegistrationId)
return Mono
.zip(ServerOAuth2AuthorizedClientExchangeFilterFunction.this.currentAuthenticationMono,
serverWebExchange, clientRegistrationId)
.flatMap(tuple3 -> handleAuthorizationFailure(tuple3.getT1(), // Authentication
// principal
tuple3.getT2().orElse(null), // ServerWebExchange exchange
@@ -723,7 +725,9 @@ public final class ServerOAuth2AuthorizedClientExchangeFilterFunction implements
Mono<String> clientRegistrationId = effectiveClientRegistrationId(request);
return Mono.zip(currentAuthenticationMono, serverWebExchange, clientRegistrationId)
return Mono
.zip(ServerOAuth2AuthorizedClientExchangeFilterFunction.this.currentAuthenticationMono,
serverWebExchange, clientRegistrationId)
.flatMap(tuple3 -> handleAuthorizationFailure(tuple3.getT1(), // Authentication
// principal
tuple3.getT2().orElse(null), // ServerWebExchange exchange
@@ -744,11 +748,13 @@ public final class ServerOAuth2AuthorizedClientExchangeFilterFunction implements
private Mono<Void> handleAuthorizationException(ClientRequest request, OAuth2AuthorizationException exception) {
Mono<Optional<ServerWebExchange>> serverWebExchange = effectiveServerWebExchange(request);
return Mono.zip(currentAuthenticationMono, serverWebExchange)
.flatMap(tuple2 -> handleAuthorizationFailure(tuple2.getT1(), // Authentication
return Mono.zip(ServerOAuth2AuthorizedClientExchangeFilterFunction.this.currentAuthenticationMono,
serverWebExchange).flatMap(
tuple2 -> handleAuthorizationFailure(tuple2.getT1(), // Authentication
// principal
tuple2.getT2().orElse(null), // ServerWebExchange exchange
exception));
tuple2.getT2().orElse(null), // ServerWebExchange
// exchange
exception));
}
/**

View File

@@ -637,7 +637,7 @@ public final class ServletOAuth2AuthorizedClientExchangeFilterFunction implement
*
* @since 5.3
*/
private static class AuthorizationFailureForwarder implements ClientResponseHandler {
private static final class AuthorizationFailureForwarder implements ClientResponseHandler {
/**
* A map of HTTP status code to OAuth 2.0 error code for HTTP status codes that

View File

@@ -398,7 +398,7 @@ public class JdbcOAuth2AuthorizedClientServiceTests {
return new OAuth2AuthorizedClient(clientRegistration, principal.getName(), accessToken, refreshToken);
}
private static class CustomTableDefinitionJdbcOAuth2AuthorizedClientService
private final static class CustomTableDefinitionJdbcOAuth2AuthorizedClientService
extends JdbcOAuth2AuthorizedClientService {
private static final String COLUMN_NAMES = "clientRegistrationId, " + "principalName, " + "accessTokenType, "
@@ -453,7 +453,7 @@ public class JdbcOAuth2AuthorizedClientServiceTests {
this.jdbcOperations.update(REMOVE_AUTHORIZED_CLIENT_SQL, pss);
}
private static class OAuth2AuthorizedClientRowMapper implements RowMapper<OAuth2AuthorizedClient> {
private final static class OAuth2AuthorizedClientRowMapper implements RowMapper<OAuth2AuthorizedClient> {
private final ClientRegistrationRepository clientRegistrationRepository;

View File

@@ -47,8 +47,9 @@ public class DelegatingOAuth2UserServiceTests {
@Test(expected = IllegalArgumentException.class)
@SuppressWarnings("unchecked")
public void loadUserWhenUserRequestIsNullThenThrowIllegalArgumentException() {
OAuth2UserService<OAuth2UserRequest, OAuth2User> userService = mock(OAuth2UserService.class);
DelegatingOAuth2UserService<OAuth2UserRequest, OAuth2User> delegatingUserService = new DelegatingOAuth2UserService<>(
Arrays.asList(mock(OAuth2UserService.class), mock(OAuth2UserService.class)));
Arrays.asList(userService, userService));
delegatingUserService.loadUser(null);
}

View File

@@ -94,7 +94,7 @@ public final class OAuth2AccessTokenResponse {
/**
* A builder for {@link OAuth2AccessTokenResponse}.
*/
public static class Builder {
public static final class Builder {
private String tokenValue;

View File

@@ -226,7 +226,7 @@ public final class OAuth2AuthorizationRequest implements Serializable {
/**
* A builder for {@link OAuth2AuthorizationRequest}.
*/
public static class Builder {
public static final class Builder {
private String authorizationUri;

View File

@@ -118,7 +118,7 @@ public final class OAuth2AuthorizationResponse {
/**
* A builder for {@link OAuth2AuthorizationResponse}.
*/
public static class Builder {
public static final class Builder {
private String redirectUri;