public String[] getPaths(EndpointHandlerMapping endpointHandlerMapping) { if (endpointHandlerMapping == null) { return NO_PATHS; } Set<? extends MvcEndpoint> endpoints = endpointHandlerMapping.getEndpoints(); Set<String> paths = new LinkedHashSet<String>(endpoints.size()); for (MvcEndpoint endpoint : endpoints) { if (isIncluded(endpoint)) { String path = endpointHandlerMapping.getPath(endpoint.getPath()); paths.add(path); if (!path.equals("")) { if (endpoint.isSensitive()) { // Ensure that nested paths are secured paths.add(path + "/**"); // Add Spring MVC-generated additional paths paths.add(path + ".*"); } } paths.add(path + "/"); } } return paths.toArray(new String[paths.size()]); }
@Bean @ConditionalOnMissingBean public EndpointHandlerMapping endpointHandlerMapping() { Set<? extends MvcEndpoint> endpoints = mvcEndpoints().getEndpoints(); CorsConfiguration corsConfiguration = getCorsConfiguration(this.corsProperties); EndpointHandlerMapping mapping = new EndpointHandlerMapping(endpoints, corsConfiguration); boolean disabled = this.managementServerProperties.getPort() != null && this.managementServerProperties.getPort() == -1; mapping.setDisabled(disabled); if (!disabled) { mapping.setPrefix(this.managementServerProperties.getContextPath()); } if (this.mappingCustomizers != null) { for (EndpointHandlerMappingCustomizer customizer : this.mappingCustomizers) { customizer.customize(mapping); } } return mapping; }
protected final EndpointHandlerMapping getRequiredEndpointHandlerMapping() { if (this.endpointHandlerMapping == null) { ApplicationContext context = (this.contextResolver == null ? null : this.contextResolver.getApplicationContext()); if (context != null && context .getBeanNamesForType(EndpointHandlerMapping.class).length > 0) { this.endpointHandlerMapping = context .getBean(EndpointHandlerMapping.class); } if (this.endpointHandlerMapping == null) { this.endpointHandlerMapping = new EndpointHandlerMapping( Collections.<MvcEndpoint>emptySet()); } } return this.endpointHandlerMapping; }
@Profile("standalone") @ConditionalOnBean(name = "configurationPropertiesEnvironmentManager") @Bean @RefreshScope public MvcEndpoint internalConfigController() { return new ConfigurationStateController(casProperties); }
@Autowired @Bean @RefreshScope public MvcEndpoint statisticsController(@Qualifier("auditTrailManager") final DelegatingAuditTrailManager auditTrailManager) { return new StatisticsController(auditTrailManager, centralAuthenticationService, metricsRegistry, healthCheckRegistry, casProperties); }
public void addEndpointLinks(ResourceSupport resource, String self) { if (!resource.hasLink("self")) { resource.add(linkTo(LinksEnhancer.class).slash(this.rootPath + self) .withSelfRel()); } Set<String> added = new HashSet<String>(); for (MvcEndpoint endpoint : this.endpoints.getEndpoints()) { if (!endpoint.getPath().equals(self) && !added.contains(endpoint.getPath())) { addEndpointLink(resource, endpoint); } added.add(endpoint.getPath()); } }
private void addEndpointLink(ResourceSupport resource, MvcEndpoint endpoint) { Class<?> type = endpoint.getEndpointType(); type = (type == null ? Object.class : type); String path = endpoint.getPath(); String rel = (path.startsWith("/") ? path.substring(1) : path); if (StringUtils.hasText(rel)) { String fullPath = this.rootPath + endpoint.getPath(); resource.add(linkTo(type).slash(fullPath).withRel(rel)); } }
@Test public void endpointsDefaultConfiguration() throws Exception { this.applicationContext.register(RootConfig.class, BaseConfiguration.class, ServerPortConfig.class, EndpointWebMvcAutoConfiguration.class); this.applicationContext.refresh(); // /health, /metrics, /env, /actuator, /heapdump (/shutdown is disabled by default) assertThat(this.applicationContext.getBeansOfType(MvcEndpoint.class)).hasSize(5); }
@Test public void endpointsAllDisabled() throws Exception { this.applicationContext.register(RootConfig.class, BaseConfiguration.class, ServerPortConfig.class, EndpointWebMvcAutoConfiguration.class); EnvironmentTestUtils.addEnvironment(this.applicationContext, "ENDPOINTS_ENABLED:false"); this.applicationContext.refresh(); assertThat(this.applicationContext.getBeansOfType(MvcEndpoint.class)).isEmpty(); }
private void endpointDisabled(String name, Class<? extends MvcEndpoint> type) { this.applicationContext.register(RootConfig.class, BaseConfiguration.class, ServerPortConfig.class, EndpointWebMvcAutoConfiguration.class); EnvironmentTestUtils.addEnvironment(this.applicationContext, String.format("endpoints.%s.enabled:false", name)); this.applicationContext.refresh(); assertThat(this.applicationContext.getBeansOfType(type)).isEmpty(); }
private void endpointEnabledOverride(String name, Class<? extends MvcEndpoint> type) throws Exception { this.applicationContext.register(RootConfig.class, BaseConfiguration.class, ServerPortConfig.class, EndpointWebMvcAutoConfiguration.class); EnvironmentTestUtils.addEnvironment(this.applicationContext, "endpoints.enabled:false", String.format("endpoints_%s_enabled:true", name)); this.applicationContext.refresh(); assertThat(this.applicationContext.getBeansOfType(type)).hasSize(1); }
private String getConfiguredPath() { if (MvcEndpoint.class.isAssignableFrom(this.endpointClass)) { return ((MvcEndpoint) this.context.getBean(this.endpointClass)).getPath(); } for (MvcEndpoint endpoint : this.context.getBean(MvcEndpoints.class) .getEndpoints()) { if (endpoint instanceof EndpointMvcAdapter && this.endpointClass .isInstance(((EndpointMvcAdapter) endpoint).getDelegate())) { return ((EndpointMvcAdapter) endpoint).getPath(); } } throw new IllegalStateException( "Could not get configured path for " + this.endpointClass); }
private Collection<? extends MvcEndpoint> getEndpoints() { List<? extends MvcEndpoint> endpoints = new ArrayList<MvcEndpoint>( this.mvcEndpoints.getEndpoints()); Collections.sort(endpoints, new Comparator<MvcEndpoint>() { @Override public int compare(MvcEndpoint o1, MvcEndpoint o2) { return o1.getPath().compareTo(o2.getPath()); } }); return endpoints; }
@Test public void endpointsDefaultConfiguration() throws Exception { this.applicationContext.register(RootConfig.class, BaseConfiguration.class, ServerPortConfig.class, EndpointWebMvcAutoConfiguration.class); this.applicationContext.refresh(); // /health, /metrics, /env, /actuator (/shutdown is disabled by default) assertThat(this.applicationContext.getBeansOfType(MvcEndpoint.class)).hasSize(4); }
@Test public void endpointsAllListed() throws Exception { for (MvcEndpoint endpoint : this.mvcEndpoints.getEndpoints()) { String path = endpoint.getPath(); if ("/actuator".equals(path)) { continue; } path = path.startsWith("/") ? path.substring(1) : path; path = path.length() > 0 ? path : "self"; this.mockMvc.perform(get("/admin").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("$._links.%s.href", path) .value("http://localhost/admin" + endpoint.getPath())); } }
@Test public void endpointsDefaultConfiguration() throws Exception { this.applicationContext.register(RootConfig.class, BaseConfiguration.class, ServerPortConfig.class, EndpointWebMvcAutoConfiguration.class); this.applicationContext.refresh(); // /health, /metrics, /env, /actuator (/shutdown is disabled by default) assertThat(this.applicationContext.getBeansOfType(MvcEndpoint.class).size(), is(equalTo(4))); }
@Test public void endpointsAllDisabled() throws Exception { this.applicationContext.register(RootConfig.class, BaseConfiguration.class, ServerPortConfig.class, EndpointWebMvcAutoConfiguration.class); EnvironmentTestUtils.addEnvironment(this.applicationContext, "ENDPOINTS_ENABLED:false"); this.applicationContext.refresh(); assertThat(this.applicationContext.getBeansOfType(MvcEndpoint.class).size(), is(equalTo(0))); }
private void endpointDisabled(String name, Class<? extends MvcEndpoint> type) { this.applicationContext.register(RootConfig.class, BaseConfiguration.class, ServerPortConfig.class, EndpointWebMvcAutoConfiguration.class); EnvironmentTestUtils.addEnvironment(this.applicationContext, String.format("endpoints.%s.enabled:false", name)); this.applicationContext.refresh(); assertThat(this.applicationContext.getBeansOfType(type).size(), is(equalTo(0))); }
private void endpointEnabledOverride(String name, Class<? extends MvcEndpoint> type) throws Exception { this.applicationContext.register(RootConfig.class, BaseConfiguration.class, ServerPortConfig.class, EndpointWebMvcAutoConfiguration.class); EnvironmentTestUtils.addEnvironment(this.applicationContext, "endpoints.enabled:false", String.format("endpoints_%s_enabled:true", name)); this.applicationContext.refresh(); assertThat(this.applicationContext.getBeansOfType(type).size(), is(equalTo(1))); }
@Test public void endpointsAllListed() throws Exception { for (MvcEndpoint endpoint : this.mvcEndpoints.getEndpoints()) { String path = endpoint.getPath(); if ("/actuator".equals(path)) { continue; } path = path.startsWith("/") ? path.substring(1) : path; this.mockMvc.perform(get("/actuator").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("$._links.%s.href", path).exists()); } }
@Test public void endpointsEachHaveSelf() throws Exception { for (MvcEndpoint endpoint : this.mvcEndpoints.getEndpoints()) { String path = endpoint.getPath(); path = path.length() > 0 ? path : "/"; this.mockMvc.perform(get(path).accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()).andExpect(jsonPath("$._links.self.href") .value("http://localhost" + endpoint.getPath())); } }
@Bean @RefreshScope public MvcEndpoint dashboardController() { return new DashboardController(casProperties); }
@Bean @RefreshScope public MvcEndpoint personDirectoryAttributeResolutionController() { return new PersonDirectoryAttributeResolutionController(casProperties); }
@Bean @RefreshScope public MvcEndpoint healthCheckController() { return new HealthCheckController(healthCheckMonitor, casProperties); }
@Bean @RefreshScope public MvcEndpoint singleSignOnSessionsReportController() { return new SingleSignOnSessionsReportController(centralAuthenticationService, casProperties); }
@Bean @RefreshScope @Autowired public MvcEndpoint loggingConfigController(@Qualifier("auditTrailManager") final DelegatingAuditTrailManager auditTrailManager) { return new LoggingConfigController(auditTrailManager, casProperties); }