Pranav C Balan
Pranav C Balan

Reputation: 115242

Spring Security antMatcher expression not works with path variable

I need to provide certain role for accessing a URL in the following format:

/connector/{programId}/order/{anything here}

Where programId is an integer value so I'd tried the following and it doesn't work at all.

.antMatchers('/connector/{programId:\\d+}/order/**').access("hasRole('CONNECTOR')")

But when I used ** instead of the programId part it's working well. But how can I make it work with pathVariable (which is always an integer).

Upvotes: 1

Views: 4015

Answers (2)

chính huỳnh
chính huỳnh

Reputation: 91

I am using: .regexMatchers("/connector/(\\d+)/order/.*").access("hasRole('CONNECTOR')") But server response 405 error

Upvotes: 1

Chao Luo
Chao Luo

Reputation: 2696

You should use RegexRequestMatcher instead of AntPathRequestMatcher.

.regexMatchers("/connector/(\\d+)/order/.*").access("hasRole('CONNECTOR')")

Upvotes: 6

Related Questions