- 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
-
Method Details
-
manage
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 contextpermittedRoles- The permitted roles for the endpoint
-