From 79fd00434645081ea42a0d3ab39cfd1f1935e0ce Mon Sep 17 00:00:00 2001 From: Joe Grandja Date: Thu, 22 Jul 2021 03:55:35 -0400 Subject: [PATCH] Use OAuth2Token in OAuth2Authorization Closes gh-364 --- .../authorization/OAuth2Authorization.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/OAuth2Authorization.java b/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/OAuth2Authorization.java index b9cc4ee3..8e5f596c 100644 --- a/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/OAuth2Authorization.java +++ b/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/OAuth2Authorization.java @@ -25,12 +25,12 @@ import java.util.UUID; import java.util.function.Consumer; import org.springframework.lang.Nullable; -import org.springframework.security.oauth2.core.Version; -import org.springframework.security.oauth2.core.AbstractOAuth2Token; import org.springframework.security.oauth2.core.AuthorizationGrantType; import org.springframework.security.oauth2.core.OAuth2AccessToken; import org.springframework.security.oauth2.core.OAuth2RefreshToken; import org.springframework.security.oauth2.core.OAuth2RefreshToken2; +import org.springframework.security.oauth2.core.OAuth2Token; +import org.springframework.security.oauth2.core.Version; import org.springframework.security.oauth2.server.authorization.client.RegisteredClient; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -46,7 +46,7 @@ import org.springframework.util.StringUtils; * @since 0.0.1 * @see RegisteredClient * @see AuthorizationGrantType - * @see AbstractOAuth2Token + * @see OAuth2Token * @see OAuth2AccessToken * @see OAuth2RefreshToken */ @@ -64,7 +64,7 @@ public class OAuth2Authorization implements Serializable { private String registeredClientId; private String principalName; private AuthorizationGrantType authorizationGrantType; - private Map, Token> tokens; + private Map, Token> tokens; private Map attributes; protected OAuth2Authorization() { @@ -134,7 +134,7 @@ public class OAuth2Authorization implements Serializable { */ @Nullable @SuppressWarnings("unchecked") - public Token getToken(Class tokenType) { + public Token getToken(Class tokenType) { Assert.notNull(tokenType, "tokenType cannot be null"); Token token = this.tokens.get(tokenType); return token != null ? (Token) token : null; @@ -149,7 +149,7 @@ public class OAuth2Authorization implements Serializable { */ @Nullable @SuppressWarnings("unchecked") - public Token getToken(String tokenValue) { + public Token getToken(String tokenValue) { Assert.hasText(tokenValue, "tokenValue cannot be empty"); Token token = this.tokens.values().stream() .filter(t -> t.getToken().getTokenValue().equals(tokenValue)) @@ -237,7 +237,7 @@ public class OAuth2Authorization implements Serializable { * @author Joe Grandja * @since 0.1.0 */ - public static class Token implements Serializable { + public static class Token implements Serializable { private static final long serialVersionUID = Version.SERIAL_VERSION_UID; protected static final String TOKEN_METADATA_BASE = "metadata.token."; @@ -264,9 +264,9 @@ public class OAuth2Authorization implements Serializable { } /** - * Returns the token of type {@link AbstractOAuth2Token}. + * Returns the token of type {@link OAuth2Token}. * - * @return the token of type {@link AbstractOAuth2Token} + * @return the token of type {@link OAuth2Token} */ public T getToken() { return this.token; @@ -380,7 +380,7 @@ public class OAuth2Authorization implements Serializable { private final String registeredClientId; private String principalName; private AuthorizationGrantType authorizationGrantType; - private Map, Token> tokens = new HashMap<>(); + private Map, Token> tokens = new HashMap<>(); private final Map attributes = new HashMap<>(); protected Builder(String registeredClientId) { @@ -441,25 +441,25 @@ public class OAuth2Authorization implements Serializable { } /** - * Sets the {@link AbstractOAuth2Token token}. + * Sets the {@link OAuth2Token token}. * * @param token the token * @param the type of the token * @return the {@link Builder} */ - public Builder token(T token) { + public Builder token(T token) { return token(token, (metadata) -> {}); } /** - * Sets the {@link AbstractOAuth2Token token} and associated metadata. + * Sets the {@link OAuth2Token token} and associated metadata. * * @param token the token * @param metadataConsumer a {@code Consumer} of the metadata {@code Map} * @param the type of the token * @return the {@link Builder} */ - public Builder token(T token, + public Builder token(T token, Consumer> metadataConsumer) { Assert.notNull(token, "token cannot be null"); @@ -469,7 +469,7 @@ public class OAuth2Authorization implements Serializable { metadata.putAll(existingToken.getMetadata()); } metadataConsumer.accept(metadata); - Class tokenClass = token.getClass(); + Class tokenClass = token.getClass(); if (tokenClass.equals(OAuth2RefreshToken2.class)) { tokenClass = OAuth2RefreshToken.class; } @@ -477,7 +477,7 @@ public class OAuth2Authorization implements Serializable { return this; } - protected final Builder tokens(Map, Token> tokens) { + protected final Builder tokens(Map, Token> tokens) { this.tokens = new HashMap<>(tokens); return this; }