[Building Sakai] Question: Getting the user from the current session

Sergio Muriel sergioame at hotmail.com
Sat Jul 19 09:01:19 PDT 2014


Thank you for your answer Nguni!Could you tell me where can I get information about "developerHelperService" or how can I use it?Thank you in advance.


Best Regards,

Sergio MurielPhone: 641-451-7186
Email: sergioame at hotmail.com


Date: Sat, 19 Jul 2014 00:07:28 +0200
Subject: Re: [Building Sakai] Question: Getting the user from the current session
From: nguni52 at gmail.com
To: sergioame at hotmail.com
CC: sakai-dev at collab.sakaiproject.org

Hi Sergio,
Try using developerHelperService. I have used it to get the current reference to see who is logged in. This might be of help.
Kind Regards,Nguni
--Nguni Phakela
Cell: 061-131-2053
skype: nguni52
twitter: @nguni52



On Fri, Jul 18, 2014 at 11:29 PM, Sergio Muriel <sergioame at hotmail.com> wrote:







Dear All,I've been trying to obtain the user from the current session (if there is a user logged in), or from somewhere else using the API or a web service, but I've been having difficulties finding an example that works. 

All I need from the user is his/her type (table sakai_user, field type). 

This is what I have in my web service:
import org.sakaiproject.tool.api.Session;import org.sakaiproject.tool.api.SessionManager;
import org.sakaiproject.user.api.User;import org.sakaiproject.user.api.UserDirectoryService;
	private UserDirectoryService userDirectoryService;
	......		userDirectoryService = (UserDirectoryService) ComponentManager.get(UserDirectoryService.class.getName());
........		Session session  = sessionManager.getCurrentSession();		
		// check if session is active		if (session == null) {			System.out.println("*** Current session is null.");
			LOG.warn("WS RemoteReportCourses.establishSession(): Session " + sessionid + " is not active.");				throw new AxisFault("WS RemoteReportCourses.establishSession(): Session " + sessionid + " is not active");
		} else {			System.out.println("*** Session: " + session);			System.out.println("*** session id: " + session.getId());
			System.out.println("*** user id: " + session.getUserId());			User currentUser = null;			try {
				currentUser = userDirectoryService.getUser(session.getUserId());			} catch (UserNotDefinedException unde) {
				System.out.println("*** An error occurred: " + unde.getMessage());				unde.printStackTrace();			}
			if (currentUser == null) {				System.out.println("*** Current user is null.");			} else {
				System.out.println("*** User: " + currentUser);				System.out.println("*** User.getId(): " + currentUser.getId());
				System.out.println("*** User.getEid(): " + currentUser.getEid());				System.out.println("*** User.getType(): " + currentUser.getType());
			}			}
According to this page:https://confluence.sakaiproject.org/display/BOOT/Using+the+UserDirectoryService
it should work, but this is all I get no matter if I'm logged into Sakai or not (I'm doing local development/testing):
2014-07-17 14:23:21,470  INFO http-bio-8080-exec-6 org.sakaiproject.util.RemoteHostFilter - Access granted (.+): 127.0.0.1/127.0.0.1
*** Session: org.sakaiproject.tool.impl.MySession at 5414ede*** session id: 8bd4e3bb-0733-47f6-b383-6e855435fa5c*** user id: null*** An error occurred: null*** Current user is null.


There's another option to try but looks a little bit more complicated since it uses Spring framework injection and I don't really know how to configure it for a web service.

Can anybody help me with this issue? Or with any web service that can give me the information that I want?Please note that I don't want the user give me his/her login/password again in a customized form, I want to take it from the current session. My Sakai version: 2.9.1

Thank you in advance. I really appreciate any help.




Best Regards,

Sergio MurielPhone: 641-451-7186
Email: sergioame at hotmail.com


 		 	   		  

_______________________________________________

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/20140719/0d8df916/attachment.html 


More information about the sakai-dev mailing list