I have written an HandlerInterceptorAdapter implementation and would like to exclude the path patterns that authenticate the user and refresh the user while registering token, the URLS of thje resource mostly has the email address as a path param, which of the below code snippet is a valid form to do so
@Override
public void addInterceptors(InterceptorRegistry registry) {
super.addInterceptors(registry);
registry.addInterceptor(new AuthorizationInterceptor()).excludePathPatterns("/somepath/*/someresource/*");
}
or
@Override
public void addInterceptors(InterceptorRegistry registry) {
super.addInterceptors(registry);
registry.addInterceptor(new AuthorizationInterceptor()).excludePathPatterns("/somepath/{email}/someresource/*");
}
EDIT:::
Enhanced the code using the PatternMatcher, still not working
@Override
public void addInterceptors(InterceptorRegistry registry) {
super.addInterceptors(registry);
registry.addInterceptor(new AuthorizationInterceptor())
.excludePathPatterns(
"/somepath",
"/somepath/*/authenticate",
"somapath/*/someresource/verify"
).pathMatcher(new AntPathMatcher());
}
Try this:
@Override
public void addInterceptors(InterceptorRegistry registry) {
super.addInterceptors(registry);
registry.addInterceptor(new AuthorizationInterceptor())
.excludePathPatterns(
"/somepath",
"/somepath/**/authenticate",
"somapath/**/someresource/verify"
).pathMatcher(new AntPathMatcher());
}
The mapping matches URLs using the following rules:
? matches one character
* matches zero or more characters
** matches zero or more directories in a path
It will be better if you could simply have different url for excluding. For example:
@Override
public void addInterceptors(InterceptorRegistry registry) {
super.addInterceptors(registry);
registry.addInterceptor(new AuthorizationInterceptor()).excludePathPatterns("/somepath/someresource/**");
}
Than, everything starting with "/somepath/someresource/" will be excluded. Hope it helps.
More links on that: Spring MVC 3, Interceptor on all excluding some defined paths or About mvc:intercepter,how to set excluded path or simply docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With