logo       

Re: Setting the current user id in 2.2: msg#00738

cms.sakai.devel

Subject: Re: Setting the current user id in 2.2

Glenn,

Correct me if I am wrong here - but a simpler way to say this is that getCurrentUser first looks in the thread and if the user is not there, it looks in the session?

It is like a cache in some ways but just simpler.

Is it a good idea to clear *everything* in the thread just to solve this problem - especially if we are in code past the Request Filter?

I would personally prefer to see a situation where the code to set thew current user updates tboth the session and thread - r at least clears the user variable in the thread - or something.

Scattering ThreadLocalManager.clear() code throughout things might lead to painful consequences.

If on the other hand this is limited to unit tests and we want to simulate multiple "requests", clearing ThreadLocal seems like a fine idea.

/Chuck

On Apr 27, 2006, at 10:13 PM, Glenn R. Golden wrote:

Josh -

The user directory service impl caches the current user in the thread. So if you have already asked for the current user (or any code has so to trigger the caching), then change user, then ask again, all in the same thread, things might not work.

After setting the user and eid in the session, you can ask the thread local manager to clear the thread - that will reset any thread caching, including the user directory service:

ThreadLocalManager.clear();

See if that does the trick.

The user directory service impl. uses this to get the current user id:

String id = sessionManager().getCurrentSessionUserId();

so this really should work!

Non-request processing code in Sakai like the tests and background threads should keep this caching in mind (many services do it) and clear the thread at appropriate times (emulating the end of a typical end-user request processing cycle).

- Glenn

Glenn R. Golden
Software Architect, University Of Michigan
ggolden@xxxxxxxxx



On Apr 18, 2006, at 5:55 PM, Josh Holtzman wrote:

It almost works with:

Session session = SessionManager.startSession();
session.setUserId(userUid);
session.setUserEid(userUid);
SessionManager.setCurrentSession(session);
AuthzGroupService.refreshUser(userUid);

Unfortunately, UserDirectoryService.getCurrentUser().getId() returns a different answer (an empty string) than SessionManager.getCurrentSessionUserId() ("admin", as expected). The user object returned by UDS has a reference of "/user/null".

[scratches head...]

Josh

Ian Boston wrote:
This worked ok for me,

but ( from memory)

only after I had started tomcat once to perform all necessary population. etc.

Do you get a NPE at session.setUserId("admin") ?

Ian

Josh Holtzman wrote:
I'm trying to update the test-harness in 2.2, and I'm having difficulty "logging in" to sakai.

Here's what used to work for me:

Session session = SessionManager.getCurrentSession();
session.setUserId("admin");
session.setUserEid("admin");

But now calling UserDirectoryService.getCurrentUser().getId() returns an empty string. And when I try to take actions such as adding users, adding sites, etc, I get a PermissionException, since user is null.

I've even tried AuthzGroupService.refreshUser("admin"), but that doesn't fix this either. Does anyone have any ideas what I need to do to set the current userID in 2.2?

Thanks,
Josh



--
Josh Holtzman
Educational Technology Services, UC Berkeley
jholtzman@xxxxxxxxxxxx
510.643.7380

----------------------
This automatic notification message was sent by Sakai Collab (http://collab.sakaiproject.org/portal) from the DG: Development site.
You can modify how you receive notifications at My Workspace > Preferences.


[see attachment: "message0.html", size: 10249 bytes]


Attachments:

message0.html
http://collab.sakaiproject.org/access/content/attachment/ d41086f1-959e-4389-0008-d9b7aeb50b70/message0.html

----------------------
This automatic notification message was sent by Sakai Collab (http://collab.sakaiproject.org/portal) from the DG: Development site.
You can modify how you receive notifications at My Workspace > Preferences.




----------------------
This automatic notification message was sent by Sakai Collab
(http://collab.sakaiproject.org/portal) from the DG: Development site.
You can modify how you receive notifications at My Workspace > Preferences.




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise