应用场景:
Liferay访问时,根据不同用户角色跳转到不同登陆页面,例如拥有管理员角色的用户登陆后跳转到控制台,而普通用户登陆后跳转到门户首页。
解决思路:
使用Liferay的hook,当用户登录时,修改用户的访问路径
解决步骤:
一、创建hook工程,并在hook工程下创建hook组件
重写run()方法
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();
}
}