javaplayframework-2.0deadbolt

How to access to the user session in Deadbolt2 Handler


I'm trying to use Deadbolt2 in a play2 application and i'm stuck with the implementation of getRolesHolder() in my Deadbolt Handler.

In the sample application, there is this example :

public class MyDeadboltHandler extends AbstractDeadboltHandler
{
    public RoleHolder getRoleHolder()
    {
        // in a real application, the user name would probably be
        // in the session following a login process
        return User.findByUserName("steve");
    }
}

My problem is : how can I get the session in getRoleHolder() ?

I've tried to call Context.current().session(); but I've got the following error :
There is no HTTP Context available from here.

Any ideas ?
Thanks


Solution

  • The seemingly variable availability of the context is starting to get a bit annoying. I'll change the signature of getRoleHolder() to take the context. Check in github in about 10 minutes, and update your Build.scala version of Deadbolt to take 1.1-SNAPSHOT