From dd965f496151c150e0dd26af398134c8b39ef46e Mon Sep 17 00:00:00 2001 From: Tran Ngoc Nhan Date: Wed, 9 Sep 2026 02:32:04 +0700 Subject: [PATCH] Apply pattern matching in Oauth2 Advanced Configuration examples Signed-off-by: Tran Ngoc Nhan --- .../ROOT/pages/reactive/oauth2/login/advanced.adoc | 8 +++----- .../modules/ROOT/pages/servlet/oauth2/login/advanced.adoc | 6 ++---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/docs/modules/ROOT/pages/reactive/oauth2/login/advanced.adoc b/docs/modules/ROOT/pages/reactive/oauth2/login/advanced.adoc index 1386480e092..2989d5f0025 100644 --- a/docs/modules/ROOT/pages/reactive/oauth2/login/advanced.adoc +++ b/docs/modules/ROOT/pages/reactive/oauth2/login/advanced.adoc @@ -361,8 +361,7 @@ public class OAuth2LoginSecurityConfig { Set mappedAuthorities = new HashSet<>(); authorities.forEach(authority -> { - if (OidcUserAuthority.class.isInstance(authority)) { - OidcUserAuthority oidcUserAuthority = (OidcUserAuthority)authority; + if (authority instanceof OidcUserAuthority oidcUserAuthority) { OidcIdToken idToken = oidcUserAuthority.getIdToken(); OidcUserInfo userInfo = oidcUserAuthority.getUserInfo(); @@ -370,8 +369,7 @@ public class OAuth2LoginSecurityConfig { // Map the claims found in idToken and/or userInfo // to one or more GrantedAuthority's and add it to mappedAuthorities - } else if (OAuth2UserAuthority.class.isInstance(authority)) { - OAuth2UserAuthority oauth2UserAuthority = (OAuth2UserAuthority)authority; + } else if (authority instanceof OAuth2UserAuthority oauth2UserAuthority) { Map userAttributes = oauth2UserAuthority.getAttributes(); @@ -675,7 +673,7 @@ The ID Token is represented as a https://tools.ietf.org/html/rfc7519[JSON Web To The `ReactiveOidcIdTokenDecoderFactory` provides a `ReactiveJwtDecoder` used for `OidcIdToken` signature verification. The default algorithm is `RS256` but may be different when assigned during client registration. For these cases, a resolver may be configured to return the expected JWS algorithm assigned for a specific client. -The JWS algorithm resolver is a `Function` that accepts a `ClientRegistration` and returns the expected `JwsAlgorithm` for the client, eg. `SignatureAlgorithm.RS256` or `MacAlgorithm.HS256` +The JWS algorithm resolver is a `Function` that accepts a `ClientRegistration` and returns the expected `JwsAlgorithm` for the client, e.g. `SignatureAlgorithm.RS256` or `MacAlgorithm.HS256` The following code shows how to configure the `OidcIdTokenDecoderFactory` `@Bean` to default to `MacAlgorithm.HS256` for all `ClientRegistration`: diff --git a/docs/modules/ROOT/pages/servlet/oauth2/login/advanced.adoc b/docs/modules/ROOT/pages/servlet/oauth2/login/advanced.adoc index 3c8488384bf..85576b6b441 100644 --- a/docs/modules/ROOT/pages/servlet/oauth2/login/advanced.adoc +++ b/docs/modules/ROOT/pages/servlet/oauth2/login/advanced.adoc @@ -483,8 +483,7 @@ public class OAuth2LoginSecurityConfig { Set mappedAuthorities = new HashSet<>(); authorities.forEach(authority -> { - if (OidcUserAuthority.class.isInstance(authority)) { - OidcUserAuthority oidcUserAuthority = (OidcUserAuthority)authority; + if (authority instanceof OidcUserAuthority oidcUserAuthority) { OidcIdToken idToken = oidcUserAuthority.getIdToken(); OidcUserInfo userInfo = oidcUserAuthority.getUserInfo(); @@ -492,8 +491,7 @@ public class OAuth2LoginSecurityConfig { // Map the claims found in idToken and/or userInfo // to one or more GrantedAuthority's and add it to mappedAuthorities - } else if (OAuth2UserAuthority.class.isInstance(authority)) { - OAuth2UserAuthority oauth2UserAuthority = (OAuth2UserAuthority)authority; + } else if (authority instanceof OAuth2UserAuthority oauth2UserAuthority) { Map userAttributes = oauth2UserAuthority.getAttributes();