User Landing page validation based on roles
================================
Portal.properties
==================
login.events.post=com.agco.dealer.hook.events.controller.CustomLoginPostAction
liferay-hooks.xml
=================
<hook>
<portal-properties>portal.properties</portal-properties>
</hook>
package com.agco.dealer.hook.events.controller;
public class CustomLoginPostAction extends Action {
public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException {
ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
long companyId = themeDisplay.getCompanyId();
User user = themeDisplay.getUser();
long userId = user.getUserId();
List<Role> userRoles = RoleLocalServiceUtil.getUserRoles(user.getUserId());
for(Role role : userRoles) {
if(role.getName().equalsIgnoreCase("X")){
response.sendRedirect("/web/test");
}
if(role.getName().equalsIgnoreCase("Y")){
response.sendRedirect("/web/sample");
}
}
}
}
================================
Portal.properties
==================
login.events.post=com.agco.dealer.hook.events.controller.CustomLoginPostAction
liferay-hooks.xml
=================
<hook>
<portal-properties>portal.properties</portal-properties>
</hook>
package com.agco.dealer.hook.events.controller;
public class CustomLoginPostAction extends Action {
public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException {
ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
long companyId = themeDisplay.getCompanyId();
User user = themeDisplay.getUser();
long userId = user.getUserId();
List<Role> userRoles = RoleLocalServiceUtil.getUserRoles(user.getUserId());
for(Role role : userRoles) {
if(role.getName().equalsIgnoreCase("X")){
response.sendRedirect("/web/test");
}
if(role.getName().equalsIgnoreCase("Y")){
response.sendRedirect("/web/sample");
}
}
}
}