Browse Source

Polish gh-1143

pull/1161/head
Steve Riesenberg 3 years ago
parent
commit
5c6879d979
No known key found for this signature in database
GPG Key ID: 5F311AB48A55D521
  1. 27
      oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/JdbcOAuth2AuthorizationService.java
  2. 49
      oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/OAuth2Authorization.java
  3. 2
      oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/OAuth2TokenType.java

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

@ -47,7 +47,12 @@ import org.springframework.jdbc.support.lob.LobCreator;
import org.springframework.jdbc.support.lob.LobHandler; import org.springframework.jdbc.support.lob.LobHandler;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.security.jackson2.SecurityJackson2Modules; import org.springframework.security.jackson2.SecurityJackson2Modules;
import org.springframework.security.oauth2.core.*; import org.springframework.security.oauth2.core.AuthorizationGrantType;
import org.springframework.security.oauth2.core.OAuth2AccessToken;
import org.springframework.security.oauth2.core.OAuth2DeviceCode;
import org.springframework.security.oauth2.core.OAuth2RefreshToken;
import org.springframework.security.oauth2.core.OAuth2Token;
import org.springframework.security.oauth2.core.OAuth2UserCode;
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames; import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
import org.springframework.security.oauth2.core.oidc.OidcIdToken; import org.springframework.security.oauth2.core.oidc.OidcIdToken;
import org.springframework.security.oauth2.core.oidc.endpoint.OidcParameterNames; import org.springframework.security.oauth2.core.oidc.endpoint.OidcParameterNames;
@ -118,8 +123,8 @@ public class JdbcOAuth2AuthorizationService implements OAuth2AuthorizationServic
private static final String PK_FILTER = "id = ?"; private static final String PK_FILTER = "id = ?";
private static final String UNKNOWN_TOKEN_TYPE_FILTER = "state = ? OR authorization_code_value = ? OR " private static final String UNKNOWN_TOKEN_TYPE_FILTER = "state = ? OR authorization_code_value = ? OR "
+ "access_token_value = ? OR oidc_id_token_value = ? OR refresh_token_value = ? OR " + "access_token_value = ? OR oidc_id_token_value = ? OR refresh_token_value = ? OR user_code_value = ? OR "
+ "user_code_value = ? OR device_code_value = ?"; + "device_code_value = ?";
private static final String STATE_FILTER = "state = ?"; private static final String STATE_FILTER = "state = ?";
private static final String AUTHORIZATION_CODE_FILTER = "authorization_code_value = ?"; private static final String AUTHORIZATION_CODE_FILTER = "authorization_code_value = ?";
@ -272,10 +277,10 @@ public class JdbcOAuth2AuthorizationService implements OAuth2AuthorizationServic
} else if (OAuth2TokenType.REFRESH_TOKEN.equals(tokenType)) { } else if (OAuth2TokenType.REFRESH_TOKEN.equals(tokenType)) {
parameters.add(mapToSqlParameter("refresh_token_value", token)); parameters.add(mapToSqlParameter("refresh_token_value", token));
return findBy(REFRESH_TOKEN_FILTER, parameters); return findBy(REFRESH_TOKEN_FILTER, parameters);
} else if (OAuth2TokenType.USER_CODE.equals(tokenType)) { } else if (OAuth2ParameterNames.USER_CODE.equals(tokenType.getValue())) {
parameters.add(mapToSqlParameter("user_code_value", token)); parameters.add(mapToSqlParameter("user_code_value", token));
return findBy(USER_CODE_FILTER, parameters); return findBy(USER_CODE_FILTER, parameters);
} else if (OAuth2TokenType.DEVICE_CODE.equals(tokenType)) { } else if (OAuth2ParameterNames.DEVICE_CODE.equals(tokenType.getValue())) {
parameters.add(mapToSqlParameter("device_code_value", token)); parameters.add(mapToSqlParameter("device_code_value", token));
return findBy(DEVICE_CODE_FILTER, parameters); return findBy(DEVICE_CODE_FILTER, parameters);
} }
@ -447,11 +452,7 @@ public class JdbcOAuth2AuthorizationService implements OAuth2AuthorizationServic
String userCodeValue = getLobValue(rs, "user_code_value"); String userCodeValue = getLobValue(rs, "user_code_value");
if (StringUtils.hasText(userCodeValue)) { if (StringUtils.hasText(userCodeValue)) {
tokenIssuedAt = rs.getTimestamp("user_code_issued_at").toInstant(); tokenIssuedAt = rs.getTimestamp("user_code_issued_at").toInstant();
tokenExpiresAt = null; tokenExpiresAt = rs.getTimestamp("user_code_expires_at").toInstant();
Timestamp userCodeExpiresAt = rs.getTimestamp("user_code_expires_at");
if (userCodeExpiresAt != null) {
tokenExpiresAt = userCodeExpiresAt.toInstant();
}
Map<String, Object> userCodeMetadata = parseMap(getLobValue(rs, "user_code_metadata")); Map<String, Object> userCodeMetadata = parseMap(getLobValue(rs, "user_code_metadata"));
OAuth2UserCode userCode = new OAuth2UserCode(userCodeValue, tokenIssuedAt, tokenExpiresAt); OAuth2UserCode userCode = new OAuth2UserCode(userCodeValue, tokenIssuedAt, tokenExpiresAt);
@ -461,11 +462,7 @@ public class JdbcOAuth2AuthorizationService implements OAuth2AuthorizationServic
String deviceCodeValue = getLobValue(rs, "device_code_value"); String deviceCodeValue = getLobValue(rs, "device_code_value");
if (StringUtils.hasText(deviceCodeValue)) { if (StringUtils.hasText(deviceCodeValue)) {
tokenIssuedAt = rs.getTimestamp("device_code_issued_at").toInstant(); tokenIssuedAt = rs.getTimestamp("device_code_issued_at").toInstant();
tokenExpiresAt = null; tokenExpiresAt = rs.getTimestamp("device_code_expires_at").toInstant();
Timestamp deviceCodeExpiresAt = rs.getTimestamp("device_code_expires_at");
if (deviceCodeExpiresAt != null) {
tokenExpiresAt = deviceCodeExpiresAt.toInstant();
}
Map<String, Object> deviceCodeMetadata = parseMap(getLobValue(rs, "device_code_metadata")); Map<String, Object> deviceCodeMetadata = parseMap(getLobValue(rs, "device_code_metadata"));
OAuth2DeviceCode deviceCode = new OAuth2DeviceCode(deviceCodeValue, tokenIssuedAt, tokenExpiresAt); OAuth2DeviceCode deviceCode = new OAuth2DeviceCode(deviceCodeValue, tokenIssuedAt, tokenExpiresAt);

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

@ -27,7 +27,10 @@ import java.util.UUID;
import java.util.function.Consumer; import java.util.function.Consumer;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.security.oauth2.core.*; 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.OAuth2Token;
import org.springframework.security.oauth2.server.authorization.client.RegisteredClient; import org.springframework.security.oauth2.server.authorization.client.RegisteredClient;
import org.springframework.security.oauth2.server.authorization.util.SpringAuthorizationServerVersion; import org.springframework.security.oauth2.server.authorization.util.SpringAuthorizationServerVersion;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -47,8 +50,6 @@ import org.springframework.util.StringUtils;
* @see OAuth2Token * @see OAuth2Token
* @see OAuth2AccessToken * @see OAuth2AccessToken
* @see OAuth2RefreshToken * @see OAuth2RefreshToken
* @see OAuth2UserCode
* @see OAuth2DeviceCode
*/ */
public class OAuth2Authorization implements Serializable { public class OAuth2Authorization implements Serializable {
private static final long serialVersionUID = SpringAuthorizationServerVersion.SERIAL_VERSION_UID; private static final long serialVersionUID = SpringAuthorizationServerVersion.SERIAL_VERSION_UID;
@ -128,28 +129,6 @@ public class OAuth2Authorization implements Serializable {
return getToken(OAuth2RefreshToken.class); return getToken(OAuth2RefreshToken.class);
} }
/**
* Returns the {@link Token} of type {@link OAuth2UserCode}.
*
* @return the {@link Token} of type {@link OAuth2UserCode}, or {@code null} if not
* available
*/
@Nullable
public Token<OAuth2UserCode> getUserCode() {
return getToken(OAuth2UserCode.class);
}
/**
* Returns the {@link Token} of type {@link OAuth2DeviceCode}.
*
* @return the {@link Token} of type {@link OAuth2DeviceCode}, or {@code null} if not
* available
*/
@Nullable
public Token<OAuth2DeviceCode> getDeviceCode() {
return getToken(OAuth2DeviceCode.class);
}
/** /**
* Returns the {@link Token} of type {@code tokenType}. * Returns the {@link Token} of type {@code tokenType}.
* *
@ -481,26 +460,6 @@ public class OAuth2Authorization implements Serializable {
return token(refreshToken); return token(refreshToken);
} }
/**
* Sets the {@link OAuth2UserCode user token}.
*
* @param userCode the {@link OAuth2UserCode}
* @return the {@link Builder}
*/
public Builder userCode(OAuth2UserCode userCode) {
return token(userCode);
}
/**
* Sets the {@link OAuth2DeviceCode device token}.
*
* @param deviceCode the {@link OAuth2DeviceCode}
* @return the {@link Builder}
*/
public Builder deviceCode(OAuth2DeviceCode deviceCode) {
return token(deviceCode);
}
/** /**
* Sets the {@link OAuth2Token token}. * Sets the {@link OAuth2Token token}.
* *

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

@ -31,8 +31,6 @@ public final class OAuth2TokenType implements Serializable {
private static final long serialVersionUID = SpringAuthorizationServerVersion.SERIAL_VERSION_UID; private static final long serialVersionUID = SpringAuthorizationServerVersion.SERIAL_VERSION_UID;
public static final OAuth2TokenType ACCESS_TOKEN = new OAuth2TokenType("access_token"); public static final OAuth2TokenType ACCESS_TOKEN = new OAuth2TokenType("access_token");
public static final OAuth2TokenType REFRESH_TOKEN = new OAuth2TokenType("refresh_token"); public static final OAuth2TokenType REFRESH_TOKEN = new OAuth2TokenType("refresh_token");
public static final OAuth2TokenType USER_CODE = new OAuth2TokenType("user_code");
public static final OAuth2TokenType DEVICE_CODE = new OAuth2TokenType("device_code");
private final String value; private final String value;
/** /**

Loading…
Cancel
Save