use of org.springframework.web.servlet.HandlerInterceptor in project spring-boot by spring-projects.
the class CloudFoundryActuatorAutoConfiguration method getSecurityInterceptor.
private HandlerInterceptor getSecurityInterceptor(RestTemplateBuilder restTemplateBuilder, Environment environment) {
CloudFoundrySecurityService cloudfoundrySecurityService = getCloudFoundrySecurityService(restTemplateBuilder, environment);
TokenValidator tokenValidator = new TokenValidator(cloudfoundrySecurityService);
HandlerInterceptor securityInterceptor = new CloudFoundrySecurityInterceptor(tokenValidator, cloudfoundrySecurityService, environment.getProperty("vcap.application.application_id"));
return securityInterceptor;
}
use of org.springframework.web.servlet.HandlerInterceptor in project spring-boot by spring-projects.
the class AbstractEndpointHandlerMappingTests method securityInterceptorShouldBePresentForNonCorsRequest.
@Test
public void securityInterceptorShouldBePresentForNonCorsRequest() throws Exception {
HandlerInterceptor securityInterceptor = mock(HandlerInterceptor.class);
TestActionEndpoint endpoint = new TestActionEndpoint(new TestEndpoint("a"));
AbstractEndpointHandlerMapping<?> mapping = new TestEndpointHandlerMapping<>(Collections.singletonList(endpoint));
mapping.setApplicationContext(this.context);
mapping.setSecurityInterceptor(securityInterceptor);
mapping.afterPropertiesSet();
assertThat(mapping.getHandler(request("POST", "/a")).getInterceptors()).contains(securityInterceptor);
}
use of org.springframework.web.servlet.HandlerInterceptor in project spring-boot by spring-projects.
the class SitePreferenceAutoConfigurationTests method sitePreferenceHandlerInterceptorRegistered.
@Test
public void sitePreferenceHandlerInterceptorRegistered() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(Config.class, WebMvcAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, SitePreferenceAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
RequestMappingHandlerMapping mapping = this.context.getBean(RequestMappingHandlerMapping.class);
HandlerInterceptor[] interceptors = mapping.getHandler(new MockHttpServletRequest()).getInterceptors();
assertThat(interceptors).hasAtLeastOneElementOfType(SitePreferenceHandlerInterceptor.class);
}
use of org.springframework.web.servlet.HandlerInterceptor in project spring-boot by spring-projects.
the class DeviceResolverAutoConfigurationTests method deviceResolverHandlerInterceptorRegistered.
@Test
public void deviceResolverHandlerInterceptorRegistered() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(Config.class);
this.context.refresh();
RequestMappingHandlerMapping mapping = this.context.getBean(RequestMappingHandlerMapping.class);
HandlerInterceptor[] interceptors = mapping.getHandler(new MockHttpServletRequest()).getInterceptors();
assertThat(interceptors).hasAtLeastOneElementOfType(DeviceResolverHandlerInterceptor.class);
}
use of org.springframework.web.servlet.HandlerInterceptor in project spring-framework by spring-projects.
the class InterceptorRegistryTests method getInterceptorsForPath.
private List<HandlerInterceptor> getInterceptorsForPath(String lookupPath) {
PathMatcher pathMatcher = new AntPathMatcher();
List<HandlerInterceptor> result = new ArrayList<>();
for (Object interceptor : this.registry.getInterceptors()) {
if (interceptor instanceof MappedInterceptor) {
MappedInterceptor mappedInterceptor = (MappedInterceptor) interceptor;
if (mappedInterceptor.matches(lookupPath, pathMatcher)) {
result.add(mappedInterceptor.getInterceptor());
}
} else if (interceptor instanceof HandlerInterceptor) {
result.add((HandlerInterceptor) interceptor);
} else {
fail("Unexpected interceptor type: " + interceptor.getClass().getName());
}
}
return result;
}
Aggregations