Search in sources :

Example 1 with EndpointHandlerMapping

use of org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping in project spring-boot by spring-projects.

the class EndpointWebMvcManagementContextConfigurationTests method endpointHandlerMapping.

@Test
public void endpointHandlerMapping() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.context, "management.security.enabled=false", "management.security.roles=my-role,your-role");
    this.context.refresh();
    EndpointHandlerMapping mapping = this.context.getBean("endpointHandlerMapping", EndpointHandlerMapping.class);
    assertThat(mapping.getPrefix()).isEmpty();
    MvcEndpointSecurityInterceptor securityInterceptor = (MvcEndpointSecurityInterceptor) ReflectionTestUtils.getField(mapping, "securityInterceptor");
    Object secure = ReflectionTestUtils.getField(securityInterceptor, "secure");
    List<String> roles = getRoles(securityInterceptor);
    assertThat(secure).isEqualTo(false);
    assertThat(roles).containsExactly("my-role", "your-role");
}
Also used : MvcEndpointSecurityInterceptor(org.springframework.boot.actuate.endpoint.mvc.MvcEndpointSecurityInterceptor) EndpointHandlerMapping(org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping) Test(org.junit.Test)

Example 2 with EndpointHandlerMapping

use of org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping in project spring-boot by spring-projects.

the class RequestMappingEndpointTests method beanMethodMappings.

@Test
public void beanMethodMappings() {
    StaticApplicationContext context = new StaticApplicationContext();
    EndpointHandlerMapping mapping = new EndpointHandlerMapping(Arrays.asList(new EndpointMvcAdapter(new DumpEndpoint())));
    mapping.setApplicationContext(new StaticApplicationContext());
    mapping.afterPropertiesSet();
    context.getDefaultListableBeanFactory().registerSingleton("mapping", mapping);
    this.endpoint.setApplicationContext(context);
    Map<String, Object> result = this.endpoint.invoke();
    assertThat(result).hasSize(1);
    assertThat(result.keySet().iterator().next().contains("/dump")).isTrue();
    @SuppressWarnings("unchecked") Map<String, Object> handler = (Map<String, Object>) result.values().iterator().next();
    assertThat(handler.containsKey("method")).isTrue();
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) EndpointMvcAdapter(org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter) EndpointHandlerMapping(org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping) Map(java.util.Map) Test(org.junit.Test)

Example 3 with EndpointHandlerMapping

use of org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping in project spring-boot by spring-projects.

the class RequestMappingEndpointTests method concreteMethodMappings.

@Test
public void concreteMethodMappings() {
    EndpointHandlerMapping mapping = new EndpointHandlerMapping(Arrays.asList(new EndpointMvcAdapter(new DumpEndpoint())));
    mapping.setApplicationContext(new StaticApplicationContext());
    mapping.afterPropertiesSet();
    this.endpoint.setMethodMappings(Collections.<AbstractHandlerMethodMapping<?>>singletonList(mapping));
    Map<String, Object> result = this.endpoint.invoke();
    assertThat(result).hasSize(1);
    assertThat(result.keySet().iterator().next().contains("/dump")).isTrue();
    @SuppressWarnings("unchecked") Map<String, Object> handler = (Map<String, Object>) result.values().iterator().next();
    assertThat(handler.containsKey("method")).isTrue();
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) EndpointMvcAdapter(org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter) EndpointHandlerMapping(org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping) Map(java.util.Map) Test(org.junit.Test)

Example 4 with EndpointHandlerMapping

use of org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping in project spring-boot by spring-projects.

the class EndpointWebMvcManagementContextConfiguration method endpointHandlerMapping.

@Bean
@ConditionalOnMissingBean
public EndpointHandlerMapping endpointHandlerMapping() {
    Set<MvcEndpoint> endpoints = mvcEndpoints().getEndpoints();
    CorsConfiguration corsConfiguration = getCorsConfiguration(this.corsProperties);
    EndpointHandlerMapping mapping = new EndpointHandlerMapping(endpoints, corsConfiguration);
    mapping.setPrefix(this.managementServerProperties.getContextPath());
    MvcEndpointSecurityInterceptor securityInterceptor = new MvcEndpointSecurityInterceptor(this.managementServerProperties.getSecurity().isEnabled(), this.managementServerProperties.getSecurity().getRoles());
    mapping.setSecurityInterceptor(securityInterceptor);
    for (EndpointHandlerMappingCustomizer customizer : this.mappingCustomizers) {
        customizer.customize(mapping);
    }
    return mapping;
}
Also used : EnvironmentMvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint) HeapdumpMvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.HeapdumpMvcEndpoint) LogFileMvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.LogFileMvcEndpoint) LoggersMvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.LoggersMvcEndpoint) ShutdownMvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.ShutdownMvcEndpoint) AuditEventsMvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.AuditEventsMvcEndpoint) MetricsMvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.MetricsMvcEndpoint) HealthMvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint) MvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint) EndpointHandlerMappingCustomizer(org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMappingCustomizer) CorsConfiguration(org.springframework.web.cors.CorsConfiguration) MvcEndpointSecurityInterceptor(org.springframework.boot.actuate.endpoint.mvc.MvcEndpointSecurityInterceptor) EndpointHandlerMapping(org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

EndpointHandlerMapping (org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping)4 Test (org.junit.Test)3 Map (java.util.Map)2 EndpointMvcAdapter (org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter)2 MvcEndpointSecurityInterceptor (org.springframework.boot.actuate.endpoint.mvc.MvcEndpointSecurityInterceptor)2 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)2 AuditEventsMvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.AuditEventsMvcEndpoint)1 EndpointHandlerMappingCustomizer (org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMappingCustomizer)1 EnvironmentMvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint)1 HealthMvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint)1 HeapdumpMvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.HeapdumpMvcEndpoint)1 LogFileMvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.LogFileMvcEndpoint)1 LoggersMvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.LoggersMvcEndpoint)1 MetricsMvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.MetricsMvcEndpoint)1 MvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint)1 ShutdownMvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.ShutdownMvcEndpoint)1 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1 CorsConfiguration (org.springframework.web.cors.CorsConfiguration)1