Skip to content

Commit 79fd004

Browse files
committed
Use OAuth2Token in OAuth2Authorization
Closes spring-projectsgh-364
1 parent 70142f3 commit 79fd004

File tree

1 file changed

+16
-16
lines changed
  • oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization

1 file changed

+16
-16
lines changed

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/OAuth2Authorization.java

+16-16
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
import java.util.function.Consumer;
2626

2727
import org.springframework.lang.Nullable;
28-
import org.springframework.security.oauth2.core.Version;
29-
import org.springframework.security.oauth2.core.AbstractOAuth2Token;
3028
import org.springframework.security.oauth2.core.AuthorizationGrantType;
3129
import org.springframework.security.oauth2.core.OAuth2AccessToken;
3230
import org.springframework.security.oauth2.core.OAuth2RefreshToken;
3331
import org.springframework.security.oauth2.core.OAuth2RefreshToken2;
32+
import org.springframework.security.oauth2.core.OAuth2Token;
33+
import org.springframework.security.oauth2.core.Version;
3434
import org.springframework.security.oauth2.server.authorization.client.RegisteredClient;
3535
import org.springframework.util.Assert;
3636
import org.springframework.util.CollectionUtils;
@@ -46,7 +46,7 @@
4646
* @since 0.0.1
4747
* @see RegisteredClient
4848
* @see AuthorizationGrantType
49-
* @see AbstractOAuth2Token
49+
* @see OAuth2Token
5050
* @see OAuth2AccessToken
5151
* @see OAuth2RefreshToken
5252
*/
@@ -64,7 +64,7 @@ public class OAuth2Authorization implements Serializable {
6464
private String registeredClientId;
6565
private String principalName;
6666
private AuthorizationGrantType authorizationGrantType;
67-
private Map<Class<? extends AbstractOAuth2Token>, Token<?>> tokens;
67+
private Map<Class<? extends OAuth2Token>, Token<?>> tokens;
6868
private Map<String, Object> attributes;
6969

7070
protected OAuth2Authorization() {
@@ -134,7 +134,7 @@ public Token<OAuth2RefreshToken> getRefreshToken() {
134134
*/
135135
@Nullable
136136
@SuppressWarnings("unchecked")
137-
public <T extends AbstractOAuth2Token> Token<T> getToken(Class<T> tokenType) {
137+
public <T extends OAuth2Token> Token<T> getToken(Class<T> tokenType) {
138138
Assert.notNull(tokenType, "tokenType cannot be null");
139139
Token<?> token = this.tokens.get(tokenType);
140140
return token != null ? (Token<T>) token : null;
@@ -149,7 +149,7 @@ public <T extends AbstractOAuth2Token> Token<T> getToken(Class<T> tokenType) {
149149
*/
150150
@Nullable
151151
@SuppressWarnings("unchecked")
152-
public <T extends AbstractOAuth2Token> Token<T> getToken(String tokenValue) {
152+
public <T extends OAuth2Token> Token<T> getToken(String tokenValue) {
153153
Assert.hasText(tokenValue, "tokenValue cannot be empty");
154154
Token<?> token = this.tokens.values().stream()
155155
.filter(t -> t.getToken().getTokenValue().equals(tokenValue))
@@ -237,7 +237,7 @@ public static Builder from(OAuth2Authorization authorization) {
237237
* @author Joe Grandja
238238
* @since 0.1.0
239239
*/
240-
public static class Token<T extends AbstractOAuth2Token> implements Serializable {
240+
public static class Token<T extends OAuth2Token> implements Serializable {
241241
private static final long serialVersionUID = Version.SERIAL_VERSION_UID;
242242
protected static final String TOKEN_METADATA_BASE = "metadata.token.";
243243

@@ -264,9 +264,9 @@ protected Token(T token, Map<String, Object> metadata) {
264264
}
265265

266266
/**
267-
* Returns the token of type {@link AbstractOAuth2Token}.
267+
* Returns the token of type {@link OAuth2Token}.
268268
*
269-
* @return the token of type {@link AbstractOAuth2Token}
269+
* @return the token of type {@link OAuth2Token}
270270
*/
271271
public T getToken() {
272272
return this.token;
@@ -380,7 +380,7 @@ public static class Builder implements Serializable {
380380
private final String registeredClientId;
381381
private String principalName;
382382
private AuthorizationGrantType authorizationGrantType;
383-
private Map<Class<? extends AbstractOAuth2Token>, Token<?>> tokens = new HashMap<>();
383+
private Map<Class<? extends OAuth2Token>, Token<?>> tokens = new HashMap<>();
384384
private final Map<String, Object> attributes = new HashMap<>();
385385

386386
protected Builder(String registeredClientId) {
@@ -441,25 +441,25 @@ public Builder refreshToken(OAuth2RefreshToken refreshToken) {
441441
}
442442

443443
/**
444-
* Sets the {@link AbstractOAuth2Token token}.
444+
* Sets the {@link OAuth2Token token}.
445445
*
446446
* @param token the token
447447
* @param <T> the type of the token
448448
* @return the {@link Builder}
449449
*/
450-
public <T extends AbstractOAuth2Token> Builder token(T token) {
450+
public <T extends OAuth2Token> Builder token(T token) {
451451
return token(token, (metadata) -> {});
452452
}
453453

454454
/**
455-
* Sets the {@link AbstractOAuth2Token token} and associated metadata.
455+
* Sets the {@link OAuth2Token token} and associated metadata.
456456
*
457457
* @param token the token
458458
* @param metadataConsumer a {@code Consumer} of the metadata {@code Map}
459459
* @param <T> the type of the token
460460
* @return the {@link Builder}
461461
*/
462-
public <T extends AbstractOAuth2Token> Builder token(T token,
462+
public <T extends OAuth2Token> Builder token(T token,
463463
Consumer<Map<String, Object>> metadataConsumer) {
464464

465465
Assert.notNull(token, "token cannot be null");
@@ -469,15 +469,15 @@ public <T extends AbstractOAuth2Token> Builder token(T token,
469469
metadata.putAll(existingToken.getMetadata());
470470
}
471471
metadataConsumer.accept(metadata);
472-
Class<? extends AbstractOAuth2Token> tokenClass = token.getClass();
472+
Class<? extends OAuth2Token> tokenClass = token.getClass();
473473
if (tokenClass.equals(OAuth2RefreshToken2.class)) {
474474
tokenClass = OAuth2RefreshToken.class;
475475
}
476476
this.tokens.put(tokenClass, new Token<>(token, metadata));
477477
return this;
478478
}
479479

480-
protected final Builder tokens(Map<Class<? extends AbstractOAuth2Token>, Token<?>> tokens) {
480+
protected final Builder tokens(Map<Class<? extends OAuth2Token>, Token<?>> tokens) {
481481
this.tokens = new HashMap<>(tokens);
482482
return this;
483483
}

0 commit comments

Comments
 (0)