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

来源:互联网 发布:河南省大数据谷 编辑:程序博客网 时间:2024/05/20 03:41
应用场景:
Liferay访问时,根据不同用户角色跳转到不同登陆页面,例如拥有管理员角色的用户登陆后跳转到控制台,而普通用户登陆后跳转到门户首页。

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

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





二、配置不同角色用户的访问路径
重写run()方法
public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException {// TODO Auto-generated method stubHttpSession session=request.getSession();String useridStr=(String) session.getAttribute("j_username");    //获取用户IDtry {long userid=GetterUtil.getLong(useridStr);User user=UserLocalServiceUtil.getUser(userid);       //根据用户ID获取用户对象long[] roles=user.getRoleIds();           //获取用户角色IDint 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 blocke.printStackTrace();} catch (SystemException e) {// TODO Auto-generated catch blocke.printStackTrace();}}

阅读全文
0 0