Foros de discusión

How to hide "Guest" pages after login, or how to get roles of a navItem

Christian Johannes Haarmann, modificado hace 15 años.

How to hide "Guest" pages after login, or how to get roles of a navItem

New Member Mensajes: 7 Fecha de incorporación: 2/01/09 Mensajes recientes
I have a menu item in the top menu that links to a portlet with "Guest" role only. So it is shown before login. My problem is that it is also shown after login, although I removed the "User" role from it. I don't want to show this menu item after login, only before.

Is there a general option somewhere that "User" does not inherit "Guest" somehow?

In my workaround I couldn't proceed because I don't know how to check if a special role is assigned to a special menu item (page). Can somebody help me out there?

What I tried so far:
a) I am not sure if I tried to set the appropriate roles correctly: I went to "Manage Pages", selected the wanted page, clicked on "Permissions".
There are 3 tabs: regular roles, community roles, guest. By default "Guest" and "Owner" were set. (so why did it show up after login?) I removed all roles under "Community roles"-tab. I added "User"-role to "regular roles"-tab and magically it was also added to "guest"-tab (For testing, I removed "Guest"-role from "guest"-tab and it was also magically removed from "Community roles"-tab. Then I added it again and it was added under both tabs. So why are there 2 different tabs if they do the same? Can somebody explain to me the differences between them? Basically I thought my problem is solved if I can remove the "guest"-role only from the "regular role" tab, but keep it in the "guest" tab.)

b) I modified the template "navigation.vm".
Basically my idea was to hide every menu item if the user is logged-in and the menu item has the "User"-role assigned.
So I changed (original):

to: (modified)



But the layoutPermission.contains(..) somehow seems to check the permissions of the current user and not of the page, because if the user is logged-out, it returns "false" for all navItems, but the user is logged in it returns true for all navItems. That is strange, because I thought for checking the user's permissions, I should use "userPermission.contains()". Is it a bug? Or do I need to obtain a special §permissionChecker from the layout somehow? I am still confused about how the permissionChecker works. I was wondering if I just could find a simple function user.hasRole("") or navItem.hasRole("") somewhere in Liferay, but there is none!
So how can I get the roles from the nav-item?

Help would be much appreciated!
thumbnail
Madhu Yadav, modificado hace 15 años.

RE: How to hide "Guest" pages after login, or how to get roles of

Regular Member Mensajes: 118 Fecha de incorporación: 23/01/09 Mensajes recientes
i had a similar requirement which i had posted here
from the information i got, we have to customize liferay to do this
Christian Johannes Haarmann, modificado hace 15 años.

RE: How to hide "Guest" pages after login, or how to get roles of

New Member Mensajes: 7 Fecha de incorporación: 2/01/09 Mensajes recientes
Madhu Yadav:
i had a similar requirement which i had posted here
from the information i got, we have to customize liferay to do this


