Message Boards

Registering and using permissions in Liferay 7.3.2 GA

thumbnail
Andre Kreienbring, modified 3 Years ago.

Registering and using permissions in Liferay 7.3.2 GA

Regular Member Posts: 152 Join Date: 12/18/06 Recent Posts
I followed
https://help.liferay.com/hc/en-us/articles/360028725272-Registering-Permissions
and was able to define custom permissions in the
src/main/resources/resource-actions
folder.
These are properly shown when I configure the corresponding role.
But I'm stuck with registering the permissions. Helpcenter says:
Registering Permissions Resources in the Database
All this takes is a call to Liferay’s resource service in your service layer. If you’re using Service Builder, this is very easy to do.
Open your
-LocalServiceImpl
class
But this class wasn't generated by Service Builder. Maybe because I use an external data source...
But I guess this "database registration" is only necessary for Entities and the created Models if you need fine grained permission control for them. Is this assumption right?
On the portlet level I also have my custom permissions in place.
Now... how to use them?
I tried with
PortalPermissionUtil.contains(_themeDisplay.getPermissionChecker(), "CREATE_CONTENT");
where "CREATE_CONTENT" is the action key from the default.xml. But no luck.
Any advice?
thumbnail
Andre Kreienbring, modified 3 Years ago.

RE: Registering and using permissions in Liferay 7.3.2 GA

Regular Member Posts: 152 Join Date: 12/18/06 Recent Posts
Using this code when trying to register my permissions:
    @Reference(
        target = "(resource.name=" + OpenHABConstants.RESOURCE_NAME + ")"
    )
    private PortletResourcePermission _portletResourcePermission;

where OpenHABConstants.RESOURCE_NAME is exactly what I defined in
&nbsp;&nbsp;&nbsp; <model-resource>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; <model-name>openHAB</model-name>
</model-resource>

I end up with an unsatisfied reference:
[code]Declarative Service {id: 5929, name: openHAB.security.permission.resource.DeviceModelResourcePermissionRegistrar, unsatisfied references: 
		{name: _portletResourcePermission, target: (resource.name=openHAB)}
}

Why?
thumbnail
Andre Kreienbring, modified 3 Years ago.

RE: Registering and using permissions in Liferay 7.3.2 GA

Regular Member Posts: 152 Join Date: 12/18/06 Recent Posts
Finally found it in the sources.
There's now a PortletResourcePermissionFactory that creates a PortletResourcePermission  service when the module is started.
So the way it is described in the mentioned tutorial of 7.2 doesn't work anymore. It's time for a documentation of Liferay 7.3!