@Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new HandlerInterceptorAdapter() { @Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { //clear thread local ThreadLocalUtils.clear(); } }); } };
@Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(timeInterceptor); } }
@Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(tokenInterceptor); } }
@Override public void addInterceptors(InterceptorRegistry registry) { super.addInterceptors(registry); registry.addInterceptor(interceptor); }
@Bean public PagePopulationInterceptor pagePopulationInterceptor() { return new PagePopulationInterceptor(); } public @Override void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(pagePopulationInterceptor()); }
@Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(permissionInterceptor).addPathPatterns("/**"); registry.addInterceptor(cookieInterceptor).addPathPatterns("/**"); super.addInterceptors(registry); }
@Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new LocaleChangeInterceptor()); }
@Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new TwoFactorHandlerInterceptorAdapter(manager)); super.addInterceptors(registry); } };
@Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new WebUserTokenInterceptor(userTokenManager, userTokenParser, parser)); super.addInterceptors(registry); } };
@Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new FescarHandlerInterceptor()).addPathPatterns("/**"); } }
/** * Provide access to the shared handler interceptors used to configure * {@link HandlerMapping} instances with. * <p>This method cannot be overridden; use {@link #addInterceptors} instead. */ protected final Object[] getInterceptors() { if (this.interceptors == null) { InterceptorRegistry registry = new InterceptorRegistry(); addInterceptors(registry); registry.addInterceptor(new ConversionServiceExposingInterceptor(mvcConversionService())); registry.addInterceptor(new ResourceUrlProviderExposingInterceptor(mvcResourceUrlProvider())); this.interceptors = registry.getInterceptors(); } return this.interceptors.toArray(); }
@Override public void addInterceptors(final InterceptorRegistry registry) { registry.addInterceptor(new AuthInterceptor()).addPathPatterns("/**"); } };
@Test public void addTwoInterceptors() { this.registry.addInterceptor(this.interceptor1); this.registry.addInterceptor(this.interceptor2); List<HandlerInterceptor> interceptors = getInterceptorsForPath(null); assertEquals(Arrays.asList(this.interceptor1, this.interceptor2), interceptors); }
@Override protected void addInterceptors(InterceptorRegistry registry) { for (MappedInterceptor interceptor : mappedInterceptors) { InterceptorRegistration registration = registry.addInterceptor(interceptor.getInterceptor()); if (interceptor.getPathPatterns() != null) { registration.addPathPatterns(interceptor.getPathPatterns()); } } }
@Test public void addInterceptor() { this.registry.addInterceptor(this.interceptor1); List<HandlerInterceptor> interceptors = getInterceptorsForPath(null); assertEquals(Arrays.asList(this.interceptor1), interceptors); }
@Test public void orderedInterceptors() throws Exception { this.registry.addInterceptor(this.interceptor1).order(Ordered.LOWEST_PRECEDENCE); this.registry.addInterceptor(this.interceptor2).order(Ordered.HIGHEST_PRECEDENCE); List<Object> interceptors = this.registry.getInterceptors(); assertEquals(2, interceptors.size()); assertSame(this.interceptor2, interceptors.get(0)); assertSame(this.interceptor1, interceptors.get(1)); }
@Test public void nonOrderedInterceptors() throws Exception { this.registry.addInterceptor(this.interceptor1).order(0); this.registry.addInterceptor(this.interceptor2).order(0); List<Object> interceptors = this.registry.getInterceptors(); assertEquals(2, interceptors.size()); assertSame(this.interceptor1, interceptors.get(0)); assertSame(this.interceptor2, interceptors.get(1)); } }
@Test // SPR-11130 public void addInterceptorWithExcludePathPatternOnly() { this.registry.addInterceptor(this.interceptor1).excludePathPatterns("/path1/secret"); this.registry.addInterceptor(this.interceptor2).addPathPatterns("/path2"); assertEquals(Collections.singletonList(this.interceptor1), getInterceptorsForPath("/path1")); assertEquals(Arrays.asList(this.interceptor1, this.interceptor2), getInterceptorsForPath("/path2")); assertEquals(Collections.emptyList(), getInterceptorsForPath("/path1/secret")); }
@Test public void addInterceptorsWithUrlPatterns() { this.registry.addInterceptor(this.interceptor1).addPathPatterns("/path1/**").excludePathPatterns("/path1/secret"); this.registry.addInterceptor(this.interceptor2).addPathPatterns("/path2"); assertEquals(Arrays.asList(this.interceptor1), getInterceptorsForPath("/path1/test")); assertEquals(Arrays.asList(this.interceptor2), getInterceptorsForPath("/path2")); assertEquals(Collections.emptyList(), getInterceptorsForPath("/path1/secret")); }
@Test public void addInterceptorsWithCustomPathMatcher() { PathMatcher pathMatcher = Mockito.mock(PathMatcher.class); this.registry.addInterceptor(interceptor1).addPathPatterns("/path1/**").pathMatcher(pathMatcher); MappedInterceptor mappedInterceptor = (MappedInterceptor) this.registry.getInterceptors().get(0); assertSame(pathMatcher, mappedInterceptor.getPathMatcher()); }