We use play-pac4j for our authentication in our play application.
We would like to have the same route/controller endpoint but with a different behaviour dependending on the user Role.
Conceptually, this would do something like:
val ACTION_ONE: ActionBuilder[Request, AnyContent] = Secure(
JWT_CLIENT, Authorizers.Role1
)(anyContentLarge)
val ACTION_TWO: ActionBuilder[Request, AnyContent] = Secure(
JWT_CLIENT, Authorizers.Role2
)(anyContentLarge)
def index = ACTION_ONE.async{ req => index1(req) } orElse ACTION_TWO.async{ req => index2(req) }
def index1(req: Request[AnyContent]) = //... behavior with role1
def index2(req: Request[AnyContent]) = //... behavior with role2
But the composition of Play Actions provides only andThen, no orElse.
Is there a way to achieve that ?