Search in sources :

Example 6 with MvcEndpoint

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();
    }
}
Also used : ArrayList(java.util.ArrayList) ResultHandler(org.springframework.test.web.servlet.ResultHandler) MvcResult(org.springframework.test.web.servlet.MvcResult) LinkedHashMap(java.util.LinkedHashMap) Template(groovy.text.Template) MvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint) File(java.io.File) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 7 with MvcEndpoint

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;
}
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)

Example 8 with MvcEndpoint

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;
}
Also used : MvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint) HandlerMethod(org.springframework.web.method.HandlerMethod)

Example 9 with MvcEndpoint

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());
            }
        }
    }
}
Also used : MvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint) NamedMvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.NamedMvcEndpoint) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap)

Aggregations

MvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint)9 Test (org.junit.Test)5 AbstractMvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.AbstractMvcEndpoint)5 ResourceSupport (org.springframework.hateoas.ResourceSupport)4 Template (groovy.text.Template)1 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 AuditEventsMvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.AuditEventsMvcEndpoint)1 EndpointHandlerMapping (org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping)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 MvcEndpointSecurityInterceptor (org.springframework.boot.actuate.endpoint.mvc.MvcEndpointSecurityInterceptor)1 MvcEndpoints (org.springframework.boot.actuate.endpoint.mvc.MvcEndpoints)1