Foren

get user details from authentication token (p_auth)

Alex Man, geändert vor 7 Jahren.

get user details from authentication token (p_auth)

Junior Member Beiträge: 70 Beitrittsdatum: 08.02.16 Neueste Beiträge
I need to get the user details from authentication token (p_auth). I have a restful webservice where I will pass the authentication token (p_auth) and from the p_auth I need to find the user details.

The restfull webservice is Liferay Service Builder Project.

Can anyone please help me on this
thumbnail
Sandeep Nair, geändert vor 7 Jahren.

RE: get user details from authentication token (p_auth)

Liferay Legend Beiträge: 1744 Beitrittsdatum: 06.11.08 Neueste Beiträge
I am not sure if you will get user from p_auth. I am assuming that you are using EntityServiceImpl to expose REST based services. In the method you should get the user details directly by using getUser() method. Sample FooServiceImpl (Dont quote me for correctness)

public class FooServiceImpl extends FooServiceBaseImpl {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never reference this interface directly. Always use {@link com.test.service.FooServiceUtil} to access the foo remote service.
	 */
	
	@JSONWebService(value = "getHelloWorld", method = "POST") 
	public String getHelloWorld(String input) {
		try {
			User user = getUser();
			LOGGER.debug("User :"+ user.getScreenName());
		   
		} catch (PortalException e) {
			// Handle exception
		} catch (SystemException e) {
			// Handle Exception
		}
		
		 return "Hello world: ";


Regards,
Sandeep
Alex Man, geändert vor 7 Jahren.

RE: get user details from authentication token (p_auth)

Junior Member Beiträge: 70 Beitrittsdatum: 08.02.16 Neueste Beiträge
Sandeep Nair:
User user = getUser();


Does this gives the logined user details
thumbnail
Sandeep Nair, geändert vor 7 Jahren.

RE: get user details from authentication token (p_auth)

Liferay Legend Beiträge: 1744 Beitrittsdatum: 06.11.08 Neueste Beiträge
This will give details of the user who has made web service call.
Alex Man, geändert vor 7 Jahren.

RE: get user details from authentication token (p_auth)

Junior Member Beiträge: 70 Beitrittsdatum: 08.02.16 Neueste Beiträge
Sandeep Nair:
This will give details of the user who has made web service call.



what will i get if the user is not logined and the service is guest enabled....
thumbnail
Sandeep Nair, geändert vor 7 Jahren.

RE: get user details from authentication token (p_auth) (Antwort)

Liferay Legend Beiträge: 1744 Beitrittsdatum: 06.11.08 Neueste Beiträge
It will give userId of the default user. Liferay creates a default user when you setup your portal (not admin test user).

Regards,
Sandeep
thumbnail
David H Nebinger, geändert vor 7 Jahren.

RE: get user details from authentication token (p_auth)

Liferay Legend Beiträge: 14919 Beitrittsdatum: 02.09.06 Neueste Beiträge
And really the only thing you want to use the user object for is permission checking, so it won't matter if you have a guest user or a real user.

Do not build in logic like "if user is johnie then {}" sort of junk. As soon as johnie is gone you'll be left hacking all of the code to replace johnie with suzie or whatever.