Integrating Spring Expression Language (SpEL)
Spring Security leverages Spring Expression Language (SpEL) integration in order to easily articulate various authorization requirements. If you recall, we have already looked at the use of SpEL in Chapter 2, Getting Started with Spring Security, when we defined our requestMatchers()
method:
.requestMatchers("/events/").hasRole("ADMIN")
Spring Security provides an o.s.s.access.expression.SecurityExpressionRoot
object that provides the methods and objects available for use, in order to make an access control decision. For example, one of the methods available to use is hasRole
method, which accepts a string. This corresponds to the value of the access attribute (in the preceding code snippet). In fact, there are a number of other expressions available, as shown in the following table:
Expression |
Description |
|