Module io.avaje.jex
Package io.avaje.jex

Interface AccessManager

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface AccessManager
Provide access check for routes that have permitted roles assigned to them.

An example implementation might look like the code below.



   var app = Jex.create()
     .accessManager((handler, ctx, permittedRoles) -> {

         // obtain current users role(s)
         final String userRole = ...

         if (userRole == null || !permittedRoles.contains(AppRoles.valueOf(userRole))) {
           ctx.status(401).text("Unauthorized");
         } else {
           // allow
           handler.handle(ctx);
         }
       })

 
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    manage(Handler handler, Context ctx, Set<Role> permittedRoles)
    Check that the current user has one of the required roles.
  • Method Details

    • manage

      void manage(Handler handler, Context ctx, Set<Role> permittedRoles)
      Check that the current user has one of the required roles.

      Implementations should call the handler if the user has one of the permitted roles.

      Parameters:
      handler - The handler to call if the user has an appropriate role.
      ctx - The context
      permittedRoles - The permitted roles for the endpoint