Reputation: 58083
Java - Spring Annotation param from property value
Following is my @Secured
annotation i want to define string "USER_ABC" in .properties file and use it over here like @Secured({myProp})
but it gives me error
@Value('${my.property}') private string myProp;
@Secured({myProp,"ADMIN_123"})
public void mySecureMethod(){
}
instead of
@Secured({"USER_ABC","ADMIN_123"})
public void mySecureMethod(){
}
any solution appreciated in advance.
Upvotes: 0
Views: 616
Reputation: 6540
While you can't use @Secured
because as Edwin points out, it can't handle constant expressions, you can use the @PreAuthorize
annotation which will evaluate an SPEL expression.
Just be aware that @PreAuthorize
works slightly differently in terms of the Spring Security Filter chain and when it gets invoked.
There is a very good question that should probably be your first port of call here. If there is some reason why you can't use @PreAuthorize
, let me know.
Upvotes: 1