Fórum

Hiding Portlets from Guests

Pedro Almeida, modificado 11 Anos atrás.

Hiding Portlets from Guests

Junior Member Postagens: 41 Data de Entrada: 30/07/12 Postagens Recentes
Hello;

I believe I am asking yet another very requested functionality: to hide a Portlet from guests. As for others, it doesn't seem to be easily achievable for beginners. I opened a new topic because those I found were old and as versions come out some things tend to change a lot from what I've seen.

So far I have created a Portlet with the Plugins SDK and modified the liferay-portlet.xml and portlet.xml by commenting/removing the nodes that correspond to guests, such as
<security-role-ref>
			<role-name>administrator</role-name>
		</security-role-ref>
		<!-- <security-role-ref>
			<role-name>guest</role-name>
		</security-role-ref> -->
		<security-role-ref>
			<role-name>power-user</role-name>
		</security-role-ref>


By deploying with just these modifications, it doesn't change anything. Then I checked Resource Actions, created the resource-actions folder inside WEB-INF/src with the following content inside default.xml:

<resource-action-mapping>
  <portlet-resource>
    <portlet-name>HidePortlet</portlet-name>
    <permissions>
      <supports>
        <action-key>VIEW</action-key>
      </supports>
      <site-defaults>
      	<action-key>VIEW</action-key>
      </site-defaults>
      <guest-unsupported>
        <action-key>VIEW</action-key>
      </guest-unsupported>
    </permissions>
  </portlet-resource>  
</resource-action-mapping>


Then I created the portlet.preferences file too on its parent with the content "resource.actions.configs=resource-actions/default.xml".
This results in an "explosion" during deploy.

13:09:13,404 INFO  [AutoDeployDir:167] Processing HidePortlet-portlet-6.1.0.1.war
13:09:13,405 INFO  [PortletAutoDeployListener:71] Copying portlets for E:\20-HidePortlet\workspace\LifeRay\deploy\HidePortlet-portlet-6.1.0.1.war
  Expanding: E:\20-HidePortlet\workspace\LifeRay\deploy\HidePortlet-portlet-6.1.0.1.war into E:\20-HidePortlet\workspace\LifeRay\tomcat-7.0.23\temp\20120803130913412
  Copying 1 file to E:\20-HidePortlet\workspace\LifeRay\tomcat-7.0.23\temp\20120803130913412\WEB-INF
  Copying 1 file to E:\20-HidePortlet\workspace\LifeRay\tomcat-7.0.23\temp\20120803130913412\WEB-INF\classes
  Copying 1 file to E:\20-HidePortlet\workspace\LifeRay\tomcat-7.0.23\temp\20120803130913412\WEB-INF\classes
  Copying 1 file to E:\20-HidePortlet\workspace\LifeRay\tomcat-7.0.23\temp\20120803130913412\META-INF
  Copying 1 file to E:\20-HidePortlet\workspace\LifeRay\tomcat-7.0.23\temp\20120803130913412\WEB-INF\jsp
  Warning: WEB-INF\classes\resource-actions\default.xml modified in the future.
  Warning: WEB-INF\src\resource-actions\default.xml modified in the future.
  Warning: WEB-INF\classes\resource-actions modified in the future.
  Copying 19 files to E:\20-HidePortlet\workspace\LifeRay\tomcat-7.0.23\webapps\HidePortlet-portlet
  Copying 1 file to E:\20-HidePortlet\workspace\LifeRay\tomcat-7.0.23\webapps\HidePortlet-portlet
  Deleting directory E:\20-HidePortlet\workspace\LifeRay\tomcat-7.0.23\temp\20120803130913412
