Foren

REST APIs for User Permission Check

thumbnail
Subhasis Roy, geändert vor 8 Jahren.

REST APIs for User Permission Check

Expert Beiträge: 275 Beitrittsdatum: 20.01.12 Neueste Beiträge
Hi All,

I have to check the User Permission in one scenario.
As per my knowledge Liferay does not expose any REST APIs for permission check. (Please correct me if I am wrong)

Reference URLs:
http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Using+Liferay's+Permission+System+from+a+portlet


What should be the right steps, if I need to expose a REST API based on Liferay's permission checker.

Any pointers will be very helpful.
thumbnail
Subhasis Roy, geändert vor 8 Jahren.

[Solved: ]RE: REST APIs for User Permission Check

Expert Beiträge: 275 Beitrittsdatum: 20.01.12 Neueste Beiträge
Hi Got it resolved.

Used the following code, in Utility class. And exposed the method using ServiceImpl as REST service.
The following method takes permission name as parameter and returns true or false based on the logged in user permission.

Code Snippet:

public static Map<string,boolean> fetchUserPermissionStatus(final String permission) throws PortalException, SystemException{
		boolean permissionStatus = false;
		Map<string,boolean> userStatusMap = new HashMap<string,boolean>();
		PermissionChecker permissionChecker=PermissionThreadLocal.getPermissionChecker();
		permissionStatus = PortletPermissionUtil.contains(permissionChecker, <your_portlet_id>, permission);
		userStatusMap.put("userStatus",permissionStatus);
		
		return userStatusMap;
}
</your_portlet_id></string,boolean></string,boolean></string,boolean>