Liferay hides control panel from common users

Source: Internet
Author: User

1. Cancel the display of the above dockbar

This is the default code in the liferay topic, that is, all login users will display this control bar.

Dockbar is the top column.

#if ($is_signed_in) #dockbar()#end

Change to the following:

#if (($is_signed_in) && $permissionChecker.isCompanyAdmin($company_id)) #dockbar()#end

Non-admin users will not be displayed

Ii. Access prohibited

You can still access the Control Panel through this connection:

Http: // localhost: 8080/group/control_panel

If you want to prohibit users from entering the control panel, you need to use a hook.

1)
IntoLiferay-hook.xmlAdd
Following:

<portal-properties>portal.properties</portal-properties>

2) addPortal. PropertiesFile
To hook's SRC folder and add this line to it:

Servlet. Service. Events. Pre = My. event. Portal. controlpanelaccesspreaction


 
3) createControlpanelaccesspreaction. JavaInto
Appropriate package and add next code it

package my.event.portal; import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse; import com.liferay.portal.kernel.events.Action;import com.liferay.portal.kernel.events.ActionException;import com.liferay.portal.kernel.util.WebKeys;import com.liferay.portal.model.User;import com.liferay.portal.security.auth.PrincipalException;import com.liferay.portal.service.GroupLocalServiceUtil;import com.liferay.portal.service.RoleServiceUtil;import com.liferay.portal.service.UserServiceUtil;import com.liferay.portal.theme.ThemeDisplay; /** * The ControlPanelAccessPreAction restricts access to Control panel of simple * users. */public class ControlPanelAccessPreAction extends Action {   /**   * Instantiates a new control panel access pre action.   */  public ControlPanelAccessPreAction() { super();  }   /*   * @see com.liferay.portal.kernel.events.Action#run(javax.servlet.http. HttpServletRequest,   * javax.servlet.http.HttpServletResponse)   */  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 (!RoleServiceUtil.hasUserRole(currentUser.getUserId(),           currentUser.getCompanyId(),           "administrator",           true)) {    throw new PrincipalException("User " + request.getRemoteUser()     + " can't access the control panel.");  }      } } catch (Exception ex) {   throw new ActionException(ex); }  }}

4) Deploy hook



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.