@Override public String lambda(Role x) { return x.getName(); } }.go();
private void resourcePermission(long companyId, ExpandoColumn expandoColumn, String roleName) { try { if (roleLocalService != null && resourcePermissionLocalService != null) { Role permissionRole = roleLocalService.getRole(companyId, roleName); resourcePermissionLocalService.setResourcePermissions(companyId, ExpandoColumn.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(expandoColumn.getColumnId()), permissionRole.getRoleId(), new String[]{ActionKeys.VIEW, ActionKeys.UPDATE}); } } catch (Exception e) { LOGGER.error("resource permission", e); throw new RuntimeException(e); } }
public static List<String> getRegularRoleNames() { List<String> roleNames = new ArrayList<String>(); try { List<Role> roles = RoleLocalServiceUtil.getRoles(PortalUtil.getDefaultCompanyId()); for (Role r : roles) { if (r.getType() == RoleConstants.TYPE_REGULAR) { roleNames.add(r.getName()); } } } catch (SystemException e) { logger.log(Level.SEVERE, e.getMessage(), e); } return roleNames; } }
public static UserData convertLiferayUser(User user) throws SystemException { if (user == null) { return null; } UserData ud = new UserData(); ud.setEmail(user.getEmailAddress()); ud.setLogin(user.getScreenName()); ud.setFirstName(user.getFirstName()); ud.setLastName(user.getLastName()); ud.setJobTitle(user.getJobTitle()); ud.setCompanyId(user.getCompanyId()); ud.setLiferayUserId(user.getUserId()); for (Role role : user.getRoles()) { ud.addRoleName(role.getName(), role.getDescription()); } setGroupRoles(ud, user); return ud; }
public static boolean createRoleIfNotExists(String roleName, String description) { try { /* Look for the role with provided name */ Role role = null; try { /* Look for the role with provided name */ role = getRoleByName(roleName); } catch(RoleNotFoundException ex) { Map<Locale, String> titles = new HashMap<Locale, String>(); RoleLocalServiceUtil.addRole(0, PortalUtil.getDefaultCompanyId(), roleName, titles, description, RoleConstants.TYPE_REGULAR); return true; } /* Role found, maybe there is need to update description */ if(description != null && !description.equals(role.getDescription())) { role.setDescription(description); RoleLocalServiceUtil.updateRole(role); } return false; } catch (Exception e) { throw new LiferayBridgeException(e); } }
public static List<String> getRoleNames(long companyId) { List<String> roleNames = new ArrayList<String>(); try { List<Role> roles = RoleLocalServiceUtil.getRoles(companyId); for (Role r : roles) { roleNames.add(r.getName()); } } catch (SystemException e) { logger.log(Level.SEVERE, "Error getting liferay roles", e); } return roleNames; }
private LinkedList<String> getUserGroupRoleByRoleAndGroup(Idea idea, LinkedList<String> toEmail, String roleName) throws PortalException, SystemException { Role roleInnovationsslussen = roleLocalService.getRole(idea.getCompanyId(), roleName); List<UserGroupRole> roleUsersInnovationsslussen = userGroupRoleLocalService.getUserGroupRolesByGroupAndRole(idea.getGroupId(), roleInnovationsslussen.getRoleId()); for (UserGroupRole userGroupRole : roleUsersInnovationsslussen) { String email = userGroupRole.getUser().getEmailAddress(); if (!toEmail.contains(email)) { toEmail.add(email); } } return toEmail; }
public boolean userHasRole(String roleName) { try { List<Role> roles = getUserRoles(); for (Role role : roles) { if (role.getName().equals(roleName)) { return true; } } } catch (Exception e) { logger.error(e.getMessage(), e); } return false; }
public boolean userHasRole(String roleName) { try { List<Role> roles = getUserRoles(); for (Role role : roles) { if (role.getName().equals(roleName)) { return true; } } } catch (Exception e) { logger.error(e.getMessage(), e); } return false; }
long userIds[] = {userid}; Role role = roleLocalService.getRole(companyId, "User"); userLocalService.addRoleUsers(role.getRoleId(), userIds); long roleids[] = {role.getRoleId()}; userGroupRoleLocalService.addUserGroupRoles(user.getUserId(), groupId, roleids); ClassName clsNameUser = classNameLocalService.getClassName("com.liferay.portal.model.User"); rpEntry.setPrimaryKey(userid); rpEntry.setPrimKey("" + userid); rpEntry.setRoleId(role.getRoleId()); rpEntry.setScope(4); resourcePermissionLocalService.addResourcePermission(rpEntry);
public static String[] getUserRoles(String userId) { if (debug) { log("getting user roles " + userId); } if (userId == null || userId.isEmpty()) { if (debug) { log("returning empty roles"); } return new String[0]; } ArrayList<String> result = new ArrayList<String>(); try { List<Role> roles = RoleLocalServiceUtil.getUserRoles(Long.valueOf(userId,10)); for(Role g: roles) { result.add(g.getName()); } } catch (Exception ex) { Logger.getLogger(SecurityHelper.class.getName()).log(Level.SEVERE, null, ex); } if (debug) { log("returning roles " + result); } return result.toArray(new String[0]); }
private boolean hasBadgeRole(final User user) throws SystemException { try { List<Role> userRoles = RoleLocalServiceUtil .getUserRoles(liferayUser(user).getUserId()); for (final Role role : userRoles) { if (BADGE_ROLE_NAME.equals(role.getName())) { getLogger().debug("Has badge role " + BADGE_ROLE_NAME); return true; } } } catch (Exception e) { getLogger().error("Exception while trying to list user roles", e); } getLogger().debug("Didn't have badge role " + BADGE_ROLE_NAME); return false; }
private static void setGroupRoles(UserData ud, User user) { try { for (UserGroup userGroup : user.getUserGroups()) { List<Role> roles = RoleLocalServiceUtil.getGroupRoles(userGroup.getGroup().getGroupId()); for (Role role : roles) { ud.addRoleName(role.getName()); } } } catch (Exception e) { throw new LiferayBridgeException(e); } }
private static void setGroupRoles(UserDataBean ud, User user) { try { for (UserGroup userGroup : user.getUserGroups()) { List<Role> roles = RoleLocalServiceUtil.getGroupRoles(userGroup.getGroup().getGroupId()); for (Role role : roles) { ud.addRole(role.getName()); } } } catch (Exception e) { throw new UserSourceException(e); } }
public static UserData convertLiferayUser(User user) throws SystemException { if (user == null) { return null; } UserDataBean ud = new UserDataBean(); ud.setEmail(user.getEmailAddress()); ud.setLogin(user.getScreenName()); ud.setFirstName(user.getFirstName()); ud.setLastName(user.getLastName()); ud.setJobTitle(user.getJobTitle()); ud.setCompanyId(user.getCompanyId()); for (Role role : user.getRoles()) { ud.addRole(role.getName()); } setGroupRoles(ud, user); Map<String, Serializable> customAttributes = user.getExpandoBridge().getAttributes(false); Map<String, Object> attributes = new HashMap<String, Object>(); for(Map.Entry<String, Serializable> entry: customAttributes.entrySet()) { String attributeKey = entry.getKey(); Serializable value = entry.getValue(); if(attributeKey.contains(APERTE_PREFIX_ATTRIBUTE)) attributes.put(attributeKey, value); } ud.setAttributes(attributes); return ud; }