Vert.x - Auth (Authentication/Authorization) - 4.0.0

About

User

The authenticated user, or null if the current user is not authenticated. This will usually be injected by an auth handler if authentication if successful.

User user = routingContext.user();

// Create
// https://vertx.io/docs/apidocs/io/vertx/ext/auth/User.html#create-io.vertx.core.json.JsonObject-
User.create(JsonObject)

// Set
routingContext.setUser(user)

// Delete
routingContext.clearUser()

// Snippet
cerdential = new UsernamePasswordCredentials(username, password)

Handler

An auth handler allows your application to provide authentication/authorization support .Interface

An Auth handler requires a SessionHandler to be on the routing chain before it.

The whole implementation is in the AuthenticationHandlerImpl#handle function. To create your handler, just extends it.

It checks:

  • that the user is null
User user = ctx.user();
  • if this is the case, it call the AuthenticationHandlerImpl#parseCredentials to extract the credentials
JsonObject authInfo = new JsonObject()
  .put("username", "tim")
  .put("password", "mypassword");
  • and call the authenticationProvider
authenticationProvider.authenticate(authInfo)
  .onSuccess(user -> {
    System.out.println("User " + user.principal() + " is now authenticated");
  })
  .onFailure(Throwable::printStackTrace);

Method

Oauth

See multi-tenant with google and github

Form

PropertyFileAuthorization

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

Example

Documentation


Powered by ComboStrap