13:09:14,291 INFO  [PortletAutoDeployListener:81] Portlets for E:\20-HidePortlet\workspace\LifeRay\deploy\HidePortlet-portlet-6.1.0.1.war copied successfully. Deployment will start in a few seconds.
3/Ago/2012 13:09:20 org.apache.catalina.startup.HostConfig checkResources
INFO: Undeploying context [/HidePortlet-portlet]
13:09:20,845 INFO  [PluginPackageUtil:1099] Reading plugin package for HidePortlet-portlet
13:09:30,853 WARN  [PluginPackageUtil:1364] Unable to reindex unistalled package HidePortlet-portlet: Unable to communicate with repository http://plugins.liferay.com/official
3/Ago/2012 13:09:31 org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory E:\20-HidePortlet\workspace\LifeRay\tomcat-7.0.23\webapps\HidePortlet-portlet
13:09:33,305 INFO  [PluginPackageUtil:1099] Reading plugin package for HidePortlet-portlet
Loading file:/E:/20-ProjectFolder/workspace/LifeRay/tomcat-7.0.23/temp/14-HidePortlet-portlet/WEB-INF/classes/portlet.properties
13:09:33,418 INFO  [PortletHotDeployListener:614] Registering portlets for HidePortlet-portlet
Loading file:/E:/20-ProjectFolder/workspace/LifeRay/tomcat-7.0.23/temp/14-HidePortlet-portlet/WEB-INF/classes/portlet.properties
13:09:33,445 ERROR [HotDeployUtil:114] com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering portlets for HidePortlet-portlet
com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering portlets for HidePortlet-portlet
	at com.liferay.portal.kernel.deploy.hot.BaseHotDeployListener.throwHotDeployException(BaseHotDeployListener.java:46)
	at com.liferay.portal.deploy.hot.PortletHotDeployListener.invokeDeploy(PortletHotDeployListener.java:118)
	at com.liferay.portal.kernel.deploy.hot.HotDeployUtil._doFireDeployEvent(HotDeployUtil.java:111)
	at com.liferay.portal.kernel.deploy.hot.HotDeployUtil._fireDeployEvent(HotDeployUtil.java:188)
	at com.liferay.portal.kernel.deploy.hot.HotDeployUtil.fireDeployEvent(HotDeployUtil.java:40)
	at com.liferay.portal.kernel.servlet.PortletContextListener.doPortalInit(PortletContextListener.java:101)
	at com.liferay.portal.kernel.util.BasePortalLifecycle.portalInit(BasePortalLifecycle.java:42)
	at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:61)
	at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:53)
	at com.liferay.portal.kernel.util.BasePortalLifecycle.registerPortalLifecycle(BasePortalLifecycle.java:52)
	at com.liferay.portal.kernel.servlet.PortletContextListener.contextInitialized(PortletContextListener.java:55)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4765)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5260)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:866)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:842)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1095)
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1617)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
	at com.liferay.portal.security.permission.ResourceActionsImpl.readActionKeys(ResourceActionsImpl.java:852)
	at com.liferay.portal.security.permission.ResourceActionsImpl.readGroupDefaultActions(ResourceActionsImpl.java:886)
	at com.liferay.portal.security.permission.ResourceActionsImpl.readPortletResource(ResourceActionsImpl.java:1057)
	at com.liferay.portal.security.permission.ResourceActionsImpl.read(ResourceActionsImpl.java:838)
	at com.liferay.portal.security.permission.ResourceActionsImpl.read(ResourceActionsImpl.java:620)
	at com.liferay.portal.security.permission.ResourceActionsUtil.read(ResourceActionsUtil.java:275)
	at com.liferay.portal.deploy.hot.PortletHotDeployListener.processPortletProperties(PortletHotDeployListener.java:664)
	at com.liferay.portal.deploy.hot.PortletHotDeployListener.doInvokeDeploy(PortletHotDeployListener.java:356)
	at com.liferay.portal.deploy.hot.PortletHotDeployListener.invokeDeploy(PortletHotDeployListener.java:115)
	... 23 more



So what am I failing? Are these configurations not enough?

I am looking for configurations in-portlet and not through Control Panel.

Thanks.
thumbnail
David H Nebinger, modificado 11 Anos atrás.

RE: Hiding Portlets from Guests

Liferay Legend Postagens: 14916 Data de Entrada: 02/09/06 Postagens Recentes
Everybody wants to do things the hard way, so you're going to hammer away at the code until you get there, I get that...

