Skip to content

Commit d569eed

Browse files
committed
Correct Servlet Path Kotlin Documentation
1 parent 036486f commit d569eed

File tree

1 file changed

+27
-14
lines changed
  • docs/modules/ROOT/pages/servlet/integrations

1 file changed

+27
-14
lines changed

docs/modules/ROOT/pages/servlet/integrations/mvc.adoc

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ We could add additional rules for all the permutations of Spring MVC, but this w
199199
Fortunately, when using the `requestMatchers` DSL method, Spring Security automatically creates a `PathPatternRequestMatcher` if it detects that Spring MVC is available in the classpath.
200200
Therefore, it will protect the same URLs that Spring MVC will match on by using Spring MVC to match on the URL.
201201

202-
One common requirement when using Spring MVC is to specify the servlet path property, for that you can use the `PathPatternRequestMatcher.Builder` to create multiple `PathPatternRequestMatcher` instances that share the same servlet path:
202+
One common requirement when using Spring MVC is to specify the servlet path property.
203+
204+
For Java-based Configuration, you can use the `PathPatternRequestMatcher.Builder` to create multiple `PathPatternRequestMatcher` instances that share the same servlet path:
203205

204206
[tabs]
205207
======
@@ -218,38 +220,49 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
218220
return http.build();
219221
}
220222
----
223+
======
224+
225+
[NOTE]
226+
=====
227+
For your convenience, you also can use `ServletRequestMatcherBuilders` which exposes an API that more directly reflects the Servlet spec.
228+
=====
229+
230+
For Kotlin and XML, this happens automatically when you specify the servlet path in the configuration:
221231

232+
[tabs]
233+
======
222234
Kotlin::
223235
+
224236
[source,kotlin,role="secondary"]
225237
----
226238
@Bean
227239
open fun filterChain(http: HttpSecurity): SecurityFilterChain {
228-
val mvcMatcherBuilder = PathPatternRequestMatcher.Builder().servletPath("/path")
229240
http {
230241
authorizeHttpRequests {
231-
authorize(mvcMatcherBuilder.pattern("/admin"), hasRole("ADMIN"))
232-
authorize(mvcMatcherBuilder.pattern("/user"), hasRole("USER"))
242+
authorize("/admin", "/path", hasRole("ADMIN"))
243+
authorize("/user", "/path", hasRole("USER"))
233244
}
234245
}
246+
235247
return http.build()
236248
}
237249
----
238-
======
239-
240-
[NOTE]
241-
=====
242-
For your convenience, you also can use `ServletRequestMatcherBuilders` which exposes an API that more directly reflects the Servlet spec.
243-
=====
244-
245-
The following XML has the same effect:
246250
247-
[source,xml]
251+
Xml::
252+
+
253+
[source,xml,role="secondary"]
248254
----
249255
<http request-matcher="mvc">
250-
<intercept-url pattern="/admin" access="hasRole('ADMIN')"/>
256+
<intercept-url pattern="/admin" servlet-path="/path" access="hasRole('ADMIN')"/>
257+
<intercept-url pattern="/user" servlet-path="/path" access="hasRole('USER')"/>
251258
</http>
252259
----
260+
======
261+
262+
263+
The following XML has the same effect:
264+
265+
253266

254267
[[mvc-authentication-principal]]
255268
== @AuthenticationPrincipal

0 commit comments

Comments
 (0)