This page is about authentication in Vertx
In Vertx Web, you add a handler (called an authentication handler) that will add a user to the routing context upon successful authentication.
User user = routingContext.user();
if(user !=null ){
// authenticated
} else {
// non-authenticated
}
An auth handler sets or not the user in the routing context.
They requires a SessionHandler to be on the routing chain before it.
The whole implementation is in the handle function.
If you want to create your handler, just extend it.
What does does it do? It checks:
User user = ctx.user();
JsonObject authInfo = new JsonObject()
.put("username", "tim")
.put("password", "mypassword");
authenticationProvider.authenticate(authInfo)
.onSuccess(user -> {
System.out.println("User " + user.principal() + " is now authenticated");
})
.onFailure(Throwable::printStackTrace);
See multi-tenant with google and github
Redirect and FormLoginHandlerImpl
Simple auth service which uses a properties file to gets user/password/role information
Known also under the old name:
Java example:
// import io.vertx.ext.auth.properties.PropertyFileAuthentication;
PropertyFileAuthorization authorizationProvider = PropertyFileAuthorization.create(vertx, "vertx-users.properties");
Syntax of the properties file:
user.{username}={password},{roleName1},{roleName2},…,{roleNameN}
role.{roleName}={permissionName1},{permissionName2},…,{permissionNameN}
Example:
user.tim = mypassword,administrator,developer
user.bob = hispassword,developer
user.joe = anotherpassword,manager
role.administrator=*
role.manager=play_golf,say_buzzwords
role.developer=do_actual_work
// The authenticated user, or null if the current user is not authenticated.
User user = routingContext.user();
// Set
routingContext.setUser(user)
// Create a user
// https://vertx.io/docs/apidocs/io/vertx/ext/auth/User.html#create-io.vertx.core.json.JsonObject-
User.create(principalJsonObject)
// Delete
routingContext.clearUser()
// Snippet
cerdential = new UsernamePasswordCredentials(username, password)