I see that you had the same problem, but there is no solution given in the link you provided. (one guy there wrote how to add/delete permissions, but that's something you already knew and which was not your described problem)

Can you please describe how you fixed it? Or do you still have no solution?
thumbnail
Michael Poznecki, modificado hace 15 años.

RE: How to hide "Guest" pages after login, or how to get roles of

Expert Mensajes: 301 Fecha de incorporación: 10/12/08 Mensajes recientes
Hello Christian,

To do this you can modify the portal-ext.properties file by adding this:


## Set the default landing page after successful login
default.landing.page.path=/web/YOUR_NEW_COMMUNITY/YOUR_PAGE

This will set the default page to go to after logging in.

If you want to change what page they go to before the log in you can do the same as above but with:

## Set the default page to the tone page
company.default.home.url=/web/YOUR_NEW_COMMUNITY/YOUR_PAGE

Please let me know if this helps.

Michael
Christian Johannes Haarmann, modificado hace 15 años.

RE: How to hide "Guest" pages after login, or how to get roles of

New Member Mensajes: 7 Fecha de incorporación: 2/01/09 Mensajes recientes
Thank you very much Michael and Minhchau.

Problem solved.

I tried Michael's solution first, and it worked right away. I didn't know that it was so easy, I spent 10 hours before just to find a solution for it. I did not play with communities before, because I was thinking that communities is something to categorize users, but not to display a whole new set of independent webpages. Still there was one more difficulty: how to assign a friendly URL to a new created community. (I don't want to put a number for the default landing path because of compatibility). Basically I was searching under "manage pages" of the dock, but there you could give only the friendly URL for pages under that community, but not for the community itself. At the end I found it in the community-portlet when you select "manage pages" from the tools-button of the listed community there.

Then I couldn't add portlets to pages of the new community, because the "Add application" crashed (the pane was always showing "loading" forever). But this was a browser issue (Internet explorer). I retried with Firefox, and it worked.

Minhchau's solution is clever, but it goes too far for the moment (Maybe I'll implement it when there comes up the need to change the permission check generally).
Still I would like to know how you can list all roles by name of a page for example in navigation.vm template. Maybe this knowledge becomes useful later on. I've spent a huge time to analyze the code of the pages that list the roles when you click on the permission button for the pages, but couldn't figure it out somehow.

I am glad that you, Michael and Minhchau, helped me out here. Thank you sooo much.
Best regards,
Chris
thumbnail
Minhchau Dang, modificado hace 15 años.

RE: How to hide "Guest" pages after login, or how to get roles of

Liferay Master Mensajes: 598 Fecha de incorporación: 22/10/07 Mensajes recientes
In the default permission checker shipped with Liferay, inherited permissions cannot be revoked, and everyone inherits guest permissions. So, once you've granted access to a guest user, all logged in users will have those permissions.

If you need to have the permission checker behave differently when checking layout permissions, you can inject your own implementation of LayoutPermission via Spring. The original definition can be found in util-spring.xml (if you need to know the names of the beans involved), and this is what your class might look like:

public class CustomLayoutPermissionImpl
	extends LayoutPermissionImpl {

	@Override
	public boolean contains(
			PermissionChecker permissionChecker, long groupId,
			boolean privateLayout, long layoutId, String actionId)
		throws PortalException, SystemException {

		permissionChecker.setCheckGuest(false);

		boolean result = super.contains(
			permissionChecker, groupId, privateLayout, layoutId, actionId);

		permissionChecker.setCheckGuest(true);

		return result;
	}
}

Alternatively, if this is behavior that is needed across your customized portal instance, then it would be best to write your own custom permission checker and set it as the default using the "permissions.checker" property in your portal-ext.properties
pappu pager, modificado hace 14 años.

RE: How to hide "Guest" pages after login, or how to get roles of

New Member Mensaje: 1 Fecha de incorporación: 12/05/09 Mensajes recientes
Hi,

Am facing a similar problem and i tried the above mentioned solutions but it is not working in my case.

changing the default landing page will make sure the page is redirected to the right page(HOME in MY CASE).

My requirement is to hide the Login page after a successful login. i.e. after a successful login i should not be able to see the login page/tab for any type of user.

This is urgent and a quick response will be greatly appreciated
thumbnail
jose fernandez, modificado hace 14 años.

RE: How to hide "Guest" pages after login, or how to get roles of

Junior Member Mensajes: 32 Fecha de incorporación: 26/05/08 Mensajes recientes
Hi,

This is a navigation issue, so I suggest to edit the navigation.vm in the theme display and redeploy the theme again.

Another option is to make the default page in a different community than the home page. Also you can restrict permissions to see all the pages, only to members of the community, so they will be forced to login in the default login page.

You must choose the best solution for you.

Cheers.
Jose
thumbnail
Muhammad Asif, modificado hace 12 años.

RE: How to hide "Guest" pages after login, or how to get roles of

Junior Member Mensajes: 25 Fecha de incorporación: 11/04/11 Mensajes recientes
Minhchau Dang:
In the default permission checker shipped with Liferay, inherited permissions cannot be revoked, and everyone inherits guest permissions. So, once you've granted access to a guest user, all logged in users will have those permissions.

If you need to have the permission checker behave differently when checking layout permissions, you can inject your own implementation of LayoutPermission via Spring. The original definition can be found in util-spring.xml (if you need to know the names of the beans involved), and this is what your class might look like:

public class CustomLayoutPermissionImpl
	extends LayoutPermissionImpl {

	@Override
	public boolean contains(
			PermissionChecker permissionChecker, long groupId,
			boolean privateLayout, long layoutId, String actionId)
		throws PortalException, SystemException {

		permissionChecker.setCheckGuest(false);

		boolean result = super.contains(
			permissionChecker, groupId, privateLayout, layoutId, actionId);

		permissionChecker.setCheckGuest(true);

		return result;
	}
}

Alternatively, if this is behavior that is needed across your customized portal instance, then it would be best to write your own custom permission checker and set it as the default using the "permissions.checker" property in your portal-ext.properties


Hello I have tried to use your solution but it did not work although it got loaded in the server the CustomLayoutPermissionImpl but it still shows the menu item for the page which I only want to show to the guest for the logged in user. Can you please suggest what might be the reason.

Regards,
Asif
thumbnail
Hitoshi Ozawa, modificado hace 12 años.

RE: How to hide "Guest" pages after login, or how to get roles of

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
it still shows the menu item for the page which I only want to show to the guest for the logged in user. Can you please suggest what might be the reason.


As Jose suggested, you'll need to modify the template to do this.
thumbnail
tinu c p, modificado hace 12 años.

RE: How to hide "Guest" pages after login, or how to get roles of

Junior Member Mensajes: 78 Fecha de incorporación: 7/01/10 Mensajes recientes
Hi Asif

Add a check as #if(! $is_signed_in) in your portal_normal.vm for your theme.
This tells that the user is guest user since it is logged in.

Regards,
AP
thumbnail
Hitoshi Ozawa, modificado hace 12 años.

RE: How to hide "Guest" pages after login, or how to get roles of

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
Add a check as #if(! $is_signed_in) in your portal_normal.vm for your theme.


If you're going to answer this much, might as well give concrete code on how to actually modify the existing code. emoticon
thumbnail
Muhammad Asif, modificado hace 12 años.

RE: How to hide "Guest" pages after login, or how to get roles of

Junior Member Mensajes: 25 Fecha de incorporación: 11/04/11 Mensajes recientes
This is perfect. Thanks.
thumbnail
Gurumurthy Godlaveeti, modificado hace 10 años.

RE: How to hide "Guest" pages after login, or how to get roles of

Regular Member Mensajes: 208 Fecha de incorporación: 12/08/11 Mensajes recientes
Muhammad Asif:
Minhchau Dang:
In the default permission checker shipped with Liferay, inherited permissions cannot be revoked, and everyone inherits guest permissions. So, once you've granted access to a guest user, all logged in users will have those permissions.

If you need to have the permission checker behave differently when checking layout permissions, you can inject your own implementation of LayoutPermission via Spring. The original definition can be found in util-spring.xml (if you need to know the names of the beans involved), and this is what your class might look like:

public class CustomLayoutPermissionImpl
	extends LayoutPermissionImpl {

	@Override
	public boolean contains(
			PermissionChecker permissionChecker, long groupId,
			boolean privateLayout, long layoutId, String actionId)
		throws PortalException, SystemException {

		permissionChecker.setCheckGuest(false);

		boolean result = super.contains(
			permissionChecker, groupId, privateLayout, layoutId, actionId);

		permissionChecker.setCheckGuest(true);

		return result;
	}
}

Alternatively, if this is behavior that is needed across your customized portal instance, then it would be best to write your own custom permission checker and set it as the default using the "permissions.checker" property in your portal-ext.properties


Hello I have tried to use your solution but it did not work although it got loaded in the server the CustomLayoutPermissionImpl but it still shows the menu item for the page which I only want to show to the guest for the logged in user. Can you please suggest what might be the reason.

Regards,
Asif



Hello Asif,
i changed the util-spring.xml & kept CustomLayoutPermissionImpl also in portal. Those changes also updated into tomcat but still i am unable to hide the guest pages for logged in user. Can u plz make some more awareness to achieve it.

Thanks,
Guru