Polish class names in oauth2-core
Fixes gh-4720
This commit is contained in:
@@ -34,15 +34,15 @@ import java.util.Set;
|
||||
* @since 5.0
|
||||
* @see <a target="_blank" href="https://tools.ietf.org/html/rfc6749#section-1.4">Section 1.4 Access Token</a>
|
||||
*/
|
||||
public class AccessToken extends AbstractOAuth2Token {
|
||||
public class OAuth2AccessToken extends AbstractOAuth2Token {
|
||||
private final TokenType tokenType;
|
||||
private final Set<String> scopes;
|
||||
|
||||
public AccessToken(TokenType tokenType, String tokenValue, Instant issuedAt, Instant expiresAt) {
|
||||
public OAuth2AccessToken(TokenType tokenType, String tokenValue, Instant issuedAt, Instant expiresAt) {
|
||||
this(tokenType, tokenValue, issuedAt, expiresAt, Collections.emptySet());
|
||||
}
|
||||
|
||||
public AccessToken(TokenType tokenType, String tokenValue, Instant issuedAt, Instant expiresAt, Set<String> scopes) {
|
||||
public OAuth2AccessToken(TokenType tokenType, String tokenValue, Instant issuedAt, Instant expiresAt, Set<String> scopes) {
|
||||
super(tokenValue, issuedAt, expiresAt);
|
||||
Assert.notNull(tokenType, "tokenType cannot be null");
|
||||
this.tokenType = tokenType;
|
||||
@@ -21,7 +21,7 @@ package org.springframework.security.oauth2.core;
|
||||
* @author Joe Grandja
|
||||
* @since 5.0
|
||||
*/
|
||||
public interface OAuth2ErrorCode {
|
||||
public interface OAuth2ErrorCodes {
|
||||
|
||||
String INVALID_REQUEST = "invalid_request";
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.security.oauth2.core.endpoint;
|
||||
|
||||
import org.springframework.security.oauth2.core.AccessToken;
|
||||
import org.springframework.security.oauth2.core.OAuth2AccessToken;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
@@ -29,21 +29,21 @@ import java.util.Set;
|
||||
*
|
||||
* @author Joe Grandja
|
||||
* @since 5.0
|
||||
* @see AccessToken
|
||||
* @see OAuth2AccessToken
|
||||
* @see <a target="_blank" href="https://tools.ietf.org/html/rfc6749#section-5.1">Section 5.1 Access Token Response</a>
|
||||
*/
|
||||
public final class TokenResponse {
|
||||
private AccessToken accessToken;
|
||||
public final class OAuth2AccessTokenResponse {
|
||||
private OAuth2AccessToken accessToken;
|
||||
private Map<String,Object> additionalParameters;
|
||||
|
||||
private TokenResponse() {
|
||||
private OAuth2AccessTokenResponse() {
|
||||
}
|
||||
|
||||
public String getTokenValue() {
|
||||
return this.accessToken.getTokenValue();
|
||||
}
|
||||
|
||||
public AccessToken.TokenType getTokenType() {
|
||||
public OAuth2AccessToken.TokenType getTokenType() {
|
||||
return this.accessToken.getTokenType();
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public final class TokenResponse {
|
||||
|
||||
public static class Builder {
|
||||
private String tokenValue;
|
||||
private AccessToken.TokenType tokenType;
|
||||
private OAuth2AccessToken.TokenType tokenType;
|
||||
private long expiresIn;
|
||||
private Set<String> scopes;
|
||||
private Map<String,Object> additionalParameters;
|
||||
@@ -78,7 +78,7 @@ public final class TokenResponse {
|
||||
this.tokenValue = tokenValue;
|
||||
}
|
||||
|
||||
public Builder tokenType(AccessToken.TokenType tokenType) {
|
||||
public Builder tokenType(OAuth2AccessToken.TokenType tokenType) {
|
||||
this.tokenType = tokenType;
|
||||
return this;
|
||||
}
|
||||
@@ -98,15 +98,15 @@ public final class TokenResponse {
|
||||
return this;
|
||||
}
|
||||
|
||||
public TokenResponse build() {
|
||||
public OAuth2AccessTokenResponse build() {
|
||||
Assert.isTrue(this.expiresIn >= 0, "expiresIn must be a positive number");
|
||||
Instant issuedAt = Instant.now();
|
||||
TokenResponse tokenResponse = new TokenResponse();
|
||||
tokenResponse.accessToken = new AccessToken(this.tokenType, this.tokenValue, issuedAt,
|
||||
OAuth2AccessTokenResponse accessTokenResponse = new OAuth2AccessTokenResponse();
|
||||
accessTokenResponse.accessToken = new OAuth2AccessToken(this.tokenType, this.tokenValue, issuedAt,
|
||||
issuedAt.plusSeconds(this.expiresIn), this.scopes);
|
||||
tokenResponse.additionalParameters = Collections.unmodifiableMap(
|
||||
accessTokenResponse.additionalParameters = Collections.unmodifiableMap(
|
||||
CollectionUtils.isEmpty(this.additionalParameters) ? Collections.emptyMap() : this.additionalParameters);
|
||||
return tokenResponse;
|
||||
return accessTokenResponse;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,26 +23,26 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Joe Grandja
|
||||
* @since 5.0
|
||||
* @see AuthorizationRequest
|
||||
* @see AuthorizationResponse
|
||||
* @see OAuth2AuthorizationRequest
|
||||
* @see OAuth2AuthorizationResponse
|
||||
*/
|
||||
public final class AuthorizationExchange {
|
||||
private final AuthorizationRequest authorizationRequest;
|
||||
private final AuthorizationResponse authorizationResponse;
|
||||
public final class OAuth2AuthorizationExchange {
|
||||
private final OAuth2AuthorizationRequest authorizationRequest;
|
||||
private final OAuth2AuthorizationResponse authorizationResponse;
|
||||
|
||||
public AuthorizationExchange(AuthorizationRequest authorizationRequest,
|
||||
AuthorizationResponse authorizationResponse) {
|
||||
public OAuth2AuthorizationExchange(OAuth2AuthorizationRequest authorizationRequest,
|
||||
OAuth2AuthorizationResponse authorizationResponse) {
|
||||
Assert.notNull(authorizationRequest, "authorizationRequest cannot be null");
|
||||
Assert.notNull(authorizationResponse, "authorizationResponse cannot be null");
|
||||
this.authorizationRequest = authorizationRequest;
|
||||
this.authorizationResponse = authorizationResponse;
|
||||
}
|
||||
|
||||
public AuthorizationRequest getAuthorizationRequest() {
|
||||
public OAuth2AuthorizationRequest getAuthorizationRequest() {
|
||||
return this.authorizationRequest;
|
||||
}
|
||||
|
||||
public AuthorizationResponse getAuthorizationResponse() {
|
||||
public OAuth2AuthorizationResponse getAuthorizationResponse() {
|
||||
return this.authorizationResponse;
|
||||
}
|
||||
}
|
||||
@@ -36,22 +36,22 @@ import java.util.stream.Collectors;
|
||||
* @author Joe Grandja
|
||||
* @since 5.0
|
||||
* @see AuthorizationGrantType
|
||||
* @see ResponseType
|
||||
* @see OAuth2AuthorizationResponseType
|
||||
* @see <a target="_blank" href="https://tools.ietf.org/html/rfc6749#section-4.1.1">Section 4.1.1 Authorization Code Grant Request</a>
|
||||
* @see <a target="_blank" href="https://tools.ietf.org/html/rfc6749#section-4.2.1">Section 4.2.1 Implicit Grant Request</a>
|
||||
*/
|
||||
public final class AuthorizationRequest implements Serializable {
|
||||
public final class OAuth2AuthorizationRequest implements Serializable {
|
||||
private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;
|
||||
private String authorizationUri;
|
||||
private AuthorizationGrantType authorizationGrantType;
|
||||
private ResponseType responseType;
|
||||
private OAuth2AuthorizationResponseType responseType;
|
||||
private String clientId;
|
||||
private String redirectUri;
|
||||
private Set<String> scopes;
|
||||
private String state;
|
||||
private Map<String,Object> additionalParameters;
|
||||
|
||||
private AuthorizationRequest() {
|
||||
private OAuth2AuthorizationRequest() {
|
||||
}
|
||||
|
||||
public String getAuthorizationUri() {
|
||||
@@ -62,7 +62,7 @@ public final class AuthorizationRequest implements Serializable {
|
||||
return this.authorizationGrantType;
|
||||
}
|
||||
|
||||
public ResponseType getResponseType() {
|
||||
public OAuth2AuthorizationResponseType getResponseType() {
|
||||
return this.responseType;
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public final class AuthorizationRequest implements Serializable {
|
||||
public static class Builder {
|
||||
private String authorizationUri;
|
||||
private AuthorizationGrantType authorizationGrantType;
|
||||
private ResponseType responseType;
|
||||
private OAuth2AuthorizationResponseType responseType;
|
||||
private String clientId;
|
||||
private String redirectUri;
|
||||
private Set<String> scopes;
|
||||
@@ -108,9 +108,9 @@ public final class AuthorizationRequest implements Serializable {
|
||||
Assert.notNull(authorizationGrantType, "authorizationGrantType cannot be null");
|
||||
this.authorizationGrantType = authorizationGrantType;
|
||||
if (AuthorizationGrantType.AUTHORIZATION_CODE.equals(authorizationGrantType)) {
|
||||
this.responseType = ResponseType.CODE;
|
||||
this.responseType = OAuth2AuthorizationResponseType.CODE;
|
||||
} else if (AuthorizationGrantType.IMPLICIT.equals(authorizationGrantType)) {
|
||||
this.responseType = ResponseType.TOKEN;
|
||||
this.responseType = OAuth2AuthorizationResponseType.TOKEN;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,14 +152,14 @@ public final class AuthorizationRequest implements Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public AuthorizationRequest build() {
|
||||
public OAuth2AuthorizationRequest build() {
|
||||
Assert.hasText(this.authorizationUri, "authorizationUri cannot be empty");
|
||||
Assert.hasText(this.clientId, "clientId cannot be empty");
|
||||
if (AuthorizationGrantType.IMPLICIT.equals(this.authorizationGrantType)) {
|
||||
Assert.hasText(this.redirectUri, "redirectUri cannot be empty");
|
||||
}
|
||||
|
||||
AuthorizationRequest authorizationRequest = new AuthorizationRequest();
|
||||
OAuth2AuthorizationRequest authorizationRequest = new OAuth2AuthorizationRequest();
|
||||
authorizationRequest.authorizationUri = this.authorizationUri;
|
||||
authorizationRequest.authorizationGrantType = this.authorizationGrantType;
|
||||
authorizationRequest.responseType = this.responseType;
|
||||
@@ -26,13 +26,13 @@ import org.springframework.util.StringUtils;
|
||||
* @since 5.0
|
||||
* @see <a target="_blank" href="https://tools.ietf.org/html/rfc6749#section-4.1.2">Section 4.1.2 Authorization Response</a>
|
||||
*/
|
||||
public final class AuthorizationResponse {
|
||||
public final class OAuth2AuthorizationResponse {
|
||||
private String redirectUri;
|
||||
private String state;
|
||||
private String code;
|
||||
private OAuth2Error error;
|
||||
|
||||
private AuthorizationResponse() {
|
||||
private OAuth2AuthorizationResponse() {
|
||||
}
|
||||
|
||||
public String getRedirectUri() {
|
||||
@@ -110,13 +110,13 @@ public final class AuthorizationResponse {
|
||||
return this;
|
||||
}
|
||||
|
||||
public AuthorizationResponse build() {
|
||||
public OAuth2AuthorizationResponse build() {
|
||||
if (StringUtils.hasText(this.code) && StringUtils.hasText(this.errorCode)) {
|
||||
throw new IllegalArgumentException("code and errorCode cannot both be set");
|
||||
}
|
||||
Assert.hasText(this.redirectUri, "redirectUri cannot be empty");
|
||||
|
||||
AuthorizationResponse authorizationResponse = new AuthorizationResponse();
|
||||
OAuth2AuthorizationResponse authorizationResponse = new OAuth2AuthorizationResponse();
|
||||
authorizationResponse.redirectUri = this.redirectUri;
|
||||
authorizationResponse.state = this.state;
|
||||
if (StringUtils.hasText(this.code)) {
|
||||
@@ -33,13 +33,13 @@ import java.io.Serializable;
|
||||
* @since 5.0
|
||||
* @see <a target="_blank" href="https://tools.ietf.org/html/rfc6749#section-3.1.1">Section 3.1.1 Response Type</a>
|
||||
*/
|
||||
public final class ResponseType implements Serializable {
|
||||
public final class OAuth2AuthorizationResponseType implements Serializable {
|
||||
private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;
|
||||
public static final ResponseType CODE = new ResponseType("code");
|
||||
public static final ResponseType TOKEN = new ResponseType("token");
|
||||
public static final OAuth2AuthorizationResponseType CODE = new OAuth2AuthorizationResponseType("code");
|
||||
public static final OAuth2AuthorizationResponseType TOKEN = new OAuth2AuthorizationResponseType("token");
|
||||
private final String value;
|
||||
|
||||
private ResponseType(String value) {
|
||||
private OAuth2AuthorizationResponseType(String value) {
|
||||
Assert.hasText(value, "value cannot be empty");
|
||||
this.value = value;
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public final class ResponseType implements Serializable {
|
||||
if (obj == null || this.getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
ResponseType that = (ResponseType) obj;
|
||||
OAuth2AuthorizationResponseType that = (OAuth2AuthorizationResponseType) obj;
|
||||
return this.getValue().equals(that.getValue());
|
||||
}
|
||||
|
||||
@@ -16,14 +16,14 @@
|
||||
package org.springframework.security.oauth2.core.endpoint;
|
||||
|
||||
/**
|
||||
* Standard and additional (custom) parameters defined in the OAuth Parameters Registry
|
||||
* Standard and additional (custom) parameter names defined in the OAuth Parameters Registry
|
||||
* and used by the authorization endpoint and token endpoint.
|
||||
*
|
||||
* @author Joe Grandja
|
||||
* @since 5.0
|
||||
* @see <a target="_blank" href="https://tools.ietf.org/html/rfc6749#section-11.2">11.2 OAuth Parameters Registry</a>
|
||||
*/
|
||||
public interface OAuth2Parameter {
|
||||
public interface OAuth2ParameterNames {
|
||||
|
||||
String RESPONSE_TYPE = "response_type";
|
||||
|
||||
@@ -25,7 +25,7 @@ package org.springframework.security.oauth2.core.oidc;
|
||||
* @see <a target="_blank" href="http://openid.net/specs/openid-connect-core-1_0.html#UserInfoResponse">UserInfo Response</a>
|
||||
* @see <a target="_blank" href="http://openid.net/specs/openid-connect-core-1_0.html#IDToken">ID Token</a>
|
||||
*/
|
||||
public interface Address {
|
||||
public interface AddressStandardClaim {
|
||||
|
||||
String getFormatted();
|
||||
|
||||
@@ -18,13 +18,13 @@ package org.springframework.security.oauth2.core.oidc;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The default implementation of an {@link Address}.
|
||||
* The default implementation of an {@link AddressStandardClaim Address Claim}.
|
||||
*
|
||||
* @author Joe Grandja
|
||||
* @since 5.0
|
||||
* @see Address
|
||||
* @see AddressStandardClaim
|
||||
*/
|
||||
public final class DefaultAddress implements Address {
|
||||
public final class DefaultAddressStandardClaim implements AddressStandardClaim {
|
||||
private String formatted;
|
||||
private String streetAddress;
|
||||
private String locality;
|
||||
@@ -32,7 +32,7 @@ public final class DefaultAddress implements Address {
|
||||
private String postalCode;
|
||||
private String country;
|
||||
|
||||
private DefaultAddress() {
|
||||
private DefaultAddressStandardClaim() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -121,8 +121,8 @@ public final class DefaultAddress implements Address {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Address build() {
|
||||
DefaultAddress address = new DefaultAddress();
|
||||
public AddressStandardClaim build() {
|
||||
DefaultAddressStandardClaim address = new DefaultAddressStandardClaim();
|
||||
address.formatted = this.formatted;
|
||||
address.streetAddress = this.streetAddress;
|
||||
address.locality = this.locality;
|
||||
@@ -27,9 +27,9 @@ import java.util.List;
|
||||
*
|
||||
* @see ClaimAccessor
|
||||
* @see StandardClaimAccessor
|
||||
* @see StandardClaim
|
||||
* @see IdTokenClaim
|
||||
* @see IdToken
|
||||
* @see StandardClaimNames
|
||||
* @see IdTokenClaimNames
|
||||
* @see OidcIdToken
|
||||
* @see <a target="_blank" href="http://openid.net/specs/openid-connect-core-1_0.html#IDToken">ID Token</a>
|
||||
* @see <a target="_blank" href="http://openid.net/specs/openid-connect-core-1_0.html#StandardClaims">Standard Claims</a>
|
||||
* @author Joe Grandja
|
||||
@@ -38,50 +38,50 @@ import java.util.List;
|
||||
public interface IdTokenClaimAccessor extends StandardClaimAccessor {
|
||||
|
||||
default URL getIssuer() {
|
||||
return this.getClaimAsURL(IdTokenClaim.ISS);
|
||||
return this.getClaimAsURL(IdTokenClaimNames.ISS);
|
||||
}
|
||||
|
||||
default String getSubject() {
|
||||
return this.getClaimAsString(IdTokenClaim.SUB);
|
||||
return this.getClaimAsString(IdTokenClaimNames.SUB);
|
||||
}
|
||||
|
||||
default List<String> getAudience() {
|
||||
return this.getClaimAsStringList(IdTokenClaim.AUD);
|
||||
return this.getClaimAsStringList(IdTokenClaimNames.AUD);
|
||||
}
|
||||
|
||||
default Instant getExpiresAt() {
|
||||
return this.getClaimAsInstant(IdTokenClaim.EXP);
|
||||
return this.getClaimAsInstant(IdTokenClaimNames.EXP);
|
||||
}
|
||||
|
||||
default Instant getIssuedAt() {
|
||||
return this.getClaimAsInstant(IdTokenClaim.IAT);
|
||||
return this.getClaimAsInstant(IdTokenClaimNames.IAT);
|
||||
}
|
||||
|
||||
default Instant getAuthenticatedAt() {
|
||||
return this.getClaimAsInstant(IdTokenClaim.AUTH_TIME);
|
||||
return this.getClaimAsInstant(IdTokenClaimNames.AUTH_TIME);
|
||||
}
|
||||
|
||||
default String getNonce() {
|
||||
return this.getClaimAsString(IdTokenClaim.NONCE);
|
||||
return this.getClaimAsString(IdTokenClaimNames.NONCE);
|
||||
}
|
||||
|
||||
default String getAuthenticationContextClass() {
|
||||
return this.getClaimAsString(IdTokenClaim.ACR);
|
||||
return this.getClaimAsString(IdTokenClaimNames.ACR);
|
||||
}
|
||||
|
||||
default List<String> getAuthenticationMethods() {
|
||||
return this.getClaimAsStringList(IdTokenClaim.AMR);
|
||||
return this.getClaimAsStringList(IdTokenClaimNames.AMR);
|
||||
}
|
||||
|
||||
default String getAuthorizedParty() {
|
||||
return this.getClaimAsString(IdTokenClaim.AZP);
|
||||
return this.getClaimAsString(IdTokenClaimNames.AZP);
|
||||
}
|
||||
|
||||
default String getAccessTokenHash() {
|
||||
return this.getClaimAsString(IdTokenClaim.AT_HASH);
|
||||
return this.getClaimAsString(IdTokenClaimNames.AT_HASH);
|
||||
}
|
||||
|
||||
default String getAuthorizationCodeHash() {
|
||||
return this.getClaimAsString(IdTokenClaim.C_HASH);
|
||||
return this.getClaimAsString(IdTokenClaimNames.C_HASH);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,16 +16,16 @@
|
||||
package org.springframework.security.oauth2.core.oidc;
|
||||
|
||||
/**
|
||||
* The "Claims" defined by the <i>OpenID Connect Core 1.0</i> specification
|
||||
* The names of the "Claims" defined by the <i>OpenID Connect Core 1.0</i> specification
|
||||
* that can be returned in the <i>ID Token</i>.
|
||||
*
|
||||
* @author Joe Grandja
|
||||
* @since 5.0
|
||||
* @see IdToken
|
||||
* @see OidcIdToken
|
||||
* @see <a target="_blank" href="http://openid.net/specs/openid-connect-core-1_0.html#IDToken">ID Token</a>
|
||||
*/
|
||||
|
||||
public interface IdTokenClaim {
|
||||
public interface IdTokenClaimNames {
|
||||
|
||||
String ISS = "iss";
|
||||
|
||||
@@ -27,7 +27,7 @@ import java.util.Map;
|
||||
* An implementation of an {@link AbstractOAuth2Token} representing an <i>OpenID Connect Core 1.0 ID Token</i>.
|
||||
*
|
||||
* <p>
|
||||
* The <code>IdToken</code> is a security token that contains "Claims"
|
||||
* The <code>OidcIdToken</code> is a security token that contains "Claims"
|
||||
* about the authentication of an End-User by an Authorization Server.
|
||||
*
|
||||
* @author Joe Grandja
|
||||
@@ -38,10 +38,10 @@ import java.util.Map;
|
||||
* @see <a target="_blank" href="http://openid.net/specs/openid-connect-core-1_0.html#IDToken">ID Token</a>
|
||||
* @see <a target="_blank" href="http://openid.net/specs/openid-connect-core-1_0.html#StandardClaims">Standard Claims</a>
|
||||
*/
|
||||
public class IdToken extends AbstractOAuth2Token implements IdTokenClaimAccessor {
|
||||
public class OidcIdToken extends AbstractOAuth2Token implements IdTokenClaimAccessor {
|
||||
private final Map<String, Object> claims;
|
||||
|
||||
public IdToken(String tokenValue, Instant issuedAt, Instant expiresAt, Map<String, Object> claims) {
|
||||
public OidcIdToken(String tokenValue, Instant issuedAt, Instant expiresAt, Map<String, Object> claims) {
|
||||
super(tokenValue, issuedAt, expiresAt);
|
||||
Assert.notEmpty(claims, "claims cannot be empty");
|
||||
this.claims = Collections.unmodifiableMap(new LinkedHashMap<>(claims));
|
||||
@@ -15,22 +15,22 @@
|
||||
*/
|
||||
package org.springframework.security.oauth2.core.oidc;
|
||||
|
||||
import org.springframework.security.oauth2.core.AccessToken;
|
||||
import org.springframework.security.oauth2.core.OAuth2AccessToken;
|
||||
|
||||
/**
|
||||
* The <i>scope</i> values defined by the <i>OpenID Connect Core 1.0</i> specification
|
||||
* that can be used to request {@link StandardClaim Claims}.
|
||||
* that can be used to request {@link StandardClaimNames Claims}.
|
||||
* <p>
|
||||
* The scope(s) associated to an {@link AccessToken} determine what claims (resources)
|
||||
* The scope(s) associated to an {@link OAuth2AccessToken} determine what claims (resources)
|
||||
* will be available when they are used to access <i>OAuth 2.0 Protected Endpoints</i>,
|
||||
* such as the <i>UserInfo Endpoint</i>.
|
||||
*
|
||||
* @author Joe Grandja
|
||||
* @since 5.0
|
||||
* @see StandardClaim
|
||||
* @see StandardClaimNames
|
||||
* @see <a target="_blank" href="http://openid.net/specs/openid-connect-core-1_0.html#ScopeClaims">Requesting Claims using Scope Values</a>
|
||||
*/
|
||||
public interface OidcScope {
|
||||
public interface OidcScopes {
|
||||
|
||||
String OPENID = "openid";
|
||||
|
||||
@@ -26,7 +26,7 @@ import java.util.Map;
|
||||
* from the OAuth 2.0 Protected Resource <i>UserInfo Endpoint</i>.
|
||||
*
|
||||
* <p>
|
||||
* The <code>UserInfo</code> contains a set of "Standard Claims" about the authentication of an End-User.
|
||||
* The <code>OidcUserInfo</code> contains a set of "Standard Claims" about the authentication of an End-User.
|
||||
*
|
||||
* @author Joe Grandja
|
||||
* @since 5.0
|
||||
@@ -35,10 +35,10 @@ import java.util.Map;
|
||||
* @see <a target="_blank" href="http://openid.net/specs/openid-connect-core-1_0.html#UserInfo">UserInfo Endpoint</a>
|
||||
* @see <a target="_blank" href="http://openid.net/specs/openid-connect-core-1_0.html#StandardClaims">Standard Claims</a>
|
||||
*/
|
||||
public class UserInfo implements StandardClaimAccessor {
|
||||
public class OidcUserInfo implements StandardClaimAccessor {
|
||||
private final Map<String, Object> claims;
|
||||
|
||||
public UserInfo(Map<String, Object> claims) {
|
||||
public OidcUserInfo(Map<String, Object> claims) {
|
||||
Assert.notEmpty(claims, "claims cannot be empty");
|
||||
this.claims = Collections.unmodifiableMap(new LinkedHashMap<>(claims));
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public class UserInfo implements StandardClaimAccessor {
|
||||
return false;
|
||||
}
|
||||
|
||||
UserInfo that = (UserInfo) obj;
|
||||
OidcUserInfo that = (OidcUserInfo) obj;
|
||||
|
||||
return this.getClaims().equals(that.getClaims());
|
||||
}
|
||||
@@ -26,8 +26,8 @@ import java.util.Map;
|
||||
* either in the <i>UserInfo Response</i> or the <i>ID Token</i>.
|
||||
*
|
||||
* @see ClaimAccessor
|
||||
* @see StandardClaim
|
||||
* @see UserInfo
|
||||
* @see StandardClaimNames
|
||||
* @see OidcUserInfo
|
||||
* @see <a target="_blank" href="http://openid.net/specs/openid-connect-core-1_0.html#UserInfoResponse">UserInfo Response</a>
|
||||
* @see <a target="_blank" href="http://openid.net/specs/openid-connect-core-1_0.html#StandardClaims">Standard Claims</a>
|
||||
* @author Joe Grandja
|
||||
@@ -36,85 +36,85 @@ import java.util.Map;
|
||||
public interface StandardClaimAccessor extends ClaimAccessor {
|
||||
|
||||
default String getSubject() {
|
||||
return this.getClaimAsString(StandardClaim.SUB);
|
||||
return this.getClaimAsString(StandardClaimNames.SUB);
|
||||
}
|
||||
|
||||
default String getFullName() {
|
||||
return this.getClaimAsString(StandardClaim.NAME);
|
||||
return this.getClaimAsString(StandardClaimNames.NAME);
|
||||
}
|
||||
|
||||
default String getGivenName() {
|
||||
return this.getClaimAsString(StandardClaim.GIVEN_NAME);
|
||||
return this.getClaimAsString(StandardClaimNames.GIVEN_NAME);
|
||||
}
|
||||
|
||||
default String getFamilyName() {
|
||||
return this.getClaimAsString(StandardClaim.FAMILY_NAME);
|
||||
return this.getClaimAsString(StandardClaimNames.FAMILY_NAME);
|
||||
}
|
||||
|
||||
default String getMiddleName() {
|
||||
return this.getClaimAsString(StandardClaim.MIDDLE_NAME);
|
||||
return this.getClaimAsString(StandardClaimNames.MIDDLE_NAME);
|
||||
}
|
||||
|
||||
default String getNickName() {
|
||||
return this.getClaimAsString(StandardClaim.NICKNAME);
|
||||
return this.getClaimAsString(StandardClaimNames.NICKNAME);
|
||||
}
|
||||
|
||||
default String getPreferredUsername() {
|
||||
return this.getClaimAsString(StandardClaim.PREFERRED_USERNAME);
|
||||
return this.getClaimAsString(StandardClaimNames.PREFERRED_USERNAME);
|
||||
}
|
||||
|
||||
default String getProfile() {
|
||||
return this.getClaimAsString(StandardClaim.PROFILE);
|
||||
return this.getClaimAsString(StandardClaimNames.PROFILE);
|
||||
}
|
||||
|
||||
default String getPicture() {
|
||||
return this.getClaimAsString(StandardClaim.PICTURE);
|
||||
return this.getClaimAsString(StandardClaimNames.PICTURE);
|
||||
}
|
||||
|
||||
default String getWebsite() {
|
||||
return this.getClaimAsString(StandardClaim.WEBSITE);
|
||||
return this.getClaimAsString(StandardClaimNames.WEBSITE);
|
||||
}
|
||||
|
||||
default String getEmail() {
|
||||
return this.getClaimAsString(StandardClaim.EMAIL);
|
||||
return this.getClaimAsString(StandardClaimNames.EMAIL);
|
||||
}
|
||||
|
||||
default Boolean getEmailVerified() {
|
||||
return this.getClaimAsBoolean(StandardClaim.EMAIL_VERIFIED);
|
||||
return this.getClaimAsBoolean(StandardClaimNames.EMAIL_VERIFIED);
|
||||
}
|
||||
|
||||
default String getGender() {
|
||||
return this.getClaimAsString(StandardClaim.GENDER);
|
||||
return this.getClaimAsString(StandardClaimNames.GENDER);
|
||||
}
|
||||
|
||||
default String getBirthdate() {
|
||||
return this.getClaimAsString(StandardClaim.BIRTHDATE);
|
||||
return this.getClaimAsString(StandardClaimNames.BIRTHDATE);
|
||||
}
|
||||
|
||||
default String getZoneInfo() {
|
||||
return this.getClaimAsString(StandardClaim.ZONEINFO);
|
||||
return this.getClaimAsString(StandardClaimNames.ZONEINFO);
|
||||
}
|
||||
|
||||
default String getLocale() {
|
||||
return this.getClaimAsString(StandardClaim.LOCALE);
|
||||
return this.getClaimAsString(StandardClaimNames.LOCALE);
|
||||
}
|
||||
|
||||
default String getPhoneNumber() {
|
||||
return this.getClaimAsString(StandardClaim.PHONE_NUMBER);
|
||||
return this.getClaimAsString(StandardClaimNames.PHONE_NUMBER);
|
||||
}
|
||||
|
||||
default Boolean getPhoneNumberVerified() {
|
||||
return this.getClaimAsBoolean(StandardClaim.PHONE_NUMBER_VERIFIED);
|
||||
return this.getClaimAsBoolean(StandardClaimNames.PHONE_NUMBER_VERIFIED);
|
||||
}
|
||||
|
||||
default Address getAddress() {
|
||||
Map<String, Object> addressFields = this.getClaimAsMap(StandardClaim.ADDRESS);
|
||||
default AddressStandardClaim getAddress() {
|
||||
Map<String, Object> addressFields = this.getClaimAsMap(StandardClaimNames.ADDRESS);
|
||||
return (!CollectionUtils.isEmpty(addressFields) ?
|
||||
new DefaultAddress.Builder(addressFields).build() :
|
||||
new DefaultAddress.Builder().build());
|
||||
new DefaultAddressStandardClaim.Builder(addressFields).build() :
|
||||
new DefaultAddressStandardClaim.Builder().build());
|
||||
}
|
||||
|
||||
default Instant getUpdatedAt() {
|
||||
return this.getClaimAsInstant(StandardClaim.UPDATED_AT);
|
||||
return this.getClaimAsInstant(StandardClaimNames.UPDATED_AT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
package org.springframework.security.oauth2.core.oidc;
|
||||
|
||||
/**
|
||||
* The "Standard Claims" defined by the <i>OpenID Connect Core 1.0</i> specification
|
||||
* The names of the "Standard Claims" defined by the <i>OpenID Connect Core 1.0</i> specification
|
||||
* that can be returned either in the <i>UserInfo Response</i> or the <i>ID Token</i>.
|
||||
*
|
||||
* @author Joe Grandja
|
||||
@@ -25,7 +25,7 @@ package org.springframework.security.oauth2.core.oidc;
|
||||
* @see <a target="_blank" href="http://openid.net/specs/openid-connect-core-1_0.html#UserInfoResponse">UserInfo Response</a>
|
||||
* @see <a target="_blank" href="http://openid.net/specs/openid-connect-core-1_0.html#IDToken">ID Token</a>
|
||||
*/
|
||||
public interface StandardClaim {
|
||||
public interface StandardClaimNames {
|
||||
|
||||
String SUB = "sub";
|
||||
|
||||
@@ -16,14 +16,14 @@
|
||||
package org.springframework.security.oauth2.core.oidc.endpoint;
|
||||
|
||||
/**
|
||||
* Standard parameters defined in the OAuth Parameters Registry
|
||||
* Standard parameter names defined in the OAuth Parameters Registry
|
||||
* and used by the authorization endpoint and token endpoint.
|
||||
*
|
||||
* @author Joe Grandja
|
||||
* @since 5.0
|
||||
* @see <a target="_blank" href="http://openid.net/specs/openid-connect-core-1_0.html#OAuthParametersRegistry">18.2 OAuth Parameters Registration</a>
|
||||
*/
|
||||
public interface OidcParameter {
|
||||
public interface OidcParameterNames {
|
||||
|
||||
String ID_TOKEN = "id_token";
|
||||
|
||||
@@ -17,11 +17,10 @@
|
||||
package org.springframework.security.oauth2.core.oidc.user;
|
||||
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.oauth2.core.oidc.user.OidcUser;
|
||||
import org.springframework.security.oauth2.core.oidc.OidcIdToken;
|
||||
import org.springframework.security.oauth2.core.oidc.OidcUserInfo;
|
||||
import org.springframework.security.oauth2.core.user.DefaultOAuth2User;
|
||||
import org.springframework.security.oauth2.core.oidc.IdToken;
|
||||
import org.springframework.security.oauth2.core.oidc.IdTokenClaim;
|
||||
import org.springframework.security.oauth2.core.oidc.UserInfo;
|
||||
import org.springframework.security.oauth2.core.oidc.IdTokenClaimNames;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -32,34 +31,34 @@ import java.util.Set;
|
||||
* <p>
|
||||
* The claim used for accessing the "name" of the
|
||||
* user <code>Principal</code> via {@link #getClaims()}
|
||||
* is {@link IdTokenClaim#SUB}.
|
||||
* is {@link IdTokenClaimNames#SUB}.
|
||||
*
|
||||
* @author Joe Grandja
|
||||
* @author Vedran Pavic
|
||||
* @since 5.0
|
||||
* @see OidcUser
|
||||
* @see DefaultOAuth2User
|
||||
* @see IdToken
|
||||
* @see UserInfo
|
||||
* @see OidcIdToken
|
||||
* @see OidcUserInfo
|
||||
*/
|
||||
public class DefaultOidcUser extends DefaultOAuth2User implements OidcUser {
|
||||
private final IdToken idToken;
|
||||
private final UserInfo userInfo;
|
||||
private final OidcIdToken idToken;
|
||||
private final OidcUserInfo userInfo;
|
||||
|
||||
public DefaultOidcUser(Set<GrantedAuthority> authorities, IdToken idToken) {
|
||||
this(authorities, idToken, IdTokenClaim.SUB);
|
||||
public DefaultOidcUser(Set<GrantedAuthority> authorities, OidcIdToken idToken) {
|
||||
this(authorities, idToken, IdTokenClaimNames.SUB);
|
||||
}
|
||||
|
||||
public DefaultOidcUser(Set<GrantedAuthority> authorities, IdToken idToken, String nameAttributeKey) {
|
||||
public DefaultOidcUser(Set<GrantedAuthority> authorities, OidcIdToken idToken, String nameAttributeKey) {
|
||||
this(authorities, idToken, null, nameAttributeKey);
|
||||
}
|
||||
|
||||
public DefaultOidcUser(Set<GrantedAuthority> authorities, IdToken idToken, UserInfo userInfo) {
|
||||
this(authorities, idToken, userInfo, IdTokenClaim.SUB);
|
||||
public DefaultOidcUser(Set<GrantedAuthority> authorities, OidcIdToken idToken, OidcUserInfo userInfo) {
|
||||
this(authorities, idToken, userInfo, IdTokenClaimNames.SUB);
|
||||
}
|
||||
|
||||
public DefaultOidcUser(Set<GrantedAuthority> authorities, IdToken idToken, UserInfo userInfo,
|
||||
String nameAttributeKey) {
|
||||
public DefaultOidcUser(Set<GrantedAuthority> authorities, OidcIdToken idToken, OidcUserInfo userInfo,
|
||||
String nameAttributeKey) {
|
||||
super(authorities, OidcUser.collectClaims(idToken, userInfo), nameAttributeKey);
|
||||
this.idToken = idToken;
|
||||
this.userInfo = userInfo;
|
||||
@@ -70,11 +69,11 @@ public class DefaultOidcUser extends DefaultOAuth2User implements OidcUser {
|
||||
return this.getAttributes();
|
||||
}
|
||||
|
||||
public IdToken getIdToken() {
|
||||
public OidcIdToken getIdToken() {
|
||||
return this.idToken;
|
||||
}
|
||||
|
||||
public UserInfo getUserInfo() {
|
||||
public OidcUserInfo getUserInfo() {
|
||||
return this.userInfo;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@ package org.springframework.security.oauth2.core.oidc.user;
|
||||
|
||||
import org.springframework.security.core.AuthenticatedPrincipal;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.oauth2.core.oidc.OidcUserInfo;
|
||||
import org.springframework.security.oauth2.core.user.OAuth2User;
|
||||
import org.springframework.security.oauth2.core.oidc.IdToken;
|
||||
import org.springframework.security.oauth2.core.oidc.OidcIdToken;
|
||||
import org.springframework.security.oauth2.core.oidc.IdTokenClaimAccessor;
|
||||
import org.springframework.security.oauth2.core.oidc.StandardClaimAccessor;
|
||||
import org.springframework.security.oauth2.core.oidc.UserInfo;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -33,7 +33,7 @@ import java.util.Map;
|
||||
*
|
||||
* <p>
|
||||
* An <code>OidcUser</code> contains "Claims" about the Authentication of the End-User.
|
||||
* The claims are aggregated from the <code>IdToken</code> and optionally the <code>UserInfo</code>.
|
||||
* The claims are aggregated from the <code>OidcIdToken</code> and optionally the <code>OidcUserInfo</code>.
|
||||
*
|
||||
* <p>
|
||||
* Implementation instances of this interface represent an {@link AuthenticatedPrincipal}
|
||||
@@ -44,8 +44,8 @@ import java.util.Map;
|
||||
* @since 5.0
|
||||
* @see DefaultOidcUser
|
||||
* @see OAuth2User
|
||||
* @see IdToken
|
||||
* @see UserInfo
|
||||
* @see OidcIdToken
|
||||
* @see OidcUserInfo
|
||||
* @see IdTokenClaimAccessor
|
||||
* @see StandardClaimAccessor
|
||||
* @see <a target="_blank" href="http://openid.net/specs/openid-connect-core-1_0.html#IDToken">ID Token</a>
|
||||
@@ -55,7 +55,7 @@ public interface OidcUser extends OAuth2User, IdTokenClaimAccessor {
|
||||
|
||||
Map<String, Object> getClaims();
|
||||
|
||||
static Map<String, Object> collectClaims(IdToken idToken, UserInfo userInfo) {
|
||||
static Map<String, Object> collectClaims(OidcIdToken idToken, OidcUserInfo userInfo) {
|
||||
Assert.notNull(idToken, "idToken cannot be null");
|
||||
Map<String, Object> claims = new HashMap<>();
|
||||
if (userInfo != null) {
|
||||
|
||||
@@ -16,10 +16,9 @@
|
||||
package org.springframework.security.oauth2.core.oidc.user;
|
||||
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.oauth2.core.oidc.user.OidcUser;
|
||||
import org.springframework.security.oauth2.core.oidc.OidcUserInfo;
|
||||
import org.springframework.security.oauth2.core.user.OAuth2UserAuthority;
|
||||
import org.springframework.security.oauth2.core.oidc.IdToken;
|
||||
import org.springframework.security.oauth2.core.oidc.UserInfo;
|
||||
import org.springframework.security.oauth2.core.oidc.OidcIdToken;
|
||||
|
||||
/**
|
||||
* A {@link GrantedAuthority} that is associated with an {@link OidcUser}.
|
||||
@@ -29,28 +28,28 @@ import org.springframework.security.oauth2.core.oidc.UserInfo;
|
||||
* @see OidcUser
|
||||
*/
|
||||
public class OidcUserAuthority extends OAuth2UserAuthority {
|
||||
private final IdToken idToken;
|
||||
private final UserInfo userInfo;
|
||||
private final OidcIdToken idToken;
|
||||
private final OidcUserInfo userInfo;
|
||||
|
||||
public OidcUserAuthority(IdToken idToken) {
|
||||
public OidcUserAuthority(OidcIdToken idToken) {
|
||||
this(idToken, null);
|
||||
}
|
||||
|
||||
public OidcUserAuthority(IdToken idToken, UserInfo userInfo) {
|
||||
public OidcUserAuthority(OidcIdToken idToken, OidcUserInfo userInfo) {
|
||||
this("ROLE_USER", idToken, userInfo);
|
||||
}
|
||||
|
||||
public OidcUserAuthority(String authority, IdToken idToken, UserInfo userInfo) {
|
||||
public OidcUserAuthority(String authority, OidcIdToken idToken, OidcUserInfo userInfo) {
|
||||
super(authority, OidcUser.collectClaims(idToken, userInfo));
|
||||
this.idToken = idToken;
|
||||
this.userInfo = userInfo;
|
||||
}
|
||||
|
||||
public IdToken getIdToken() {
|
||||
public OidcIdToken getIdToken() {
|
||||
return this.idToken;
|
||||
}
|
||||
|
||||
public UserInfo getUserInfo() {
|
||||
public OidcUserInfo getUserInfo() {
|
||||
return this.userInfo;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,16 +16,16 @@
|
||||
package org.springframework.security.oauth2.core.endpoint;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.oauth2.core.AccessToken;
|
||||
import org.springframework.security.oauth2.core.OAuth2AccessToken;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* Tests {@link TokenResponse}
|
||||
* Tests {@link OAuth2AccessTokenResponse}
|
||||
*
|
||||
* @author Luander Ribeiro
|
||||
*/
|
||||
public class TokenResponseTest {
|
||||
public class OAuth2AccessTokenResponseTests {
|
||||
|
||||
private static final String TOKEN = "token";
|
||||
private static final long INVALID_EXPIRES_IN = -1L;
|
||||
@@ -33,27 +33,27 @@ public class TokenResponseTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void buildWhenTokenValueIsNullThenThrowIllegalArgumentException() {
|
||||
TokenResponse.withToken(null)
|
||||
OAuth2AccessTokenResponse.withToken(null)
|
||||
.expiresIn(EXPIRES_IN)
|
||||
.additionalParameters(Collections.emptyMap())
|
||||
.scopes(Collections.emptySet())
|
||||
.tokenType(AccessToken.TokenType.BEARER)
|
||||
.tokenType(OAuth2AccessToken.TokenType.BEARER)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void buildWhenExpiresInIsNegativeThenThrowIllegalArgumentException() {
|
||||
TokenResponse.withToken(TOKEN)
|
||||
OAuth2AccessTokenResponse.withToken(TOKEN)
|
||||
.expiresIn(INVALID_EXPIRES_IN)
|
||||
.additionalParameters(Collections.emptyMap())
|
||||
.scopes(Collections.emptySet())
|
||||
.tokenType(AccessToken.TokenType.BEARER)
|
||||
.tokenType(OAuth2AccessToken.TokenType.BEARER)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void buildWhenTokenTypeIsInvalidThenThrowIllegalArgumentException() {
|
||||
TokenResponse.withToken(TOKEN)
|
||||
OAuth2AccessTokenResponse.withToken(TOKEN)
|
||||
.expiresIn(EXPIRES_IN)
|
||||
.additionalParameters(Collections.emptyMap())
|
||||
.tokenType(null)
|
||||
@@ -62,7 +62,7 @@ public class TokenResponseTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void buildWhenTokenTypeNotSetThenThrowIllegalArgumentException() {
|
||||
TokenResponse.withToken(TOKEN)
|
||||
OAuth2AccessTokenResponse.withToken(TOKEN)
|
||||
.expiresIn(EXPIRES_IN)
|
||||
.additionalParameters(Collections.emptyMap())
|
||||
.build();
|
||||
@@ -24,11 +24,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
|
||||
/**
|
||||
* Tests {@link AuthorizationRequest}
|
||||
* Tests {@link OAuth2AuthorizationRequest}
|
||||
*
|
||||
* @author Luander Ribeiro
|
||||
*/
|
||||
public class AuthorizationRequestTest {
|
||||
public class OAuth2AuthorizationRequestTests {
|
||||
private static final String AUTHORIZE_URI = "http://authorize.uri/";
|
||||
private static final String CLIENT_ID = "client id";
|
||||
private static final String REDIRECT_URI = "http://redirect.uri/";
|
||||
@@ -37,7 +37,7 @@ public class AuthorizationRequestTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void buildWhenAuthorizationUriIsNullThenThrowIllegalArgumentException() {
|
||||
AuthorizationRequest.authorizationCode()
|
||||
OAuth2AuthorizationRequest.authorizationCode()
|
||||
.authorizationUri(null)
|
||||
.clientId(CLIENT_ID)
|
||||
.redirectUri(REDIRECT_URI)
|
||||
@@ -48,7 +48,7 @@ public class AuthorizationRequestTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void buildWhenAuthorizeUriNotSetThenThrowIllegalArgumentException() {
|
||||
AuthorizationRequest.authorizationCode()
|
||||
OAuth2AuthorizationRequest.authorizationCode()
|
||||
.clientId(CLIENT_ID)
|
||||
.redirectUri(REDIRECT_URI)
|
||||
.scopes(SCOPE)
|
||||
@@ -58,7 +58,7 @@ public class AuthorizationRequestTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void buildWhenClientIdIsNullThenThrowIllegalArgumentException() {
|
||||
AuthorizationRequest.authorizationCode()
|
||||
OAuth2AuthorizationRequest.authorizationCode()
|
||||
.authorizationUri(AUTHORIZE_URI)
|
||||
.clientId(null)
|
||||
.redirectUri(REDIRECT_URI)
|
||||
@@ -69,7 +69,7 @@ public class AuthorizationRequestTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void buildWhenClientIdNotSetThenThrowIllegalArgumentException() {
|
||||
AuthorizationRequest.authorizationCode()
|
||||
OAuth2AuthorizationRequest.authorizationCode()
|
||||
.authorizationUri(AUTHORIZE_URI)
|
||||
.redirectUri(REDIRECT_URI)
|
||||
.scopes(SCOPE)
|
||||
@@ -79,8 +79,8 @@ public class AuthorizationRequestTest {
|
||||
|
||||
@Test
|
||||
public void buildWhenGetResponseTypeIsCalledThenReturnCode() {
|
||||
AuthorizationRequest authorizationRequest;
|
||||
authorizationRequest = AuthorizationRequest.authorizationCode()
|
||||
OAuth2AuthorizationRequest authorizationRequest;
|
||||
authorizationRequest = OAuth2AuthorizationRequest.authorizationCode()
|
||||
.authorizationUri(AUTHORIZE_URI)
|
||||
.clientId(CLIENT_ID)
|
||||
.redirectUri(REDIRECT_URI)
|
||||
@@ -88,12 +88,12 @@ public class AuthorizationRequestTest {
|
||||
.state(STATE)
|
||||
.build();
|
||||
|
||||
assertThat(authorizationRequest.getResponseType()).isEqualTo(ResponseType.CODE);
|
||||
assertThat(authorizationRequest.getResponseType()).isEqualTo(OAuth2AuthorizationResponseType.CODE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildWhenRedirectUriIsNullThenDoesNotThrowAnyException() {
|
||||
assertThatCode(() -> AuthorizationRequest.authorizationCode()
|
||||
assertThatCode(() -> OAuth2AuthorizationRequest.authorizationCode()
|
||||
.authorizationUri(AUTHORIZE_URI)
|
||||
.clientId(CLIENT_ID)
|
||||
.redirectUri(null)
|
||||
@@ -104,7 +104,7 @@ public class AuthorizationRequestTest {
|
||||
|
||||
@Test
|
||||
public void buildWhenRedirectUriNotSetThenDoesNotThrowAnyException() {
|
||||
assertThatCode(() -> AuthorizationRequest.authorizationCode()
|
||||
assertThatCode(() -> OAuth2AuthorizationRequest.authorizationCode()
|
||||
.authorizationUri(AUTHORIZE_URI)
|
||||
.clientId(CLIENT_ID)
|
||||
.scopes(SCOPE)
|
||||
@@ -114,7 +114,7 @@ public class AuthorizationRequestTest {
|
||||
|
||||
@Test
|
||||
public void buildWhenScopesIsNullThenDoesNotThrowAnyException() {
|
||||
assertThatCode(() -> AuthorizationRequest.authorizationCode()
|
||||
assertThatCode(() -> OAuth2AuthorizationRequest.authorizationCode()
|
||||
.authorizationUri(AUTHORIZE_URI)
|
||||
.clientId(CLIENT_ID)
|
||||
.redirectUri(REDIRECT_URI)
|
||||
@@ -125,7 +125,7 @@ public class AuthorizationRequestTest {
|
||||
|
||||
@Test
|
||||
public void buildWhenScopesNotSetThenDoesNotThrowAnyException() {
|
||||
assertThatCode(() -> AuthorizationRequest.authorizationCode()
|
||||
assertThatCode(() -> OAuth2AuthorizationRequest.authorizationCode()
|
||||
.authorizationUri(AUTHORIZE_URI)
|
||||
.clientId(CLIENT_ID)
|
||||
.redirectUri(REDIRECT_URI)
|
||||
@@ -135,7 +135,7 @@ public class AuthorizationRequestTest {
|
||||
|
||||
@Test
|
||||
public void buildWhenStateIsNullThenDoesNotThrowAnyException() {
|
||||
assertThatCode(() -> AuthorizationRequest.authorizationCode()
|
||||
assertThatCode(() -> OAuth2AuthorizationRequest.authorizationCode()
|
||||
.authorizationUri(AUTHORIZE_URI)
|
||||
.clientId(CLIENT_ID)
|
||||
.redirectUri(REDIRECT_URI)
|
||||
@@ -146,7 +146,7 @@ public class AuthorizationRequestTest {
|
||||
|
||||
@Test
|
||||
public void buildWhenStateNotSetThenDoesNotThrowAnyException() {
|
||||
assertThatCode(() -> AuthorizationRequest.authorizationCode()
|
||||
assertThatCode(() -> OAuth2AuthorizationRequest.authorizationCode()
|
||||
.authorizationUri(AUTHORIZE_URI)
|
||||
.clientId(CLIENT_ID)
|
||||
.redirectUri(REDIRECT_URI)
|
||||
@@ -27,10 +27,10 @@ import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.oauth2.core.oidc.IdToken;
|
||||
import org.springframework.security.oauth2.core.oidc.IdTokenClaim;
|
||||
import org.springframework.security.oauth2.core.oidc.StandardClaim;
|
||||
import org.springframework.security.oauth2.core.oidc.UserInfo;
|
||||
import org.springframework.security.oauth2.core.oidc.OidcIdToken;
|
||||
import org.springframework.security.oauth2.core.oidc.IdTokenClaimNames;
|
||||
import org.springframework.security.oauth2.core.oidc.OidcUserInfo;
|
||||
import org.springframework.security.oauth2.core.oidc.StandardClaimNames;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -52,13 +52,13 @@ public class DefaultOidcUserTests {
|
||||
private static final Map<String, Object> TEST_ID_TOKEN_CLAIMS = new HashMap<>();
|
||||
|
||||
static {
|
||||
TEST_ID_TOKEN_CLAIMS.put(IdTokenClaim.ISS, "https://example.com");
|
||||
TEST_ID_TOKEN_CLAIMS.put(IdTokenClaim.SUB, TEST_SUBJECT);
|
||||
TEST_ID_TOKEN_CLAIMS.put(IdTokenClaimNames.ISS, "https://example.com");
|
||||
TEST_ID_TOKEN_CLAIMS.put(IdTokenClaimNames.SUB, TEST_SUBJECT);
|
||||
}
|
||||
|
||||
private static final IdToken TEST_ID_TOKEN = new IdToken("value", Instant.EPOCH, Instant.MAX, TEST_ID_TOKEN_CLAIMS);
|
||||
private static final OidcIdToken TEST_ID_TOKEN = new OidcIdToken("value", Instant.EPOCH, Instant.MAX, TEST_ID_TOKEN_CLAIMS);
|
||||
|
||||
private static final UserInfo TEST_USER_INFO = new UserInfo(Collections.singletonMap(StandardClaim.EMAIL, TEST_EMAIL));
|
||||
private static final OidcUserInfo TEST_USER_INFO = new OidcUserInfo(Collections.singletonMap(StandardClaimNames.EMAIL, TEST_EMAIL));
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
@@ -70,17 +70,17 @@ public class DefaultOidcUserTests {
|
||||
assertThat(user.getName()).isEqualTo(TEST_SUBJECT);
|
||||
assertThat(user.getAuthorities()).hasSize(1);
|
||||
assertThat(user.getAuthorities().iterator().next()).isEqualTo(TEST_AUTHORITY);
|
||||
assertThat(user.getAttributes()).containsOnlyKeys(IdTokenClaim.ISS, IdTokenClaim.SUB);
|
||||
assertThat(user.getAttributes()).containsOnlyKeys(IdTokenClaimNames.ISS, IdTokenClaimNames.SUB);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenAuthoritiesAndIdTokenAndNameAttributeKeyThenIsCreated() {
|
||||
DefaultOidcUser user = new DefaultOidcUser(TEST_AUTHORITIES, TEST_ID_TOKEN, IdTokenClaim.SUB);
|
||||
DefaultOidcUser user = new DefaultOidcUser(TEST_AUTHORITIES, TEST_ID_TOKEN, IdTokenClaimNames.SUB);
|
||||
|
||||
assertThat(user.getName()).isEqualTo(TEST_SUBJECT);
|
||||
assertThat(user.getAuthorities()).hasSize(1);
|
||||
assertThat(user.getAuthorities().iterator().next()).isEqualTo(TEST_AUTHORITY);
|
||||
assertThat(user.getAttributes()).containsOnlyKeys(IdTokenClaim.ISS, IdTokenClaim.SUB);
|
||||
assertThat(user.getAttributes()).containsOnlyKeys(IdTokenClaimNames.ISS, IdTokenClaimNames.SUB);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -90,17 +90,17 @@ public class DefaultOidcUserTests {
|
||||
assertThat(user.getName()).isEqualTo(TEST_SUBJECT);
|
||||
assertThat(user.getAuthorities()).hasSize(1);
|
||||
assertThat(user.getAuthorities().iterator().next()).isEqualTo(TEST_AUTHORITY);
|
||||
assertThat(user.getAttributes()).containsOnlyKeys(IdTokenClaim.ISS, IdTokenClaim.SUB, StandardClaim.EMAIL);
|
||||
assertThat(user.getAttributes()).containsOnlyKeys(IdTokenClaimNames.ISS, IdTokenClaimNames.SUB, StandardClaimNames.EMAIL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenAuthoritiesAndIdTokenAndUserInfoAndNameAttributeKeyThenIsCreated() {
|
||||
DefaultOidcUser user = new DefaultOidcUser(TEST_AUTHORITIES, TEST_ID_TOKEN, TEST_USER_INFO, StandardClaim.EMAIL);
|
||||
DefaultOidcUser user = new DefaultOidcUser(TEST_AUTHORITIES, TEST_ID_TOKEN, TEST_USER_INFO, StandardClaimNames.EMAIL);
|
||||
|
||||
assertThat(user.getName()).isEqualTo(TEST_EMAIL);
|
||||
assertThat(user.getAuthorities()).hasSize(1);
|
||||
assertThat(user.getAuthorities().iterator().next()).isEqualTo(TEST_AUTHORITY);
|
||||
assertThat(user.getAttributes()).containsOnlyKeys(IdTokenClaim.ISS, IdTokenClaim.SUB, StandardClaim.EMAIL);
|
||||
assertThat(user.getAttributes()).containsOnlyKeys(IdTokenClaimNames.ISS, IdTokenClaimNames.SUB, StandardClaimNames.EMAIL);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,9 +114,9 @@ public class DefaultOidcUserTests {
|
||||
@Test
|
||||
public void constructorWhenNameAttributeKeyClaimIsNotPresentThenThrowsException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Missing attribute '" + StandardClaim.NAME + "' in attributes");
|
||||
this.thrown.expectMessage("Missing attribute '" + StandardClaimNames.NAME + "' in attributes");
|
||||
|
||||
new DefaultOidcUser(TEST_AUTHORITIES, TEST_ID_TOKEN, TEST_USER_INFO, StandardClaim.NAME);
|
||||
new DefaultOidcUser(TEST_AUTHORITIES, TEST_ID_TOKEN, TEST_USER_INFO, StandardClaimNames.NAME);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user