Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Rupesh Chotai
Custom entitlement in liferay
December 20, 2012 1:41 PM
Answer

Rupesh Chotai

Rank: Regular Member

Posts: 163

Join Date: March 23, 2011

Recent Posts

Hi,
Migrating my old system developed in java/javascript to LR6.1 The existing system has already implemented complex entitlements for certain pages. Like displaying few pages, enabling features on that pages based on login etc. How can I reuse this implementation in LR.

I saw there is PermissionCheckerImpl class handling all permission checks for pages and portlets. Can I over-ride its behavior, may be using Hook?
I read few posts related to this but couldn't come to conclusion what and how it should be done in liferay.

Please suggest what is recommended way of handling this scenario.

Thanks.
Hitoshi Ozawa
RE: Custom entitlement in liferay
December 22, 2012 5:40 AM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

Permission is internal part of liferay so you probably have to create an ext plugin.

https://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/ext-plugi-4
Bart Simpson
RE: Custom entitlement in liferay
December 24, 2012 4:38 AM
Answer

Bart Simpson

Rank: Liferay Master

Posts: 524

Join Date: August 29, 2011

Recent Posts

I am not sure if this will suffice, but rather then going to EXT , you could extend the AdvancedPermissionChecker and add it as a hook using the property
1permissions.checker=com.liferay.portal.security.permission.CustomPermissionCheckerExtendingAdvancedPermissionChecker
Rupesh Chotai
RE: Custom entitlement in liferay
December 24, 2012 9:06 AM
Answer

Rupesh Chotai

Rank: Regular Member

Posts: 163

Join Date: March 23, 2011

Recent Posts

Thanks Hitoshi for reply.
I read few posts about EXT creation however seems its lot of work and upgrades also has some issues with it. I am exploring more on this.
http://www.liferay.com/community/forums/-/message_boards/message/18638417


Thanks Brat for the reply.
I found from post that it is not possible till liferay 5, to write hook for it. I am trying to create one in Liferay 6.1. Will keep this post updated once got some conclusion out of it.
FYI : http://www.liferay.com/community/forums/-/message_boards/message/4574131


Any clue/suggestion are most welcome.
Venkat Koppavolu
RE: Custom entitlement in liferay
December 28, 2012 10:25 AM
Answer

Venkat Koppavolu

Rank: Junior Member

Posts: 85

Join Date: July 25, 2010

Recent Posts

Hi Rupesh,

We have done same implementation using Overriding the Role Service using hooks

step-1 Define your custom service implementation in your liferay-hook.xml
<hook>
<service>
<service-type>com.liferay.portal.service.RoleLocalService</service-type>
<service-impl>com.portal.liferay.service.CustomRoleLocalServiceImpl</service-impl>
</service>
</hook>
step-2
public class CustomRoleLocalServiceImpl extends com.liferay.portal.service.RoleLocalServiceWrapper {

@Override
public List<Role> getUserRoles(long userId) throws SystemException{

List<Role> userRoles = super.getUserRoles(userId);

//This call makes external system roles for given user
List<Role> customRoles= CustomUtil.getCustomRoles(userId);

if(userRoles != null && customRoles != null)
{
customRoles.addAll(userRoles);
}

return customRoles;
}
}

1. Define external Roles in Liferay portal
2. Assign permissions to these newly defined Roles on various portal resources
3. Deploy a custom Role Service which
a. Executes the default behavior of fetching the User Role mapping from Liferay DB
b. Additionally fetches the User Role mapping from the external entitlement systems
c. Consolidates the User Role mapping obtained from the two sources
d. Returns the consolidated list to the Permission Checker ( This will make use of Liferay Permission Cache without impacting performance)

Let me know if you need any help
Rupesh Chotai
RE: Custom entitlement in liferay
December 28, 2012 11:08 AM
Answer

Rupesh Chotai

Rank: Regular Member

Posts: 163

Join Date: March 23, 2011

Recent Posts

Hi Venkat,
Many thanks for your reply and detail steps.

I created hook as you described. Created new role in the liferay portal and assigned one user to that role. Also added some permission for that user - role on one of the portlet. However, when I click on "Option" button of portlet and select "Configuration" I don't think my customized getUserRoles(long usrId) method is getting invoked. I added couple of system.out.println statements but nothing is getting printed.

Any idea if I am missing anything here?
Appreciated your help.

Thanks.
Venkat Koppavolu
RE: Custom entitlement in liferay
December 28, 2012 11:40 AM
Answer

Venkat Koppavolu

Rank: Junior Member

Posts: 85

Join Date: July 25, 2010

Recent Posts

Hi Rupesh,

It's Because of permissionCahe for that user at portal level, permission Cache object created by the portal for first time user logs(if it doesn't find cache object) in and passed through out the portal for performance issues. It the normal behavior of portal.

Your getUserRoles() will be invoked by the portal in below cases.
1. Go to any user profile view
a. Control Panel -> Users-> Click any user profile
b. Click My Account Link after user Login
2. Any updates made by Admin like create a page, update page permission will call clear permissionCache.clear() and will invoke your custom method.

Please let me know if you need any help.
Thanks,
Venkat
Rupesh Chotai
RE: Custom entitlement in liferay
December 28, 2012 12:34 PM
Answer

Rupesh Chotai

Rank: Regular Member

Posts: 163

Join Date: March 23, 2011

Recent Posts

Hi Venkat,
Appreciated your quick reply !

You are correct - I checked for some user profile and my custom role implementation class is getting invoked, I was under impression that while assigning permission for portlet this gets called.
EDIT - There is explicit constructor required for this custom class like below
1
2        public CustomRoleLocalServiceImpl(RoleLocalService roleLocalService) {
3        super(roleLocalService);
4    }


However, using this approach you have to create an external role in liferay portal, then assign this role to user and give permission for some page/portlet. Correct?
So this role is nothing but just a container, if I called it for simplicity, which holds the entitlements details from some external system. And liferay's permission cache can be used in this way and get benefit of already implemented entitlement system.

Correct me if I am wrong.

Again, thanks for your prompt and accurate replies. emoticon
Venkat Koppavolu
RE: Custom entitlement in liferay
December 28, 2012 1:26 PM
Answer

Venkat Koppavolu

Rank: Junior Member

Posts: 85

Join Date: July 25, 2010

Recent Posts

You are correct Rupesh ,

Excellent emoticon

Thanks,
Venkat