Skip to content

Commit 1fbb868

Browse files
authored
Update authorize-http-requests.adoc
Fix patterns in the Security Matchers documentation Signed-off-by: Bragolgirith <6455473+Bragolgirith@users.noreply.github.com>
1 parent 2afd2b9 commit 1fbb868

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
@@ -1044,8 +1044,8 @@ public class SecurityConfig {
10441044
http
10451045
.securityMatcher("/api/**") <1>
10461046
.authorizeHttpRequests(authorize -> authorize
1047-
.requestMatchers("/user/**").hasRole("USER") <2>
1048-
.requestMatchers("/admin/**").hasRole("ADMIN") <3>
1047+
.requestMatchers("/api/user/**").hasRole("USER") <2>
1048+
.requestMatchers("/api/admin/**").hasRole("ADMIN") <3>
10491049
.anyRequest().authenticated() <4>
10501050
)
10511051
.formLogin(withDefaults());
@@ -1067,8 +1067,8 @@ open class SecurityConfig {
10671067
http {
10681068
securityMatcher("/api/**") <1>
10691069
authorizeHttpRequests {
1070-
authorize("/user/**", hasRole("USER")) <2>
1071-
authorize("/admin/**", hasRole("ADMIN")) <3>
1070+
authorize("/api/user/**", hasRole("USER")) <2>
1071+
authorize("/api/admin/**", hasRole("ADMIN")) <3>
10721072
authorize(anyRequest, authenticated) <4>
10731073
}
10741074
}
@@ -1080,8 +1080,8 @@ open class SecurityConfig {
10801080
======
10811081

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

10871087
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 javadoc:org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher[] will be used, otherwise, javadoc:org.springframework.security.web.util.matcher.AntPathRequestMatcher[] will be used.
@@ -1107,8 +1107,8 @@ public class SecurityConfig {
11071107
http
11081108
.securityMatcher(antMatcher("/api/**")) <2>
11091109
.authorizeHttpRequests(authorize -> authorize
1110-
.requestMatchers(antMatcher("/user/**")).hasRole("USER") <3>
1111-
.requestMatchers(regexMatcher("/admin/.*")).hasRole("ADMIN") <4>
1110+
.requestMatchers(antMatcher("/api/user/**")).hasRole("USER") <3>
1111+
.requestMatchers(regexMatcher("/api/admin/.*")).hasRole("ADMIN") <4>
11121112
.requestMatchers(new MyCustomRequestMatcher()).hasRole("SUPERVISOR") <5>
11131113
.anyRequest().authenticated()
11141114
)
@@ -1142,8 +1142,8 @@ open class SecurityConfig {
11421142
http {
11431143
securityMatcher(antMatcher("/api/**")) <2>
11441144
authorizeHttpRequests {
1145-
authorize(antMatcher("/user/**"), hasRole("USER")) <3>
1146-
authorize(regexMatcher("/admin/**"), hasRole("ADMIN")) <4>
1145+
authorize(antMatcher("/api/user/**"), hasRole("USER")) <3>
1146+
authorize(regexMatcher("/api/admin/**"), hasRole("ADMIN")) <4>
11471147
authorize(MyCustomRequestMatcher(), hasRole("SUPERVISOR")) <5>
11481148
authorize(anyRequest, authenticated)
11491149
}
@@ -1157,8 +1157,8 @@ open class SecurityConfig {
11571157

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

11641164
== Further Reading

0 commit comments

Comments
 (0)