private void removeIncludedGroups(Group group, Map<String, Group> groups) { Set<String> groupNames = new HashSet<String>(groups.keySet()); for (String checkGroupName : groupNames) { if (!group.getName().equals(checkGroupName) && group.hasPrivilege(checkGroupName)) { Group includedGroup = groups.get(checkGroupName); if (includedGroup != null) { removeIncludedGroups(includedGroup, groups); groups.remove(checkGroupName); } } } }
public List<SelectItem> getGroupItems() { List<SelectItem> result = new ArrayList<SelectItem>(); List<Group> groups = groupManagementService.getGroups(); for (Group group : groups) { result.add(new SelectItem(group.getName(), group.getDisplayName())); } return result; }
public List<String> getNonGroupPrivileges(Group group) { List<String> result = new ArrayList<String>(); if (group == null) { return result; } Collection<Privilege> authorities = group.getPrivileges(); for (Privilege authority : authorities) { if (!(authority instanceof Group)) { result.add(authority.getDisplayName()); } } return result; }
@Override public void addGroup(org.openl.rules.security.Group group) { Group persistGroup = new Group(); persistGroup.setName(group.getName()); persistGroup.setDescription(group.getDescription()); Set<Group> includedGroups = new HashSet<Group>(); Set<String> privileges = new HashSet<String>(); for (Privilege privilege : group.getPrivileges()) { String privilegeName = privilege.getName(); if (privilege instanceof org.openl.rules.security.Group) { includedGroups.add(groupDao.getGroupByName(privilegeName)); } else { privileges.add(privilegeName); } } if (!includedGroups.isEmpty()) { persistGroup.setIncludedGroups(includedGroups); } if (!privileges.isEmpty()) { persistGroup.setPrivileges(privileges); } groupDao.save(persistGroup); }
private void removeIncludedPrivileges(List<String> privileges, Map<String, Group> groups) { for (String privilege : new ArrayList<String>(privileges)) { for (Group group : groups.values()) { if (group.hasPrivilege(privilege)) { privileges.remove(privilege); } } } }
public String[] getOnlyAdminGroups(Object objUser) { if (!isOnlyAdmin(objUser)) { return new String[0]; } String adminPrivilege = Privileges.ADMIN.name(); List<String> groups = new ArrayList<String>(); @SuppressWarnings("unchecked") Collection<Privilege> authorities = (Collection<Privilege>) ((User) objUser).getAuthorities(); for (Privilege authority : authorities) { if (authority instanceof Group) { Group group = (Group) authority; if (group.hasPrivilege(adminPrivilege)) { groups.add(group.getAuthority()); } } } return groups.toArray(new String[groups.size()]); }
@Override public void addGroup(org.openl.rules.security.Group group) { Group persistGroup = new Group(); persistGroup.setName(group.getName()); persistGroup.setDescription(group.getDescription()); Set<Group> includedGroups = new HashSet<Group>(); Set<String> privileges = new HashSet<String>(); for (Privilege privilege : group.getPrivileges()) { String privilegeName = privilege.getName(); if (privilege instanceof org.openl.rules.security.Group) { includedGroups.add(groupDao.getGroupByName(privilegeName)); } else { privileges.add(privilegeName); } } if (!includedGroups.isEmpty()) { persistGroup.setIncludedGroups(includedGroups); } if (!privileges.isEmpty()) { persistGroup.setPrivileges(privileges); } groupDao.save(persistGroup); }
private void removeIncludedPrivileges(List<String> privileges, Map<String, Group> groups) { for (String privilege : new ArrayList<String>(privileges)) { for (Group group : groups.values()) { if (group.hasPrivilege(privilege)) { privileges.remove(privilege); } } } }
public String[] getOnlyAdminGroups(Object objUser) { if (!isOnlyAdmin(objUser)) { return new String[0]; } String adminPrivilege = Privileges.ADMIN.name(); List<String> groups = new ArrayList<String>(); @SuppressWarnings("unchecked") Collection<Privilege> authorities = (Collection<Privilege>) ((User) objUser).getAuthorities(); for (Privilege authority : authorities) { if (authority instanceof Group) { Group group = (Group) authority; if (group.hasPrivilege(adminPrivilege)) { groups.add(group.getAuthority()); } } } return groups.toArray(new String[groups.size()]); }
private void removeIncludedGroups(Group group, Map<String, Group> groups) { Set<String> groupNames = new HashSet<String>(groups.keySet()); for (String checkGroupName : groupNames) { if (!group.getName().equals(checkGroupName) && group.hasPrivilege(checkGroupName)) { Group includedGroup = groups.get(checkGroupName); if (includedGroup != null) { removeIncludedGroups(includedGroup, groups); groups.remove(checkGroupName); } } } }
@Override public void updateGroup(String name, org.openl.rules.security.Group group) { Group persistGroup = groupDao.getGroupByName(name); persistGroup.setName(group.getName()); persistGroup.setDescription(group.getDescription()); Set<Group> includedGroups = new HashSet<Group>(); Set<String> privileges = new HashSet<String>(); for (Privilege privilege : group.getPrivileges()) { String privilegeName = privilege.getName(); if (privilege instanceof org.openl.rules.security.Group) { Group includedGroup = groupDao.getGroupByName(privilegeName); if (!persistGroup.equals(includedGroup)) { // Persisting group should not include itself includedGroups.add(includedGroup); } else { // Save all privileges of itself persisting group Set<String> includedPrivileges = includedGroup.getPrivileges(); if (includedPrivileges != null) { privileges.addAll(includedPrivileges); } } } else { privileges.add(privilegeName); } } persistGroup.setIncludedGroups(!includedGroups.isEmpty() ? includedGroups : null); persistGroup.setPrivileges(privileges); groupDao.update(persistGroup); }
@Override public boolean hasPrivilege(String privilege) { for (Privilege auth : privileges) { if (auth.getName().equals(privilege)) { return true; } if (auth instanceof Group) { if (((Group) auth).hasPrivilege(privilege)) { return true; } } } return false; }
public List<SelectItem> getGroupItems() { List<SelectItem> result = new ArrayList<SelectItem>(); List<Group> groups = groupManagementService.getGroups(); for (Group group : groups) { result.add(new SelectItem(group.getName(), group.getDisplayName())); } return result; }
public List<String> getNonGroupPrivileges(Group group) { List<String> result = new ArrayList<String>(); if (group == null) { return result; } Collection<Privilege> authorities = group.getPrivileges(); for (Privilege authority : authorities) { if (!(authority instanceof Group)) { result.add(authority.getDisplayName()); } } return result; }
private void removeIncludedGroups(Group group, Map<String, Group> groups) { Set<String> groupNames = new HashSet<String>(groups.keySet()); for (String checkGroupName : groupNames) { if (!group.getName().equals(checkGroupName) && group.hasPrivilege(checkGroupName)) { Group includedGroup = groups.get(checkGroupName); if (includedGroup != null) { removeIncludedGroups(includedGroup, groups); groups.remove(checkGroupName); } } } }
@Override public void updateGroup(String name, org.openl.rules.security.Group group) { Group persistGroup = groupDao.getGroupByName(name); persistGroup.setName(group.getName()); persistGroup.setDescription(group.getDescription()); Set<Group> includedGroups = new HashSet<Group>(); Set<String> privileges = new HashSet<String>(); for (Privilege privilege : group.getPrivileges()) { String privilegeName = privilege.getName(); if (privilege instanceof org.openl.rules.security.Group) { Group includedGroup = groupDao.getGroupByName(privilegeName); if (!persistGroup.equals(includedGroup)) { // Persisting group should not include itself includedGroups.add(includedGroup); } else { // Save all privileges of itself persisting group Set<String> includedPrivileges = includedGroup.getPrivileges(); if (includedPrivileges != null) { privileges.addAll(includedPrivileges); } } } else { privileges.add(privilegeName); } } persistGroup.setIncludedGroups(!includedGroups.isEmpty() ? includedGroups : null); persistGroup.setPrivileges(privileges); groupDao.update(persistGroup); }
@Override public boolean hasPrivilege(String privilege) { for (Privilege auth : privileges) { if (auth.getName().equals(privilege)) { return true; } if (auth instanceof Group) { if (((Group) auth).hasPrivilege(privilege)) { return true; } } } return false; }
public List<String> getPrivileges(Group group) { List<String> result = new ArrayList<String>(); if (group == null) { return result; } Collection<Privilege> privileges = group.getPrivileges(); for (Privilege privilege : privileges) { if (privilege instanceof Group) { result.addAll(getPrivileges((Group) privilege)); } else { result.add(privilege.getName()); } } return result; }
private void removeIncludedGroups(Group group, Map<String, Group> groups) { Set<String> groupNames = new HashSet<String>(groups.keySet()); for (String checkGroupName : groupNames) { if (!group.getName().equals(checkGroupName) && group.hasPrivilege(checkGroupName)) { Group includedGroup = groups.get(checkGroupName); if (includedGroup != null) { removeIncludedGroups(includedGroup, groups); groups.remove(checkGroupName); } } } }
public boolean isOnlyAdmin(Group objGroup) { if (!objGroup.hasPrivilege(Privileges.ADMIN.name())) { return false; } List<Group> groups = getGroups(); int i = 0; for (Group group : groups) { if (group.hasPrivilege(Privileges.ADMIN.name())) { i++; } } return i <= 1; }