You should not do this (or even need to do this), that was actually something I was also thinking when I started using play - then I realized that I didnt use framework how it was meant to be used.
Action composition is actually something which is used to protect certain methods or controllers being accessed. (Although you can use it for other things too). - But it is needed when you are implementing login.
Instead of passing your User object around .. your user email (username) are placed into session and it cant be later retrieved inside your controller side and templates. (Any of the controllers or templates.)
public static Result authenticate() {
Form<Login> loginForm = form(Login.class).bindFromRequest();
if (loginForm.hasErrors()) {
return badRequest(login.render(loginForm));
} else {
session().clear();
session("email", loginForm.get().email);
return redirect(
routes.Application.index()
);
}
}
I highly recommend checking out full zentask tutorial, if you are just more eager to know about login, you can check zentask page 4 (working zentask example is also located inside your play/samples/java/zentasks so its really easy to pick up with).
Relevant parts includes setting up own login form, view, controller with authenticate method and Secured class to handle actual method & or controller action protecting. Dont forgot to persist your users to database - otherwise there are not much to check against ;)
Edit:
If you open up your zentask tutorial you can see an example when controller needs authentication and when username is taken from the session, see the annotation: @Security.Authenticated(Secured.class) and method of request().username() which returns username as a String.. see: Http.Request.html#username() documentation
@Security.Authenticated(Secured.class)
public class Projects extends Controller {
/**
* Display the dashboard.
*/
public static Result index() {
return ok(
dashboard.render(
Project.findInvolving(request().username()),
Task.findTodoInvolving(request().username()),
User.find.byId(request().username())
)
);
}
...
Method itself for example User.find.byId(request().username()) loads complete User from database for the model to be rendered. :)
But read the tutorial I provided, its complete example. Cheers.