You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
open fun web(http: HttpSecurity): SecurityFilterChain {
319
+
http {
320
+
securityMatcher("/api/**") <1>
321
+
authorizeHttpRequests {
322
+
authorize("/user/**", hasRole("USER")) <2>
323
+
authorize("/admin/**", hasRole("ADMIN")) <3>
324
+
authorize(anyRequest, authenticated) <4>
325
+
}
326
+
}
327
+
return http.build()
328
+
}
329
+
330
+
}
331
+
----
332
+
====
333
+
334
+
<1> Configure `HttpSecurity` to only be applied to URLs that start with `/api/`
335
+
<2> Allow access to URLs that start with `/user/` to users with the `USER` role
336
+
<3> Allow access to URLs that start with `/admin/` to users with the `ADMIN` role
337
+
<4> Any other request that doesn't match the rules above, will require authentication
338
+
339
+
The `securityMatcher(s)` and `requestMatcher(s)` methods will decide which `RequestMatcher` implementation fits best for your application: If Spring MVC is in the classpath, then `MvcRequestMatcher` will be used, otherwise, `AntPathRequestMatcher` will be used.
340
+
You can read more about the Spring MVC integration xref:servlet/integrations/mvc.adoc[here].
341
+
342
+
If you want to use a specific `RequestMatcher`, just pass an implementation to the `securityMatcher` and/or `requestMatcher` methods:
0 commit comments