Search code examples
springspring-mvcspring-securityspring-annotations

How to populate the @Secured() annotation using values from a properties file?


I can always do a @Secured("ROLE_A", "ROLE_B"). But is there a way to populate the @Secured annotation values from a properties file? Something like @Secured({property_a}, {property_b}).

Thank you.


Solution

  • Use @PreAuthorize. You can put an Spring EL expresssion compare to @Secured which is limited.

    Example :

    @PreAuthorize("#n == authentication.name")
    Contact findContactByName(@Param("n") String name);
    

    Reference :

    1) What's the difference between @Secured and @PreAuthorize in spring security 3

    2) Spring EL