14.1.3 Endpoint Sensitivity
Endpoint sensitivity can be controlled for the entire endpoint through the endpoint annotation and configuration. Individual methods can be configured independently from the endpoint as a whole, however. The @Sensitive annotation can be applied to methods to control their sensitivity.
AlertsEndpoint
import io.micronaut.context.annotation.Requires;
import io.micronaut.http.MediaType;
import io.micronaut.management.endpoint.annotation.*;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
@Endpoint(id = "alerts", defaultSensitive = false) (1)
public class AlertsEndpoint {
private final List<String> alerts = new CopyOnWriteArrayList<>();
@Read
List<String> getAlerts() {
return alerts;
}
@Delete
@Sensitive(true) (2)
void clearAlerts() {
alerts.clear();
}
@Write(consumes = MediaType.TEXT_PLAIN)
@Sensitive(property = "add.sensitive", defaultValue = true) (3)
void addAlert(String alert) {
alerts.add(alert);
}
}
AlertsEndpoint
import io.micronaut.context.annotation.Requires;
import io.micronaut.http.MediaType;
import io.micronaut.management.endpoint.annotation.*;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
@Endpoint(id = "alerts", defaultSensitive = false) (1)
class AlertsEndpoint {
private final List<String> alerts = new CopyOnWriteArrayList<>();
@Read
List<String> getAlerts() {
alerts
}
@Delete
@Sensitive(true) (2)
void clearAlerts() {
alerts.clear()
}
@Write(consumes = MediaType.TEXT_PLAIN)
@Sensitive(property = "add.sensitive", defaultValue = true) (3)
void addAlert(String alert) {
alerts.add(alert)
}
}
AlertsEndpoint
import io.micronaut.context.annotation.Requires
import io.micronaut.http.MediaType
import io.micronaut.management.endpoint.annotation.*
import java.util.concurrent.CopyOnWriteArrayList
@Endpoint(id = "alerts", defaultSensitive = false) (1)
class AlertsEndpoint {
private val alerts: MutableList<String> = CopyOnWriteArrayList()
@Read
fun getAlerts(): List<String> {
return alerts
}
@Delete
@Sensitive(true) (2)
fun clearAlerts() {
alerts.clear()
}
@Write(consumes = [MediaType.TEXT_PLAIN])
@Sensitive(property = "add.sensitive", defaultValue = true) (3)
fun addAlert(alert: String) {
alerts.add(alert)
}
}
1 | The endpoint is not sensitive by default and the default prefix of endpoints is used. |
2 | This method is always sensitive, regardless of any other factors |
3 | The property value is appended to the prefix and id to lookup a configuration value |
If the configuration key endpoints.alerts.add.sensitive
is set, that value will determine the sensitivity of the addAlert
method.
endpoint
is the first token because that is the default value forprefix
in the endpoint annotation and is not set explicity in this example.alerts
is the next token because that is the endpoint idadd.sensitive
is the next token because that is the value set to theproperty
member of the @Sensitive annotation.
If the configuration key is not set, the defaultValue
will be used (defaults to true
).