Skip to content

Commit 332d1cc

Browse files
committed
Polish gh-492
1 parent 8defe2e commit 332d1cc

File tree

3 files changed

+17
-38
lines changed

3 files changed

+17
-38
lines changed

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/core/authentication/OAuth2AuthenticationContext.java

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ public class OAuth2AuthenticationContext implements Context {
4141
*
4242
* @param authentication the {@code Authentication}
4343
* @param context a {@code Map} of additional context information
44-
* @deprecated Use {@link #with(Authentication)} instead
4544
*/
46-
@Deprecated
4745
public OAuth2AuthenticationContext(Authentication authentication, @Nullable Map<Object, Object> context) {
4846
Assert.notNull(authentication, "authentication cannot be null");
4947
Map<Object, Object> ctx = new HashMap<>();
@@ -54,7 +52,13 @@ public OAuth2AuthenticationContext(Authentication authentication, @Nullable Map<
5452
this.context = Collections.unmodifiableMap(ctx);
5553
}
5654

57-
protected OAuth2AuthenticationContext(Map<Object, Object> context) {
55+
/**
56+
* Constructs an {@code OAuth2AuthenticationContext} using the provided parameters.
57+
*
58+
* @param context a {@code Map} of context information, must contain the {@code Authentication}
59+
* @since 0.2.1
60+
*/
61+
public OAuth2AuthenticationContext(Map<Object, Object> context) {
5862
Assert.notEmpty(context, "context cannot be empty");
5963
Assert.notNull(context.get(Authentication.class), "authentication cannot be null");
6064
this.context = Collections.unmodifiableMap(new HashMap<>(context));
@@ -84,37 +88,12 @@ public boolean hasKey(Object key) {
8488
return this.context.containsKey(key);
8589
}
8690

87-
/**
88-
* Constructs a new {@link Builder} with the provided {@link Authentication}.
89-
*
90-
* @param authentication the {@link Authentication}
91-
* @return the {@link Builder}
92-
*/
93-
public static Builder with(Authentication authentication) {
94-
return new Builder(authentication);
95-
}
96-
97-
/**
98-
* A builder for {@link OAuth2AuthenticationContext}.
99-
*/
100-
public static final class Builder extends AbstractBuilder<OAuth2AuthenticationContext, Builder> {
101-
102-
private Builder(Authentication authentication) {
103-
super(authentication);
104-
}
105-
106-
@Override
107-
public OAuth2AuthenticationContext build() {
108-
return new OAuth2AuthenticationContext(getContext());
109-
}
110-
111-
}
112-
11391
/**
11492
* A builder for subclasses of {@link OAuth2AuthenticationContext}.
11593
*
11694
* @param <T> the type of the authentication context
11795
* @param <B> the type of the builder
96+
* @since 0.2.1
11897
*/
11998
protected static abstract class AbstractBuilder<T extends OAuth2AuthenticationContext, B extends AbstractBuilder<T, B>> {
12099
private final Map<Object, Object> context = new HashMap<>();

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ private Authentication authenticateAuthorizationRequest(Authentication authentic
185185
authorizationCodeRequestAuthentication, null);
186186
}
187187

188-
OAuth2AuthenticationContext authenticationContext =
189-
OAuth2AuthenticationContext.with(authorizationCodeRequestAuthentication)
190-
.put(RegisteredClient.class, registeredClient)
191-
.build();
188+
Map<Object, Object> context = new HashMap<>();
189+
context.put(RegisteredClient.class, registeredClient);
190+
OAuth2AuthenticationContext authenticationContext = new OAuth2AuthenticationContext(
191+
authorizationCodeRequestAuthentication, context);
192192

193193
OAuth2AuthenticationValidator redirectUriValidator = resolveAuthenticationValidator(OAuth2ParameterNames.REDIRECT_URI);
194194
redirectUriValidator.validate(authenticationContext);

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/oidc/authentication/OidcUserInfoAuthenticationProvider.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ public Authentication authenticate(Authentication authentication) throws Authent
9898
throw new OAuth2AuthenticationException(OAuth2ErrorCodes.INVALID_TOKEN);
9999
}
100100

101-
OAuth2AuthenticationContext authenticationContext =
102-
OAuth2AuthenticationContext.with(userInfoAuthentication)
103-
.put(OAuth2Token.class, accessTokenAuthentication.getToken())
104-
.put(OAuth2Authorization.class, authorization)
105-
.build();
101+
Map<Object, Object> context = new HashMap<>();
102+
context.put(OAuth2Token.class, accessTokenAuthentication.getToken());
103+
context.put(OAuth2Authorization.class, authorization);
104+
OAuth2AuthenticationContext authenticationContext = new OAuth2AuthenticationContext(
105+
userInfoAuthentication, context);
106106

107107
OidcUserInfo userInfo = this.userInfoMapper.apply(authenticationContext);
108108

0 commit comments

Comments
 (0)