Adding Security

To add security, such as protecting resource methods with authentication, to a MicroProfile application, add the Helidon security integration dependency to your project.

Maven Coordinates

Maven Dependency
<dependency>
  <groupId>io.helidon.microprofile</groupId>
  <artifactId>helidon-microprofile-security</artifactId>
</dependency>
Copied

Securing a Web Resource

For web server static content, see Configuration Secrets.

For JAX-RS resources, declare security by adding annotations to a resource class or method.

Protected resource method
@GET
@io.helidon.security.annotations.Authenticated
@io.helidon.security.annotations.Authorized
// you can also use io.helidon.security.abac.role.RoleValidator.Roles
@RolesAllowed("admin")
public String adminResource(@Context io.helidon.security.SecurityContext securityContext) {
  return "you are " + securityContext.getUser();
}
Copied

Security in Helidon MicroProfile is built on top of Jersey’s and can be enabled/disabled using the property security.jersey.enabled=[true|false].