Allow interceptors with excludePathPattern only
Issue: SPR-11130
This commit is contained in:
parent
52f1be7ade
commit
84c11a5cc7
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -82,7 +82,7 @@ public class InterceptorRegistration {
|
|||
* {@link MappedInterceptor}; otherwise {@link HandlerInterceptor}.
|
||||
*/
|
||||
protected Object getInterceptor() {
|
||||
if (this.includePatterns.isEmpty()) {
|
||||
if (this.includePatterns.isEmpty() && this.excludePatterns.isEmpty()) {
|
||||
return this.interceptor;
|
||||
}
|
||||
MappedInterceptor mappedInterceptor = new MappedInterceptor(
|
||||
|
|
|
@ -138,21 +138,35 @@ public class InterceptorRegistryTests {
|
|||
verifyAdaptedInterceptor(interceptors.get(0), webRequestInterceptor2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for SPR-11130
|
||||
*/
|
||||
@Test
|
||||
public void addInterceptorWithExcludePathPatternOnly() {
|
||||
registry.addInterceptor(interceptor1).excludePathPatterns("/path1/secret");
|
||||
registry.addInterceptor(interceptor2).addPathPatterns("/path2");
|
||||
|
||||
assertEquals(Arrays.asList(interceptor1), getInterceptorsForPath("/path1"));
|
||||
assertEquals(Arrays.asList(interceptor1, interceptor2), getInterceptorsForPath("/path2"));
|
||||
assertEquals(Collections.emptyList(), getInterceptorsForPath("/path1/secret"));
|
||||
}
|
||||
|
||||
|
||||
private List<HandlerInterceptor> getInterceptorsForPath(String lookupPath) {
|
||||
PathMatcher pathMatcher = new AntPathMatcher();
|
||||
List<HandlerInterceptor> result = new ArrayList<HandlerInterceptor>();
|
||||
for (Object i : registry.getInterceptors()) {
|
||||
if (i instanceof MappedInterceptor) {
|
||||
MappedInterceptor mappedInterceptor = (MappedInterceptor) i;
|
||||
for (Object interceptor : registry.getInterceptors()) {
|
||||
if (interceptor instanceof MappedInterceptor) {
|
||||
MappedInterceptor mappedInterceptor = (MappedInterceptor) interceptor;
|
||||
if (mappedInterceptor.matches(lookupPath, pathMatcher)) {
|
||||
result.add(mappedInterceptor.getInterceptor());
|
||||
}
|
||||
}
|
||||
else if (i instanceof HandlerInterceptor){
|
||||
result.add((HandlerInterceptor) i);
|
||||
else if (interceptor instanceof HandlerInterceptor) {
|
||||
result.add((HandlerInterceptor) interceptor);
|
||||
}
|
||||
else {
|
||||
fail("Unexpected interceptor type: " + i.getClass().getName());
|
||||
fail("Unexpected interceptor type: " + interceptor.getClass().getName());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
Loading…
Reference in New Issue