mkurz / deadbolt-2-scala

Idiomatic Scala API for Deadbolt 2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Passing the auth-user as a global param from the controller

shuroo opened this issue · comments

Hi,

I'm using deadbolt-2-scala with play framework.
I wish to find an elegant way to pass the auth-user in the session in order to pass this data to the logs.

Thanks,
Shiri.

Hi,

you have access to the subject from the request passed into the controller function - the request is an AuthenticatedRequest. For example,

def index = deadbolt.SubjectPresentAction().defaultHandler() { implicit request =>
    request.subject.map(sbj => /* log the request */)
    // express the result
}

Alternatively, you can log the user in the getSubject function of your DeadboltHandler - this will let you centralize the logging.

Regards,
Steve

Hi,

Well,

I'm familiar with the above tricks.

The problem is, that I'd like to access the request from the models and bl
packahes as well to get the logs.

This cannot be done unless I pass the request as a function param to the
inner functions. I wish to have a better way than that to access this
information to use the logs.

Thanks.

On Tuesday, August 30, 2016, Steve Chaloner notifications@github.com
wrote:

Hi,

you have access to the subject from the request passed into the controller
function - the request is an AuthenticatedRequest. For example,

def index = deadbolt.SubjectPresentAction().defaultHandler() { implicit request =>
request.subject.map(sbj => /* log the request */)
// express the result
}

Alternatively, you can log the user in the getSubject function of your
DeadboltHandler - this will let you centralize the logging.

Regards,
Steve


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#25 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AJoBSWO93cY1BcQP5WNfK3ss3cBYvJJEks5qlBuIgaJpZM4JnZwg
.

I've been wracking my brains trying to think of a way to resolve this without passing the request around, but it always comes back to a brute force approach of passing the request around.

Yes, I did not yet managed to resolved it other way.

The assistedinject (Guice) may be a possibility, theoretically, not
successfully tested yet.

Thank you anyway. I think I am closing this for now

(I solved it partially by initializing and passing a logger class with the
info. not the solution I was hoping for, but the easiest. And it looks fine
).

2016-09-05 9:09 GMT+03:00 Steve Chaloner notifications@github.com:

I've been wracking my brains trying to think of a way to resolve this
without passing the request around, but it always comes back to a brute
force approach of passing the request around.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#25 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AJoBSem-y8ZzsKPcdyNiH4dE4tt_wC79ks5qm7IXgaJpZM4JnZwg
.

Closed at user request.