Hi,
First off just to say thank you to everyone involved in creating and maintaining this library - I've found it very well documented and easy to use.
I am adding authentication logic to my Play Java 2.5.4 application using pac4j 1.9.0 and play-pac4j 2.4.0. I have an Authorizer which "needs" to read the request body on every request, to retrieve an ID value which is used in the isAuthorized() check. I initially tried protecting my controllers with the pac4j SecurityFilter - however, the request body is not available at this point because Play has not parsed it yet, so the Authorizer couldn't do its check.
The other option is to use a SecureAction to protect all my actions. With this approach, I have access to the parsed request body when the action is executed. Unfortunately I have quite a lot of actions which need protecting and it would be very tiresome to add the @Secure annotation to every single one (not to mention dangerous, in case one is accidentally missed off). I basically want to apply the security to all my actions and only exclude a handful of whitelisted URLs.
The Play Java API has a way to do this using an
ActionCreator. However, the pac4j SecurityAction is clearly not designed to be called in this way - it assumes there is an annotation available to read. To get this working I have had to hackily subclass the SecurityAction and invoke the "internalCall" method manually, to skip over the annotation checks in SecurityAction.call():
public static class MySecureAction extends SecureAction {
@Inject
public MySecureAction(Config config) {
super(config);
}
@Override
public CompletionStage<Result> call(Http.Context ctx) {
try {
return super.internalCall(ctx, "client", "authorizer", false);
} catch (Throwable th) {
throw new RuntimeException(th);
}
}
}
My question is basically: is this OK, or is there a better way? I am
fairly new to both Play and pac4j so I may be missing something obvious. I am nervous about invoking a method with the word "internal" in it, and although it is public there's nothing to indicate that it's acceptable to use.
Any advice would be most welcome.