How to use constants in .antmatchers.access ()

I want to use some constants from AuthoritiesConstants.java

in.antmatchers.access():

.antMatchers("/first/**").access("hasAuthority('ROLE_ALL') and hasAuthority('ROLE_ME')")

it works, but I want to use the ALL constant:

public static final String ALL = "ROLE_ALL";

I tried:

.antMatchers("/first/**").access("hasAuthority('AuthoritiesConstants.ALL')");

but it doesn't work.

Please, help

+3


source to share


1 answer


It won't work because it doesn't actually refer to a constant. It assumes that it 'AuthoritiesConstants.ALL'

is just a string literal and evaluates as such.

.antMatchers("/first/**").access("hasAuthority('AuthoritiesConstants.ALL')");

      

You can try something like:



.antMatchers("/first/**").hasAuthority(AuthoritiesConstants.ALL);

      

Or, if you need to refer to constants in an access expression, you can use the following syntax:, access("hasAuthority(T(com.example.AuthoritiesConstants).ALL) and ...")

where com.example.

is the package containing the class AuthoritiesConstants

.

+1


source







All Articles