掲示板

Overriding ServicePreAction throws exception in 6.1 GA2

thumbnail
11年前 に William Gosse によって更新されました。

Overriding ServicePreAction throws exception in 6.1 GA2

Liferay Master 投稿: 533 参加年月日: 10/07/04 最新の投稿
I had an extension that I wrote for 6.0..5 the overrides com.liferay.portal.events.ServicePreAction. I was using this extension the deny access to the control panel for certain users. Here's the code I was using :

public class SQServicePreAction extends ServicePreAction {

	@Override
	protected boolean isViewableGroup(User user, long groupId,
			boolean privateLayout, long layoutId, String controlPanelCategory,
			PermissionChecker permissionChecker) throws PortalException,
			SystemException {

		boolean isViewable = super.isViewableGroup(user, groupId, privateLayout, layoutId,
				controlPanelCategory, permissionChecker);
		
		if (isViewable) {
			Group group = GroupLocalServiceUtil.getGroup(groupId);
			
		    if (group.isControlPanel())
		    {
				long companyId = group.getCompanyId();
				long userId = user.getUserId();

				if (SQPortalUtils.isUserAdminUser(companyId, userId))
					isViewable = true;
				else
					isViewable = !SQPortalUtils.isUserEnterpriseUser(userId);
		    }
		}	
		
		return isViewable;		
	}

}


I know that isViewableGroup is now deprecated so I've tried replacing it with something else. It doesn't to matter what I put in the class now because as soon as it deploys I get the following exception:

SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
...

12:55:11,310 ERROR [http-bio-8080-exec-1][error_jsp:422] User ID null
12:55:11,311 ERROR [http-bio-8080-exec-1][error_jsp:423] Current URL /
12:55:11,311 ERROR [http-bio-8080-exec-1][error_jsp:424] Referer null
12:55:11,312 ERROR [http-bio-8080-exec-1][error_jsp:425] Remote address 127.0.0.1
12:55:11,315 ERROR [http-bio-8080-exec-1][error_jsp:427] javax.servlet.ServletException: javax.servlet.jsp.JspException: java.lang.NullPointerException
javax.servlet.ServletException: javax.servlet.jsp.JspException: java.lang.NullPointerException
at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:907)
...

Caused by: java.lang.NullPointerException
at com.liferay.taglib.util.ThemeUtil.include(ThemeUtil.java:94)
at com.liferay.taglib.theme.IncludeTag.doEndTag(IncludeTag.java:39)
at org.apache.jsp.html.common.themes.portal_jsp._jspx_meth_liferay_002dtheme_005finclude_005f1(portal_jsp.java:479)
at org.apache.jsp.html.common.themes.portal_jsp._jspService(portal_jsp.java:424)
... 161 more

As soon as I remove servlet.service.events.pre=com.salesquest.portal.events.SQServicePreAction form my portal ext properties file the exception goes away. Can theis class no longer be overwritten for some Any help understanding this issue would be greatly appreciated.
thumbnail
11年前 に William Gosse によって更新されました。

RE: Overriding ServicePreAction throws exception in 6.1 GA2

Liferay Master 投稿: 533 参加年月日: 10/07/04 最新の投稿
Ok thanks to the forum I found my answer here: https://www.liferay.com/community/forums/-/message_boards/message/13109956

There is now more then on a pre service action class that need to be listed with the like the following:
servlet.service.events.pre=com.liferay.portal.events.ServicePreAction,com.liferay.portal.events.DeviceServicePreAction,com.liferay.portal.events.ThemeServicePreAction,com.myorg.portal.events.SQServicePreAction

I also change my code it no longer use the deprecated isViewableGroup method. Here's my new code:

public class SQServicePreAction extends Action {

	public void run(HttpServletRequest request, HttpServletResponse response)
			throws ActionException {
		try {

			ThemeDisplay themeDisplay = (ThemeDisplay) request
					.getAttribute(WebKeys.THEME_DISPLAY);
			if (GroupLocalServiceUtil.getGroup(
					themeDisplay.getLayout().getGroupId()).isControlPanel()) {

				User currentUser = UserServiceUtil.getUserById(themeDisplay
						.getUserId());

				if (SQPortalUtils.isUserEnterpriseUser(currentUser.getUserId())) {
					throw new PrincipalException("Enterprise User, "
							+ currentUser.getScreenName()
							+ ", is not allowed access to the Control Panel.");
				}
			}

		} catch (Exception ex) {
			throw new ActionException(ex);
		}

	}
}


I found this approach at: http://java-liferay.blogspot.com/2012/07/hide-and-disable-access-to-liferays-61.html