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
This checks to see if the `Authentication.getPrincipal().getId()` is equal to the recipient of the `Message`.
69
69
Note that this example assumes you have customized the principal to be an Object that has an id property.
70
-
By exposing the `SecurityEvaluationContextExtension` bean, all of the xref:servlet/authorization/expression-based.adoc#common-expressions[Common Security Expressions] are available within the Query.
70
+
By exposing the `SecurityEvaluationContextExtension` bean, all of the xref:servlet/authorization/method-security.adoc#authorization-expressions[Common Security Expressions] are available within the Query.
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/servlet/appendix/namespace/http.adoc
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -163,7 +163,7 @@ Defaults to `true`.
163
163
164
164
[[nsa-http-use-expressions]]
165
165
* **use-expressions**
166
-
Enables EL-expressions in the `access` attribute, as described in the chapter on xref:servlet/authorization/expression-based.adoc#el-access-web[expression-based access-control].
166
+
Enables EL-expressions in the `access` attribute, as described in the chapter on xref:servlet/authorization/authorize-http-requests.adoc#authorization-expressions[expression-based access-control].
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/servlet/authorization/authorize-http-requests.adoc
+76Lines changed: 76 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -651,6 +651,82 @@ You will notice that since we are using the `hasRole` expression we do not need
651
651
<6> Any URL that has not already been matched on is denied access.
652
652
This is a good strategy if you do not want to accidentally forget to update your authorization rules.
653
653
654
+
[[authorization-expressions]]
655
+
== Expressing Authorization with SpEL
656
+
657
+
While using a concrete `AuthorizationManager` is recommended, there are some cases where an expression is necessary, like with `<intercept-url>` or with JSP Taglibs.
658
+
For that reason, this section will focus on examples from those domains.
659
+
660
+
Given that, let's cover Spring Security's Web Security Authorization SpEL API a bit more in depth.
661
+
662
+
Spring Security encapsulates all of its authorization fields and methods in a set of root objects.
663
+
The most generic root object is called `SecurityExpressionRoot` and it forms the basis for `WebSecurityExpressionRoot`.
664
+
Spring Security supplies this root object to `StandardEvaluationContext` when preparing to evaluate an authorization expression.
=== Using Authorization Expression Fields and Methods
668
+
669
+
The first thing this provides is an enhanced set of authorization fields and methods to your SpEL expressions.
670
+
What follows is a quick overview of the most common methods:
671
+
672
+
* `permitAll` - The request requires no authorization to be invoked; note that in this case, xref:servlet/authentication/architecture.adoc#servlet-authentication-authentication[the `Authentication`] is never retrieved from the session
673
+
* `denyAll` - The request is not allowed under any circumstances; note that in this case, the `Authentication` is never retrieved from the session
674
+
* `hasAuthority` - The request requires that the `Authentication` have xref:servlet/authorization/architecture.adoc#authz-authorities[a `GrantedAuthority`] that matches the given value
675
+
* `hasRole` - A shortcut for `hasAuthority` that prefixes `ROLE_` or whatever is configured as the default prefix
676
+
* `hasAnyAuthority` - The request requires that the `Authentication` have a `GrantedAuthority` that matches any of the given values
677
+
* `hasAnyRole` - A shortcut for `hasAnyAuthority` that prefixes `ROLE_` or whatever is configured as the default prefix
678
+
* `hasPermission` - A hook into your `PermissionEvaluator` instance for doing object-level authorization
679
+
680
+
And here is a brief look at the most common fields:
681
+
682
+
* `authentication` - The `Authentication` instance associated with this method invocation
683
+
* `principal` - The `Authentication#getPrincipal` associated with this method invocation
684
+
685
+
Having now learned the patterns, rules, and how they can be paired together, you should be able to understand what is going on in this more complex example:
This expression refers to the path variable after `/resource/` and requires that it is equal to `Authentication#getName`.
729
+
654
730
[[remote-authorization-manager]]
655
731
=== Use an Authorization Database, Policy Agent, or Other Service
656
732
If you want to configure Spring Security to use a separate service for authorization, you can create your own `AuthorizationManager` and match it to `anyRequest`.
0 commit comments