Me, I wouldn't worry about it. After dropping it on a page, I'd go to the preferences for the portlet and uncheck the guest view permission. Then I'd go about my day solving things that are more important than reinventing the wheel.

But hey, that's just me...
Pedro Almeida, modificado 11 Anos atrás.

RE: Hiding Portlets from Guests

Junior Member Postagens: 41 Data de Entrada: 30/07/12 Postagens Recentes
David H Nebinger:
Everybody wants to do things the hard way, so you're going to hammer away at the code until you get there, I get that...

Me, I wouldn't worry about it. After dropping it on a page, I'd go to the preferences for the portlet and uncheck the guest view permission. Then I'd go about my day solving things that are more important than reinventing the wheel.

But hey, that's just me...


Yes, I understand the practicality of doing it via Control Panel, more so when the LR team has put an effort into creating a very powerful Administration menu.

This is a first interaction of something that I must do involving several levels of Organizations and Users, and it is my belief that it will be unavoidable to use code-oriented permissioning. I thought it would be a good scratching of the surface to understand how LR works with this subject.

Also, all that I can bundle into the package and demands less configuration through the Control Panel, I prefer.

Thank you for all the help you can provide.
Pedro Almeida, modificado 11 Anos atrás.

RE: Hiding Portlets from Guests

Junior Member Postagens: 41 Data de Entrada: 30/07/12 Postagens Recentes
I think I was missing a line that was particular to LifeRay 6.1, evolving from 6.0.X, as I found here,

So I modified the default.xml to:

<!--?xml version="1.0"?-->


<resource-action-mapping>
    <portlet-resource>
        <portlet-name>HidePortlet</portlet-name>
        <permissions>
            <supports>
                <action-key>ACCESS_IN_CONTROL_PANEL</action-key>
                <action-key>ADD_TO_PAGE</action-key>
                <action-key>VIEW</action-key>
            </supports>
            <site-member-defaults>
                <action-key>ADD_TO_PAGE</action-key>
                <action-key>VIEW</action-key>
            </site-member-defaults>
            <guest-defaults />
            <guest-unsupported>
                <action-key>ACCESS_IN_CONTROL_PANEL</action-key>
                <action-key>ADD_TO_PAGE</action-key>
                <action-key>VIEW</action-key>
            </guest-unsupported>
        </permissions>
    </portlet-resource>
</resource-action-mapping>


and now it (seems to) works!
Pedro Almeida, modificado 11 Anos atrás.

RE: Hiding Portlets from Guests

Junior Member Postagens: 41 Data de Entrada: 30/07/12 Postagens Recentes
That solution worked into hiding the portlet.

However if reverting the configuration by passing the contents of guest-unsupported back to guest-defaults (leaving the unsupported empty), the portlet remains hidden, unable to be viewed again for guests, even after removing and adding it again after login.

It requires server re-start and re-applying the portlet to "recover" it.
thumbnail
David H Nebinger, modificado 11 Anos atrás.

RE: Hiding Portlets from Guests

Liferay Legend Postagens: 14916 Data de Entrada: 02/09/06 Postagens Recentes
Which is why doing it via the permissions for the portlet itself (found by clicking on the wrench, you don't have to go to the control panel) is easier than trying to code it in. Through the wrench you can flip it on/off at will w/o doing deployments, server restarts, etc.
thumbnail
Manish Kumar, modificado 11 Anos atrás.

RE: Hiding Portlets from Guests

Junior Member Postagens: 93 Data de Entrada: 02/03/12 Postagens Recentes
Hello Pedro Almeida,
take the reference of the following link, it might help you.
role based Permission
Pedro Almeida, modificado 11 Anos atrás.

RE: Hiding Portlets from Guests

Junior Member Postagens: 41 Data de Entrada: 30/07/12 Postagens Recentes
Manish Kumar:
Hello Pedro Almeida,
take the reference of the following link, it might help you.
role based Permission


hello!
that will certainly provide useful in the future, I had something like that planned.

thank you!