Sunday 25 September 2016

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);




No comments:

Post a Comment

  Inter Portlet Communication (IPC) in Liferay 7.4 Public Render Parameter IPC: 1) Create a new module project -> SenderPortlet 2) In  Se...