Skip to content

Commit 834e361

Browse files
committed
Merge branch '5.8.x' into 6.0.x
Closes gh-12932
2 parents 97b53f0 + 6bda1d2 commit 834e361

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,46 @@ open class SecurityConfig {
408408
<3> Allow access to URLs that start with `/user/` to users with the `USER` role, using `AntPathRequestMatcher`
409409
<4> Allow access to URLs that start with `/admin/` to users with the `ADMIN` role, using `RegexRequestMatcher`
410410
<5> Allow access to URLs that match the `MyCustomRequestMatcher` to users with the `SUPERVISOR` role, using a custom `RequestMatcher`
411+
412+
== Expressions
413+
414+
It is recommended that you use type-safe authorization managers instead of SpEL.
415+
However, `WebExpressionAuthorizationManager` is available to help migrate legacy SpEL.
416+
417+
To use `WebExpressionAuthorizationManager`, you can construct one with the expression you are trying to migrate, like so:
418+
419+
====
420+
.Java
421+
[source,java,role="primary"]
422+
----
423+
.requestMatchers("/test/**").access(new WebExpressionAuthorizationManager("hasRole('ADMIN') && hasRole('USER')"))
424+
----
425+
426+
.Kotlin
427+
[source,kotlin,role="secondary"]
428+
----
429+
.requestMatchers("/test/**").access(WebExpressionAuthorizationManager("hasRole('ADMIN') && hasRole('USER')"))
430+
----
431+
====
432+
433+
If you are referring to a bean in your expression like so: `@webSecurity.check(authentication, request)`, it's recommended that you instead call the bean directly, which will look something like the following:
434+
435+
====
436+
.Java
437+
[source,java,role="primary"]
438+
----
439+
.requestMatchers("/test/**").access((authentication, context) ->
440+
new AuthorizationDecision(webSecurity.check(authentication.get(), context.getRequest())))
441+
----
442+
443+
.Kotlin
444+
[source,kotlin,role="secondary"]
445+
----
446+
.requestMatchers("/test/**").access((authentication, context): AuthorizationManager<RequestAuthorizationContext> ->
447+
AuthorizationDecision(webSecurity.check(authentication.get(), context.getRequest())))
448+
----
449+
====
450+
451+
For complex instructions that include bean references as well as other expressions, it is recommended that you change those to implement `AuthorizationManager` and refer to them by calling `.access(AuthorizationManager)`.
452+
453+
If you are not able to do that, you can configure a `DefaultHttpSecurityExpressionHandler` with a bean resolver and supply that to `WebExpressionAuthorizationManager#setExpressionhandler`.

0 commit comments

Comments
 (0)