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?
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With