Liferay 對普通使用者隱藏控制台

來源:互聯網
上載者:User

一、取消上方dockbar的顯示

這是在liferay的主題中預設的代碼,就是所有登入的使用者都會顯示這個控制欄。

dockbar就是最上方的那個欄。

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

改成下面這樣:

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

對於非admin users 就不會顯示

二、禁止訪問

使用者依然可以通過這個串連進入控制台:

http://localhost:8080/group/control_panel

如果需要禁止使用者進入控制台的話,就需要用hook了。

 1)
Into liferay-hook.xml add
following:

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

2) Add portal.properties file
to hook's src folder and add this line to it:

servlet.service.events.pre=my.event.portal.ControlPanelAccessPreAction


 
 3) Create ControlPanelAccessPreAction.java into
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



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.