Skip to content

Commit 6e73d09

Browse files
committed
Used pattern matching
1 parent 6311e44 commit 6e73d09

File tree

11 files changed

+26
-28
lines changed

11 files changed

+26
-28
lines changed

docs/src/main/java/sample/extgrant/CustomCodeGrantAuthenticationProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ public Authentication authenticate(Authentication authentication) throws Authent
9191
OAuth2Authorization.Builder authorizationBuilder = OAuth2Authorization.withRegisteredClient(registeredClient)
9292
.principalName(clientPrincipal.getName())
9393
.authorizationGrantType(customCodeGrantAuthentication.getGrantType());
94-
if (generatedAccessToken instanceof ClaimAccessor) {
94+
if (generatedAccessToken instanceof ClaimAccessor claimAccessor) {
9595
authorizationBuilder.token(accessToken, (metadata) ->
9696
metadata.put(
9797
OAuth2Authorization.Token.CLAIMS_METADATA_NAME,
98-
((ClaimAccessor) generatedAccessToken).getClaims())
98+
claimAccessor.getClaims())
9999
);
100100
} else {
101101
authorizationBuilder.accessToken(accessToken);

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/config/annotation/web/configurers/DefaultOAuth2TokenCustomizers.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ private static void customize(OAuth2TokenContext tokenContext, Map<String, Objec
9696
Map<String, Object> jwkJson = (Map<String, Object>) dPoPProofJwt.getHeaders().get("jwk");
9797
try {
9898
JWK jwk = JWK.parse(jwkJson);
99-
if (jwk instanceof AsymmetricJWK) {
100-
publicKey = ((AsymmetricJWK) jwk).toPublicKey();
99+
if (jwk instanceof AsymmetricJWK asymmetricJWK) {
100+
publicKey = asymmetricJWK.toPublicKey();
101101
}
102102
}
103103
catch (Exception ignored) {

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/web/OAuth2AuthorizationEndpointFilter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
178178

179179
try {
180180
Authentication authentication = this.authenticationConverter.convert(request);
181-
if (authentication instanceof AbstractAuthenticationToken) {
182-
((AbstractAuthenticationToken) authentication)
181+
if (authentication instanceof AbstractAuthenticationToken abstractAuthenticationToken) {
182+
abstractAuthenticationToken
183183
.setDetails(this.authenticationDetailsSource.buildDetails(request));
184184
}
185185
Authentication authenticationResult = this.authenticationManager.authenticate(authentication);
@@ -193,13 +193,13 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
193193
return;
194194
}
195195

196-
if (authenticationResult instanceof OAuth2AuthorizationConsentAuthenticationToken) {
196+
if (authenticationResult instanceof OAuth2AuthorizationConsentAuthenticationToken oAuth2AuthorizationConsentAuthenticationToken) {
197197
if (this.logger.isTraceEnabled()) {
198198
this.logger.trace("Authorization consent is required");
199199
}
200200
sendAuthorizationConsent(request, response,
201201
(OAuth2AuthorizationCodeRequestAuthenticationToken) authentication,
202-
(OAuth2AuthorizationConsentAuthenticationToken) authenticationResult);
202+
oAuth2AuthorizationConsentAuthenticationToken);
203203
return;
204204
}
205205

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/web/OAuth2ClientAuthenticationFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
132132

133133
try {
134134
Authentication authenticationRequest = this.authenticationConverter.convert(request);
135-
if (authenticationRequest instanceof AbstractAuthenticationToken) {
136-
((AbstractAuthenticationToken) authenticationRequest)
135+
if (authenticationRequest instanceof AbstractAuthenticationToken abstractAuthenticationToken) {
136+
abstractAuthenticationToken
137137
.setDetails(this.authenticationDetailsSource.buildDetails(request));
138138
}
139139
if (authenticationRequest != null) {

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/web/OAuth2DeviceAuthorizationEndpointFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
129129

130130
try {
131131
Authentication deviceAuthorizationRequestAuthentication = this.authenticationConverter.convert(request);
132-
if (deviceAuthorizationRequestAuthentication instanceof AbstractAuthenticationToken) {
133-
((AbstractAuthenticationToken) deviceAuthorizationRequestAuthentication)
132+
if (deviceAuthorizationRequestAuthentication instanceof AbstractAuthenticationToken abstractAuthenticationToken) {
133+
abstractAuthenticationToken
134134
.setDetails(this.authenticationDetailsSource.buildDetails(request));
135135
}
136136

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/web/OAuth2DeviceVerificationEndpointFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
155155

156156
try {
157157
Authentication authentication = this.authenticationConverter.convert(request);
158-
if (authentication instanceof AbstractAuthenticationToken) {
159-
((AbstractAuthenticationToken) authentication)
158+
if (authentication instanceof AbstractAuthenticationToken abstractAuthenticationToken) {
159+
abstractAuthenticationToken
160160
.setDetails(this.authenticationDetailsSource.buildDetails(request));
161161
}
162162

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/web/OAuth2TokenEndpointFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
161161
if (authorizationGrantAuthentication == null) {
162162
throwError(OAuth2ErrorCodes.UNSUPPORTED_GRANT_TYPE, OAuth2ParameterNames.GRANT_TYPE);
163163
}
164-
if (authorizationGrantAuthentication instanceof AbstractAuthenticationToken) {
165-
((AbstractAuthenticationToken) authorizationGrantAuthentication)
164+
if (authorizationGrantAuthentication instanceof AbstractAuthenticationToken abstractAuthenticationToken) {
165+
abstractAuthenticationToken
166166
.setDetails(this.authenticationDetailsSource.buildDetails(request));
167167
}
168168

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/web/OAuth2TokenRevocationEndpointFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
114114

115115
try {
116116
Authentication tokenRevocationAuthentication = this.authenticationConverter.convert(request);
117-
if (tokenRevocationAuthentication instanceof AbstractAuthenticationToken) {
118-
((AbstractAuthenticationToken) tokenRevocationAuthentication)
117+
if (tokenRevocationAuthentication instanceof AbstractAuthenticationToken abstractAuthenticationToken) {
118+
abstractAuthenticationToken
119119
.setDetails(this.authenticationDetailsSource.buildDetails(request));
120120
}
121121

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/web/authentication/OAuth2ErrorAuthenticationFailureHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public void onAuthenticationFailure(HttpServletRequest request, HttpServletRespo
5555
ServletServerHttpResponse httpResponse = new ServletServerHttpResponse(response);
5656
httpResponse.setStatusCode(HttpStatus.BAD_REQUEST);
5757

58-
if (authenticationException instanceof OAuth2AuthenticationException) {
59-
OAuth2Error error = ((OAuth2AuthenticationException) authenticationException).getError();
58+
if (authenticationException instanceof OAuth2AuthenticationException oAuth2AuthenticationException) {
59+
OAuth2Error error = oAuth2AuthenticationException.getError();
6060
this.errorResponseConverter.write(error, null, httpResponse);
6161
}
6262
else {

samples/demo-authorizationserver/src/main/java/sample/federation/FederatedIdentityAuthenticationSuccessHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ public final class FederatedIdentityAuthenticationSuccessHandler implements Auth
5050
@Override
5151
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
5252
if (authentication instanceof OAuth2AuthenticationToken) {
53-
if (authentication.getPrincipal() instanceof OidcUser) {
54-
this.oidcUserHandler.accept((OidcUser) authentication.getPrincipal());
55-
} else if (authentication.getPrincipal() instanceof OAuth2User) {
56-
this.oauth2UserHandler.accept((OAuth2User) authentication.getPrincipal());
53+
if (authentication.getPrincipal() instanceof OidcUser oidcUser) {
54+
this.oidcUserHandler.accept(oidcUser);
55+
} else if (authentication.getPrincipal() instanceof OAuth2User oAuth2User) {
56+
this.oauth2UserHandler.accept(oAuth2User);
5757
}
5858
}
5959

0 commit comments

Comments
 (0)