Forums

Home » Liferay Portal » English » 2. Using Liferay » General

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Dominik Marks
Error Page for Users with no permission
February 6, 2013 7:48 AM
Answer

Dominik Marks

Rank: Junior Member

Posts: 45

Join Date: August 28, 2012

Recent Posts

Hello,

I have some pages in our portal which are restricted to a specific user group. That means, I set the VIEW permission for the page only for a specific role (and removed it e.g. for the "community member" role).

When I now try to access the page (using the URL) being a user without that role, I am redirected to the home page (/home).

Is there a possibility to change this behaviour? I would like to show a specific error page when a user tries to access a page without having the permission. How could I do this?

I am using Liferay CE 6.0.6.1.

Greets,
Dominik Marks
Dominik Marks
RE: Error Page for Users with no permission
February 11, 2013 7:31 AM
Answer

Dominik Marks

Rank: Junior Member

Posts: 45

Join Date: August 28, 2012

Recent Posts

Hello,

as no one replied to my request I tried to find a solution myself.

I was able to solve it using an ext-plugin.

I overwrote the class com.liferay.portal.events.ServicePreAction. In the method servicePre() there was some piece of code which set the layout variable to null when the user has no permission to view the page. For me (Liferay 6.0.6.1) this was in lines 1190 to 1195. This is the original code snippet:

1
2                else if (isViewableCommunity &&
3                        !LayoutPermissionUtil.contains(
4                            permissionChecker, layout, ActionKeys.VIEW)) {
5
6                    layout = null;
7                }


I replaced the above snippet by the following:

 1
 2                else if (isViewableCommunity &&
 3                        !LayoutPermissionUtil.contains(
 4                            permissionChecker, layout, ActionKeys.VIEW)) {
 5                                                            String errorPage = PropsUtil.get("error.view-permission.page");
 6                                                            if (Validator.isNotNull(errorPage)) {
 7                                                                   long errorplid = PortalUtil.getPlidFromFriendlyURL(layout.getCompanyId(), errorPage);
 8                                                                   layout = LayoutLocalServiceUtil.getLayout(errorplid);
 9                                                            } else {
10                                               layout = null;
11                                                            }
12                                          }


After that I put the friendly URL of the error page in the portal-ext.properties.

This works for me.