/** * Maps the given {@code health} details to a {@link WebEndpointResponse}, honouring * the mapper's default {@link ShowDetails} using the given {@code securityContext}. * <p> * If the current user does not have the right to see the details, the * {@link Supplier} is not invoked and a 404 response is returned instead. * @param health the provider of health details, invoked if the current user has the * right to see them * @param securityContext the security context * @return the mapped response */ public WebEndpointResponse<Health> mapDetails(Supplier<Health> health, SecurityContext securityContext) { if (canSeeDetails(securityContext, this.showDetails)) { Health healthDetails = health.get(); if (healthDetails != null) { return createWebEndpointResponse(healthDetails); } } return new WebEndpointResponse<>(WebEndpointResponse.STATUS_NOT_FOUND); }
private boolean canSeeDetails(SecurityContext securityContext, ShowDetails showDetails) { if (showDetails == ShowDetails.NEVER || (showDetails == ShowDetails.WHEN_AUTHORIZED && (securityContext.getPrincipal() == null || !isUserInRole(securityContext)))) { return false; } return true; }
/** * Maps the given {@code health} to a {@link WebEndpointResponse}, honouring the * mapper's default {@link ShowDetails} using the given {@code securityContext}. * @param health the health to map * @param securityContext the security context * @return the mapped response */ public WebEndpointResponse<Health> map(Health health, SecurityContext securityContext) { return map(health, securityContext, this.showDetails); }
/** * Maps the given {@code health} to a {@link WebEndpointResponse}, honouring the given * {@code showDetails} using the given {@code securityContext}. * @param health the health to map * @param securityContext the security context * @param showDetails when to show details in the response * @return the mapped response */ public WebEndpointResponse<Health> map(Health health, SecurityContext securityContext, ShowDetails showDetails) { if (showDetails == ShowDetails.NEVER || (showDetails == ShowDetails.WHEN_AUTHORIZED && (securityContext.getPrincipal() == null || !isUserInRole(securityContext)))) { health = Health.status(health.getStatus()).build(); } return createWebEndpointResponse(health); }
@ReadOperation public WebEndpointResponse<Health> healthForComponent(SecurityContext securityContext, @Selector String component) { Supplier<Health> health = () -> this.delegate.healthForComponent(component); return this.responseMapper.mapDetails(health, securityContext); }
@Bean @ConditionalOnMissingBean public HealthWebEndpointResponseMapper healthWebEndpointResponseMapper( HealthStatusHttpMapper statusHttpMapper, HealthEndpointProperties properties) { return new HealthWebEndpointResponseMapper(statusHttpMapper, properties.getShowDetails(), properties.getRoles()); }
@ReadOperation public WebEndpointResponse<Health> healthForComponentInstance( SecurityContext securityContext, @Selector String component, @Selector String instance) { Supplier<Health> health = () -> this.delegate .healthForComponentInstance(component, instance); return this.responseMapper.mapDetails(health, securityContext); }
public WebEndpointResponse<Health> getHealth(SecurityContext securityContext, ShowDetails showDetails) { return this.responseMapper.map(this.delegate.health(), securityContext, showDetails); }
public Mono<WebEndpointResponse<Health>> health(SecurityContext securityContext, ShowDetails showDetails) { return this.delegate.health().map((health) -> this.responseMapper.map(health, securityContext, showDetails)); }
@ReadOperation public Mono<WebEndpointResponse<Health>> health(SecurityContext securityContext) { return this.delegate.health() .map((health) -> this.responseMapper.map(health, securityContext)); }
@ReadOperation public WebEndpointResponse<Health> health(SecurityContext securityContext) { return this.responseMapper.map(this.delegate.health(), securityContext); }