Skip to content

Commit 5c6879d

Browse files
author
Steve Riesenberg
committed
Polish gh-1143
1 parent cf7ecc1 commit 5c6879d

File tree

3 files changed

+16
-62
lines changed

3 files changed

+16
-62
lines changed

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@
4747
import org.springframework.jdbc.support.lob.LobHandler;
4848
import org.springframework.lang.Nullable;
4949
import org.springframework.security.jackson2.SecurityJackson2Modules;
50-
import org.springframework.security.oauth2.core.*;
50+
import org.springframework.security.oauth2.core.AuthorizationGrantType;
51+
import org.springframework.security.oauth2.core.OAuth2AccessToken;
52+
import org.springframework.security.oauth2.core.OAuth2DeviceCode;
53+
import org.springframework.security.oauth2.core.OAuth2RefreshToken;
54+
import org.springframework.security.oauth2.core.OAuth2Token;
55+
import org.springframework.security.oauth2.core.OAuth2UserCode;
5156
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
5257
import org.springframework.security.oauth2.core.oidc.OidcIdToken;
5358
import org.springframework.security.oauth2.core.oidc.endpoint.OidcParameterNames;
@@ -118,8 +123,8 @@ public class JdbcOAuth2AuthorizationService implements OAuth2AuthorizationServic
118123

119124
private static final String PK_FILTER = "id = ?";
120125
private static final String UNKNOWN_TOKEN_TYPE_FILTER = "state = ? OR authorization_code_value = ? OR "
121-
+ "access_token_value = ? OR oidc_id_token_value = ? OR refresh_token_value = ? OR "
122-
+ "user_code_value = ? OR device_code_value = ?";
126+
+ "access_token_value = ? OR oidc_id_token_value = ? OR refresh_token_value = ? OR user_code_value = ? OR "
127+
+ "device_code_value = ?";
123128

