Skip to content

Commit b2d76df

Browse files
committed
Add GrantedAuthorities.FACTOR_*_AUTHORITY
Closes gh-17952
1 parent 28aad88 commit b2d76df

File tree

57 files changed

+227
-81
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+227
-81
lines changed

cas/src/main/java/org/springframework/security/cas/authentication/CasAuthenticationProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.springframework.security.cas.ServiceProperties;
3939
import org.springframework.security.core.Authentication;
4040
import org.springframework.security.core.AuthenticationException;
41+
import org.springframework.security.core.GrantedAuthorities;
4142
import org.springframework.security.core.GrantedAuthority;
4243
import org.springframework.security.core.SpringSecurityMessageSource;
4344
import org.springframework.security.core.authority.SimpleGrantedAuthority;
@@ -69,7 +70,7 @@ public class CasAuthenticationProvider implements AuthenticationProvider, Initia
6970

7071
private static final Log logger = LogFactory.getLog(CasAuthenticationProvider.class);
7172

72-
private static final String AUTHORITY = "FACTOR_CAS";
73+
private static final String AUTHORITY = GrantedAuthorities.FACTOR_CAS_AUTHORITY;
7374

7475
@SuppressWarnings("NullAway.Init")
7576
private AuthenticationUserDetailsService<CasAssertionAuthenticationToken> authenticationUserDetailsService;

cas/src/test/java/org/springframework/security/cas/authentication/CasAuthenticationProviderTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.springframework.security.cas.ServiceProperties;
3434
import org.springframework.security.core.Authentication;
3535
import org.springframework.security.core.AuthenticationException;
36+
import org.springframework.security.core.GrantedAuthorities;
3637
import org.springframework.security.core.authority.AuthorityUtils;
3738
import org.springframework.security.core.authority.SimpleGrantedAuthority;
3839
import org.springframework.security.core.userdetails.AuthenticationUserDetailsService;
@@ -360,7 +361,7 @@ public void authenticateWhenSuccessfulThenIssuesFactor() throws Exception {
360361
CasServiceTicketAuthenticationToken token = CasServiceTicketAuthenticationToken.stateful("ST-123");
361362
token.setDetails("details");
362363
Authentication result = cap.authenticate(token);
363-
SecurityAssertions.assertThat(result).hasAuthority("FACTOR_CAS");
364+
SecurityAssertions.assertThat(result).hasAuthority(GrantedAuthorities.FACTOR_CAS_AUTHORITY);
364365
}
365366

