@ -19,13 +19,20 @@ package org.springframework.boot.actuate.endpoint;
import javax.validation.constraints.NotNull ;
import javax.validation.constraints.NotNull ;
import javax.validation.constraints.Pattern ;
import javax.validation.constraints.Pattern ;
import org.springframework.context.EnvironmentAware ;
import org.springframework.core.env.Environment ;
/ * *
/ * *
* Abstract base for { @link Endpoint } implementations .
* Abstract base for { @link Endpoint } implementations .
*
*
* @author Phillip Webb
* @author Phillip Webb
* @author Christian Dupuis
* @author Christian Dupuis
* /
* /
public abstract class AbstractEndpoint < T > implements Endpoint < T > {
public abstract class AbstractEndpoint < T > implements Endpoint < T > , EnvironmentAware {
private static final String ENDPOINTS_ENABLED_PROPERTY = "endpoints.enabled" ;
private Environment environment ;
/ * *
/ * *
* Endpoint identifier . With HTTP monitoring the identifier of the endpoint is mapped
* Endpoint identifier . With HTTP monitoring the identifier of the endpoint is mapped
@ -36,25 +43,52 @@ public abstract class AbstractEndpoint<T> implements Endpoint<T> {
private String id ;
private String id ;
/ * *
/ * *
* Enable security on the endpoint .
* Mark if the endpoint exposes sensitive information .
* /
* /
private boolean sensitive ;
private boolean sensitive ;
/ * *
/ * *
* Enable the endpoint .
* Enable the endpoint .
* /
* /
private boolean enabled = true ;
private Boolean enabled ;
/ * *
* Create a new sensitive endpoint instance . The enpoint will enabled flag will be
* based on the spring { @link Environment } unless explicitly set .
* @param id the endpoint ID
* /
public AbstractEndpoint ( String id ) {
public AbstractEndpoint ( String id ) {
this ( id , true , true ) ;
this ( id , true ) ;
}
/ * *
* Create a new endpoint instance . The enpoint will enabled flag will be based on the
* spring { @link Environment } unless explicitly set .
* @param id the endpoint ID
* @param sensitive if the endpoint is sensitive
* /
public AbstractEndpoint ( String id , boolean sensitive ) {
this . id = id ;
this . sensitive = sensitive ;
}
}
/ * *
* Create a new endpoint instance .
* @param id the endpoint ID
* @param sensitive if the endpoint is sensitive
* @param enabled if the endpoint is enabled or not .
* /
public AbstractEndpoint ( String id , boolean sensitive , boolean enabled ) {
public AbstractEndpoint ( String id , boolean sensitive , boolean enabled ) {
this . id = id ;
this . id = id ;
this . sensitive = sensitive ;
this . sensitive = sensitive ;
this . enabled = enabled ;
this . enabled = enabled ;
}
}
@Override
public void setEnvironment ( Environment environment ) {
this . environment = environment ;
}
@Override
@Override
public String getId ( ) {
public String getId ( ) {
return this . id ;
return this . id ;
@ -66,10 +100,16 @@ public abstract class AbstractEndpoint<T> implements Endpoint<T> {
@Override
@Override
public boolean isEnabled ( ) {
public boolean isEnabled ( ) {
return this . enabled ;
if ( this . enabled ! = null ) {
return this . enabled ;
}
if ( this . environment ! = null ) {
this . environment . getProperty ( ENDPOINTS_ENABLED_PROPERTY , Boolean . class , true ) ;
}
return true ;
}
}
public void setEnabled ( boolean enabled ) {
public void setEnabled ( B oolean enabled ) {
this . enabled = enabled ;
this . enabled = enabled ;
}
}