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

AlertsEndpoint

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

AlertsEndpoint

  1. import io.micronaut.http.MediaType
  2. import io.micronaut.management.endpoint.annotation.Delete
  3. import io.micronaut.management.endpoint.annotation.Endpoint
  4. import io.micronaut.management.endpoint.annotation.Read
  5. import io.micronaut.management.endpoint.annotation.Sensitive
  6. import io.micronaut.management.endpoint.annotation.Write
  7. import java.util.concurrent.CopyOnWriteArrayList
  8. @Endpoint(id = "alerts", defaultSensitive = false) (1)
  9. class AlertsEndpoint {
  10. private val alerts: MutableList<String> = CopyOnWriteArrayList()
  11. @Read
  12. fun getAlerts(): List<String> {
  13. return alerts
  14. }
  15. @Delete
  16. @Sensitive(true) (2)
  17. fun clearAlerts() {
  18. alerts.clear()
  19. }
  20. @Write(consumes = [MediaType.TEXT_PLAIN])
  21. @Sensitive(property = "add.sensitive", defaultValue = true) (3)
  22. fun addAlert(alert: String) {
  23. alerts.add(alert)
  24. }
  25. }
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 determines 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 explicitly 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 is used (defaults to true).