Skip to content

Commit d435719

Browse files
committed
Polish gh-470
1 parent 4ce999c commit d435719

File tree

7 files changed

+311
-342
lines changed

7 files changed

+311
-342
lines changed

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

Lines changed: 0 additions & 212 deletions
This file was deleted.

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
import java.util.HashSet;
2525
import java.util.Map;
2626
import java.util.Set;
27+
import java.util.function.Consumer;
2728
import java.util.function.Function;
2829
import java.util.function.Supplier;
2930

3031
import org.springframework.security.authentication.AnonymousAuthenticationToken;
3132
import org.springframework.security.authentication.AuthenticationProvider;
32-
import org.springframework.security.config.Customizer;
3333
import org.springframework.security.core.Authentication;
3434
import org.springframework.security.core.AuthenticationException;
3535
import org.springframework.security.crypto.keygen.Base64StringKeyGenerator;
@@ -47,7 +47,6 @@
4747
import org.springframework.security.oauth2.core.oidc.OidcScopes;
4848
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
4949
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationConsent;
50-
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationConsentContext;
5150
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationConsentService;
5251
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
5352
import org.springframework.security.oauth2.server.authorization.client.RegisteredClient;
@@ -62,6 +61,7 @@
6261
* used in the Authorization Code Grant.
6362
*
6463
* @author Joe Grandja
64+
* @author Steve Riesenberg
6565
* @since 0.1.2
6666
* @see OAuth2AuthorizationCodeRequestAuthenticationToken
6767
* @see OAuth2AuthorizationCodeAuthenticationProvider
@@ -84,7 +84,7 @@ public final class OAuth2AuthorizationCodeRequestAuthenticationProvider implemen
8484
private final OAuth2AuthorizationConsentService authorizationConsentService;
8585
private Supplier<String> authorizationCodeGenerator = DEFAULT_AUTHORIZATION_CODE_GENERATOR::generateKey;
8686
private Function<String, OAuth2AuthenticationValidator> authenticationValidatorResolver = DEFAULT_AUTHENTICATION_VALIDATOR_RESOLVER;
87-
private Customizer<OAuth2AuthorizationConsentContext> authorizationConsentCustomizer;
87+
private Consumer<OAuth2AuthorizationConsentAuthenticationContext> authorizationConsentCustomizer;
8888

8989
/**
9090
* Constructs an {@code OAuth2AuthorizationCodeRequestAuthenticationProvider} using the provided parameters.
@@ -149,25 +149,26 @@ public void setAuthenticationValidatorResolver(Function<String, OAuth2Authentica
149149
}
150150

151151
/**
152-
* Sets the {@link Customizer} providing access to the {@link OAuth2AuthorizationConsentContext} containing an
153-
* {@link OAuth2AuthorizationConsent.Builder}.
152+
* Sets the {@code Consumer} providing access to the {@link OAuth2AuthorizationConsentAuthenticationContext}
153+
* containing an {@link OAuth2AuthorizationConsent.Builder} and additional context information.
154154
*
155155
* <p>
156156
* The following context attributes are available:
157157
* <ul>
158158
* <li>The {@link OAuth2AuthorizationConsent.Builder} used to build the authorization consent
159-
* prior to {@link OAuth2AuthorizationConsentService#save(OAuth2AuthorizationConsent)}</li>
160-
* <li>The {@link Authentication authentication principal} of type
161-
* {@link OAuth2AuthorizationCodeRequestAuthenticationToken}</li>
159+
* prior to {@link OAuth2AuthorizationConsentService#save(OAuth2AuthorizationConsent)}.</li>
160+
* <li>The {@link Authentication} of type
161+
* {@link OAuth2AuthorizationCodeRequestAuthenticationToken}.</li>
162+
* <li>The {@link RegisteredClient} associated with the authorization request.</li>
162163
* <li>The {@link OAuth2Authorization} associated with the state token presented in the
163164
* authorization consent request.</li>
164-
* <li>The {@link OAuth2AuthorizationRequest} requiring the resource owner's consent.</li>
165+
* <li>The {@link OAuth2AuthorizationRequest} associated with the authorization consent request.</li>
165166
* </ul>
166167
*
167-
* @param authorizationConsentCustomizer the {@link Customizer} providing access to the
168-
* {@link OAuth2AuthorizationConsentContext} containing an {@link OAuth2AuthorizationConsent.Builder}
168+
* @param authorizationConsentCustomizer the {@code Consumer} providing access to the
169+
* {@link OAuth2AuthorizationConsentAuthenticationContext} containing an {@link OAuth2AuthorizationConsent.Builder}
169170
*/
170-
public void setAuthorizationConsentCustomizer(Customizer<OAuth2AuthorizationConsentContext> authorizationConsentCustomizer) {
171+
public void setAuthorizationConsentCustomizer(Consumer<OAuth2AuthorizationConsentAuthenticationContext> authorizationConsentCustomizer) {
171172
Assert.notNull(authorizationConsentCustomizer, "authorizationConsentCustomizer cannot be null");
172173
this.authorizationConsentCustomizer = authorizationConsentCustomizer;
173174
}
@@ -328,8 +329,8 @@ private Authentication authenticateAuthorizationConsent(Authentication authentic
328329
Set<String> currentAuthorizedScopes = currentAuthorizationConsent != null ?
329330
currentAuthorizationConsent.getScopes() : Collections.emptySet();
330331

331-
if (authorizedScopes.isEmpty() && currentAuthorizedScopes.isEmpty()
332-
&& authorizationCodeRequestAuthentication.getAdditionalParameters().isEmpty()) {
332+
if (authorizedScopes.isEmpty() && currentAuthorizedScopes.isEmpty() &&
333+
authorizationCodeRequestAuthentication.getAdditionalParameters().isEmpty()) {
333334
// Authorization consent denied
334335
this.authorizationService.remove(authorization);
335336
throwError(OAuth2ErrorCodes.ACCESS_DENIED, OAuth2ParameterNames.CLIENT_ID,
@@ -360,15 +361,14 @@ private Authentication authenticateAuthorizationConsent(Authentication authentic
360361

361362
if (this.authorizationConsentCustomizer != null) {
362363
// @formatter:off
363-
OAuth2AuthorizationConsentContext authorizationConsentContext =
364-
OAuth2AuthorizationConsentContext.with(authorizationConsentBuilder)
365-
.principal(authorizationCodeRequestAuthentication)
364+
OAuth2AuthorizationConsentAuthenticationContext authorizationConsentAuthenticationContext =
365+
OAuth2AuthorizationConsentAuthenticationContext.with(authorizationCodeRequestAuthentication, authorizationConsentBuilder)
366366
.registeredClient(registeredClient)
367367
.authorization(authorization)
368368
.authorizationRequest(authorizationRequest)
369369
.build();
370370
// @formatter:on
371-
this.authorizationConsentCustomizer.customize(authorizationConsentContext);
371+
this.authorizationConsentCustomizer.accept(authorizationConsentAuthenticationContext);
372372
}
373373

374374
OAuth2AuthorizationConsent authorizationConsent = authorizationConsentBuilder.build();

0 commit comments

Comments
 (0)