@Override public Group getGroup(String identifier) throws AuthorizationAccessException { if (identifier == null) { return null; } return userGroupHolder.get().getGroupsById().get(identifier); }
@Override public synchronized Group addGroup(Group group) throws AuthorizationAccessException { if (group == null) { throw new IllegalArgumentException("Group cannot be null"); } final UserGroupHolder holder = userGroupHolder.get(); final Tenants tenants = holder.getTenants(); // create a new JAXB Group based on the incoming Group final org.apache.nifi.authorization.file.tenants.generated.Group jaxbGroup = new org.apache.nifi.authorization.file.tenants.generated.Group(); jaxbGroup.setIdentifier(group.getIdentifier()); jaxbGroup.setName(group.getName()); // add each user to the group for (String groupUser : group.getUsers()) { org.apache.nifi.authorization.file.tenants.generated.Group.User jaxbGroupUser = new org.apache.nifi.authorization.file.tenants.generated.Group.User(); jaxbGroupUser.setIdentifier(groupUser); jaxbGroup.getUser().add(jaxbGroupUser); } tenants.getGroups().getGroup().add(jaxbGroup); saveAndRefreshHolder(tenants); return userGroupHolder.get().getGroupsById().get(group.getIdentifier()); }
@Override public synchronized Group updateGroup(Group group) throws AuthorizationAccessException { if (group == null) { throw new IllegalArgumentException("Group cannot be null"); } final UserGroupHolder holder = userGroupHolder.get(); final Tenants tenants = holder.getTenants(); // find the group that needs to be update org.apache.nifi.authorization.file.tenants.generated.Group updateGroup = null; for (org.apache.nifi.authorization.file.tenants.generated.Group jaxbGroup : tenants.getGroups().getGroup()) { if (jaxbGroup.getIdentifier().equals(group.getIdentifier())) { updateGroup = jaxbGroup; break; } } // if the group wasn't found return null, otherwise update the group and save changes if (updateGroup == null) { return null; } // reset the list of users and add each user to the group updateGroup.getUser().clear(); for (String groupUser : group.getUsers()) { org.apache.nifi.authorization.file.tenants.generated.Group.User jaxbGroupUser = new org.apache.nifi.authorization.file.tenants.generated.Group.User(); jaxbGroupUser.setIdentifier(groupUser); updateGroup.getUser().add(jaxbGroupUser); } updateGroup.setName(group.getName()); saveAndRefreshHolder(tenants); return userGroupHolder.get().getGroupsById().get(group.getIdentifier()); }