use of org.apache.nifi.web.api.dto.AccessPolicyDTO in project nifi by apache.
the class StandardNiFiServiceFacade method updateAccessPolicy.
// -----------------------------------------
// Write Operations
// -----------------------------------------
@Override
public AccessPolicyEntity updateAccessPolicy(final Revision revision, final AccessPolicyDTO accessPolicyDTO) {
final Authorizable authorizable = authorizableLookup.getAccessPolicyById(accessPolicyDTO.getId());
final RevisionUpdate<AccessPolicyDTO> snapshot = updateComponent(revision, authorizable, () -> accessPolicyDAO.updateAccessPolicy(accessPolicyDTO), accessPolicy -> {
final Set<TenantEntity> users = accessPolicy.getUsers().stream().map(mapUserIdToTenantEntity()).collect(Collectors.toSet());
final Set<TenantEntity> userGroups = accessPolicy.getGroups().stream().map(mapUserGroupIdToTenantEntity()).collect(Collectors.toSet());
final ComponentReferenceEntity componentReference = createComponentReferenceEntity(accessPolicy.getResource());
return dtoFactory.createAccessPolicyDto(accessPolicy, userGroups, users, componentReference);
});
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(authorizable);
return entityFactory.createAccessPolicyEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions);
}
use of org.apache.nifi.web.api.dto.AccessPolicyDTO in project nifi by apache.
the class StandardNiFiServiceFacade method createAccessPolicy.
@Override
public AccessPolicyEntity createAccessPolicy(final Revision revision, final AccessPolicyDTO accessPolicyDTO) {
final Authorizable tenantAuthorizable = authorizableLookup.getTenant();
final String creator = NiFiUserUtils.getNiFiUserIdentity();
final AccessPolicy newAccessPolicy = accessPolicyDAO.createAccessPolicy(accessPolicyDTO);
final ComponentReferenceEntity componentReference = createComponentReferenceEntity(newAccessPolicy.getResource());
final AccessPolicyDTO newAccessPolicyDto = dtoFactory.createAccessPolicyDto(newAccessPolicy, newAccessPolicy.getGroups().stream().map(mapUserGroupIdToTenantEntity()).collect(Collectors.toSet()), newAccessPolicy.getUsers().stream().map(userId -> {
final RevisionDTO userRevision = dtoFactory.createRevisionDTO(revisionManager.getRevision(userId));
return entityFactory.createTenantEntity(dtoFactory.createTenantDTO(userDAO.getUser(userId)), userRevision, dtoFactory.createPermissionsDto(tenantAuthorizable));
}).collect(Collectors.toSet()), componentReference);
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(authorizableLookup.getAccessPolicyById(accessPolicyDTO.getId()));
return entityFactory.createAccessPolicyEntity(newAccessPolicyDto, dtoFactory.createRevisionDTO(new FlowModification(revision, creator)), permissions);
}
use of org.apache.nifi.web.api.dto.AccessPolicyDTO in project nifi by apache.
the class UserGroupEntityMergerTest 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 user1DTO = new TenantDTO();
user1DTO.setId("user-1");
final TenantEntity user1Entity = new TenantEntity();
user1Entity.setPermissions(permissed);
user1Entity.setId(user1DTO.getId());
user1Entity.setComponent(user1DTO);
final TenantDTO user2DTO = new TenantDTO();
user1DTO.setId("user-2");
final TenantEntity user2Entity = new TenantEntity();
user2Entity.setPermissions(permissed);
user2Entity.setId(user2DTO.getId());
user2Entity.setComponent(user2DTO);
final AccessPolicyDTO policy1DTO = new AccessPolicyDTO();
policy1DTO.setId("policy-1");
final AccessPolicyEntity policy1Entity = new AccessPolicyEntity();
policy1Entity.setPermissions(permissed);
policy1Entity.setId(policy1DTO.getId());
policy1Entity.setComponent(policy1DTO);
final AccessPolicyDTO policy2DTO = new AccessPolicyDTO();
policy2DTO.setId("policy-2");
final AccessPolicyEntity policy2Entity = new AccessPolicyEntity();
policy2Entity.setPermissions(permissed);
policy2Entity.setId(policy2DTO.getId());
policy2Entity.setComponent(policy2DTO);
final UserGroupDTO userGroup1DTO = new UserGroupDTO();
userGroup1DTO.setId("user-1");
userGroup1DTO.setAccessPolicies(Stream.of(policy1Entity, policy2Entity).collect(Collectors.toSet()));
userGroup1DTO.setUsers(Stream.of(user2Entity).collect(Collectors.toSet()));
final UserGroupEntity userGroup1Entity = new UserGroupEntity();
userGroup1Entity.setPermissions(permissed);
userGroup1Entity.setId(userGroup1DTO.getId());
userGroup1Entity.setComponent(userGroup1DTO);
final UserGroupDTO userGroup2DTO = new UserGroupDTO();
userGroup2DTO.setId("user-2");
userGroup2DTO.setAccessPolicies(Stream.of(policy1Entity).collect(Collectors.toSet()));
userGroup2DTO.setUsers(Stream.of(user1Entity, user2Entity).collect(Collectors.toSet()));
final UserGroupEntity userGroup2Entity = new UserGroupEntity();
userGroup2Entity.setPermissions(permissed);
userGroup2Entity.setId(userGroup2DTO.getId());
userGroup2Entity.setComponent(userGroup2DTO);
final Map<NodeIdentifier, UserGroupEntity> nodeMap = new HashMap<>();
nodeMap.put(node1, userGroup1Entity);
nodeMap.put(node2, userGroup2Entity);
final UserGroupEntityMerger merger = new UserGroupEntityMerger();
merger.merge(userGroup1Entity, nodeMap);
assertEquals(1, userGroup1DTO.getUsers().size());
assertTrue(userGroup1DTO.getAccessPolicies().contains(policy1Entity));
assertEquals(1, userGroup1DTO.getUsers().size());
assertTrue(userGroup1DTO.getUsers().contains(user2Entity));
}
use of org.apache.nifi.web.api.dto.AccessPolicyDTO in project nifi by apache.
the class StandardNiFiServiceFacade method deleteAccessPolicy.
@Override
public AccessPolicyEntity deleteAccessPolicy(final Revision revision, final String accessPolicyId) {
final AccessPolicy accessPolicy = accessPolicyDAO.getAccessPolicy(accessPolicyId);
final ComponentReferenceEntity componentReference = createComponentReferenceEntity(accessPolicy.getResource());
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(authorizableLookup.getAccessPolicyById(accessPolicyId));
final Set<TenantEntity> userGroups = accessPolicy != null ? accessPolicy.getGroups().stream().map(mapUserGroupIdToTenantEntity()).collect(Collectors.toSet()) : null;
final Set<TenantEntity> users = accessPolicy != null ? accessPolicy.getUsers().stream().map(mapUserIdToTenantEntity()).collect(Collectors.toSet()) : null;
final AccessPolicyDTO snapshot = deleteComponent(revision, new Resource() {
@Override
public String getIdentifier() {
return accessPolicy.getResource();
}
@Override
public String getName() {
return accessPolicy.getResource();
}
@Override
public String getSafeDescription() {
return "Policy " + accessPolicyId;
}
}, () -> accessPolicyDAO.deleteAccessPolicy(accessPolicyId), // no need to clean up any policies as it's already been removed above
false, dtoFactory.createAccessPolicyDto(accessPolicy, userGroups, users, componentReference));
return entityFactory.createAccessPolicyEntity(snapshot, null, permissions);
}
use of org.apache.nifi.web.api.dto.AccessPolicyDTO in project nifi by apache.
the class AccessPolicyEntityMerger method mergeComponents.
/**
* Merges the AccessPolicyEntity responses.
*
* @param clientEntity the entity being returned to the client
* @param entityMap all node responses
*/
public void mergeComponents(final AccessPolicyEntity clientEntity, final Map<NodeIdentifier, AccessPolicyEntity> entityMap) {
final AccessPolicyDTO clientDto = clientEntity.getComponent();
final Map<NodeIdentifier, AccessPolicyDTO> dtoMap = new HashMap<>();
for (final Map.Entry<NodeIdentifier, AccessPolicyEntity> entry : entityMap.entrySet()) {
final AccessPolicyEntity nodeAccessPolicyEntity = entry.getValue();
final AccessPolicyDTO nodeAccessPolicyDto = nodeAccessPolicyEntity.getComponent();
dtoMap.put(entry.getKey(), nodeAccessPolicyDto);
}
mergeDtos(clientDto, dtoMap);
}
Aggregations