Question

I am using Deadbolt 2 with Playframework 2.1.

In the getSubject() function of my DeadboltHandler I check the user password and retrieve the user from the database.

Is it possible to access this user in my controllers to avoid retrieving the user twice per request?

Was it helpful?

Solution

Steve, the developer of Deadbolt, suggested me the following:

the trick is to store the user in the context, and then have your controller or deadbolt handler to access it. This allows you to store the user by the actual class, and not have to use getSubject() and cast the resulting Subject to your actual User class.

So I decided to save the User object in the args-Field of Http.Context.current() and it works like a charm!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top