Oracle Helidon MP - Basic Authentication
Hi Folks,
Today I'm sharing my learning on "Oracle Helidon MP - Basic Authentication".
Basic Authentication is a easy concept by which we can authenticate and authorise a user based on his credentials and roles.
Step 0: Without Authentication.
Step 1: Add maven dependencies.
<dependency>
<groupId>io.helidon.microprofile</groupId>
<artifactId>helidon-microprofile-security</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.security.providers</groupId>
<artifactId>helidon-security-providers-http-auth</artifactId>
</dependency>
Step 2: Add Authentication & Authorisation Annotations.
import io.helidon.security.annotations.Authenticated;
import jakarta.annotation.security.RolesAllowed;
@Authenticated // this annotation itself is self-sufficient for authentication purpose,
the application will start throwing the 401 Unauthorised
Http Response, if credentials are not provided.
@RolesAllowed(value = {"users","normal"})
// this annotation will enable the roles defined
and give access to the list of roles provided
Step 3: Add values in your properties file.
security:
jersey:
enabled: true
config.require-encryption: false
providers:
- http-basic-auth:
realm: "helidon"
users:
- login: pratik
password: Welcome123#
roles: ["admin"]
- login: gaurav
password: Welcome123#
roles: ["users"]
That's it !
Let's see the results post configurations.




Comments
Post a Comment