Skip to content

Commit 7b8ff72

Browse files
committed
Fix MVC Documentation for Kotlin
Closes gh-16426
1 parent 443af32 commit 7b8ff72

File tree

1 file changed

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

1 file changed

+16
-14
lines changed

Diff for: docs/modules/ROOT/pages/servlet/integrations/mvc.adoc

+16-14
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,10 @@ 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 `MvcRequestMatcher` 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 `MvcRequestMatcher.Builder` to create multiple `MvcRequestMatcher` 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 `MvcRequestMatcher.Builder` to create multiple `MvcRequestMatcher` instances that share the same servlet path:
203205

204-
[tabs]
205-
======
206-
Java::
207-
+
208206
[source,java,role="primary"]
209207
----
210208
@Bean
@@ -219,32 +217,36 @@ public SecurityFilterChain filterChain(HttpSecurity http, HandlerMappingIntrospe
219217
}
220218
----
221219

220+
For Kotlin and XML, this happens when you specify the servlet path for each path like so:
221+
222+
[tabs]
223+
======
222224
Kotlin::
223225
+
224226
[source,kotlin,role="secondary"]
225227
----
226228
@Bean
227-
open fun filterChain(http: HttpSecurity, introspector: HandlerMappingIntrospector): SecurityFilterChain {
228-
val mvcMatcherBuilder = MvcRequestMatcher.Builder(introspector)
229+
open fun filterChain(http: HttpSecurity): SecurityFilterChain {
229230
http {
230231
authorizeHttpRequests {
231-
authorize(mvcMatcherBuilder.pattern("/admin"), hasRole("ADMIN"))
232-
authorize(mvcMatcherBuilder.pattern("/user"), hasRole("USER"))
232+
authorize("/admin/**", "/mvc", hasRole("ADMIN"))
233+
authorize("/user/**", "/mvc", hasRole("USER"))
233234
}
234235
}
235236
return http.build()
236237
}
237238
----
238-
======
239239
240-
The following XML has the same effect:
241-
242-
[source,xml]
240+
Xml::
241+
+
242+
[source,xml, role="secondary"]
243243
----
244244
<http request-matcher="mvc">
245-
<intercept-url pattern="/admin" access="hasRole('ADMIN')"/>
245+
<intercept-url pattern="/admin/**" servlet-path="/mvc" access="hasRole('ADMIN')"/>
246+
<intercept-url pattern="/user/**" servlet-path="/mvc" access="hasRole('USER')"/>
246247
</http>
247248
----
249+
======
248250

249251
[[mvc-authentication-principal]]
250252
== @AuthenticationPrincipal

0 commit comments

Comments
 (0)