logo       

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

cms.sakai.devel

Subject: Re: Setting the current user id in 2.2

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.




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

News | FAQ | advertise