Foren

Error Page for Users with no permission

thumbnail
Dominik Marks, geändert vor 11 Jahren.

Error Page for Users with no permission

Regular Member Beiträge: 149 Beitrittsdatum: 29.08.12 Neueste Beiträge
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
thumbnail
Dominik Marks, geändert vor 11 Jahren.

RE: Error Page for Users with no permission

Regular Member Beiträge: 149 Beitrittsdatum: 29.08.12 Neueste Beiträge
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:


				else if (isViewableCommunity &&
						!LayoutPermissionUtil.contains(
							permissionChecker, layout, ActionKeys.VIEW)) {

					layout = null;
				}


I replaced the above snippet by the following:


				else if (isViewableCommunity &&
						!LayoutPermissionUtil.contains(
							permissionChecker, layout, ActionKeys.VIEW)) {
                                                            String errorPage = PropsUtil.get("error.view-permission.page");
                                                            if (Validator.isNotNull(errorPage)) {
                                                                   long errorplid = PortalUtil.getPlidFromFriendlyURL(layout.getCompanyId(), errorPage);
                                                                   layout = LayoutLocalServiceUtil.getLayout(errorplid);
                                                            } else {
					                           layout = null;
                                                            }
                                      	}


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

This works for me.