Skip to content

Commit f3cb8f7

Browse files
committed
Polish gh-280
1 parent 683dad1 commit f3cb8f7

File tree

16 files changed

+408
-392
lines changed

16 files changed

+408
-392
lines changed

oauth2-authorization-server/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/server/authorization/OAuth2AuthorizationServerConfigurer.java

+15-16
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
import org.springframework.security.crypto.password.PasswordEncoder;
3636
import org.springframework.security.oauth2.jwt.JwtEncoder;
3737
import org.springframework.security.oauth2.jwt.NimbusJwsEncoder;
38-
import org.springframework.security.oauth2.server.authorization.InMemoryOAuth2AuthorizationService;
3938
import org.springframework.security.oauth2.server.authorization.InMemoryOAuth2AuthorizationConsentService;
39+
import org.springframework.security.oauth2.server.authorization.InMemoryOAuth2AuthorizationService;
4040
import org.springframework.security.oauth2.server.authorization.JwtEncodingContext;
41+
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationConsentService;
4142
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
4243
import org.springframework.security.oauth2.server.authorization.OAuth2TokenCustomizer;
43-
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationConsentService;
4444
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeAuthenticationProvider;
4545
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientAuthenticationProvider;
4646
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientCredentialsAuthenticationProvider;
@@ -79,6 +79,7 @@
7979
* @see AbstractHttpConfigurer
8080
* @see RegisteredClientRepository
8181
* @see OAuth2AuthorizationService
82+
* @see OAuth2AuthorizationConsentService
8283
* @see OAuth2AuthorizationEndpointFilter
8384
* @see OAuth2TokenEndpointFilter
8485
* @see OAuth2TokenIntrospectionEndpointFilter
@@ -138,7 +139,7 @@ public OAuth2AuthorizationServerConfigurer<B> authorizationService(OAuth2Authori
138139
/**
139140
* Sets the authorization consent service.
140141
*
141-
* @param authorizationConsentService the authorization service
142+
* @param authorizationConsentService the authorization consent service
142143
* @return the {@link OAuth2AuthorizationServerConfigurer} for further configuration
143144
*/
144145
public OAuth2AuthorizationServerConfigurer<B> authorizationConsentService(OAuth2AuthorizationConsentService authorizationConsentService) {
@@ -160,17 +161,17 @@ public OAuth2AuthorizationServerConfigurer<B> providerSettings(ProviderSettings
160161
}
161162

162163
/**
163-
* Specify the URL to redirect Resource Owners to if consent is required during
164+
* Specify the URI to redirect Resource Owners to if consent is required during
164165
* the {@code authorization_code} flow. A default consent page will be generated when
165166
* this attribute is not specified.
166167
*
167-
* If a URL is specified, users are required to process the specified URL to generate
168+
* If a URI is specified, applications are required to process the specified URI to generate
168169
* a consent page. The query string will contain the following parameters:
169170
*
170171
* <ul>
171-
* <li>{@code client_id} the client identifier</li>
172-
* <li>{@code scope} the space separated list of scopes present in the authorization request</li>
173-
* <li>{@code state} a CSRF protection token</li>
172+
* <li>{@code client_id} - the client identifier</li>
173+
* <li>{@code scope} - the space separated list of scopes present in the authorization request</li>
174+
* <li>{@code state} - a CSRF protection token</li>
174175
* </ul>
175176
*
176177
* In general, the consent page should create a form that submits
@@ -181,14 +182,13 @@ public OAuth2AuthorizationServerConfigurer<B> providerSettings(ProviderSettings
181182
* <li>It must be submitted to {@link ProviderSettings#authorizationEndpoint()}</li>
182183
* <li>It must include the received {@code client_id} as an HTTP parameter</li>
183184
* <li>It must include the received {@code state} as an HTTP parameter</li>
184-
* <li>It must include the list of {@code scope}s the {@code Resource Owners}
185-
* consents to as an HTTP parameter</li>
186-
* <li>It must include the {@code consent_action} parameter, with value either
185+
* <li>It must include the list of {@code scope}s the {@code Resource Owner}
186+
* consented to as an HTTP parameter</li>
187+
* <li>It must include the {@code consent_action} parameter, with a value either
187188
* {@code approve} or {@code cancel} as an HTTP parameter</li>
188189
* </ul>
189190
*
190-
*
191-
* @param consentPage the consent page to redirect to if consent is required (e.g. "/consent")
191+
* @param consentPage the consent page to redirect to if consent is required (e.g. "/oauth2/consent")
192192
* @return the {@link OAuth2AuthorizationServerConfigurer} for further configuration
193193
*/
194194
public OAuth2AuthorizationServerConfigurer<B> consentPage(String consentPage) {
@@ -316,9 +316,8 @@ public void configure(B builder) {
316316
getRegisteredClientRepository(builder),
317317
getAuthorizationService(builder),
318318
getAuthorizationConsentService(builder),
319-
providerSettings.authorizationEndpoint()
320-
);
321-
if (this.consentPage != null) {
319+
providerSettings.authorizationEndpoint());
320+
if (StringUtils.hasText(this.consentPage)) {
322321
authorizationEndpointFilter.setUserConsentUri(this.consentPage);
323322
}
324323
builder.addFilterBefore(postProcess(authorizationEndpointFilter), AbstractPreAuthenticatedProcessingFilter.class);

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
*/
1616
package org.springframework.security.oauth2.server.authorization;
1717

18-
import org.springframework.lang.Nullable;
19-
import org.springframework.util.Assert;
20-
2118
import java.util.Arrays;
2219
import java.util.Collections;
2320
import java.util.List;
2421
import java.util.Map;
2522
import java.util.Objects;
2623
import java.util.concurrent.ConcurrentHashMap;
2724

25+
import org.springframework.lang.Nullable;
26+
import org.springframework.util.Assert;
27+
2828
/**
2929
* An {@link OAuth2AuthorizationConsentService} that stores {@link OAuth2AuthorizationConsent}'s in-memory.
3030
*
@@ -102,4 +102,5 @@ private static int getId(String registeredClientId, String principalName) {
102102
private static int getId(OAuth2AuthorizationConsent authorizationConsent) {
103103
return getId(authorizationConsent.getRegisteredClientId(), authorizationConsent.getPrincipalName());
104104
}
105+
105106
}

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
*/
1616
package org.springframework.security.oauth2.server.authorization;
1717

18+
import java.io.Serializable;
19+
import java.util.Collections;
20+
import java.util.HashSet;
21+
import java.util.Set;
22+
import java.util.function.Consumer;
23+
import java.util.stream.Collectors;
24+
1825
import org.springframework.lang.NonNull;
1926
import org.springframework.security.core.GrantedAuthority;
2027
import org.springframework.security.core.authority.SimpleGrantedAuthority;
@@ -23,16 +30,9 @@
2330
import org.springframework.util.Assert;
2431
import org.springframework.util.CollectionUtils;
2532

26-
import java.io.Serializable;
27-
import java.util.Collections;
28-
import java.util.HashSet;
29-
import java.util.Set;
30-
import java.util.function.Consumer;
31-
import java.util.stream.Collectors;
32-
3333
/**
3434
* A representation of an OAuth 2.0 "consent" to an Authorization request, which holds state related to the
35-
* set of {@link #getAuthorities()} authorities} granted to a {@link #getRegisteredClientId() client} by the
35+
* set of {@link #getAuthorities() authorities} granted to a {@link #getRegisteredClientId() client} by the
3636
* {@link #getPrincipalName() resource owner}.
3737
* <p>
3838
* When authorizing access for a given client, the resource owner may only grant a subset of the authorities
@@ -130,7 +130,7 @@ public static Builder withId(@NonNull String registeredClientId, @NonNull String
130130
/**
131131
* A builder for {@link OAuth2AuthorizationConsent}.
132132
*/
133-
public final static class Builder implements Serializable {
133+
public static final class Builder implements Serializable {
134134
private static final long serialVersionUID = Version.SERIAL_VERSION_UID;
135135

136136
private final String registeredClientId;
@@ -151,10 +151,10 @@ private Builder(String registeredClientId, String principalName, Set<GrantedAuth
151151

152152
/**
153153
* Adds a scope to the collection of {@code authorities} in the resulting {@link OAuth2AuthorizationConsent},
154-
* wrapping it in a SimpleGrantedAuthority, prefixed by {@code SCOPE_}. For example, a
154+
* wrapping it in a {@link SimpleGrantedAuthority}, prefixed by {@code SCOPE_}. For example, a
155155
* {@code message.write} scope would be stored as {@code SCOPE_message.write}.
156156
*
157-
* @param scope the {@code scope}
157+
* @param scope the scope
158158
* @return the {@code Builder} for further configuration
159159
*/
160160
public Builder scope(String scope) {

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

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* @see OAuth2AuthorizationConsent
3030
*/
3131
public interface OAuth2AuthorizationConsentService {
32+
3233
/**
3334
* Saves the {@link OAuth2AuthorizationConsent}.
3435
*
@@ -53,4 +54,5 @@ public interface OAuth2AuthorizationConsentService {
5354
*/
5455
@Nullable
5556
OAuth2AuthorizationConsent findById(String registeredClientId, String principalName);
57+
5658
}

0 commit comments

Comments
 (0)