Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Gurumurthy Godlaveeti
How to hide a page for logged in user
July 5, 2013 12:32 AM
Answer

Gurumurthy Godlaveeti

Rank: Regular Member

Posts: 143

Join Date: August 11, 2011

Recent Posts

Hello Liferay Guys,

I would like to hide some of the static content pages once user logged in.

My requirement is,
I have configured some of the pages only for owner & Guest so this pages should be visible to only Guest & administrator. If i configured the page to Guest, Organization Member, Administrator then the page has to visible for all these three role users.

I need to use same theme in different organizations so page names vary.


Can i somebody make awareness to me for achieving it.
Jan Geißler
RE: How to hide a page for logged in user
July 5, 2013 8:26 AM
Answer

Jan Geißler

Community Moderator

Rank: Liferay Master

Posts: 720

Join Date: July 5, 2011

Recent Posts

Well in short:
User inherits Permissions from Guest. So what Guest can do, a User is able to do as well. As the permissions work cumulative not restrictive (meaning, if any of a users roles allow something, he is allowed to do so) you can't do that in an "easy" way. At least I am not aware of any.
Even if I can't point you in a direction, I could at least tell you why it's not working ;)
Gurumurthy Godlaveeti
RE: How to hide a page for logged in user
July 10, 2013 9:38 PM
Answer

Gurumurthy Godlaveeti

Rank: Regular Member

Posts: 143

Join Date: August 11, 2011

Recent Posts

Jan Geißler:
Well in short:
User inherits Permissions from Guest. So what Guest can do, a User is able to do as well. As the permissions work cumulative not restrictive (meaning, if any of a users roles allow something, he is allowed to do so) you can't do that in an "easy" way. At least I am not aware of any.
Even if I can't point you in a direction, I could at least tell you why it's not working ;)



Hi Jan,

Thanks for your reply,
I cam to know that AdvancePermissionChecker is taking care of permissions in Liferay ( version is 6.0.6) , but with respect to pages (i mean layouts), LayoutPermissionImpl is having methods to check the permissions of layout. Can we disable checking guest user permissions by over riding the methods of this class.

another approach is
I would like to get all the roles of user in theme & I will check whether any user role (except Guest role) is having view permission on respective pages. I want write this logic in navigation.vm file.

Can i achieve with any of above approaches , if any more ways are there then please let me know.
Oliver Bayer
RE: How to hide a page for logged in user
July 11, 2013 1:22 AM
Answer

Oliver Bayer

Rank: Liferay Master

Posts: 883

Join Date: February 18, 2009

Recent Posts

Hi Gurumurthy,

why don't you use the private pages concept for your requirement? If I understood you right you're trying to achieve that guest users are able to access some pages and group members are able to access other pages. This can be used ootb without any modifications/ coding. Public pages can be accessed by anyone while private pages can only be accessed by site members (you can assign them by using user groups).

HTH Oli
Gurumurthy Godlaveeti
RE: How to hide a page for logged in user
July 11, 2013 1:58 AM
Answer

Gurumurthy Godlaveeti

Rank: Regular Member

Posts: 143

Join Date: August 11, 2011

Recent Posts

Hi Oliver,

My requirement is
Some pages has to visible only to Guest users
Some pages has to visible only to logged in users
Some pages has to visible for both

I go to page permissions & choosing that page has to visible only to Guest. Even i signed in, that page is visible. but i don't want like like that. If i configure that page has to visible for guest then that page shouldn't visible for logged in user.

For much clarification:

page 1: given permissions only to Guest --> It has to visible only to Guest , not to logged in user
Page 2: given permissions only to Organization Member --> It has to visible only to logged in user , not to Guest
Page 3: given permissions to Guest & Organization Member --> it has to visible for both.

Even i go for private pages, it won't work for my requirement.
I need to disable guest role for logged user while checking the permissions of page & later it has to work as it is.

Any idea for this?
Oliver Bayer
RE: How to hide a page for logged in user
July 15, 2013 1:18 AM
Answer

Oliver Bayer

Rank: Liferay Master

Posts: 883

Join Date: February 18, 2009

Recent Posts

Hi Gurumurthy,

thanks for more info about your requirements. Your first requirement is NOT possible ootb without any coding. The reason is that everybody accessing your portal has automatically the guest role. You can configure that a page can be seen by a special role but as soon as the guest user is allowed to everybody is able to access.

Greets Oli
Jan Geißler
RE: How to hide a page for logged in user
July 23, 2013 3:37 AM
Answer

Jan Geißler

Community Moderator

Rank: Liferay Master

Posts: 720

Join Date: July 5, 2011

Recent Posts

What you could do (We just had a relatet problem):

First way:
Create an Expando Field for the Site Object.
Let's call it cssClass and make it a TextField.
There you add a cssClass like "onlyForGuests"
Than you create a hook, so that the navigation will consider this custom field and write it to the cssClass attribute of the Navigation Element.
Now hide it with CSS.

Second way:
Create an Expando Field for the Site Object.
Let's call it guestsOnly and make it a Boolean Value.
Now overwrite the permission checker for Layout to reflect this via an EXT plugin.

Needless to say, some coding is involved in both solutions.

Hope this helps.
Gurumurthy Godlaveeti
RE: How to hide a page for logged in user
July 23, 2013 4:26 AM
Answer

Gurumurthy Godlaveeti

Rank: Regular Member

Posts: 143

Join Date: August 11, 2011

Recent Posts

Hi,

Finally, i got it but it was by overriding LayoutPermissionImpl class in ext.

There is a contains() method in this class.

1public boolean contains(
2            PermissionChecker permissionChecker, Layout layout, String actionId)
3        throws PortalException, SystemException {
4
5}


In this method 1st line, i disabled Guest permission on User by wrtting

1permissionChecker.setCheckGuest(false);


We should enable it at last of method once again like

1permissionChecker.setCheckGuest(true);


This way i did.

but Liferay people might upgrade this LayoutPermissionImpl class in next versions of Liferay, we can't go in this approach. So i followed Oliver Bayer process , made private pages for logged-in user & public pages for Guest.

I provided one article to navigate from public pages to private pages so it's resolved my solution.