use of org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint in project spring-boot by spring-projects.
the class EndpointDocumentation method endpoints.
@Test
public void endpoints() throws Exception {
final File docs = new File("src/main/asciidoc");
final Map<String, Object> model = new LinkedHashMap<>();
final List<EndpointDoc> endpoints = new ArrayList<>();
model.put("endpoints", endpoints);
for (MvcEndpoint endpoint : getEndpoints()) {
final String endpointPath = (StringUtils.hasText(endpoint.getPath()) ? endpoint.getPath() : "/");
if (!SKIPPED.contains(endpointPath)) {
String output = endpointPath.substring(1);
output = output.length() > 0 ? output : "./";
this.mockMvc.perform(get(endpointPath).accept(ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON)).andExpect(status().isOk()).andDo(document(output)).andDo(new ResultHandler() {
@Override
public void handle(MvcResult mvcResult) throws Exception {
EndpointDoc endpoint = new EndpointDoc(docs, endpointPath);
endpoints.add(endpoint);
}
});
}
}
File file = new File(RESTDOCS_OUTPUT_DIR + "/endpoints.adoc");
file.getParentFile().mkdirs();
PrintWriter writer = new PrintWriter(file, "UTF-8");
try {
Template template = this.templates.createTemplate(new File("src/restdoc/resources/templates/endpoints.adoc.tpl"));
template.make(model).writeTo(writer);
} finally {
writer.close();
}
}
use of org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint 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;
}
use of org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint in project spring-boot by spring-projects.
the class CloudFoundrySecurityInterceptor method preHandle.
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (CorsUtils.isPreFlightRequest(request)) {
return true;
}
try {
if (!StringUtils.hasText(this.applicationId)) {
throw new CloudFoundryAuthorizationException(Reason.SERVICE_UNAVAILABLE, "Application id is not available");
}
if (this.cloudFoundrySecurityService == null) {
throw new CloudFoundryAuthorizationException(Reason.SERVICE_UNAVAILABLE, "Cloud controller URL is not available");
}
HandlerMethod handlerMethod = (HandlerMethod) handler;
if (HttpMethod.OPTIONS.matches(request.getMethod()) && !(handlerMethod.getBean() instanceof MvcEndpoint)) {
return true;
}
MvcEndpoint mvcEndpoint = (MvcEndpoint) handlerMethod.getBean();
check(request, mvcEndpoint);
} catch (CloudFoundryAuthorizationException ex) {
logger.error(ex);
response.setContentType(MediaType.APPLICATION_JSON.toString());
response.getWriter().write("{\"security_error\":\"" + ex.getMessage() + "\"}");
response.setStatus(ex.getStatusCode().value());
return false;
}
return true;
}
use of org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint in project spring-boot by spring-projects.
the class LinksEnhancer method addEndpointLinks.
public void addEndpointLinks(ResourceSupport resource, String self) {
if (!resource.hasLink("self")) {
resource.add(linkTo(LinksEnhancer.class).slash(this.rootPath + self).withSelfRel());
}
MultiValueMap<String, String> added = new LinkedMultiValueMap<>();
for (MvcEndpoint endpoint : this.endpoints.getEndpoints()) {
if (!endpoint.getPath().equals(self)) {
String rel = getRel(endpoint);
List<String> paths = added.get(rel);
if (paths == null || !paths.contains(endpoint.getPath())) {
addEndpointLink(resource, endpoint, rel);
added.add(rel, endpoint.getPath());
}
}
}
}
Aggregations