Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Deadbolt user from within Controller

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?

like image 360
user2440437 Avatar asked May 31 '13 12:05

user2440437


1 Answers

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!

like image 115
user2440437 Avatar answered Jan 04 '23 07:01

user2440437