diff --git a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/authentication/OAuth2AuthenticationToken.java b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/authentication/OAuth2AuthenticationToken.java index 8e2796355c..44e6875dc1 100644 --- a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/authentication/OAuth2AuthenticationToken.java +++ b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/authentication/OAuth2AuthenticationToken.java @@ -101,7 +101,7 @@ public class OAuth2AuthenticationToken extends AbstractAuthenticationToken { } /** - * A builder preserving the concrete {@link Authentication} type + * A builder of {@link OAuth2AuthenticationToken} instances * * @since 7.0 */ @@ -124,6 +124,14 @@ public class OAuth2AuthenticationToken extends AbstractAuthenticationToken { return (B) this; } + /** + * Use this + * {@link org.springframework.security.oauth2.client.registration.ClientRegistration} + * {@code registrationId}. + * @param authorizedClientRegistrationId the registration id to use + * @return the {@link Builder} for further configurations + * @see OAuth2AuthenticationToken#getAuthorizedClientRegistrationId + */ public B authorizedClientRegistrationId(String authorizedClientRegistrationId) { this.authorizedClientRegistrationId = authorizedClientRegistrationId; return (B) this; diff --git a/oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/authentication/AbstractOAuth2TokenAuthenticationToken.java b/oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/authentication/AbstractOAuth2TokenAuthenticationToken.java index 079f738460..86ae387e00 100644 --- a/oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/authentication/AbstractOAuth2TokenAuthenticationToken.java +++ b/oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/authentication/AbstractOAuth2TokenAuthenticationToken.java @@ -118,8 +118,9 @@ public abstract class AbstractOAuth2TokenAuthenticationToken getTokenAttributes(); /** - * A builder preserving the concrete {@link Authentication} type + * A builder for {@link AbstractOAuth2TokenAuthenticationToken} implementations * + * @param * @since 7.0 */ public abstract static class AbstractOAuth2TokenAuthenticationBuilder> @@ -152,8 +153,13 @@ public abstract class AbstractOAuth2TokenAuthenticationToken> extends AbstractOAuth2TokenAuthenticationBuilder { @@ -109,6 +113,44 @@ public class JwtAuthenticationToken extends AbstractOAuth2TokenAuthenticationTok this.name = token.getName(); } + /** + * A synonym for {@link #token(Jwt)} + * @return the {@link Builder} for further configurations + */ + @Override + public B principal(@Nullable Object principal) { + Assert.isInstanceOf(Jwt.class, principal, "principal must be of type Jwt"); + return token((Jwt) principal); + } + + /** + * A synonym for {@link #token(Jwt)} + * @return the {@link Builder} for further configurations + */ + @Override + public B credentials(@Nullable Object credentials) { + Assert.isInstanceOf(Jwt.class, credentials, "credentials must be of type Jwt"); + return token((Jwt) credentials); + } + + /** + * Use this {@code token} as the token, principal, and credentials. Also sets the + * {@code name} to {@link Jwt#getSubject}. + * @param token the token to use + * @return the {@link Builder} for further configurations + */ + @Override + public B token(Jwt token) { + super.principal(token); + super.credentials(token); + return super.token(token).name(token.getSubject()); + } + + /** + * The name to use. + * @param name the name to use + * @return the {@link Builder} for further configurations + */ public B name(String name) { this.name = name; return (B) this;