124129
private static final String STATE_FILTER = "state = ?";
125130
private static final String AUTHORIZATION_CODE_FILTER = "authorization_code_value = ?";
@@ -272,10 +277,10 @@ public OAuth2Authorization findByToken(String token, @Nullable OAuth2TokenType t
272277
} else if (OAuth2TokenType.REFRESH_TOKEN.equals(tokenType)) {
273278
parameters.add(mapToSqlParameter("refresh_token_value", token));
274279
return findBy(REFRESH_TOKEN_FILTER, parameters);
275-
} else if (OAuth2TokenType.USER_CODE.equals(tokenType)) {
280+
} else if (OAuth2ParameterNames.USER_CODE.equals(tokenType.getValue())) {
276281
parameters.add(mapToSqlParameter("user_code_value", token));
277282
return findBy(USER_CODE_FILTER, parameters);
278-
} else if (OAuth2TokenType.DEVICE_CODE.equals(tokenType)) {
283+
} else if (OAuth2ParameterNames.DEVICE_CODE.equals(tokenType.getValue())) {
279284
parameters.add(mapToSqlParameter("device_code_value", token));
280285
return findBy(DEVICE_CODE_FILTER, parameters);
281286
}
@@ -447,11 +452,7 @@ public OAuth2Authorization mapRow(ResultSet rs, int rowNum) throws SQLException
447452
String userCodeValue = getLobValue(rs, "user_code_value");
448453
if (StringUtils.hasText(userCodeValue)) {
449454
tokenIssuedAt = rs.getTimestamp("user_code_issued_at").toInstant();
450-
tokenExpiresAt = null;
451-
Timestamp userCodeExpiresAt = rs.getTimestamp("user_code_expires_at");
452-
if (userCodeExpiresAt != null) {
453-
tokenExpiresAt = userCodeExpiresAt.toInstant();
454-
}
455+
tokenExpiresAt = rs.getTimestamp("user_code_expires_at").toInstant();
455456
Map<String, Object> userCodeMetadata = parseMap(getLobValue(rs, "user_code_metadata"));
456457

457458
OAuth2UserCode userCode = new OAuth2UserCode(userCodeValue, tokenIssuedAt, tokenExpiresAt);
@@ -461,11 +462,7 @@ public OAuth2Authorization mapRow(ResultSet rs, int rowNum) throws SQLException
461462
String deviceCodeValue = getLobValue(rs, "device_code_value");
462463
if (StringUtils.hasText(deviceCodeValue)) {
463464
tokenIssuedAt = rs.getTimestamp("device_code_issued_at").toInstant();
464-
tokenExpiresAt = null;
465-
Timestamp deviceCodeExpiresAt = rs.getTimestamp("device_code_expires_at");
466-
if (deviceCodeExpiresAt != null) {
467-
tokenExpiresAt = deviceCodeExpiresAt.toInstant();
468-
}
465+
tokenExpiresAt = rs.getTimestamp("device_code_expires_at").toInstant();
469466
Map<String, Object> deviceCodeMetadata = parseMap(getLobValue(rs, "device_code_metadata"));
470467

471468
OAuth2DeviceCode deviceCode = new OAuth2DeviceCode(deviceCodeValue, tokenIssuedAt, tokenExpiresAt);

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

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
import java.util.function.Consumer;
2828

2929
import org.springframework.lang.Nullable;
30-
import org.springframework.security.oauth2.core.*;
30+
import org.springframework.security.oauth2.core.AuthorizationGrantType;
31+
import org.springframework.security.oauth2.core.OAuth2AccessToken;
32+
import org.springframework.security.oauth2.core.OAuth2RefreshToken;
33+
import org.springframework.security.oauth2.core.OAuth2Token;
3134
import org.springframework.security.oauth2.server.authorization.client.RegisteredClient;
3235
import org.springframework.security.oauth2.server.authorization.util.SpringAuthorizationServerVersion;
3336
import org.springframework.util.Assert;
@@ -47,8 +50,6 @@
4750
* @see OAuth2Token
4851
* @see OAuth2AccessToken
4952
* @see OAuth2RefreshToken
50-
* @see OAuth2UserCode
51-
* @see OAuth2DeviceCode
5253
*/
5354
public class OAuth2Authorization implements Serializable {
5455
private static final long serialVersionUID = SpringAuthorizationServerVersion.SERIAL_VERSION_UID;
@@ -128,28 +129,6 @@ public Token<OAuth2RefreshToken> getRefreshToken() {
128129
return getToken(OAuth2RefreshToken.class);
129130
}
130131

131-
/**
132-
* Returns the {@link Token} of type {@link OAuth2UserCode}.
133-
*
134-
* @return the {@link Token} of type {@link OAuth2UserCode}, or {@code null} if not
135-
* available
136-
*/
137-
@Nullable
138-
public Token<OAuth2UserCode> getUserCode() {
139-
return getToken(OAuth2UserCode.class);
140-
}
141-
142-
/**
143-
* Returns the {@link Token} of type {@link OAuth2DeviceCode}.
144-
*
145-
* @return the {@link Token} of type {@link OAuth2DeviceCode}, or {@code null} if not
146-
* available
147-
*/
148-
@Nullable
149-
public Token<OAuth2DeviceCode> getDeviceCode() {
150-
return getToken(OAuth2DeviceCode.class);
151-
}
152-
153132
/**
154133
* Returns the {@link Token} of type {@code tokenType}.
155134
*
@@ -481,26 +460,6 @@ public Builder refreshToken(OAuth2RefreshToken refreshToken) {
481460
return token(refreshToken);
482461
}
483462

484-
/**
485-
* Sets the {@link OAuth2UserCode user token}.
486-
*
487-
* @param userCode the {@link OAuth2UserCode}
488-
* @return the {@link Builder}
489-
*/
490-
public Builder userCode(OAuth2UserCode userCode) {
491-
return token(userCode);
492-
}
493-
494-
/**
495-
* Sets the {@link OAuth2DeviceCode device token}.
496-
*
497-
* @param deviceCode the {@link OAuth2DeviceCode}
498-
* @return the {@link Builder}
499-
*/
500-
public Builder deviceCode(OAuth2DeviceCode deviceCode) {
501-
return token(deviceCode);
502-
}
503-
504463
/**
505464
* Sets the {@link OAuth2Token token}.
506465
*

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ public final class OAuth2TokenType implements Serializable {
3131
private static final long serialVersionUID = SpringAuthorizationServerVersion.SERIAL_VERSION_UID;
3232
public static final OAuth2TokenType ACCESS_TOKEN = new OAuth2TokenType("access_token");
3333
public static final OAuth2TokenType REFRESH_TOKEN = new OAuth2TokenType("refresh_token");
34-
public static final OAuth2TokenType USER_CODE = new OAuth2TokenType("user_code");
35-
public static final OAuth2TokenType DEVICE_CODE = new OAuth2TokenType("device_code");
3634
private final String value;
3735

3836
/**

0 commit comments

Comments
 (0)