It’s not clear for me what is the difference in spring security between :
@PreAuthorize("hasRole('ROLE_USER')")
public void create(Contact contact)
And
@Secured("ROLE_USER")
public void create(Contact contact)
I understand PreAuthorize can work with spring el but in my sample, is there a real difference ?
The real difference is that
@PreAuthorizecan work with Spring Expression Language (SpEL). You can:SecurityExpressionRoot.Access method arguments (requires compilation with debug info or custom
ParameterNameDiscoverer):MethodSecurityExpressionHandlerand set it as<global-method-security><expression-handler ... /></...>).