Skip to content

Commit d2b33a2

Browse files
Fix docs
Closes gh-11396
1 parent 74e8fa1 commit d2b33a2

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

docs/modules/ROOT/pages/servlet/authorization/authorize-http-requests.adoc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ SecurityFilterChain web(HttpSecurity http) throws Exception {
6868
.requestMatchers("/resources/**", "/signup", "/about").permitAll() // <2>
6969
.requestMatchers("/admin/**").hasRole("ADMIN") // <3>
7070
.requestMatchers("/db/**").access(new WebExpressionAuthorizationManager("hasRole('ADMIN') and hasRole('DBA')")) // <4>
71-
.anyRequest().denyAll() // <5>
71+
// .requestMatchers("/db/**").access(AuthorizationManagers.allOf(AuthorityAuthorizationManager.hasRole("ADMIN"), AuthorityAuthorizationManager.hasRole("DBA"))) // <5>
72+
.anyRequest().denyAll() // <6>
7273
);
7374
7475
return http.build();
@@ -83,7 +84,8 @@ Specifically, any user can access a request if the URL starts with "/resources/"
8384
You will notice that since we are invoking the `hasRole` method we do not need to specify the "ROLE_" prefix.
8485
<4> Any URL that starts with "/db/" requires the user to have both "ROLE_ADMIN" and "ROLE_DBA".
8586
You will notice that since we are using the `hasRole` expression we do not need to specify the "ROLE_" prefix.
86-
<5> Any URL that has not already been matched on is denied access.
87+
<5> The same rule from 4, could be written by combining multiple `AuthorizationManager`.
88+
<6> Any URL that has not already been matched on is denied access.
8789
This is a good strategy if you do not want to accidentally forget to update your authorization rules.
8890

8991
You can take a bean-based approach by constructing your own xref:servlet/authorization/architecture.adoc#authz-delegate-authorization-manager[`RequestMatcherDelegatingAuthorizationManager`] like so:
@@ -116,7 +118,7 @@ AuthorizationManager<RequestAuthorizationContext> requestMatcherAuthorizationMan
116118
RequestMatcher admin = mvcMatcherBuilder.pattern("/admin/**");
117119
RequestMatcher db = mvcMatcherBuilder.pattern("/db/**");
118120
RequestMatcher any = AnyRequestMatcher.INSTANCE;
119-
AuthorizationManager<HttpRequestServlet> manager = RequestMatcherDelegatingAuthorizationManager.builder()
121+
AuthorizationManager<HttpServletRequest> manager = RequestMatcherDelegatingAuthorizationManager.builder()
120122
.add(permitAll, (context) -> new AuthorizationDecision(true))
121123
.add(admin, AuthorityAuthorizationManager.hasRole("ADMIN"))
122124
.add(db, AuthorityAuthorizationManager.hasRole("DBA"))
@@ -161,7 +163,7 @@ Or you can provide it for all requests as seen below:
161163
SecurityFilterChain web(HttpSecurity http) throws Exception {
162164
http
163165
.authorizeHttpRequests((authorize) -> authorize
164-
.anyRequest.access(new CustomAuthorizationManager());
166+
.anyRequest().access(new CustomAuthorizationManager());
165167
)
166168
// ...
167169

docs/modules/ROOT/pages/servlet/authorization/expression-based.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ You could refer to the method using:
145145
----
146146
http
147147
.authorizeHttpRequests(authorize -> authorize
148-
.requestMatchers("/user/**").access("@webSecurity.check(authentication,request)")
148+
.requestMatchers("/user/**").access(new WebExpressionAuthorizationManager("@webSecurity.check(authentication,request)"))
149149
...
150150
)
151151
----

0 commit comments

Comments
 (0)