Search in sources :

Example 6 with Tenants

use of org.apache.nifi.registry.security.authorization.file.tenants.generated.Tenants in project nifi-registry by apache.

the class FileUserGroupProvider method addUser.

@Override
public synchronized User addUser(User user) throws AuthorizationAccessException {
    if (user == null) {
        throw new IllegalArgumentException("User cannot be null");
    }
    final org.apache.nifi.registry.security.authorization.file.tenants.generated.User jaxbUser = createJAXBUser(user);
    final UserGroupHolder holder = userGroupHolder.get();
    final Tenants tenants = holder.getTenants();
    tenants.getUsers().getUser().add(jaxbUser);
    saveAndRefreshHolder(tenants);
    return userGroupHolder.get().getUsersById().get(user.getIdentifier());
}
Also used : Tenants(org.apache.nifi.registry.security.authorization.file.tenants.generated.Tenants)

Example 7 with Tenants

use of org.apache.nifi.registry.security.authorization.file.tenants.generated.Tenants in project nifi-registry by apache.

the class FileUserGroupProvider method deleteUser.

@Override
public synchronized User deleteUser(String userIdentifier) throws AuthorizationAccessException {
    if (userIdentifier == null) {
        throw new IllegalArgumentException("User identifier cannot be null");
    }
    final UserGroupHolder holder = userGroupHolder.get();
    final User deletedUser = holder.getUsersById().get(userIdentifier);
    if (deletedUser == null) {
        return null;
    }
    // for each group iterate over the user references and remove the user reference if it matches the user being deleted
    final Tenants tenants = holder.getTenants();
    for (org.apache.nifi.registry.security.authorization.file.tenants.generated.Group group : tenants.getGroups().getGroup()) {
        Iterator<org.apache.nifi.registry.security.authorization.file.tenants.generated.Group.User> groupUserIter = group.getUser().iterator();
        while (groupUserIter.hasNext()) {
            org.apache.nifi.registry.security.authorization.file.tenants.generated.Group.User groupUser = groupUserIter.next();
            if (groupUser.getIdentifier().equals(userIdentifier)) {
                groupUserIter.remove();
                break;
            }
        }
    }
    // remove the actual user
    Iterator<org.apache.nifi.registry.security.authorization.file.tenants.generated.User> iter = tenants.getUsers().getUser().iterator();
    while (iter.hasNext()) {
        org.apache.nifi.registry.security.authorization.file.tenants.generated.User jaxbUser = iter.next();
        if (userIdentifier.equals(jaxbUser.getIdentifier())) {
            iter.remove();
            break;
        }
    }
    saveAndRefreshHolder(tenants);
    return deletedUser;
}
Also used : Group(org.apache.nifi.registry.security.authorization.Group) User(org.apache.nifi.registry.security.authorization.User) Tenants(org.apache.nifi.registry.security.authorization.file.tenants.generated.Tenants)

Example 8 with Tenants

use of org.apache.nifi.registry.security.authorization.file.tenants.generated.Tenants in project nifi-registry by apache.

the class FileUserGroupProvider method addGroup.

@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.registry.security.authorization.file.tenants.generated.Group jaxbGroup = new org.apache.nifi.registry.security.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.registry.security.authorization.file.tenants.generated.Group.User jaxbGroupUser = new org.apache.nifi.registry.security.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());
}
Also used : Group(org.apache.nifi.registry.security.authorization.Group) User(org.apache.nifi.registry.security.authorization.User) Tenants(org.apache.nifi.registry.security.authorization.file.tenants.generated.Tenants)

Example 9 with Tenants

use of org.apache.nifi.registry.security.authorization.file.tenants.generated.Tenants in project nifi-registry by apache.

the class FileUserGroupProvider method updateUser.

@Override
public synchronized User updateUser(User user) throws AuthorizationAccessException {
    if (user == null) {
        throw new IllegalArgumentException("User cannot be null");
    }
    final UserGroupHolder holder = userGroupHolder.get();
    final Tenants tenants = holder.getTenants();
    final List<org.apache.nifi.registry.security.authorization.file.tenants.generated.User> users = tenants.getUsers().getUser();
    // fine the User that needs to be updated
    org.apache.nifi.registry.security.authorization.file.tenants.generated.User updateUser = null;
    for (org.apache.nifi.registry.security.authorization.file.tenants.generated.User jaxbUser : users) {
        if (user.getIdentifier().equals(jaxbUser.getIdentifier())) {
            updateUser = jaxbUser;
            break;
        }
    }
    // if user wasn't found return null, otherwise update the user and save changes
    if (updateUser == null) {
        return null;
    } else {
        updateUser.setIdentity(user.getIdentity());
        saveAndRefreshHolder(tenants);
        return userGroupHolder.get().getUsersById().get(user.getIdentifier());
    }
}
Also used : User(org.apache.nifi.registry.security.authorization.User) Tenants(org.apache.nifi.registry.security.authorization.file.tenants.generated.Tenants)

Aggregations

Tenants (org.apache.nifi.registry.security.authorization.file.tenants.generated.Tenants)9 Group (org.apache.nifi.registry.security.authorization.Group)4 User (org.apache.nifi.registry.security.authorization.User)4 File (java.io.File)1 IOException (java.io.IOException)1 Date (java.util.Date)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 StreamSource (javax.xml.transform.stream.StreamSource)1 UserAndGroups (org.apache.nifi.registry.security.authorization.UserAndGroups)1 Groups (org.apache.nifi.registry.security.authorization.file.tenants.generated.Groups)1 Users (org.apache.nifi.registry.security.authorization.file.tenants.generated.Users)1 SecurityProviderCreationException (org.apache.nifi.registry.security.exception.SecurityProviderCreationException)1 PropertyValue (org.apache.nifi.registry.util.PropertyValue)1 SAXException (org.xml.sax.SAXException)1