Skip to content

Commit d099a62

Browse files
msdoustirwinch
authored andcommitted
hasRole should not be called on a string with "ROLE_" prefix (#6353)
Removed "ROLE_" from UrlAuthorizationConfigurer This fixes IllegalArgumentException: ROLE_ANONYMOUS should not start with ROLE_ since ROLE_
1 parent 5fbf953 commit d099a62

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public StandardInterceptUrlRegistry hasAnyAuthority(String... authorities) {
344344
* @return the {@link UrlAuthorizationConfigurer} for further customization
345345
*/
346346
public StandardInterceptUrlRegistry anonymous() {
347-
return hasRole("ROLE_ANONYMOUS");
347+
return hasRole("ANONYMOUS");
348348
}
349349

350350
/**

config/src/test/java/org/springframework/security/config/annotation/web/configurers/UrlAuthorizationConfigurerTests.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
/**
4343
* @author Rob Winch
44+
* @author M.S. Dousti
4445
*
4546
*/
4647
public class UrlAuthorizationConfigurerTests {
@@ -203,6 +204,24 @@ public String path() {
203204
}
204205
}
205206

207+
@Test
208+
public void anonymousUrlAuthorization() {
209+
loadConfig(AnonymousUrlAuthorizationConfig.class);
210+
}
211+
212+
@EnableWebSecurity
213+
@Configuration
214+
static class AnonymousUrlAuthorizationConfig extends WebSecurityConfigurerAdapter {
215+
@Override
216+
public void configure(HttpSecurity http) throws Exception {
217+
// @formatter:off
218+
http
219+
.apply(new UrlAuthorizationConfigurer<>(null)).getRegistry()
220+
.anyRequest().anonymous();
221+
// @formatter:on
222+
}
223+
}
224+
206225
public void loadConfig(Class<?>... configs) {
207226
this.context = new AnnotationConfigWebApplicationContext();
208227
this.context.register(configs);

0 commit comments

Comments
 (0)