我编写了一个HandlerInterceptorAdapter实现,并希望排除验证用户的路径模式,并在注册令牌时刷新用户,资源的URL主要是将电子邮件地址作为路径参数,以下代码片段中的哪一个这是一个有效的表格
@Override
public void addInterceptors(InterceptorRegistry registry) {
super.addInterceptors(registry);
registry.addInterceptor(new AuthorizationInterceptor()).excludePathPatterns("/somepath/*/someresource/*");
}
或
@Override
public void addInterceptors(InterceptorRegistry registry) {
super.addInterceptors(registry);
registry.addInterceptor(new AuthorizationInterceptor()).excludePathPatterns("/somepath/{email}/someresource/*");
}
EDIT :::
使用PatternMatcher增强代码,仍无法正常工作
@Override
public void addInterceptors(InterceptorRegistry registry) {
super.addInterceptors(registry);
registry.addInterceptor(new AuthorizationInterceptor())
.excludePathPatterns(
"/somepath",
"/somepath/*/authenticate",
"somapath/*/someresource/verify"
).pathMatcher(new AntPathMatcher());
}
答案 0 :(得分:2)
试试这个:
@Override
public void addInterceptors(InterceptorRegistry registry) {
super.addInterceptors(registry);
registry.addInterceptor(new AuthorizationInterceptor())
.excludePathPatterns(
"/somepath",
"/somepath/**/authenticate",
"somapath/**/someresource/verify"
).pathMatcher(new AntPathMatcher());
}
映射使用以下规则匹配URL:
? matches one character
* matches zero or more characters
** matches zero or more directories in a path
答案 1 :(得分:0)
如果您可以简单地使用不同的网址进行排除,那会更好。例如:
@Override
public void addInterceptors(InterceptorRegistry registry) {
super.addInterceptors(registry);
registry.addInterceptor(new AuthorizationInterceptor()).excludePathPatterns("/somepath/someresource/**");
}
然后,将排除以“/ somepath / someresource /”开头的所有内容。希望它有所帮助。
更多链接: Spring MVC 3, Interceptor on all excluding some defined paths或 About mvc:intercepter,how to set excluded path或仅docs