@Test public void testDeleteUser() throws Exception { writeFile(primaryTenants, TENANTS); userGroupProvider.onConfigured(configurationContext); assertEquals(2, userGroupProvider.getUsers().size()); final User user = userGroupProvider.getUser("user-1"); assertEquals("user-1", user.getIdentifier()); final User deletedUser = userGroupProvider.deleteUser(user); assertNotNull(deletedUser); assertEquals("user-1", deletedUser.getIdentifier()); assertEquals(1, userGroupProvider.getUsers().size()); assertNull(userGroupProvider.getUser(user.getIdentifier())); }
@Override public synchronized User deleteUser(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.authorization.file.tenants.generated.User> users = tenants.getUsers().getUser(); for (org.apache.nifi.authorization.file.tenants.generated.Group group : tenants.getGroups().getGroup()) { Iterator<org.apache.nifi.authorization.file.tenants.generated.Group.User> groupUserIter = group.getUser().iterator(); while (groupUserIter.hasNext()) { org.apache.nifi.authorization.file.tenants.generated.Group.User groupUser = groupUserIter.next(); if (groupUser.getIdentifier().equals(user.getIdentifier())) { groupUserIter.remove(); break; } } } boolean removedUser = false; Iterator<org.apache.nifi.authorization.file.tenants.generated.User> iter = users.iterator(); while (iter.hasNext()) { org.apache.nifi.authorization.file.tenants.generated.User jaxbUser = iter.next(); if (user.getIdentifier().equals(jaxbUser.getIdentifier())) { iter.remove(); removedUser = true; break; } } if (removedUser) { saveAndRefreshHolder(tenants); return user; } else { return null; } }
FileUserGroupProvider implements ConfigurableUserGroupProvider { @Override public synchronized User deleteUser(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.authorization.file.tenants.generated.User> users = tenants.getUsers().getUser(); for (org.apache.nifi.authorization.file.tenants.generated.Group group : tenants.getGroups().getGroup()) { Iterator<org.apache.nifi.authorization.file.tenants.generated.Group.User> groupUserIter = group.getUser().iterator(); while (groupUserIter.hasNext()) { org.apache.nifi.authorization.file.tenants.generated.Group.User groupUser = groupUserIter.next(); if (groupUser.getIdentifier().equals(user.getIdentifier())) { groupUserIter.remove(); break; } } } boolean removedUser = false; Iterator<org.apache.nifi.authorization.file.tenants.generated.User> iter = users.iterator(); while (iter.hasNext()) { org.apache.nifi.authorization.file.tenants.generated.User jaxbUser = iter.next(); if (user.getIdentifier().equals(jaxbUser.getIdentifier())) { iter.remove(); removedUser = true; break; } } if (removedUser) { saveAndRefreshHolder(tenants); return user; } else { return null; } } }
FileUserGroupProvider implements ConfigurableUserGroupProvider { @Override public synchronized User deleteUser(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.authorization.file.tenants.generated.User> users = tenants.getUsers().getUser(); for (org.apache.nifi.authorization.file.tenants.generated.Group group : tenants.getGroups().getGroup()) { Iterator<org.apache.nifi.authorization.file.tenants.generated.Group.User> groupUserIter = group.getUser().iterator(); while (groupUserIter.hasNext()) { org.apache.nifi.authorization.file.tenants.generated.Group.User groupUser = groupUserIter.next(); if (groupUser.getIdentifier().equals(user.getIdentifier())) { groupUserIter.remove(); break; } } } boolean removedUser = false; Iterator<org.apache.nifi.authorization.file.tenants.generated.User> iter = users.iterator(); while (iter.hasNext()) { org.apache.nifi.authorization.file.tenants.generated.User jaxbUser = iter.next(); if (user.getIdentifier().equals(jaxbUser.getIdentifier())) { iter.remove(); removedUser = true; break; } } if (removedUser) { saveAndRefreshHolder(tenants); return user; } else { return null; } }  }
FileUserGroupProvider implements ConfigurableUserGroupProvider { @Override public synchronized User deleteUser(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.authorization.file.tenants.generated.User> users = tenants.getUsers().getUser(); for (org.apache.nifi.authorization.file.tenants.generated.Group group : tenants.getGroups().getGroup()) { Iterator<org.apache.nifi.authorization.file.tenants.generated.Group.User> groupUserIter = group.getUser().iterator(); while (groupUserIter.hasNext()) { org.apache.nifi.authorization.file.tenants.generated.Group.User groupUser = groupUserIter.next(); if (groupUser.getIdentifier().equals(user.getIdentifier())) { groupUserIter.remove(); break; } } } boolean removedUser = false; Iterator<org.apache.nifi.authorization.file.tenants.generated.User> iter = users.iterator(); while (iter.hasNext()) { org.apache.nifi.authorization.file.tenants.generated.User jaxbUser = iter.next(); if (user.getIdentifier().equals(jaxbUser.getIdentifier())) { iter.remove(); removedUser = true; break; } } if (removedUser) { saveAndRefreshHolder(tenants); return user; } else { return null; } }  @Override void initialize(UserGroupProviderInitializationContext initializationContext); @Override void onConfigured(AuthorizerConfigurationContext configurationContext); @Override Set<User> getUsers(); @Override synchronized User addUser(User user); @Override User getUser(String identifier); @Override synchronized User updateUser(User user); @Override User getUserByIdentity(String identity); @Override synchronized User deleteUser(User user); @Override Set<Group> getGroups(); @Override synchronized Group addGroup(Group group); @Override Group getGroup(String identifier); @Override UserAndGroups getUserAndGroups(final String identity); @Override synchronized Group updateGroup(Group group); @Override synchronized Group deleteGroup(Group group); @AuthorizerContext void setNiFiProperties(NiFiProperties properties); @Override synchronized void inheritFingerprint(String fingerprint); @Override void checkInheritability(String proposedFingerprint); @Override String getFingerprint(); @Override void preDestruction(); }
FileUserGroupProvider implements ConfigurableUserGroupProvider { @Override public synchronized User deleteUser(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.authorization.file.tenants.generated.User> users = tenants.getUsers().getUser(); for (org.apache.nifi.authorization.file.tenants.generated.Group group : tenants.getGroups().getGroup()) { Iterator<org.apache.nifi.authorization.file.tenants.generated.Group.User> groupUserIter = group.getUser().iterator(); while (groupUserIter.hasNext()) { org.apache.nifi.authorization.file.tenants.generated.Group.User groupUser = groupUserIter.next(); if (groupUser.getIdentifier().equals(user.getIdentifier())) { groupUserIter.remove(); break; } } } boolean removedUser = false; Iterator<org.apache.nifi.authorization.file.tenants.generated.User> iter = users.iterator(); while (iter.hasNext()) { org.apache.nifi.authorization.file.tenants.generated.User jaxbUser = iter.next(); if (user.getIdentifier().equals(jaxbUser.getIdentifier())) { iter.remove(); removedUser = true; break; } } if (removedUser) { saveAndRefreshHolder(tenants); return user; } else { return null; } }  @Override void initialize(UserGroupProviderInitializationContext initializationContext); @Override void onConfigured(AuthorizerConfigurationContext configurationContext); @Override Set<User> getUsers(); @Override synchronized User addUser(User user); @Override User getUser(String identifier); @Override synchronized User updateUser(User user); @Override User getUserByIdentity(String identity); @Override synchronized User deleteUser(User user); @Override Set<Group> getGroups(); @Override synchronized Group addGroup(Group group); @Override Group getGroup(String identifier); @Override UserAndGroups getUserAndGroups(final String identity); @Override synchronized Group updateGroup(Group group); @Override synchronized Group deleteGroup(Group group); @AuthorizerContext void setNiFiProperties(NiFiProperties properties); @Override synchronized void inheritFingerprint(String fingerprint); @Override void checkInheritability(String proposedFingerprint); @Override String getFingerprint(); @Override void preDestruction();  }