366367
private class MockAuthoritiesPopulator implements AuthenticationUserDetailsService {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.springframework.security.config.annotation.web.HttpSecurityBuilder;
2222
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
2323
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
24+
import org.springframework.security.core.GrantedAuthorities;
2425
import org.springframework.security.web.AuthenticationEntryPoint;
2526
import org.springframework.security.web.authentication.ForwardAuthenticationFailureHandler;
2627
import org.springframework.security.web.authentication.ForwardAuthenticationSuccessHandler;
@@ -236,7 +237,7 @@ public void init(H http) throws Exception {
236237
AuthenticationEntryPoint entryPoint = getAuthenticationEntryPoint();
237238
RequestMatcher requestMatcher = getAuthenticationEntryPointMatcher(http);
238239
exceptions.defaultDeniedHandlerForMissingAuthority((ep) -> ep.addEntryPointFor(entryPoint, requestMatcher),
239-
"FACTOR_PASSWORD");
240+
GrantedAuthorities.FACTOR_PASSWORD_AUTHORITY);
240241
}
241242
}
242243

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.springframework.security.config.Customizer;
2929
import org.springframework.security.config.annotation.web.HttpSecurityBuilder;
3030
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
31+
import org.springframework.security.core.GrantedAuthorities;
3132
import org.springframework.security.web.AuthenticationEntryPoint;
3233
import org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint;
3334
import org.springframework.security.web.authentication.HttpStatusEntryPoint;
@@ -195,7 +196,8 @@ private void registerDefaultEntryPoint(B http, RequestMatcher preferredMatcher)
195196
AuthenticationEntryPoint entryPoint = postProcess(this.authenticationEntryPoint);
196197
exceptionHandling.defaultAuthenticationEntryPointFor(entryPoint, preferredMatcher);
197198
exceptionHandling.defaultDeniedHandlerForMissingAuthority(
198-
(ep) -> ep.addEntryPointFor(entryPoint, preferredMatcher), "FACTOR_PASSWORD");
199+
(ep) -> ep.addEntryPointFor(entryPoint, preferredMatcher),
200+
GrantedAuthorities.FACTOR_PASSWORD_AUTHORITY);
199201
}
200202

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

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.springframework.http.converter.HttpMessageConverter;
2727
import org.springframework.security.authentication.ProviderManager;
2828
import org.springframework.security.config.annotation.web.HttpSecurityBuilder;
29+
import org.springframework.security.core.GrantedAuthorities;
2930
import org.springframework.security.core.userdetails.UserDetailsService;
3031
import org.springframework.security.web.AuthenticationEntryPoint;
3132
import org.springframework.security.web.access.intercept.AuthorizationFilter;
@@ -159,7 +160,8 @@ public void init(H http) throws Exception {
159160
if (exceptions != null) {
160161
AuthenticationEntryPoint entryPoint = new LoginUrlAuthenticationEntryPoint("/login");
161162
exceptions.defaultDeniedHandlerForMissingAuthority(
162-
(ep) -> ep.addEntryPointFor(entryPoint, AnyRequestMatcher.INSTANCE), "FACTOR_WEBAUTHN");
163+
(ep) -> ep.addEntryPointFor(entryPoint, AnyRequestMatcher.INSTANCE),
164+
GrantedAuthorities.FACTOR_WEBAUTHN_AUTHORITY);
163165
}
164166
}
165167

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.springframework.security.config.annotation.web.HttpSecurityBuilder;
2626
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
2727
import org.springframework.security.core.Authentication;
28+
import org.springframework.security.core.GrantedAuthorities;
2829
import org.springframework.security.core.authority.AuthorityUtils;
2930
import org.springframework.security.core.userdetails.AuthenticationUserDetailsService;
3031
import org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper;
@@ -179,14 +180,16 @@ public X509Configurer<H> subjectPrincipalRegex(String subjectPrincipalRegex) {
179180
public void init(H http) {
180181
PreAuthenticatedAuthenticationProvider authenticationProvider = new PreAuthenticatedAuthenticationProvider();
181182
authenticationProvider.setPreAuthenticatedUserDetailsService(getAuthenticationUserDetailsService(http));
182-
authenticationProvider.setGrantedAuthoritySupplier(() -> AuthorityUtils.createAuthorityList("FACTOR_X509"));
183+
authenticationProvider.setGrantedAuthoritySupplier(
184+
() -> AuthorityUtils.createAuthorityList(GrantedAuthorities.FACTOR_X509_AUTHORITY));
183185
http.authenticationProvider(authenticationProvider)
184186
.setSharedObject(AuthenticationEntryPoint.class, new Http403ForbiddenEntryPoint());
185187
ExceptionHandlingConfigurer<H> exceptions = http.getConfigurer(ExceptionHandlingConfigurer.class);
186188
if (exceptions != null) {
187189
AuthenticationEntryPoint forbidden = new Http403ForbiddenEntryPoint();
188190
exceptions.defaultDeniedHandlerForMissingAuthority(
189-
(ep) -> ep.addEntryPointFor(forbidden, AnyRequestMatcher.INSTANCE), "FACTOR_X509");
191+
(ep) -> ep.addEntryPointFor(forbidden, AnyRequestMatcher.INSTANCE),
192+
GrantedAuthorities.FACTOR_X509_AUTHORITY);
190193
}
191194
}
192195

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.springframework.security.context.DelegatingApplicationListener;
4646
import org.springframework.security.core.Authentication;
4747
import org.springframework.security.core.AuthenticationException;
48+
import org.springframework.security.core.GrantedAuthorities;
4849
import org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper;
4950
import org.springframework.security.core.session.AbstractSessionEvent;
5051
import org.springframework.security.core.session.SessionDestroyedEvent;
@@ -566,7 +567,8 @@ private AuthenticationEntryPoint getLoginEntryPoint(B http, String providerLogin
566567
if (exceptions != null) {
567568
RequestMatcher requestMatcher = getAuthenticationEntryPointMatcher(http);
568569
exceptions.defaultDeniedHandlerForMissingAuthority(
569-
(ep) -> ep.addEntryPointFor(loginEntryPoint, requestMatcher), "FACTOR_AUTHORIZATION_CODE");
570+
(ep) -> ep.addEntryPointFor(loginEntryPoint, requestMatcher),
571+
GrantedAuthorities.FACTOR_AUTHORIZATION_CODE_AUTHORITY);
570572
}
571573
return loginEntryPoint;
572574
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.springframework.security.config.annotation.web.configurers.ExceptionHandlingConfigurer;
3939
import org.springframework.security.config.http.SessionCreationPolicy;
4040
import org.springframework.security.core.Authentication;
41+
import org.springframework.security.core.GrantedAuthorities;
4142
import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
4243
import org.springframework.security.oauth2.jwt.Jwt;
4344
import org.springframework.security.oauth2.jwt.JwtDecoder;
@@ -328,7 +329,8 @@ private void registerDefaultEntryPoint(H http) {
328329
Arrays.asList(this.requestMatcher, X_REQUESTED_WITH, restNotHtmlMatcher, allMatcher));
329330
exceptionHandling.defaultAuthenticationEntryPointFor(this.authenticationEntryPoint, preferredMatcher);
330331
exceptionHandling.defaultDeniedHandlerForMissingAuthority(
331-
(ep) -> ep.addEntryPointFor(this.authenticationEntryPoint, preferredMatcher), "FACTOR_BEARER");
332+
(ep) -> ep.addEntryPointFor(this.authenticationEntryPoint, preferredMatcher),
333+
GrantedAuthorities.FACTOR_BEARER_AUTHORITY);
332334
}
333335
}
334336

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
3838
import org.springframework.security.config.annotation.web.configurers.ExceptionHandlingConfigurer;
3939
import org.springframework.security.core.Authentication;
40+
import org.springframework.security.core.GrantedAuthorities;
4041
import org.springframework.security.core.userdetails.UserDetailsService;
4142
import org.springframework.security.web.AuthenticationEntryPoint;
4243
import org.springframework.security.web.authentication.AuthenticationConverter;
@@ -141,7 +142,7 @@ public void init(H http) throws Exception {
141142
AuthenticationEntryPoint entryPoint = getAuthenticationEntryPoint();
142143
RequestMatcher requestMatcher = getAuthenticationEntryPointMatcher(http);
143144
exceptions.defaultDeniedHandlerForMissingAuthority((ep) -> ep.addEntryPointFor(entryPoint, requestMatcher),
144-
"FACTOR_OTT");
145+
GrantedAuthorities.FACTOR_OTT_AUTHORITY);
145146
}
146147
}
147148

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer;
3636
import org.springframework.security.config.annotation.web.configurers.ExceptionHandlingConfigurer;
3737
import org.springframework.security.core.Authentication;
38+
import org.springframework.security.core.GrantedAuthorities;
3839
import org.springframework.security.saml2.provider.service.authentication.AbstractSaml2AuthenticationRequest;
3940
import org.springframework.security.saml2.provider.service.authentication.OpenSaml5AuthenticationProvider;
4041
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration;
@@ -353,7 +354,8 @@ private AuthenticationEntryPoint getLoginEntryPoint(B http, String providerLogin
353354
if (exceptions != null) {
354355
RequestMatcher requestMatcher = getAuthenticationEntryPointMatcher(http);
355356
exceptions.defaultDeniedHandlerForMissingAuthority(
356-
(ep) -> ep.addEntryPointFor(loginEntryPoint, requestMatcher), "FACTOR_SAML_RESPONSE");
357+
(ep) -> ep.addEntryPointFor(loginEntryPoint, requestMatcher),
358+
GrantedAuthorities.FACTOR_SAML_RESPONSE_AUTHORITY);
357359
}
358360
return loginEntryPoint;
359361
}

0 commit comments

Comments
 (0)