Polish gh-492

This commit is contained in:
Joe Grandja
2021-11-30 05:18:51 -05:00
parent 8defe2eb3a
commit 332d1cc318
3 changed files with 17 additions and 38 deletions

View File

@@ -41,9 +41,7 @@ public class OAuth2AuthenticationContext implements Context {
*
* @param authentication the {@code Authentication}
* @param context a {@code Map} of additional context information
* @deprecated Use {@link #with(Authentication)} instead
*/
@Deprecated
public OAuth2AuthenticationContext(Authentication authentication, @Nullable Map<Object, Object> context) {
Assert.notNull(authentication, "authentication cannot be null");
Map<Object, Object> ctx = new HashMap<>();
@@ -54,7 +52,13 @@ public class OAuth2AuthenticationContext implements Context {
this.context = Collections.unmodifiableMap(ctx);
}
protected OAuth2AuthenticationContext(Map<Object, Object> context) {
/**
* Constructs an {@code OAuth2AuthenticationContext} using the provided parameters.
*
* @param context a {@code Map} of context information, must contain the {@code Authentication}
* @since 0.2.1
*/
public OAuth2AuthenticationContext(Map<Object, Object> context) {
Assert.notEmpty(context, "context cannot be empty");
Assert.notNull(context.get(Authentication.class), "authentication cannot be null");
this.context = Collections.unmodifiableMap(new HashMap<>(context));
@@ -84,37 +88,12 @@ public class OAuth2AuthenticationContext implements Context {
return this.context.containsKey(key);
}
/**
* Constructs a new {@link Builder} with the provided {@link Authentication}.
*
* @param authentication the {@link Authentication}
* @return the {@link Builder}
*/
public static Builder with(Authentication authentication) {
return new Builder(authentication);
}
/**
* A builder for {@link OAuth2AuthenticationContext}.
*/
public static final class Builder extends AbstractBuilder<OAuth2AuthenticationContext, Builder> {
private Builder(Authentication authentication) {
super(authentication);
}
@Override
public OAuth2AuthenticationContext build() {
return new OAuth2AuthenticationContext(getContext());
}
}
/**
* A builder for subclasses of {@link OAuth2AuthenticationContext}.
*
* @param <T> the type of the authentication context
* @param <B> the type of the builder
* @since 0.2.1
*/
protected static abstract class AbstractBuilder<T extends OAuth2AuthenticationContext, B extends AbstractBuilder<T, B>> {
private final Map<Object, Object> context = new HashMap<>();

View File

@@ -185,10 +185,10 @@ public final class OAuth2AuthorizationCodeRequestAuthenticationProvider implemen
authorizationCodeRequestAuthentication, null);
}
OAuth2AuthenticationContext authenticationContext =
OAuth2AuthenticationContext.with(authorizationCodeRequestAuthentication)
.put(RegisteredClient.class, registeredClient)
.build();
Map<Object, Object> context = new HashMap<>();
context.put(RegisteredClient.class, registeredClient);
OAuth2AuthenticationContext authenticationContext = new OAuth2AuthenticationContext(
authorizationCodeRequestAuthentication, context);
OAuth2AuthenticationValidator redirectUriValidator = resolveAuthenticationValidator(OAuth2ParameterNames.REDIRECT_URI);
redirectUriValidator.validate(authenticationContext);

View File

@@ -98,11 +98,11 @@ public final class OidcUserInfoAuthenticationProvider implements AuthenticationP
throw new OAuth2AuthenticationException(OAuth2ErrorCodes.INVALID_TOKEN);
}
OAuth2AuthenticationContext authenticationContext =
OAuth2AuthenticationContext.with(userInfoAuthentication)
.put(OAuth2Token.class, accessTokenAuthentication.getToken())
.put(OAuth2Authorization.class, authorization)
.build();
Map<Object, Object> context = new HashMap<>();
context.put(OAuth2Token.class, accessTokenAuthentication.getToken());
context.put(OAuth2Authorization.class, authorization);
OAuth2AuthenticationContext authenticationContext = new OAuth2AuthenticationContext(
userInfoAuthentication, context);
OidcUserInfo userInfo = this.userInfoMapper.apply(authenticationContext);