Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Used pattern matching #1907

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ public Authentication authenticate(Authentication authentication) throws Authent
OAuth2Authorization.Builder authorizationBuilder = OAuth2Authorization.withRegisteredClient(registeredClient)
.principalName(clientPrincipal.getName())
.authorizationGrantType(customCodeGrantAuthentication.getGrantType());
if (generatedAccessToken instanceof ClaimAccessor) {
if (generatedAccessToken instanceof ClaimAccessor claimAccessor) {
authorizationBuilder.token(accessToken, (metadata) ->
metadata.put(
OAuth2Authorization.Token.CLAIMS_METADATA_NAME,
((ClaimAccessor) generatedAccessToken).getClaims())
claimAccessor.getClaims())
);
} else {
authorizationBuilder.accessToken(accessToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ private static void customize(OAuth2TokenContext tokenContext, Map<String, Objec
Map<String, Object> jwkJson = (Map<String, Object>) dPoPProofJwt.getHeaders().get("jwk");
try {
JWK jwk = JWK.parse(jwkJson);
if (jwk instanceof AsymmetricJWK) {
publicKey = ((AsymmetricJWK) jwk).toPublicKey();
if (jwk instanceof AsymmetricJWK asymmetricJWK) {
publicKey = asymmetricJWK.toPublicKey();
}
}
catch (Exception ignored) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse

try {
Authentication authentication = this.authenticationConverter.convert(request);
if (authentication instanceof AbstractAuthenticationToken) {
((AbstractAuthenticationToken) authentication)
if (authentication instanceof AbstractAuthenticationToken abstractAuthenticationToken) {
abstractAuthenticationToken
.setDetails(this.authenticationDetailsSource.buildDetails(request));
}
Authentication authenticationResult = this.authenticationManager.authenticate(authentication);
Expand All @@ -193,13 +193,13 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
return;
}

if (authenticationResult instanceof OAuth2AuthorizationConsentAuthenticationToken) {
if (authenticationResult instanceof OAuth2AuthorizationConsentAuthenticationToken oAuth2AuthorizationConsentAuthenticationToken) {
if (this.logger.isTraceEnabled()) {
this.logger.trace("Authorization consent is required");
}
sendAuthorizationConsent(request, response,
(OAuth2AuthorizationCodeRequestAuthenticationToken) authentication,
(OAuth2AuthorizationConsentAuthenticationToken) authenticationResult);
oAuth2AuthorizationConsentAuthenticationToken);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse

try {
Authentication authenticationRequest = this.authenticationConverter.convert(request);
if (authenticationRequest instanceof AbstractAuthenticationToken) {
((AbstractAuthenticationToken) authenticationRequest)
if (authenticationRequest instanceof AbstractAuthenticationToken abstractAuthenticationToken) {
abstractAuthenticationToken
.setDetails(this.authenticationDetailsSource.buildDetails(request));
}
if (authenticationRequest != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse

try {
Authentication deviceAuthorizationRequestAuthentication = this.authenticationConverter.convert(request);
if (deviceAuthorizationRequestAuthentication instanceof AbstractAuthenticationToken) {
((AbstractAuthenticationToken) deviceAuthorizationRequestAuthentication)
if (deviceAuthorizationRequestAuthentication instanceof AbstractAuthenticationToken abstractAuthenticationToken) {
abstractAuthenticationToken
.setDetails(this.authenticationDetailsSource.buildDetails(request));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse

try {
Authentication authentication = this.authenticationConverter.convert(request);
if (authentication instanceof AbstractAuthenticationToken) {
((AbstractAuthenticationToken) authentication)
if (authentication instanceof AbstractAuthenticationToken abstractAuthenticationToken) {
abstractAuthenticationToken
.setDetails(this.authenticationDetailsSource.buildDetails(request));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
if (authorizationGrantAuthentication == null) {
throwError(OAuth2ErrorCodes.UNSUPPORTED_GRANT_TYPE, OAuth2ParameterNames.GRANT_TYPE);
}
if (authorizationGrantAuthentication instanceof AbstractAuthenticationToken) {
((AbstractAuthenticationToken) authorizationGrantAuthentication)
if (authorizationGrantAuthentication instanceof AbstractAuthenticationToken abstractAuthenticationToken) {
abstractAuthenticationToken
.setDetails(this.authenticationDetailsSource.buildDetails(request));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse

try {
Authentication tokenRevocationAuthentication = this.authenticationConverter.convert(request);
if (tokenRevocationAuthentication instanceof AbstractAuthenticationToken) {
((AbstractAuthenticationToken) tokenRevocationAuthentication)
if (tokenRevocationAuthentication instanceof AbstractAuthenticationToken abstractAuthenticationToken) {
abstractAuthenticationToken
.setDetails(this.authenticationDetailsSource.buildDetails(request));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public void onAuthenticationFailure(HttpServletRequest request, HttpServletRespo
ServletServerHttpResponse httpResponse = new ServletServerHttpResponse(response);
httpResponse.setStatusCode(HttpStatus.BAD_REQUEST);

if (authenticationException instanceof OAuth2AuthenticationException) {
OAuth2Error error = ((OAuth2AuthenticationException) authenticationException).getError();
if (authenticationException instanceof OAuth2AuthenticationException oAuth2AuthenticationException) {
OAuth2Error error = oAuth2AuthenticationException.getError();
this.errorResponseConverter.write(error, null, httpResponse);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public final class FederatedIdentityAuthenticationSuccessHandler implements Auth
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
if (authentication instanceof OAuth2AuthenticationToken) {
if (authentication.getPrincipal() instanceof OidcUser) {
this.oidcUserHandler.accept((OidcUser) authentication.getPrincipal());
} else if (authentication.getPrincipal() instanceof OAuth2User) {
this.oauth2UserHandler.accept((OAuth2User) authentication.getPrincipal());
if (authentication.getPrincipal() instanceof OidcUser oidcUser) {
this.oidcUserHandler.accept(oidcUser);
} else if (authentication.getPrincipal() instanceof OAuth2User oAuth2User) {
this.oauth2UserHandler.accept(oAuth2User);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,10 @@ public void customize(JwtEncodingContext context) {

private Map<String, Object> extractClaims(Authentication principal) {
Map<String, Object> claims;
if (principal.getPrincipal() instanceof OidcUser) {
OidcUser oidcUser = (OidcUser) principal.getPrincipal();
if (principal.getPrincipal() instanceof OidcUser oidcUser) {
OidcIdToken idToken = oidcUser.getIdToken();
claims = idToken.getClaims();
} else if (principal.getPrincipal() instanceof OAuth2User) {
OAuth2User oauth2User = (OAuth2User) principal.getPrincipal();
} else if (principal.getPrincipal() instanceof OAuth2User oauth2User) {
claims = oauth2User.getAttributes();
} else {
claims = Collections.emptyMap();
Expand Down