Search in sources :

Example 1 with AccessPolicySummaryDTO

use of org.apache.nifi.web.api.dto.AccessPolicySummaryDTO in project nifi by apache.

the class StandardNiFiServiceFacade method createAccessPolicySummaryEntity.

private AccessPolicySummaryEntity createAccessPolicySummaryEntity(final AccessPolicy ap) {
    final ComponentReferenceEntity componentReference = createComponentReferenceEntity(ap.getResource());
    final AccessPolicySummaryDTO apSummary = dtoFactory.createAccessPolicySummaryDto(ap, componentReference);
    final PermissionsDTO apPermissions = dtoFactory.createPermissionsDto(authorizableLookup.getAccessPolicyById(ap.getIdentifier()));
    final RevisionDTO apRevision = dtoFactory.createRevisionDTO(revisionManager.getRevision(ap.getIdentifier()));
    return entityFactory.createAccessPolicySummaryEntity(apSummary, apRevision, apPermissions);
}
Also used : ComponentReferenceEntity(org.apache.nifi.web.api.entity.ComponentReferenceEntity) PermissionsDTO(org.apache.nifi.web.api.dto.PermissionsDTO) AccessPolicySummaryDTO(org.apache.nifi.web.api.dto.AccessPolicySummaryDTO) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO)

Example 2 with AccessPolicySummaryDTO

use of org.apache.nifi.web.api.dto.AccessPolicySummaryDTO in project nifi by apache.

the class UserEntityMergerTest method testMergeAccessPolicy.

@Test
public void testMergeAccessPolicy() throws Exception {
    final NodeIdentifier node1 = new NodeIdentifier("node-1", "host-1", 8080, "host-1", 19998, null, null, null, false);
    final NodeIdentifier node2 = new NodeIdentifier("node-2", "host-2", 8081, "host-2", 19999, null, null, null, false);
    final PermissionsDTO permissed = new PermissionsDTO();
    permissed.setCanRead(true);
    permissed.setCanWrite(true);
    final TenantDTO userGroup1DTO = new TenantDTO();
    userGroup1DTO.setId("user-group-1");
    final TenantEntity userGroup1Entity = new TenantEntity();
    userGroup1Entity.setPermissions(permissed);
    userGroup1Entity.setId(userGroup1DTO.getId());
    userGroup1Entity.setComponent(userGroup1DTO);
    final TenantDTO userGroup2DTO = new TenantDTO();
    userGroup1DTO.setId("user-group-2");
    final TenantEntity userGroup2Entity = new TenantEntity();
    userGroup2Entity.setPermissions(permissed);
    userGroup2Entity.setId(userGroup2DTO.getId());
    userGroup2Entity.setComponent(userGroup2DTO);
    final AccessPolicySummaryDTO policy1DTO = new AccessPolicySummaryDTO();
    policy1DTO.setId("policy-1");
    final AccessPolicySummaryEntity policy1Entity = new AccessPolicySummaryEntity();
    policy1Entity.setPermissions(permissed);
    policy1Entity.setId(policy1DTO.getId());
    policy1Entity.setComponent(policy1DTO);
    final AccessPolicySummaryDTO policy2DTO = new AccessPolicySummaryDTO();
    policy2DTO.setId("policy-2");
    final AccessPolicySummaryEntity policy2Entity = new AccessPolicySummaryEntity();
    policy2Entity.setPermissions(permissed);
    policy2Entity.setId(policy2DTO.getId());
    policy2Entity.setComponent(policy2DTO);
    final UserDTO user1DTO = new UserDTO();
    user1DTO.setId("user-1");
    user1DTO.setAccessPolicies(Stream.of(policy1Entity, policy2Entity).collect(Collectors.toSet()));
    user1DTO.setUserGroups(Stream.of(userGroup2Entity).collect(Collectors.toSet()));
    final UserEntity user1Entity = new UserEntity();
    user1Entity.setPermissions(permissed);
    user1Entity.setId(user1DTO.getId());
    user1Entity.setComponent(user1DTO);
    final UserDTO user2DTO = new UserDTO();
    user2DTO.setId("user-2");
    user2DTO.setAccessPolicies(Stream.of(policy1Entity).collect(Collectors.toSet()));
    user2DTO.setUserGroups(Stream.of(userGroup1Entity, userGroup2Entity).collect(Collectors.toSet()));
    final UserEntity user2Entity = new UserEntity();
    user2Entity.setPermissions(permissed);
    user2Entity.setId(user2DTO.getId());
    user2Entity.setComponent(user2DTO);
    final Map<NodeIdentifier, UserEntity> nodeMap = new HashMap<>();
    nodeMap.put(node1, user1Entity);
    nodeMap.put(node2, user2Entity);
    final UserEntityMerger merger = new UserEntityMerger();
    merger.merge(user1Entity, nodeMap);
    assertEquals(1, user1DTO.getUserGroups().size());
    assertTrue(user1DTO.getAccessPolicies().contains(policy1Entity));
    assertEquals(1, user1DTO.getUserGroups().size());
    assertTrue(user1DTO.getUserGroups().contains(userGroup2Entity));
}
Also used : TenantEntity(org.apache.nifi.web.api.entity.TenantEntity) HashMap(java.util.HashMap) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) PermissionsDTO(org.apache.nifi.web.api.dto.PermissionsDTO) TenantDTO(org.apache.nifi.web.api.dto.TenantDTO) UserDTO(org.apache.nifi.web.api.dto.UserDTO) AccessPolicySummaryDTO(org.apache.nifi.web.api.dto.AccessPolicySummaryDTO) AccessPolicySummaryEntity(org.apache.nifi.web.api.entity.AccessPolicySummaryEntity) UserEntity(org.apache.nifi.web.api.entity.UserEntity) Test(org.junit.Test)

Aggregations

AccessPolicySummaryDTO (org.apache.nifi.web.api.dto.AccessPolicySummaryDTO)2 PermissionsDTO (org.apache.nifi.web.api.dto.PermissionsDTO)2 HashMap (java.util.HashMap)1 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)1 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)1 TenantDTO (org.apache.nifi.web.api.dto.TenantDTO)1 UserDTO (org.apache.nifi.web.api.dto.UserDTO)1 AccessPolicySummaryEntity (org.apache.nifi.web.api.entity.AccessPolicySummaryEntity)1 ComponentReferenceEntity (org.apache.nifi.web.api.entity.ComponentReferenceEntity)1 TenantEntity (org.apache.nifi.web.api.entity.TenantEntity)1 UserEntity (org.apache.nifi.web.api.entity.UserEntity)1 Test (org.junit.Test)1