You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/migration/servlet/authorization.adoc
+47Lines changed: 47 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1545,6 +1545,53 @@ public final class AnyRequestAuthenticatedAuthorizationManagerAdapter implements
1545
1545
1546
1546
Once you have implemented `AuthorizationManager`, please follow the details in the reference manual for xref:servlet/authorization/authorize-http-requests.adoc#custom-authorization-manager[adding a custom `AuthorizationManager`].
1547
1547
1548
+
[[replace-hasrole-hasauthority]]
1549
+
=== Replace `hasRole` with `hasAuthority` if using `GrantedAuthorityDefaults`
1550
+
1551
+
Currently, the `hasRole` method inside `authorizeHttpRequests` does not support the `GrantedAuthorityDefaults` bean like the `authorizeRequests` does.
1552
+
Therefore, if you are using `GrantedAuthorityDefaults` to change the prefix of your roles, you will need to use `hasAuthority` instead of `hasRole`.
1553
+
1554
+
For example, you will have to change from:
1555
+
1556
+
====
1557
+
.authorizeRequests with custom role prefix
1558
+
[source,java]
1559
+
----
1560
+
@Bean
1561
+
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
1562
+
http
1563
+
.authorizeRequests((authorize) -> authorize
1564
+
.anyRequest().hasRole("ADMIN")
1565
+
);
1566
+
return http.build();
1567
+
}
1568
+
1569
+
@Bean
1570
+
public GrantedAuthorityDefaults grantedAuthorityDefaults() {
1571
+
return new GrantedAuthorityDefaults("MYPREFIX_");
1572
+
}
1573
+
----
1574
+
====
1575
+
1576
+
to:
1577
+
1578
+
====
1579
+
.authorizeHttpRequests with hasAuthority and custom role prefix
1580
+
[source,java]
1581
+
----
1582
+
@Bean
1583
+
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
1584
+
http
1585
+
.authorizeHttpRequests((authorize) -> authorize
1586
+
.anyRequest().hasAuthority("MYPREFIX_ADMIN")
1587
+
);
1588
+
return http.build();
1589
+
}
1590
+
----
1591
+
====
1592
+
1593
+
This should be supported in the future, see https://github.com/spring-projects/spring-security/issues/13215[gh-13227] for more details.
0 commit comments