cancel
Showing results for 
Search instead for 
Did you mean: 

Java Web Service retrieving Portal User Information

Former Member
0 Kudos

Hi,

I have to write a Web Service that receive as parameter a "userID" and returns the information (firstname, lastname,...) from this Portal user.

I'm a bit lost, don't know where to start from.

- Should i write a java class and then wrap it in a web service?

- Should i use the librairies com.sap.security.api ?

- Is there something already existing that i could use a reference?

- What's the best way to build this Web Service?

Thanks for all your input,

Regards,

Thomas

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

I am currently developing a PHP application that will connect to Portal KM repository for document management and such. Since my PHP application resides on a separate server and I was having a very difficult time in authenticating a user and returning their assigned roles and Portal User info via MYSAPSSO2 session cookie I figured out a way to retrieve the logon name from the logon portal form and pass that valuue to a java based web service that returns all portal user information associated with that user.

The development was fairly simple. I first created an EJB Project type that had 1 session bean in it. This bean had 1 business method that had 1 input parameter (which is the currently logged in user name), that would then response/return type of a String array of the Portal users information. The code listed above is what you should start with for the actual implementation of the EJB business method you create.

You will have to include the com.sap.security.api jar file to the EJB project properties "add external jar". This will give you access to the various methods for retrieving Portal user info.

Once I had the bean created with the business method, I simply right clicked on the bean and selected create web service. After completing the web service creation wizard for that bean, all the interfaces for exposing the web service were generated automatically.

Once that was completed I built the ejb project and added the project to a new Enterprise Application project and built that which generated an EAR file. Right click on the EAR file and click on deploy to J2EE engine. Once the EAR is deployed you will see the new web service in the Portal WS Navigator.

Edited by: GS on Dec 18, 2009 11:59 PM

Former Member
0 Kudos

Hi guys,

Thanks for all tha usefull information!

I really appreciate it.

Still one more question, what about dealing with user authentication? I would like the external application to be able to call the web service without the need of user authentication. I don't know how to deal with this?

Thans for your help,

Regards,

Thomas

Former Member
0 Kudos

Do you have SSO enabled from the desktop to the Portal? If not you will have to authenticate the user somehow so they will at a minimum logon to the portal so the mysapsso2 session cookie is set.

You could set the SOAP authentication to none when generating the web service. That way you will be able to call the WS and not have to authenticate to the portal to retrieve the respons back from the web service.

How do you plan on knowing who the user you are requesting info for is if they do not log on to the portal?

Former Member
0 Kudos

Hi Thomas,

1- Yes this is the way for web service. You can create two Java Classes for web service. One for web service, one for helper class to get user information,

2- You have to use Security Libraries.

3- You can find example code for getting user information below.

4- /people/baris.buyuktanir2/blog/2007/07/30/how-to-create-a-visual-composer-user-selection-screen-with-ume-web-service-part-i

Example code to get user information:

	public static String getUserNameSurname(String uid)
	{
		String ret = "";
		IUser user = null;
		try
		{
			user = getUser(uid);
			ret = user.getFirstName() + " " + user.getLastName();
		}
		catch(Exception ex)
		{
			ex.printStackTrace();
		}
		return ret;
	}
	public static IUser getUser(String uid) throws Exception{
		if(StringUtils.isBlank(uid)){
			throw new IllegalArgumentException("uid can't be null");
		}
		IUserFactory userFactory = UMFactory.getUserFactory();
		return userFactory.getUserByLogonID(uid);
	}