concept SpEL expression in category spring

This is an excerpt from Manning's book Spring Security in Action.
To make this method easier to understand, I’ll first present it as an alternative to specifying the authorities with the hasAuthority() and hasAnyAuthority() methods. As you’ll learn in this example, you have to provide a Spring expression as a parameter to the method. The authorization rule we define becomes more challenging to read, and this is why I don’t recommend this approach for simple rules for which you could avoid it. However, the access() method has the advantage of allowing you to customize rules through the expression you provide as a parameter. And this is really powerful, as with SpEL expressions, you can basically define any condition. But in most situations, you could implement the required restrictions with the hasAuthority() and hasAnyAuthority() methods, and I recommend you use these in the first place. Use the access() method only if the other two options do not fit because you have some more generic authorization rules to implement.
To implement pre-authorization, you use the @PreAuthorize annotation with a value of a SpEL expression that defines the authorization rule.
Figure 17.8 In the SpEL expression used for authorization, we use filterObject to refer to the objects in the returned collection, and we use authentication to refer to the Authentication instance from the security context.
![]()