diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/UserDTO.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/UserDTO.java index 04d60aa85f..0d2ecde845 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/UserDTO.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/UserDTO.java @@ -29,7 +29,7 @@ import java.util.Set; public class UserDTO extends ComponentDTO { private String identity; - private Set groups; + private Set userGroups; /** * @return users identity @@ -49,11 +49,11 @@ public class UserDTO extends ComponentDTO { * @return groups to which the user belongs */ @ApiModelProperty(value = "The groups to which the user belongs.") - public Set getGroups() { - return groups; + public Set getUserGroups() { + return userGroups; } - public void setGroups(Set groups) { - this.groups = groups; + public void setUserGroups(Set userGroups) { + this.userGroups = userGroups; } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/resource/UserGroupsAuthorizable.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/entity/UserGroupsEntity.java similarity index 50% rename from nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/resource/UserGroupsAuthorizable.java rename to nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/entity/UserGroupsEntity.java index 938371c470..bdde6628bd 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/resource/UserGroupsAuthorizable.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/entity/UserGroupsEntity.java @@ -14,18 +14,31 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.nifi.authorization.resource; +package org.apache.nifi.web.api.entity; -import org.apache.nifi.authorization.Resource; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.Collection; -public class UserGroupsAuthorizable implements Authorizable { - @Override - public Authorizable getParentAuthorizable() { - return null; +/** + * A serialized representation of this class can be placed in the entity body of a request or response to or from the API. This particular entity holds a reference to a collection of + * UserGroupEntity objects. + */ +@XmlRootElement(name = "userGroupsEntity") +public class UserGroupsEntity { + + private Collection userGroups; + + /** + * The collection of UserGroupEntity objects that are being serialized. + * + * @return The UserGroupEntity objects + */ + public Collection getUserGroups() { + return userGroups; } - @Override - public Resource getResource() { - return ResourceFactory.getUserGroupsResource(); + public void setUserGroups(Collection userGroups) { + this.userGroups = userGroups; } + } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/entity/UsersEntity.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/entity/UsersEntity.java index 4acc7cb534..66243389b7 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/entity/UsersEntity.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/entity/UsersEntity.java @@ -16,45 +16,28 @@ */ package org.apache.nifi.web.api.entity; -import java.util.Collection; -import java.util.Date; import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import org.apache.nifi.web.api.dto.UserDTO; -import org.apache.nifi.web.api.dto.util.TimeAdapter; +import java.util.Collection; /** - * A serialized representation of this class can be placed in the entity body of a request or response to or from the API. This particular entity holds a reference to a collection of UserDTO. + * A serialized representation of this class can be placed in the entity body of a request or response to or from the API. This particular entity holds a reference to a collection of UserEntity + * objects. */ @XmlRootElement(name = "usersEntity") public class UsersEntity extends Entity { - private Collection users; - private Date generated; + private Collection users; /** - * The collection of UserDTOs that are being serialized. + * The collection of UserEntity objects that are being serialized. * - * @return The UserDTO object + * @return The UserEntity objects */ - public Collection getUsers() { + public Collection getUsers() { return users; } - public void setUsers(Collection users) { + public void setUsers(Collection users) { this.users = users; } - - /** - * @return When this content was generated - */ - @XmlJavaTypeAdapter(TimeAdapter.class) - public Date getGenerated() { - return generated; - } - - public void setGenerated(Date generated) { - this.generated = generated; - } - } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/main/java/org/apache/nifi/authorization/FileAuthorizer.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/main/java/org/apache/nifi/authorization/FileAuthorizer.java index 906d36993b..eb5cf48d78 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/main/java/org/apache/nifi/authorization/FileAuthorizer.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/main/java/org/apache/nifi/authorization/FileAuthorizer.java @@ -327,11 +327,8 @@ public class FileAuthorizer extends AbstractPolicyBasedAuthorizer { addAccessPolicy(authorizations, ResourceType.ProcessGroup.getValue() + "/" + rootGroupId, adminUser.getIdentifier(), READ_CODE + WRITE_CODE); } - // grant the user read/write access to the /users resource - addAccessPolicy(authorizations, ResourceType.User.getValue(), adminUser.getIdentifier(), READ_CODE + WRITE_CODE); - - // grant the user read/write access to the /groups resource - addAccessPolicy(authorizations, ResourceType.Group.getValue(), adminUser.getIdentifier(), READ_CODE + WRITE_CODE); + // grant the user read/write access to the /tenants resource + addAccessPolicy(authorizations, ResourceType.Tenant.getValue(), adminUser.getIdentifier(), READ_CODE + WRITE_CODE); // grant the user read/write access to the /policies resource addAccessPolicy(authorizations, ResourceType.Policy.getValue(), adminUser.getIdentifier(), READ_CODE + WRITE_CODE); diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/main/java/org/apache/nifi/authorization/RoleAccessPolicy.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/main/java/org/apache/nifi/authorization/RoleAccessPolicy.java index 67574022fe..32b7ce93cd 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/main/java/org/apache/nifi/authorization/RoleAccessPolicy.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/main/java/org/apache/nifi/authorization/RoleAccessPolicy.java @@ -79,8 +79,7 @@ public final class RoleAccessPolicy { if (rootGroupId != null) { adminPolicies.add(new RoleAccessPolicy(ResourceType.ProcessGroup.getValue() + "/" + rootGroupId, READ_ACTION)); } - adminPolicies.add(new RoleAccessPolicy(ResourceType.User.getValue(), READ_WRITE_ACTION)); - adminPolicies.add(new RoleAccessPolicy(ResourceType.Group.getValue(), READ_WRITE_ACTION)); + adminPolicies.add(new RoleAccessPolicy(ResourceType.Tenant.getValue(), READ_WRITE_ACTION)); adminPolicies.add(new RoleAccessPolicy(ResourceType.Policy.getValue(), READ_WRITE_ACTION)); roleAccessPolicies.put(Role.ROLE_ADMIN, Collections.unmodifiableSet(adminPolicies)); diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/test/java/org/apache/nifi/authorization/FileAuthorizerTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/test/java/org/apache/nifi/authorization/FileAuthorizerTest.java index 30a1230a7c..0b2fea45fb 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/test/java/org/apache/nifi/authorization/FileAuthorizerTest.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/test/java/org/apache/nifi/authorization/FileAuthorizerTest.java @@ -235,7 +235,7 @@ public class FileAuthorizerTest { // verify user4's policies final Map> user4Policies = getResourceActions(policies, user4); - assertEquals(6, user4Policies.size()); + assertEquals(5, user4Policies.size()); assertTrue(user4Policies.containsKey(ResourceType.Flow.getValue())); assertEquals(1, user4Policies.get(ResourceType.Flow.getValue()).size()); @@ -245,11 +245,8 @@ public class FileAuthorizerTest { assertEquals(1, user4Policies.get(ResourceType.ProcessGroup.getValue() + "/" + ROOT_GROUP_ID).size()); assertTrue(user4Policies.get(ResourceType.ProcessGroup.getValue() + "/" + ROOT_GROUP_ID).contains(RequestAction.READ)); - assertTrue(user4Policies.containsKey(ResourceType.User.getValue())); - assertEquals(2, user4Policies.get(ResourceType.User.getValue()).size()); - - assertTrue(user4Policies.containsKey(ResourceType.Group.getValue())); - assertEquals(2, user4Policies.get(ResourceType.Group.getValue()).size()); + assertTrue(user4Policies.containsKey(ResourceType.Tenant.getValue())); + assertEquals(2, user4Policies.get(ResourceType.Tenant.getValue()).size()); assertTrue(user4Policies.containsKey(ResourceType.Policy.getValue())); assertEquals(2, user4Policies.get(ResourceType.Policy.getValue()).size()); @@ -338,7 +335,7 @@ public class FileAuthorizerTest { assertEquals(adminIdentity, adminUser.getIdentity()); final Set policies = authorizer.getAccessPolicies(); - assertEquals(5, policies.size()); + assertEquals(4, policies.size()); final String rootGroupResource = ResourceType.ProcessGroup.getValue() + "/" + ROOT_GROUP_ID; @@ -375,7 +372,7 @@ public class FileAuthorizerTest { assertEquals(adminIdentity, adminUser.getIdentity()); final Set policies = authorizer.getAccessPolicies(); - assertEquals(4, policies.size()); + assertEquals(3, policies.size()); final String rootGroupResource = ResourceType.ProcessGroup.getValue() + "/" + ROOT_GROUP_ID; @@ -412,7 +409,7 @@ public class FileAuthorizerTest { assertEquals(adminIdentity, adminUser.getIdentity()); final Set policies = authorizer.getAccessPolicies(); - assertEquals(4, policies.size()); + assertEquals(3, policies.size()); final String rootGroupResource = ResourceType.ProcessGroup.getValue() + "/" + ROOT_GROUP_ID; diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/resource/ResourceFactory.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/resource/ResourceFactory.java index 0454ad73ca..5fc56af3b3 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/resource/ResourceFactory.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/resource/ResourceFactory.java @@ -17,9 +17,7 @@ package org.apache.nifi.authorization.resource; import org.apache.nifi.authorization.AccessPolicy; -import org.apache.nifi.authorization.Group; import org.apache.nifi.authorization.Resource; -import org.apache.nifi.authorization.User; import java.util.Objects; @@ -85,18 +83,6 @@ public final class ResourceFactory { } }; - private final static Resource GROUP_RESOURCE = new Resource() { - @Override - public String getIdentifier() { - return ResourceType.Group.getValue(); - } - - @Override - public String getName() { - return "Group"; - } - }; - private final static Resource INPUT_PORT_RESOURCE = new Resource() { @Override public String getIdentifier() { @@ -277,6 +263,18 @@ public final class ResourceFactory { } }; + private final static Resource TENANT_RESOURCE = new Resource() { + @Override + public String getIdentifier() { + return ResourceType.Tenant.getValue(); + } + + @Override + public String getName() { + return "Tenant"; + } + }; + private final static Resource TOKEN_RESOURCE = new Resource() { @Override public String getIdentifier() { @@ -289,18 +287,6 @@ public final class ResourceFactory { } }; - private final static Resource USER_RESOURCE = new Resource() { - @Override - public String getIdentifier() { - return ResourceType.User.getValue(); - } - - @Override - public String getName() { - return "User"; - } - }; - private final static Resource POLICIES_RESOURCE = new Resource() { @Override @@ -314,32 +300,6 @@ public final class ResourceFactory { } }; - private final static Resource USERS_RESOURCE = new Resource() { - - @Override - public String getIdentifier() { - return "/users"; - } - - @Override - public String getName() { - return "Users"; - } - }; - - private final static Resource USERGROUPS_RESOURCE = new Resource() { - - @Override - public String getIdentifier() { - return "/user-groups"; - } - - @Override - public String getName() { - return "User Groups"; - } - }; - /** * Gets the Resource for accessing Connections. * @@ -385,15 +345,6 @@ public final class ResourceFactory { return FLOW_RESOURCE; } - /** - * Gets the Resource for accessing Groups which allows management of user groups. - * - * @return The resource for accessing Groups - */ - public static Resource getGroupResource() { - return GROUP_RESOURCE; - } - /** * Gets the Resource for accessing Input Ports. * @@ -541,12 +492,12 @@ public final class ResourceFactory { } /** - * Gets the Resource for accessing Users which includes creating, modifying, and deleting Users. + * Gets the Resource for accessing Tenants which includes creating, modifying, and deleting Users and UserGroups. * - * @return The Resource for accessing Users + * @return The Resource for accessing Tenants */ - public static Resource getUserResource() { - return USER_RESOURCE; + public static Resource getTenantResource() { + return TENANT_RESOURCE; } /** @@ -602,24 +553,6 @@ public final class ResourceFactory { }; } - /** - * Gets a Resource for accessing {@link User} configurations. - * - * @return The resource - */ - public static Resource getUsersResource() { - return USERS_RESOURCE; - } - - /** - * Gets a Resource for accessing {@link Group}s configuration. - * - * @return The resource - */ - public static Resource getUserGroupsResource() { - return USERGROUPS_RESOURCE; - } - /** * Gets a Resource for accessing a component configuration. * diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/resource/ResourceType.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/resource/ResourceType.java index 94b61181ef..eb08cec547 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/resource/ResourceType.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/resource/ResourceType.java @@ -20,9 +20,9 @@ public enum ResourceType { Connection("/connections"), Controller("/controller"), ControllerService("/controller-services"), + Counters("/counters"), Funnel("/funnel"), Flow("/flow"), - Group("/groups"), InputPort("/input-ports"), Label("/labels"), OutputPort("/output-ports"), @@ -37,9 +37,8 @@ public enum ResourceType { SiteToSite("/site-to-site"), System("/system"), Template("/templates"), - Token("/token"), - Counters("/counters"), - User("/users"); + Tenant("/tenants"), + Token("/token"); final String value; diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/resource/UsersAuthorizable.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/resource/TenantAuthorizable.java similarity index 90% rename from nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/resource/UsersAuthorizable.java rename to nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/resource/TenantAuthorizable.java index 2b255d47db..e7fe42ea0b 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/resource/UsersAuthorizable.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/resource/TenantAuthorizable.java @@ -18,7 +18,7 @@ package org.apache.nifi.authorization.resource; import org.apache.nifi.authorization.Resource; -public class UsersAuthorizable implements Authorizable { +public class TenantAuthorizable implements Authorizable { @Override public Authorizable getParentAuthorizable() { @@ -27,7 +27,7 @@ public class UsersAuthorizable implements Authorizable { @Override public Resource getResource() { - return ResourceFactory.getUsersResource(); + return ResourceFactory.getTenantResource(); } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/AuthorizableLookup.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/AuthorizableLookup.java index f98878082f..f5421e50a7 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/AuthorizableLookup.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/AuthorizableLookup.java @@ -17,8 +17,6 @@ package org.apache.nifi.web; import org.apache.nifi.authorization.AccessPolicy; -import org.apache.nifi.authorization.Group; -import org.apache.nifi.authorization.User; import org.apache.nifi.authorization.resource.Authorizable; import org.apache.nifi.controller.Snippet; @@ -163,16 +161,10 @@ public interface AuthorizableLookup { Snippet getSnippet(String id); /** - * Get the {@link Authorizable} that represents the resource of {@link User}s. + * Get the {@link Authorizable} that represents the resource of users and user groups. * @return authorizable */ - Authorizable getUsersAuthorizable(); - - /** - * Get the {@link Authorizable} that represents the resource of {@link Group}s. - * @return authorizable - */ - Authorizable getUserGroupsAuthorizable(); + Authorizable getTenantAuthorizable(); /** * Get the {@link Authorizable} the represents the parent resource of {@link AccessPolicy} resources. diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java index 1c08f7529d..6eaa8d06ca 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java @@ -1220,6 +1220,13 @@ public interface NiFiServiceFacade { */ UserEntity getUser(String userId, boolean prune); + /** + * Gets all the users. + * @param prune If true, the users in the groups to which the users belong will not be returned + * @return The user transfer objects + */ + Set getUsers(boolean prune); + /** * Updates the specified user. * @param revision Revision to compare with current base revision @@ -1255,6 +1262,13 @@ public interface NiFiServiceFacade { */ UserGroupEntity getUserGroup(String userGroupId, boolean prune); + /** + * Gets all user groups. + * @param prune If true, the user groups of the users in the user groups will not be returned + * @return The user group transfer objects + */ + Set getUserGroups(boolean prune); + /** * Updates the specified user group. * @param revision Revision to compare with current base revision diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardAuthorizableLookup.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardAuthorizableLookup.java index f702ffc6cc..13a5c20c3a 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardAuthorizableLookup.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardAuthorizableLookup.java @@ -19,8 +19,7 @@ package org.apache.nifi.web; import org.apache.nifi.authorization.resource.AccessPoliciesAuthorizable; import org.apache.nifi.authorization.resource.AccessPolicyAuthorizable; import org.apache.nifi.authorization.resource.Authorizable; -import org.apache.nifi.authorization.resource.UserGroupsAuthorizable; -import org.apache.nifi.authorization.resource.UsersAuthorizable; +import org.apache.nifi.authorization.resource.TenantAuthorizable; import org.apache.nifi.controller.ConfiguredComponent; import org.apache.nifi.controller.Snippet; import org.apache.nifi.controller.service.ControllerServiceNode; @@ -44,8 +43,7 @@ import org.apache.nifi.web.dao.TemplateDAO; class StandardAuthorizableLookup implements AuthorizableLookup { - private static final UsersAuthorizable USERS_AUTHORIZABLE = new UsersAuthorizable(); - private static final UserGroupsAuthorizable USER_GROUPS_AUTHORIZABLE = new UserGroupsAuthorizable(); + private static final TenantAuthorizable TENANT_AUTHORIZABLE = new TenantAuthorizable(); private static final Authorizable ACCESS_POLICIES_AUTHORIZABLE = new AccessPoliciesAuthorizable(); // nifi core components @@ -159,13 +157,8 @@ class StandardAuthorizableLookup implements AuthorizableLookup { } @Override - public Authorizable getUsersAuthorizable() { - return USERS_AUTHORIZABLE; - } - - @Override - public Authorizable getUserGroupsAuthorizable() { - return USER_GROUPS_AUTHORIZABLE; + public Authorizable getTenantAuthorizable() { + return TENANT_AUTHORIZABLE; } @Override diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java index eaaef986bb..4373472aba 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java @@ -535,7 +535,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade { @Override public UserEntity updateUser(final Revision revision, final UserDTO userDTO) { - final Authorizable usersAuthorizable = authorizableLookup.getUsersAuthorizable(); + final Authorizable usersAuthorizable = authorizableLookup.getTenantAuthorizable(); final RevisionUpdate snapshot = updateComponent(revision, usersAuthorizable, () -> userDAO.updateUser(userDTO), @@ -547,7 +547,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade { @Override public UserGroupEntity updateUserGroup(final Revision revision, final UserGroupDTO userGroupDTO) { - final Authorizable userGroupsAuthorizable = authorizableLookup.getUserGroupsAuthorizable(); + final Authorizable userGroupsAuthorizable = authorizableLookup.getTenantAuthorizable(); final RevisionUpdate snapshot = updateComponent(revision, userGroupsAuthorizable, () -> userGroupDAO.updateUserGroup(userGroupDTO), @@ -985,7 +985,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade { final Set userGroups = user != null ? user.getGroups().stream().map(userGroupId -> getUserGroup(userGroupId, true)).collect(Collectors.toSet()) : null; final UserDTO snapshot = deleteComponent( revision, - authorizableLookup.getUsersAuthorizable(), + authorizableLookup.getTenantAuthorizable(), () -> userDAO.deleteUser(userId), dtoFactory.createUserDto(user, userGroups)); @@ -999,7 +999,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade { null; final UserGroupDTO snapshot = deleteComponent( revision, - authorizableLookup.getUserGroupsAuthorizable(), + authorizableLookup.getTenantAuthorizable(), () -> userGroupDAO.deleteUserGroup(userGroupId), dtoFactory.createUserGroupDto(userGroup, users)); @@ -1283,7 +1283,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade { final User newUser = userDAO.createUser(userDTO); final UserDTO newUserDto = dtoFactory.createUserDto(newUser, newUser.getGroups().stream().map(userGroupId -> getUserGroup(userGroupId, true)).collect(Collectors.toSet())); - final AccessPolicyDTO accessPolicy = dtoFactory.createAccessPolicyDto(authorizableLookup.getUsersAuthorizable()); + final AccessPolicyDTO accessPolicy = dtoFactory.createAccessPolicyDto(authorizableLookup.getTenantAuthorizable()); return entityFactory.createUserEntity(newUserDto, dtoFactory.createRevisionDTO(new FlowModification(revision, creator)), accessPolicy); } @@ -1296,7 +1296,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade { final Group newUserGroup = userGroupDAO.createUserGroup(userGroupDTO); final UserGroupDTO newUserGroupDto = dtoFactory.createUserGroupDto(newUserGroup, newUserGroup.getUsers().stream().map(userId -> getUser(userId, true)).collect(Collectors.toSet())); - final AccessPolicyDTO accessPolicy = dtoFactory.createAccessPolicyDto(authorizableLookup.getUserGroupsAuthorizable()); + final AccessPolicyDTO accessPolicy = dtoFactory.createAccessPolicyDto(authorizableLookup.getTenantAuthorizable()); return entityFactory.createUserGroupEntity(newUserGroupDto, dtoFactory.createRevisionDTO(new FlowModification(revision, creator)), accessPolicy); } @@ -2354,7 +2354,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade { @Override public UserEntity getUser(final String userId, final boolean prune) { return revisionManager.get(userId, rev -> { - final Authorizable usersAuthorizable = authorizableLookup.getUsersAuthorizable(); + final Authorizable usersAuthorizable = authorizableLookup.getTenantAuthorizable(); final RevisionDTO revision = dtoFactory.createRevisionDTO(rev); final AccessPolicyDTO accessPolicy = dtoFactory.createAccessPolicyDto(usersAuthorizable); final User user = userDAO.getUser(userId); @@ -2367,7 +2367,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade { private UserEntity getUserPruned(final String userId) { return revisionManager.get(userId, rev -> { - final Authorizable usersAuthorizable = authorizableLookup.getUsersAuthorizable(); + final Authorizable usersAuthorizable = authorizableLookup.getTenantAuthorizable(); final RevisionDTO revision = dtoFactory.createRevisionDTO(rev); final AccessPolicyDTO accessPolicy = dtoFactory.createAccessPolicyDto(usersAuthorizable); final User user = userDAO.getUser(userId); @@ -2375,10 +2375,29 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade { }); } + @Override + public Set getUsers(boolean prune) { + final Authorizable userAuthorizable = authorizableLookup.getTenantAuthorizable(); + final Set users = userDAO.getUsers(); + final Set ids = users.stream().map(user -> user.getIdentifier()).collect(Collectors.toSet()); + return revisionManager.get(ids, () -> { + return users.stream() + .map(user -> { + final RevisionDTO revision = dtoFactory.createRevisionDTO(revisionManager.getRevision(user.getIdentifier())); + final AccessPolicyDTO accessPolicy = dtoFactory.createAccessPolicyDto(userAuthorizable); + final Set userGroups = user.getGroups().stream() + .map(userGroupId -> prune ? getUserGroupPruned(userGroupId) : getUserGroup(userGroupId, false)) + .collect(Collectors.toSet()); + return entityFactory.createUserEntity(dtoFactory.createUserDto(user, userGroups), revision, accessPolicy); + }) + .collect(Collectors.toSet()); + }); + } + @Override public UserGroupEntity getUserGroup(final String userGroupId, final boolean prune) { return revisionManager.get(userGroupId, rev -> { - final Authorizable userGroupsAuthorizable = authorizableLookup.getUserGroupsAuthorizable(); + final Authorizable userGroupsAuthorizable = authorizableLookup.getTenantAuthorizable(); final RevisionDTO revision = dtoFactory.createRevisionDTO(rev); final AccessPolicyDTO accessPolicy = dtoFactory.createAccessPolicyDto(userGroupsAuthorizable); final Group userGroup = userGroupDAO.getUserGroup(userGroupId); @@ -2390,7 +2409,7 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade { private UserGroupEntity getUserGroupPruned(final String userGroupId) { return revisionManager.get(userGroupId, rev -> { - final Authorizable userGroupsAuthorizable = authorizableLookup.getUserGroupsAuthorizable(); + final Authorizable userGroupsAuthorizable = authorizableLookup.getTenantAuthorizable(); final RevisionDTO revision = dtoFactory.createRevisionDTO(rev); final AccessPolicyDTO accessPolicy = dtoFactory.createAccessPolicyDto(userGroupsAuthorizable); final Group userGroup = userGroupDAO.getUserGroup(userGroupId); @@ -2398,6 +2417,25 @@ public class StandardNiFiServiceFacade implements NiFiServiceFacade { }); } + @Override + public Set getUserGroups(boolean prune) { + final Authorizable userGroupAuthorizable = authorizableLookup.getTenantAuthorizable(); + final Set userGroups = userGroupDAO.getUserGroups(); + final Set ids = userGroups.stream().map(userGroup -> userGroup.getIdentifier()).collect(Collectors.toSet()); + return revisionManager.get(ids, () -> { + return userGroups.stream() + .map(userGroup -> { + final RevisionDTO revision = dtoFactory.createRevisionDTO(revisionManager.getRevision(userGroup.getIdentifier())); + final AccessPolicyDTO accessPolicy = dtoFactory.createAccessPolicyDto(userGroupAuthorizable); + final Set users = userGroup.getUsers().stream() + .map(userGroupId -> prune ? getUserPruned(userGroupId) : getUser(userGroupId, false)) + .collect(Collectors.toSet()); + return entityFactory.createUserGroupEntity(dtoFactory.createUserGroupDto(userGroup, users), revision, accessPolicy); + }) + .collect(Collectors.toSet()); + }); + } + @Override public Set getLabels(final String groupId) { final Set