掲示板

Custom entitlement in liferay

11年前 に Rupesh Chotai によって更新されました。

Custom entitlement in liferay

Regular Member 投稿: 163 参加年月日: 11/03/23 最新の投稿
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.
thumbnail
11年前 に Hitoshi Ozawa によって更新されました。

RE: Custom entitlement in liferay

Liferay Legend 投稿: 7942 参加年月日: 10/03/24 最新の投稿
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
thumbnail
11年前 に Bart Simpson によって更新されました。

RE: Custom entitlement in liferay

Liferay Master 投稿: 522 参加年月日: 11/08/29 最新の投稿
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
permissions.checker=com.liferay.portal.security.permission.CustomPermissionCheckerExtendingAdvancedPermissionChecker
11年前 に Rupesh Chotai によって更新されました。

RE: Custom entitlement in liferay

Regular Member 投稿: 163 参加年月日: 11/03/23 最新の投稿
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.
11年前 に Venkat Koppavolu によって更新されました。

RE: Custom entitlement in liferay (回答)

Junior Member 投稿: 85 参加年月日: 10/07/26 最新の投稿
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
11年前 に Rupesh Chotai によって更新されました。

RE: Custom entitlement in liferay

Regular Member 投稿: 163 参加年月日: 11/03/23 最新の投稿
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.
11年前 に Venkat Koppavolu によって更新されました。

RE: Custom entitlement in liferay (回答)

Junior Member 投稿: 85 参加年月日: 10/07/26 最新の投稿
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
11年前 に Rupesh Chotai によって更新されました。

RE: Custom entitlement in liferay (回答)

Regular Member 投稿: 163 参加年月日: 11/03/23 最新の投稿
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

        public CustomRoleLocalServiceImpl(RoleLocalService roleLocalService) {
		super(roleLocalService);
	}


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
11年前 に Venkat Koppavolu によって更新されました。

RE: Custom entitlement in liferay

Junior Member 投稿: 85 参加年月日: 10/07/26 最新の投稿
You are correct Rupesh ,

Excellent emoticon

Thanks,
Venkat