Get the user roles in programtically :
if we want to get the roles of postlogin add the below code:
------------------------------------------------------------------------
HttpServletRequest request;
HttpServletResponse response;
HttpSession session = request.getSession(false);
User user = PortalUtil.getUser(request);
if(Validator.isNotNull(user)){
List<Role> userRoles = RoleLocalServiceUtil.getUserRoles(user.getUserId());
Map<String, String> rolesMap = new HashMap<String, String>();
for (Role role : userRoles) {
rolesMap.put(role.getName(), role.getName());
}
}
session.setAttribute("roles", rolesMap);
Get the roels in appropriate portlet:
============================
HashMap<String, String> rolesMap = (HashMap<String, String>) portletSession.getAttribute("roles",
PortletSession.APPLICATION_SCOPE);
if we want to get the roles of postlogin add the below code:
------------------------------------------------------------------------
HttpServletRequest request;
HttpServletResponse response;
HttpSession session = request.getSession(false);
User user = PortalUtil.getUser(request);
if(Validator.isNotNull(user)){
List<Role> userRoles = RoleLocalServiceUtil.getUserRoles(user.getUserId());
Map<String, String> rolesMap = new HashMap<String, String>();
for (Role role : userRoles) {
rolesMap.put(role.getName(), role.getName());
}
}
session.setAttribute("roles", rolesMap);
Get the roels in appropriate portlet:
============================
HashMap<String, String> rolesMap = (HashMap<String, String>) portletSession.getAttribute("roles",
PortletSession.APPLICATION_SCOPE);