|
@@ -19,10 +19,13 @@ package org.springframework.security.oauth2.server.resource.authentication;
|
|
|
import java.util.Collection;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+import org.jspecify.annotations.Nullable;
|
|
|
+
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
import org.springframework.security.core.GrantedAuthority;
|
|
|
import org.springframework.security.core.Transient;
|
|
|
import org.springframework.security.oauth2.jwt.Jwt;
|
|
|
+import org.springframework.util.Assert;
|
|
|
|
|
|
/**
|
|
|
* An implementation of an {@link AbstractOAuth2TokenAuthenticationToken} representing a
|
|
@@ -96,9 +99,10 @@ public class JwtAuthenticationToken extends AbstractOAuth2TokenAuthenticationTok
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * A builder preserving the concrete {@link Authentication} type
|
|
|
+ * A builder for {@link JwtAuthenticationToken} instances
|
|
|
*
|
|
|
* @since 7.0
|
|
|
+ * @see Authentication.Builder
|
|
|
*/
|
|
|
public static class Builder<B extends Builder<B>> extends AbstractOAuth2TokenAuthenticationBuilder<Jwt, B> {
|
|
|
|
|
@@ -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;
|