Skip to content

Commit 72554f7

Browse files
Bragolgirithjzheaux
authored andcommitted
Update authorize-http-requests.adoc
Fix patterns in the Security Matchers documentation Signed-off-by: Bragolgirith <[email protected]>
1 parent 65e83f8 commit 72554f7

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,8 +1035,8 @@ public class SecurityConfig {
10351035
http
10361036
.securityMatcher("/api/**") <1>
10371037
.authorizeHttpRequests(authorize -> authorize
1038-
.requestMatchers("/user/**").hasRole("USER") <2>
1039-
.requestMatchers("/admin/**").hasRole("ADMIN") <3>
1038+
.requestMatchers("/api/user/**").hasRole("USER") <2>
1039+
.requestMatchers("/api/admin/**").hasRole("ADMIN") <3>
10401040
.anyRequest().authenticated() <4>
10411041
)
10421042
.formLogin(withDefaults());
@@ -1058,8 +1058,8 @@ open class SecurityConfig {
10581058
http {
10591059
securityMatcher("/api/**") <1>
10601060
authorizeHttpRequests {
1061-
authorize("/user/**", hasRole("USER")) <2>
1062-
authorize("/admin/**", hasRole("ADMIN")) <3>
1061+
authorize("/api/user/**", hasRole("USER")) <2>
1062+
authorize("/api/admin/**", hasRole("ADMIN")) <3>
10631063
authorize(anyRequest, authenticated) <4>
10641064
}
10651065
}
@@ -1071,8 +1071,8 @@ open class SecurityConfig {
10711071
======
10721072

10731073
<1> Configure `HttpSecurity` to only be applied to URLs that start with `/api/`
1074-
<2> Allow access to URLs that start with `/user/` to users with the `USER` role
1075-
<3> Allow access to URLs that start with `/admin/` to users with the `ADMIN` role
1074+
<2> Allow access to URLs that start with `/api/user/` to users with the `USER` role
1075+
<3> Allow access to URLs that start with `/api/admin/` to users with the `ADMIN` role
10761076
<4> Any other request that doesn't match the rules above, will require authentication
10771077

10781078
The `securityMatcher(s)` and `requestMatcher(s)` methods will decide which `RequestMatcher` implementation fits best for your application: If {spring-framework-reference-url}web.html#spring-web[Spring MVC] is in the classpath, then {security-api-url}org/springframework/security/web/servlet/util/matcher/MvcRequestMatcher.html[`MvcRequestMatcher`] will be used, otherwise, {security-api-url}org/springframework/security/web/servlet/util/matcher/AntPathRequestMatcher.html[`AntPathRequestMatcher`] will be used.
@@ -1098,8 +1098,8 @@ public class SecurityConfig {
10981098
http
10991099
.securityMatcher(antMatcher("/api/**")) <2>
11001100
.authorizeHttpRequests(authorize -> authorize
1101-
.requestMatchers(antMatcher("/user/**")).hasRole("USER") <3>
1102-
.requestMatchers(regexMatcher("/admin/.*")).hasRole("ADMIN") <4>
1101+
.requestMatchers(antMatcher("/api/user/**")).hasRole("USER") <3>
1102+
.requestMatchers(regexMatcher("/api/admin/.*")).hasRole("ADMIN") <4>
11031103
.requestMatchers(new MyCustomRequestMatcher()).hasRole("SUPERVISOR") <5>
11041104
.anyRequest().authenticated()
11051105
)
@@ -1133,8 +1133,8 @@ open class SecurityConfig {
11331133
http {
11341134
securityMatcher(antMatcher("/api/**")) <2>
11351135
authorizeHttpRequests {
1136-
authorize(antMatcher("/user/**"), hasRole("USER")) <3>
1137-
authorize(regexMatcher("/admin/**"), hasRole("ADMIN")) <4>
1136+
authorize(antMatcher("/api/user/**"), hasRole("USER")) <3>
1137+
authorize(regexMatcher("/api/admin/**"), hasRole("ADMIN")) <4>
11381138
authorize(MyCustomRequestMatcher(), hasRole("SUPERVISOR")) <5>
11391139
authorize(anyRequest, authenticated)
11401140
}
@@ -1148,8 +1148,8 @@ open class SecurityConfig {
11481148

11491149
<1> Import the static factory methods from `AntPathRequestMatcher` and `RegexRequestMatcher` to create `RequestMatcher` instances.
11501150
<2> Configure `HttpSecurity` to only be applied to URLs that start with `/api/`, using `AntPathRequestMatcher`
1151-
<3> Allow access to URLs that start with `/user/` to users with the `USER` role, using `AntPathRequestMatcher`
1152-
<4> Allow access to URLs that start with `/admin/` to users with the `ADMIN` role, using `RegexRequestMatcher`
1151+
<3> Allow access to URLs that start with `/api/user/` to users with the `USER` role, using `AntPathRequestMatcher`
1152+
<4> Allow access to URLs that start with `/api/admin/` to users with the `ADMIN` role, using `RegexRequestMatcher`
11531153
<5> Allow access to URLs that match the `MyCustomRequestMatcher` to users with the `SUPERVISOR` role, using a custom `RequestMatcher`
11541154

11551155
== Further Reading

0 commit comments

Comments
 (0)