Skip to content

Commit 4283aeb

Browse files
committed
Response to Additional Feedback
- Moved request attribute to WebAttributes - Renamed ExceptionHandlingConfigurer methods - Removed varargs from DelegatingMissingAuthorityAccessDeniedHandler
1 parent 5585a18 commit 4283aeb

File tree

13 files changed

+60
-50
lines changed

13 files changed

+60
-50
lines changed

config/src/main/java/org/springframework/security/config/annotation/web/configurers/ExceptionHandlingConfigurer.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ public final class ExceptionHandlingConfigurer<H extends HttpSecurityBuilder<H>>
8080

8181
private LinkedHashMap<RequestMatcher, AccessDeniedHandler> defaultDeniedHandlerMappings = new LinkedHashMap<>();
8282

83-
private final DelegatingMissingAuthorityAccessDeniedHandler.Builder missingAuthoritiesHandlerBuilder = DelegatingMissingAuthorityAccessDeniedHandler
84-
.builder();
83+
private DelegatingMissingAuthorityAccessDeniedHandler.@Nullable Builder missingAuthoritiesHandlerBuilder;
8584

8685
/**
8786
* Creates a new instance
@@ -142,8 +141,11 @@ public ExceptionHandlingConfigurer<H> defaultAccessDeniedHandlerFor(AccessDenied
142141
* @return the {@link ExceptionHandlingConfigurer} for further customizations
143142
* @since 7.0
144143
*/
145-
public ExceptionHandlingConfigurer<H> defaultAuthenticationEntryPointFor(AuthenticationEntryPoint entryPoint,
144+
public ExceptionHandlingConfigurer<H> defaultDeniedHandlerForMissingAuthority(AuthenticationEntryPoint entryPoint,
146145
String authority) {
146+
if (this.missingAuthoritiesHandlerBuilder == null) {
147+
this.missingAuthoritiesHandlerBuilder = DelegatingMissingAuthorityAccessDeniedHandler.builder();
148+
}
147149
this.missingAuthoritiesHandlerBuilder.addEntryPointFor(entryPoint, authority);
148150
return this;
149151
}
@@ -158,14 +160,18 @@ public ExceptionHandlingConfigurer<H> defaultAuthenticationEntryPointFor(Authent
158160
* @return the {@link ExceptionHandlingConfigurer} for further customizations
159161
* @since 7.0
160162
*/
161-
public ExceptionHandlingConfigurer<H> defaultAuthenticationEntryPointFor(
163+
public ExceptionHandlingConfigurer<H> defaultDeniedHandlerForMissingAuthority(
162164
Consumer<DelegatingAuthenticationEntryPoint.Builder> entryPoint, String authority) {
165+
if (this.missingAuthoritiesHandlerBuilder == null) {
166+
this.missingAuthoritiesHandlerBuilder = DelegatingMissingAuthorityAccessDeniedHandler.builder();
167+
}
163168
this.missingAuthoritiesHandlerBuilder.addEntryPointFor(entryPoint, authority);
164169
return this;
165170
}
166171

167172
/**
168-
* Sets the {@link AuthenticationEntryPoint} to be used.
173+
* Sets the {@link AuthenticationEntryPoint} to be used. =
174+
* DelegatingMissingAuthorityAccessDeniedHandler .builder();
169175
*
170176
* <p>
171177
* If no {@link #authenticationEntryPoint(AuthenticationEntryPoint)} is specified,
@@ -267,6 +273,9 @@ AuthenticationEntryPoint getAuthenticationEntryPoint(H http) {
267273

268274
private AccessDeniedHandler createDefaultDeniedHandler(H http) {
269275
AccessDeniedHandler defaults = createDefaultAccessDeniedHandler(http);
276+
if (this.missingAuthoritiesHandlerBuilder == null) {
277+
return defaults;
278+
}
270279
DelegatingMissingAuthorityAccessDeniedHandler deniedHandler = this.missingAuthoritiesHandlerBuilder.build();
271280
deniedHandler.setRequestCache(getRequestCache(http));
272281
deniedHandler.setDefaultAccessDeniedHandler(defaults);

config/src/main/java/org/springframework/security/config/annotation/web/configurers/FormLoginConfigurer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public void init(H http) throws Exception {
235235
if (exceptions != null) {
236236
AuthenticationEntryPoint entryPoint = getAuthenticationEntryPoint();
237237
RequestMatcher requestMatcher = getAuthenticationEntryPointMatcher(http);
238-
exceptions.defaultAuthenticationEntryPointFor((ep) -> ep.addEntryPointFor(entryPoint, requestMatcher),
238+
exceptions.defaultDeniedHandlerForMissingAuthority((ep) -> ep.addEntryPointFor(entryPoint, requestMatcher),
239239
"FACTOR_PASSWORD");
240240
}
241241
}

config/src/main/java/org/springframework/security/config/annotation/web/configurers/HttpBasicConfigurer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ private void registerDefaultEntryPoint(B http, RequestMatcher preferredMatcher)
194194
}
195195
AuthenticationEntryPoint entryPoint = postProcess(this.authenticationEntryPoint);
196196
exceptionHandling.defaultAuthenticationEntryPointFor(entryPoint, preferredMatcher);
197-
exceptionHandling.defaultAuthenticationEntryPointFor((ep) -> ep.addEntryPointFor(entryPoint, preferredMatcher),
198-
"FACTOR_PASSWORD");
197+
exceptionHandling.defaultDeniedHandlerForMissingAuthority(
198+
(ep) -> ep.addEntryPointFor(entryPoint, preferredMatcher), "FACTOR_PASSWORD");
199199
}
200200

201201
private void registerDefaultLogoutSuccessHandler(B http, RequestMatcher preferredMatcher) {

config/src/main/java/org/springframework/security/config/annotation/web/configurers/WebAuthnConfigurer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public void init(H http) throws Exception {
158158
ExceptionHandlingConfigurer<H> exceptions = http.getConfigurer(ExceptionHandlingConfigurer.class);
159159
if (exceptions != null) {
160160
AuthenticationEntryPoint entryPoint = new LoginUrlAuthenticationEntryPoint("/login");
161-
exceptions.defaultAuthenticationEntryPointFor(
161+
exceptions.defaultDeniedHandlerForMissingAuthority(
162162
(ep) -> ep.addEntryPointFor(entryPoint, AnyRequestMatcher.INSTANCE), "FACTOR_WEBAUTHN");
163163
}
164164
}

config/src/main/java/org/springframework/security/config/annotation/web/configurers/X509Configurer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public void init(H http) {
186186
if (exceptions != null) {
187187
AuthenticationEntryPoint forbidden = new Http403ForbiddenEntryPoint();
188188
exceptions.defaultAuthenticationEntryPointFor(forbidden, AnyRequestMatcher.INSTANCE);
189-
exceptions.defaultAuthenticationEntryPointFor(
189+
exceptions.defaultDeniedHandlerForMissingAuthority(
190190
(ep) -> ep.addEntryPointFor(forbidden, AnyRequestMatcher.INSTANCE), "FACTOR_X509");
191191
}
192192
}

config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/OAuth2LoginConfigurer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,8 @@ private AuthenticationEntryPoint getLoginEntryPoint(B http, String providerLogin
565565
ExceptionHandlingConfigurer<B> exceptions = http.getConfigurer(ExceptionHandlingConfigurer.class);
566566
if (exceptions != null) {
567567
RequestMatcher requestMatcher = getAuthenticationEntryPointMatcher(http);
568-
exceptions.defaultAuthenticationEntryPointFor((ep) -> ep.addEntryPointFor(loginEntryPoint, requestMatcher),
569-
"FACTOR_AUTHORIZATION_CODE");
568+
exceptions.defaultDeniedHandlerForMissingAuthority(
569+
(ep) -> ep.addEntryPointFor(loginEntryPoint, requestMatcher), "FACTOR_AUTHORIZATION_CODE");
570570
}
571571
return loginEntryPoint;
572572
}

config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/server/resource/OAuth2ResourceServerConfigurer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ private void registerDefaultEntryPoint(H http) {
327327
RequestMatcher preferredMatcher = new OrRequestMatcher(
328328
Arrays.asList(this.requestMatcher, X_REQUESTED_WITH, restNotHtmlMatcher, allMatcher));
329329
exceptionHandling.defaultAuthenticationEntryPointFor(this.authenticationEntryPoint, preferredMatcher);
330-
exceptionHandling.defaultAuthenticationEntryPointFor(
330+
exceptionHandling.defaultDeniedHandlerForMissingAuthority(
331331
(ep) -> ep.addEntryPointFor(this.authenticationEntryPoint, preferredMatcher), "FACTOR_BEARER");
332332
}
333333
}

config/src/main/java/org/springframework/security/config/annotation/web/configurers/ott/OneTimeTokenLoginConfigurer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public void init(H http) throws Exception {
140140
if (exceptions != null) {
141141
AuthenticationEntryPoint entryPoint = getAuthenticationEntryPoint();
142142
RequestMatcher requestMatcher = getAuthenticationEntryPointMatcher(http);
143-
exceptions.defaultAuthenticationEntryPointFor((ep) -> ep.addEntryPointFor(entryPoint, requestMatcher),
143+
exceptions.defaultDeniedHandlerForMissingAuthority((ep) -> ep.addEntryPointFor(entryPoint, requestMatcher),
144144
"FACTOR_OTT");
145145
}
146146
}

config/src/main/java/org/springframework/security/config/annotation/web/configurers/saml2/Saml2LoginConfigurer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,8 @@ private AuthenticationEntryPoint getLoginEntryPoint(B http, String providerLogin
352352
ExceptionHandlingConfigurer<B> exceptions = http.getConfigurer(ExceptionHandlingConfigurer.class);
353353
if (exceptions != null) {
354354
RequestMatcher requestMatcher = getAuthenticationEntryPointMatcher(http);
355-
exceptions.defaultAuthenticationEntryPointFor((ep) -> ep.addEntryPointFor(loginEntryPoint, requestMatcher),
356-
"FACTOR_SAML_RESPONSE");
355+
exceptions.defaultDeniedHandlerForMissingAuthority(
356+
(ep) -> ep.addEntryPointFor(loginEntryPoint, requestMatcher), "FACTOR_SAML_RESPONSE");
357357
}
358358
return loginEntryPoint;
359359
}

core/src/main/java/org/springframework/security/core/GrantedAuthority.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
*/
3232
public interface GrantedAuthority extends Serializable {
3333

34-
String MISSING_AUTHORITIES_ATTRIBUTE = GrantedAuthority.class + ".missingAuthorities";
35-
3634
/**
3735
* If the <code>GrantedAuthority</code> can be represented as a <code>String</code>
3836
* and that <code>String</code> is sufficient in precision to be relied upon for an

0 commit comments

Comments
 (0)