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

  1. import io.micronaut.context.annotation.Requires;
  2. import io.micronaut.http.MediaType;
  3. import io.micronaut.management.endpoint.annotation.*;
  4. import java.util.List;
  5. import java.util.concurrent.CopyOnWriteArrayList;
  6. @Endpoint(id = "alerts", defaultSensitive = false) (1)
  7. public class AlertsEndpoint {
  8. private final List<String> alerts = new CopyOnWriteArrayList<>();
  9. @Read
  10. List<String> getAlerts() {
  11. return alerts;
  12. }
  13. @Delete
  14. @Sensitive(true) (2)
  15. void clearAlerts() {
  16. alerts.clear();
  17. }
  18. @Write(consumes = MediaType.TEXT_PLAIN)
  19. @Sensitive(property = "add.sensitive", defaultValue = true) (3)
  20. void addAlert(String alert) {
  21. alerts.add(alert);
  22. }
  23. }

AlertsEndpoint

  1. import io.micronaut.context.annotation.Requires;
  2. import io.micronaut.http.MediaType;
  3. import io.micronaut.management.endpoint.annotation.*;
  4. import java.util.List;
  5. import java.util.concurrent.CopyOnWriteArrayList;
  6. @Endpoint(id = "alerts", defaultSensitive = false) (1)
  7. class AlertsEndpoint {
  8. private final List<String> alerts = new CopyOnWriteArrayList<>();
  9. @Read
  10. List<String> getAlerts() {
  11. alerts
  12. }
  13. @Delete
  14. @Sensitive(true) (2)
  15. void clearAlerts() {
  16. alerts.clear()
  17. }
  18. @Write(consumes = MediaType.TEXT_PLAIN)
  19. @Sensitive(property = "add.sensitive", defaultValue = true) (3)
  20. void addAlert(String alert) {
  21. alerts.add(alert)
  22. }
  23. }

AlertsEndpoint

  1. import io.micronaut.context.annotation.Requires
  2. import io.micronaut.http.MediaType
  3. import io.micronaut.management.endpoint.annotation.*
  4. import java.util.concurrent.CopyOnWriteArrayList
  5. @Endpoint(id = "alerts", defaultSensitive = false) (1)
  6. class AlertsEndpoint {
  7. private val alerts: MutableList<String> = CopyOnWriteArrayList()
  8. @Read
  9. fun getAlerts(): List<String> {
  10. return alerts
  11. }
  12. @Delete
  13. @Sensitive(true) (2)
  14. fun clearAlerts() {
  15. alerts.clear()
  16. }
  17. @Write(consumes = [MediaType.TEXT_PLAIN])
  18. @Sensitive(property = "add.sensitive", defaultValue = true) (3)
  19. fun addAlert(alert: String) {
  20. alerts.add(alert)
  21. }
  22. }
1The endpoint is not sensitive by default and the default prefix of endpoints is used.
2This method is always sensitive, regardless of any other factors
3The 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.

  1. endpoint is the first token because that is the default value for prefix in the endpoint annotation and is not set explicity in this example.

  2. alerts is the next token because that is the endpoint id

  3. add.sensitive is the next token because that is the value set to the property member of the @Sensitive annotation.

If the configuration key is not set, the defaultValue will be used (defaults to true).