[Building Sakai] Retrieving current user from session

Steve Swinsburg steve.swinsburg at gmail.com
Tue Jul 29 04:31:33 PDT 2014


What does the login code look like? If you have established a session
previously you can pass the returned sessionid along to subsequent requests
(just like how SakaiScript does it). You can't rely on the session to be
passed in for you like you can with a browser because there is no
session/cookie management in a stateless request such as this.

cheers,
Steve


On Tue, Jul 29, 2014 at 8:13 AM, Sergio Muriel <sergioame at hotmail.com>
wrote:

> Yes, I'm writing a web service, that's why I named my class 'MyWebService'.
>
> I log in to this particular bit of code through a Web Service Consumer
> called from a JSP page.
>
>
>
> Best Regards,
> Sergio Muriel
>
> ------------------------------
> Date: Mon, 28 Jul 2014 08:19:12 +1000
> Subject: RE: [Building Sakai] Retrieving current user from session
> From: steve.swinsburg at gmail.com
> To: sergioame at hotmail.com
> CC: ottenhoff at longsight.com; sakai-dev at collab.sakaiproject.org
>
>
> Yes that is correct for the component manager. Note you are using axis
> though,  are you writing a Web service? How are you logging in to this
> particular bit of code?
>
> sent from my mobile device
> On 25/07/2014 2:50 AM, "Sergio Muriel" <sergioame at hotmail.com> wrote:
>
> Dear Steve,
> I don't really know what you mean by your question.
> This is how I think I'm pulling dependency from the component manager:
>
> public class MyWebService {
>
> private SessionManager sessionManager;
> private SiteService siteService;
> private UserDirectoryService userDirectoryService;
>  private DeveloperHelperService developerHelperService;
>
> public MyWebService() {
> sessionManager = (SessionManager)
> ComponentManager.get(SessionManager.class.getName());
>  siteService = (SiteService)
> ComponentManager.get(SiteService.class.getName());
> userDirectoryService = (UserDirectoryService)
> ComponentManager.get(UserDirectoryService.class.getName());
>  developerHelperService = (DeveloperHelperService)
> ComponentManager.get(DeveloperHelperService.class);
> }
>
>  private Session myMethod() throws AxisFault {
> Session session = sessionManager.getCurrentSession(); // this gives me
> the Sakai session
>  User currentUser = userDirectoryService.getCurrentUser(); // this gives
> me a User object but it has null or empty properties, no matter if I'm
> logged into Sakai or not.
>
> ...... etc
> }
>
> I really appreciate any help.
>
>
> Best Regards,
> Sergio Muriel
>
>
> ------------------------------
> Date: Thu, 24 Jul 2014 09:19:12 +1000
> Subject: Re: [Building Sakai] Retrieving current user from session
> From: steve.swinsburg at gmail.com
> To: sergioame at hotmail.com
> CC: sakai-dev at collab.sakaiproject.org; ottenhoff at longsight.com
>
> The issue is your dependency injection. Either use spring to inject the
> dependency or use the component manager to pull the dependency in.
>
> What is your code for setting the saki api's?
>
> Cheers
> Steve
>
> sent from my mobile device
> On 23/07/2014 9:01 AM, "Sergio Muriel" <sergioame at hotmail.com> wrote:
>
> Dear Sam,
> I'm having a org.sakaiproject.user.api.User object, but when I fetch it
> into, like this:
>
>  User currentUser = userDirectoryService.getCurrentUser();
> System.out.println("*** User.getFirstName(): " +
> currentUser.getFirstName());
>  System.out.println("*** User.getDisplayId(): " +
> currentUser.getDisplayId());
> System.out.println("*** User.getDisplayName(): " +
> currentUser.getDisplayName());
>  System.out.println("*** User.getEid(): " + currentUser.getEid());
> System.out.println("*** User.getEmail(): " + currentUser.getEmail());
>  System.out.println("*** User.getFirstName(): " +
> currentUser.getFirstName());
> System.out.println("*** User.getId(): " + currentUser.getId());
>  System.out.println("*** User.getLastName(): " +
> currentUser.getLastName());
> System.out.println("*** User.getSortName(): " + currentUser.getSortName());
>  System.out.println("*** User.getType(): " + currentUser.getType());
> System.out.println("*** User.getUrl(): " + currentUser.getUrl());
>
> I get:
>
> *** User.getFirstName():
> *** User.getDisplayId(): null
> *** User.getDisplayName(): null
> *** User.getEid(): null
> *** User.getEmail():
> *** User.getFirstName():
> *** User.getId():
> *** User.getLastName():
> *** User.getSortName(): null
> *** User.getType(): null
> *** User.getUrl(): http://localhost:8080/access/user
>
> And this is actually the information that I have in the database:
>
>
> USER_ID;EMAIL;EMAIL_LC;FIRST_NAME;LAST_NAME;TYPE;PW;CREATEDBY;MODIFIEDBY;CREATEDON;MODIFIEDON
> 849c5404-47ea-418e-bb6e-3a7ca8d760b6;sergioame at hotmail dot
> com;sergioame at hotmail dot com;Sergio;Muriel;Web Services
> Accessor;cceylQ==:hNIh42AwPO6m39+Ucnp+BvJgBhEm/jt1hf9OWUiOBoU=;admin;admin;2014-05-06
> 16:42:38;2014-05-06 16:42:38
>
> And this is actually what Sakai shows me:
> My Account Details User User Idsergioame at hotmail dot com First Name
> SergioLast Name MurielEmailsergioame at hotmail dot com TypeWeb Services
> Accessor Created BySakai Administrator CreatedMay 6, 2014 4:42 pmModified
> By Sakai AdministratorModifiedMay 6, 2014 4:42 pm
>
> Do you have any clue about what could be going on with that object? I'm
> testing it using the same browser but different tabs: One for logging into
> Sakai, and the other for calls the web service. Am I doing it right?
>
> I appreciate any help.
>
>
>
> Best Regards,
> Sergio Muriel
>
>
>
> ------------------------------
> From: ottenhoff at longsight.com
> Date: Tue, 22 Jul 2014 16:51:16 -0400
> Subject: Re: [Building Sakai] Retrieving current user from session
> To: sergioame at hotmail.com
> CC: sakai-dev at collab.sakaiproject.org
>
> /**
>  * Get a user's email address based on their session id
>  *
>  * @param   sessionid       the session id of the user who's email address
> you wish to retrieve
>  * @return                  the email address for the user
>  * @throws  AxisFault
>  *
>  */
> public String getUserEmailForSession( String sessionid ) throws AxisFault
> {
>     Session session = establishSession(sessionid);
>     User user = userDirectoryService.getCurrentUser();
>     return user.getEmail();
> }
>
>
>
> On Tue, Jul 22, 2014 at 4:44 PM, Sergio Muriel <sergioame at hotmail.com>
> wrote:
>
> Dear All,
> Does anyone have a good working example of a web service in which the
> current user is retrieved from the current session?
> Please note that what I need to retrieve is an object of the class:
> org.sakaiproject.user.api.User
>
> Best Regards,
> Sergio Muriel
>
>
> _______________________________________________
> sakai-dev mailing list
> sakai-dev at collab.sakaiproject.org
> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>
> TO UNSUBSCRIBE: send email to
> sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of
> "unsubscribe"
>
>
>
> _______________________________________________
> sakai-dev mailing list
> sakai-dev at collab.sakaiproject.org
> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>
> TO UNSUBSCRIBE: send email to
> sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of
> "unsubscribe"
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20140729/a1a71db2/attachment.html 


More information about the sakai-dev mailing list