Skip to content

Commit 0b4502b

Browse files
eleftheriasrwinch
authored andcommitted
Remove exceptions from lambda security configuration
Fixes: gh-7128
1 parent b55322b commit 0b4502b

File tree

23 files changed

+115
-168
lines changed

23 files changed

+115
-168
lines changed

config/src/main/java/org/springframework/security/config/Customizer.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
package org.springframework.security.config;
1818

1919
/**
20-
* Callback interface that accepts a single input argument and returns no result,
21-
* with the ability to throw a (checked) exception.
20+
* Callback interface that accepts a single input argument and returns no result.
2221
*
2322
* @author Eleftheria Stein
2423
* @param <T> the type of the input to the operation
@@ -31,9 +30,8 @@ public interface Customizer<T> {
3130
* Performs the customizations on the input argument.
3231
*
3332
* @param t the input argument
34-
* @throws Exception if any error occurs
3533
*/
36-
void customize(T t) throws Exception;
34+
void customize(T t);
3735

3836
/**
3937
* Returns a {@link Customizer} that does not alter the input argument.

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

+8-19
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,8 @@ public ContentTypeOptionsConfig contentTypeOptions() {
136136
* @param contentTypeOptionsCustomizer the {@link Customizer} to provide more options for
137137
* the {@link ContentTypeOptionsConfig}
138138
* @return the {@link HeadersConfigurer} for additional customizations
139-
* @throws Exception
140139
*/
141-
public HeadersConfigurer<H> contentTypeOptions(Customizer<ContentTypeOptionsConfig> contentTypeOptionsCustomizer)
142-
throws Exception {
140+
public HeadersConfigurer<H> contentTypeOptions(Customizer<ContentTypeOptionsConfig> contentTypeOptionsCustomizer) {
143141
contentTypeOptionsCustomizer.customize(contentTypeOptions.enable());
144142
return HeadersConfigurer.this;
145143
}
@@ -209,9 +207,8 @@ public XXssConfig xssProtection() {
209207
* @param xssCustomizer the {@link Customizer} to provide more options for
210208
* the {@link XXssConfig}
211209
* @return the {@link HeadersConfigurer} for additional customizations
212-
* @throws Exception
213210
*/
214-
public HeadersConfigurer<H> xssProtection(Customizer<XXssConfig> xssCustomizer) throws Exception {
211+
public HeadersConfigurer<H> xssProtection(Customizer<XXssConfig> xssCustomizer) {
215212
xssCustomizer.customize(xssProtection.enable());
216213
return HeadersConfigurer.this;
217214
}
@@ -322,14 +319,12 @@ public CacheControlConfig cacheControl() {
322319
* @param cacheControlCustomizer the {@link Customizer} to provide more options for
323320
* the {@link CacheControlConfig}
324321
* @return the {@link HeadersConfigurer} for additional customizations
325-
* @throws Exception
326322
*/
327-
public HeadersConfigurer<H> cacheControl(Customizer<CacheControlConfig> cacheControlCustomizer) throws Exception {
323+
public HeadersConfigurer<H> cacheControl(Customizer<CacheControlConfig> cacheControlCustomizer) {
328324
cacheControlCustomizer.customize(cacheControl.enable());
329325
return HeadersConfigurer.this;
330326
}
331327

332-
333328
public final class CacheControlConfig {
334329
private CacheControlHeadersWriter writer;
335330

@@ -389,9 +384,8 @@ public HstsConfig httpStrictTransportSecurity() {
389384
* @param hstsCustomizer the {@link Customizer} to provide more options for
390385
* the {@link HstsConfig}
391386
* @return the {@link HeadersConfigurer} for additional customizations
392-
* @throws Exception
393387
*/
394-
public HeadersConfigurer<H> httpStrictTransportSecurity(Customizer<HstsConfig> hstsCustomizer) throws Exception {
388+
public HeadersConfigurer<H> httpStrictTransportSecurity(Customizer<HstsConfig> hstsCustomizer) {
395389
hstsCustomizer.customize(hsts.enable());
396390
return HeadersConfigurer.this;
397391
}
@@ -523,9 +517,8 @@ public FrameOptionsConfig frameOptions() {
523517
* @param frameOptionsCustomizer the {@link Customizer} to provide more options for
524518
* the {@link FrameOptionsConfig}
525519
* @return the {@link HeadersConfigurer} for additional customizations
526-
* @throws Exception
527520
*/
528-
public HeadersConfigurer<H> frameOptions(Customizer<FrameOptionsConfig> frameOptionsCustomizer) throws Exception {
521+
public HeadersConfigurer<H> frameOptions(Customizer<FrameOptionsConfig> frameOptionsCustomizer) {
529522
frameOptionsCustomizer.customize(frameOptions.enable());
530523
return HeadersConfigurer.this;
531524
}
@@ -613,9 +606,8 @@ public HpkpConfig httpPublicKeyPinning() {
613606
* @param hpkpCustomizer the {@link Customizer} to provide more options for
614607
* the {@link HpkpConfig}
615608
* @return the {@link HeadersConfigurer} for additional customizations
616-
* @throws Exception
617609
*/
618-
public HeadersConfigurer<H> httpPublicKeyPinning(Customizer<HpkpConfig> hpkpCustomizer) throws Exception {
610+
public HeadersConfigurer<H> httpPublicKeyPinning(Customizer<HpkpConfig> hpkpCustomizer) {
619611
hpkpCustomizer.customize(hpkp.enable());
620612
return HeadersConfigurer.this;
621613
}
@@ -840,10 +832,8 @@ public ContentSecurityPolicyConfig contentSecurityPolicy(String policyDirectives
840832
* @param contentSecurityCustomizer the {@link Customizer} to provide more options for
841833
* the {@link ContentSecurityPolicyConfig}
842834
* @return the {@link HeadersConfigurer} for additional customizations
843-
* @throws Exception
844835
*/
845-
public HeadersConfigurer<H> contentSecurityPolicy(Customizer<ContentSecurityPolicyConfig> contentSecurityCustomizer)
846-
throws Exception {
836+
public HeadersConfigurer<H> contentSecurityPolicy(Customizer<ContentSecurityPolicyConfig> contentSecurityCustomizer) {
847837
this.contentSecurityPolicy.writer = new ContentSecurityPolicyHeaderWriter();
848838
contentSecurityCustomizer.customize(this.contentSecurityPolicy);
849839

@@ -1026,9 +1016,8 @@ public ReferrerPolicyConfig referrerPolicy(ReferrerPolicy policy) {
10261016
* @param referrerPolicyCustomizer the {@link Customizer} to provide more options for
10271017
* the {@link ReferrerPolicyConfig}
10281018
* @return the {@link HeadersConfigurer} for additional customizations
1029-
* @throws Exception
10301019
*/
1031-
public HeadersConfigurer<H> referrerPolicy(Customizer<ReferrerPolicyConfig> referrerPolicyCustomizer) throws Exception {
1020+
public HeadersConfigurer<H> referrerPolicy(Customizer<ReferrerPolicyConfig> referrerPolicyCustomizer) {
10321021
this.referrerPolicy.writer = new ReferrerPolicyHeaderWriter();
10331022
referrerPolicyCustomizer.customize(this.referrerPolicy);
10341023
return HeadersConfigurer.this;

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -113,9 +113,8 @@ public HttpBasicConfigurer() throws Exception {
113113
*
114114
* @param realmName the HTTP Basic realm to use
115115
* @return {@link HttpBasicConfigurer} for additional customization
116-
* @throws Exception
117116
*/
118-
public HttpBasicConfigurer<B> realmName(String realmName) throws Exception {
117+
public HttpBasicConfigurer<B> realmName(String realmName) {
119118
this.basicAuthEntryPoint.setRealmName(realmName);
120119
this.basicAuthEntryPoint.afterPropertiesSet();
121120
return this;

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,7 @@ public SessionFixationConfigurer sessionFixation() {
257257
* the {@link SessionFixationConfigurer}
258258
* @return the {@link SessionManagementConfigurer} for further customizations
259259
*/
260-
public SessionManagementConfigurer<H> sessionFixation(Customizer<SessionFixationConfigurer> sessionFixationCustomizer)
261-
throws Exception {
260+
public SessionManagementConfigurer<H> sessionFixation(Customizer<SessionFixationConfigurer> sessionFixationCustomizer) {
262261
sessionFixationCustomizer.customize(new SessionFixationConfigurer());
263262
return this;
264263
}
@@ -282,8 +281,7 @@ public ConcurrencyControlConfigurer maximumSessions(int maximumSessions) {
282281
* the {@link ConcurrencyControlConfigurer}
283282
* @return the {@link SessionManagementConfigurer} for further customizations
284283
*/
285-
public SessionManagementConfigurer<H> sessionConcurrency(Customizer<ConcurrencyControlConfigurer> sessionConcurrencyCustomizer)
286-
throws Exception {
284+
public SessionManagementConfigurer<H> sessionConcurrency(Customizer<ConcurrencyControlConfigurer> sessionConcurrencyCustomizer) {
287285
sessionConcurrencyCustomizer.customize(new ConcurrencyControlConfigurer());
288286
return this;
289287
}

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

+4-11
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,8 @@ public AuthorizationEndpointConfig authorizationEndpoint() {
208208
* @param authorizationEndpointCustomizer the {@link Customizer} to provide more options for
209209
* the {@link AuthorizationEndpointConfig}
210210
* @return the {@link OAuth2LoginConfigurer} for further customizations
211-
* @throws Exception
212211
*/
213-
public OAuth2LoginConfigurer<B> authorizationEndpoint(Customizer<AuthorizationEndpointConfig> authorizationEndpointCustomizer)
214-
throws Exception {
212+
public OAuth2LoginConfigurer<B> authorizationEndpoint(Customizer<AuthorizationEndpointConfig> authorizationEndpointCustomizer) {
215213
authorizationEndpointCustomizer.customize(this.authorizationEndpointConfig);
216214
return this;
217215
}
@@ -291,8 +289,7 @@ public TokenEndpointConfig tokenEndpoint() {
291289
* @return the {@link OAuth2LoginConfigurer} for further customizations
292290
* @throws Exception
293291
*/
294-
public OAuth2LoginConfigurer<B> tokenEndpoint(Customizer<TokenEndpointConfig> tokenEndpointCustomizer)
295-
throws Exception {
292+
public OAuth2LoginConfigurer<B> tokenEndpoint(Customizer<TokenEndpointConfig> tokenEndpointCustomizer) {
296293
tokenEndpointCustomizer.customize(this.tokenEndpointConfig);
297294
return this;
298295
}
@@ -345,10 +342,8 @@ public RedirectionEndpointConfig redirectionEndpoint() {
345342
* @param redirectionEndpointCustomizer the {@link Customizer} to provide more options for
346343
* the {@link RedirectionEndpointConfig}
347344
* @return the {@link OAuth2LoginConfigurer} for further customizations
348-
* @throws Exception
349345
*/
350-
public OAuth2LoginConfigurer<B> redirectionEndpoint(Customizer<RedirectionEndpointConfig> redirectionEndpointCustomizer)
351-
throws Exception {
346+
public OAuth2LoginConfigurer<B> redirectionEndpoint(Customizer<RedirectionEndpointConfig> redirectionEndpointCustomizer) {
352347
redirectionEndpointCustomizer.customize(this.redirectionEndpointConfig);
353348
return this;
354349
}
@@ -399,10 +394,8 @@ public UserInfoEndpointConfig userInfoEndpoint() {
399394
* @param userInfoEndpointCustomizer the {@link Customizer} to provide more options for
400395
* the {@link UserInfoEndpointConfig}
401396
* @return the {@link OAuth2LoginConfigurer} for further customizations
402-
* @throws Exception
403397
*/
404-
public OAuth2LoginConfigurer<B> userInfoEndpoint(Customizer<UserInfoEndpointConfig> userInfoEndpointCustomizer)
405-
throws Exception {
398+
public OAuth2LoginConfigurer<B> userInfoEndpoint(Customizer<UserInfoEndpointConfig> userInfoEndpointCustomizer) {
406399
userInfoEndpointCustomizer.customize(this.userInfoEndpointConfig);
407400
return this;
408401
}

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

+2-5
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,8 @@ public JwtConfigurer jwt() {
188188
* @param jwtCustomizer the {@link Customizer} to provide more options for
189189
* the {@link JwtConfigurer}
190190
* @return the {@link OAuth2ResourceServerConfigurer} for further customizations
191-
* @throws Exception
192191
*/
193-
public OAuth2ResourceServerConfigurer<H> jwt(Customizer<JwtConfigurer> jwtCustomizer) throws Exception {
192+
public OAuth2ResourceServerConfigurer<H> jwt(Customizer<JwtConfigurer> jwtCustomizer) {
194193
if ( this.jwtConfigurer == null ) {
195194
this.jwtConfigurer = new JwtConfigurer(this.context);
196195
}
@@ -212,10 +211,8 @@ public OpaqueTokenConfigurer opaqueToken() {
212211
* @param opaqueTokenCustomizer the {@link Customizer} to provide more options for
213212
* the {@link OpaqueTokenConfigurer}
214213
* @return the {@link OAuth2ResourceServerConfigurer} for further customizations
215-
* @throws Exception
216214
*/
217-
public OAuth2ResourceServerConfigurer<H> opaqueToken(Customizer<OpaqueTokenConfigurer> opaqueTokenCustomizer)
218-
throws Exception {
215+
public OAuth2ResourceServerConfigurer<H> opaqueToken(Customizer<OpaqueTokenConfigurer> opaqueTokenCustomizer) {
219216
if (this.opaqueTokenConfigurer == null) {
220217
this.opaqueTokenConfigurer = new OpaqueTokenConfigurer(this.context);
221218
}

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

+2-5
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,8 @@ public AttributeExchangeConfigurer attributeExchange(String identifierPattern) {
157157
* @param attributeExchangeCustomizer the {@link Customizer} to provide more options for
158158
* the {@link AttributeExchangeConfigurer}
159159
* @return a {@link OpenIDLoginConfigurer} for further customizations
160-
* @throws Exception
161160
*/
162-
public OpenIDLoginConfigurer<H> attributeExchange(Customizer<AttributeExchangeConfigurer> attributeExchangeCustomizer)
163-
throws Exception {
161+
public OpenIDLoginConfigurer<H> attributeExchange(Customizer<AttributeExchangeConfigurer> attributeExchangeCustomizer) {
164162
AttributeExchangeConfigurer attributeExchangeConfigurer = new AttributeExchangeConfigurer(".*");
165163
attributeExchangeCustomizer.customize(attributeExchangeConfigurer);
166164
this.attributeExchangeConfigurers.add(attributeExchangeConfigurer);
@@ -458,9 +456,8 @@ public AttributeConfigurer attribute(String name) {
458456
* @param attributeCustomizer the {@link Customizer} to provide more options for
459457
* the {@link AttributeConfigurer}
460458
* @return a {@link AttributeExchangeConfigurer} for further customizations
461-
* @throws Exception
462459
*/
463-
public AttributeExchangeConfigurer attribute(Customizer<AttributeConfigurer> attributeCustomizer) throws Exception {
460+
public AttributeExchangeConfigurer attribute(Customizer<AttributeConfigurer> attributeCustomizer) {
464461
AttributeConfigurer attributeConfigurer = new AttributeConfigurer();
465462
attributeCustomizer.customize(attributeConfigurer);
466463
this.attributeConfigurers.add(attributeConfigurer);

0 commit comments

Comments
 (0)