[Building Sakai] Retrieving current user from session

Sergio Muriel sergioame at hotmail.com
Thu Jul 31 09:46:39 PDT 2014


Hi Chris,Do you have any concrete example? That'd be great if you have one.
The advantage of using the existing Sakai API in a web service is that you don't really need to have configured any development environment. You do what you need straight away using any text editor. You don't need to compile, build and/or deploy JWS files because they do it themselves since the very first time they are called. That's why I'd better use preexisting API than creating my own entity providers.

Best Regards,

Sergio Muriel

From: cschauer at txstate.edu
To: sergioame at hotmail.com
CC: steve.swinsburg at gmail.com; sakai-dev at collab.sakaiproject.org
Subject: Re: [Building Sakai] Retrieving current user from session
Date: Wed, 30 Jul 2014 20:45:55 +0000







Hi,



We've recently had to write some web services for our sakai instance and have found the entity provider system to be far superior to axis. Depending on what you're trying to read from sakai, there might already be an entity provider that gives you what
 you need. If not, you could set up your own entity provider that does return what you need. Then all your web application needs to do is send an ajax request to get the data. It will require some configuration in your sakai server environment to allow the
 cross-site request from your webapp, but I believe this would be the best approach for what you're trying to accomplish.



-Chris




On Jul 29, 2014, at 12:48 PM, Sergio Muriel <sergioame at hotmail.com> wrote:



Oh! So, do you mean I cannot get the current user (or the current session) only by asking for them like this:



sessionManager.getCurrentSession();
userDirectoryService.getCurrentUser();



without having any log in code, and even if I have the same JSESSIONID all the time , and even if I've previously logged into Sakai using the same browser instance I'm using in my JSP page??



I don't have any log in code! I have an application that wants to read something from Sakai, and as it is a web application I just wanted to make sure the user is someone that is authentic and authorized into Sakai. I don't
 want the user to log in again in a separated form that asks for the same user and password he/she has already submitted for Sakai.



Then, do you think is there any way to do this?






Best Regards,

Sergio Muriel









Date: Tue, 29 Jul 2014 21:31:33 +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




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 Id
sergioame at hotmail dot com



First Name
Sergio



Last Name
Muriel



Email
sergioame at hotmail dot com



Type
Web Services Accessor







Created By
Sakai Administrator



Created
May 6, 2014 4:42 pm



Modified By
Sakai Administrator



Modified
May 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"





















_______________________________________________

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/20140731/a516f514/attachment.html 


More information about the sakai-dev mailing list