4

I have a requirement to display a specific portlet only if the user is logged in. My question is what would be the appropriate way to handle this kind of requirement. Should I handle it through code by using

renderRequest.setAttribute(WebKeys.PORTLET_CONFIGURATOR_VISIBILITY, Boolean.FALSE);

Or is this kind of configuration done using portlet's roles or any kind of portal properties?

As per my understanding, this might be handled by adding a role to the portlet, but I am not sure about where and how to set portlet roles.

Origineil
  • 3,108
  • 2
  • 12
  • 17
Learner
  • 976
  • 14
  • 29
  • 1
    You can simply remove VIEW permission for Portet for GUEST Role from Portlet Configuration > Permission – Pankaj Kathiriya Nov 26 '14 at 07:44
  • I did it, but when user is not logged in, I am getting error message like you don't have permission to access this portlet. – Learner Nov 26 '14 at 09:50
  • 2
    There is one portal property `layout.show.portlet.access.denied=true` available to not show such message. override it with value false then it will not show that error message. – Pankaj Kathiriya Nov 26 '14 at 10:06
  • Thanks Pankaj, I got to know this can be handled on portlet level as well. we have to set some tag in portlet.xml or some file I am not sure. Do you have any idea how to avoid such message on portlet mode. – Learner Nov 26 '14 at 10:40
  • 1
    Yes, you can define init parameter named as `show-portlet-access-denied` in portlet's portlet.xml – Pankaj Kathiriya Nov 26 '14 at 10:47

2 Answers2

9

You can simply remove VIEW permission for Portlet for GUEST Role from Portlet Configuration -> Permissions tab.

By this, GUEST user will see error message like : You do not have permission to access this portlet.

If you want to avoid this message you can override portal property layout.show.portlet.access.denied to value false. This will apply to portal level for each portlet.

If you want to hide permission error message specific to portlet, then in portlet.xml you can define init parameter show-portlet-access-denied with value as false.

HTH

Pankaj Kathiriya
  • 4,210
  • 2
  • 19
  • 26
  • Thanks Pankaj, Are you talking about something like this show-portlet-access-denied false In portlet.xml – Learner Nov 27 '14 at 04:33
  • well, in my case setting init param in portlet.xml did not worked. i dont know if I have written wrong syntax, but yes setting 'layout.show.portlet.access.denied' worked for me. – Learner Nov 27 '14 at 09:23
0

For a specific Portlet put the property in the liferay-portlet.xml under the tag <icon>

<show-portlet-access-denied>false</show-portlet-access-denied>  
ld_raivan
  • 11
  • 1