Liferay访问时,根据不同用户角色跳转到不同登陆页面

应用场景:
Liferay访问时,根据不同用户角色跳转到不同登陆页面,例如拥有管理员角色的用户登陆后跳转到控制台,而普通用户登陆后跳转到门户首页。

解决思路:
使用Liferay的hook,当用户登录时,修改用户的访问路径

解决步骤:
一、创建hook工程,并在hook工程下创建hook组件





二、配置不同角色用户的访问路径
重写run()方法
public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException {
	// TODO Auto-generated method stub
	HttpSession session=request.getSession();
	String useridStr=(String) session.getAttribute("j_username");    //获取用户ID
	try {
		long userid=GetterUtil.getLong(useridStr);
		User user=UserLocalServiceUtil.getUser(userid);       //根据用户ID获取用户对象
		long[] roles=user.getRoleIds();           //获取用户角色ID
		int arrayLength=roles.length;
		if(arrayLength>1){
			for(int i=0;i<arrayLength;i++){
				if(29812==roles[i]){             //拥有角色ID为29812的用户,跳转到控制面板
					String redirect="/group/control_panel";
					LastPath lastPath=new LastPath(StringPool.BLANK, redirect,new HashMap<String, String[]>());
					session.setAttribute(WebKeys.LAST_PATH, lastPath);
					break;
				}
				System.out.println("第"+i+"个角色ID为:"+roles[i]);
			}
		}
	} catch (PortalException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (SystemException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
		
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值