Search in sources :

Example 1 with ComponentReferenceEntity

use of org.apache.nifi.web.api.entity.ComponentReferenceEntity 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);
}
Also used : TenantEntity(org.apache.nifi.web.api.entity.TenantEntity) ComponentReferenceEntity(org.apache.nifi.web.api.entity.ComponentReferenceEntity) PermissionsDTO(org.apache.nifi.web.api.dto.PermissionsDTO) Authorizable(org.apache.nifi.authorization.resource.Authorizable) AccessPolicyDTO(org.apache.nifi.web.api.dto.AccessPolicyDTO)

Example 2 with ComponentReferenceEntity

use of org.apache.nifi.web.api.entity.ComponentReferenceEntity in project nifi by apache.

the class StandardNiFiServiceFacade method createAccessPolicyEntity.

private AccessPolicyEntity createAccessPolicyEntity(final AccessPolicy accessPolicy) {
    final RevisionDTO revision = dtoFactory.createRevisionDTO(revisionManager.getRevision(accessPolicy.getIdentifier()));
    final PermissionsDTO permissions = dtoFactory.createPermissionsDto(authorizableLookup.getAccessPolicyById(accessPolicy.getIdentifier()));
    final ComponentReferenceEntity componentReference = createComponentReferenceEntity(accessPolicy.getResource());
    return entityFactory.createAccessPolicyEntity(dtoFactory.createAccessPolicyDto(accessPolicy, accessPolicy.getGroups().stream().map(mapUserGroupIdToTenantEntity()).collect(Collectors.toSet()), accessPolicy.getUsers().stream().map(mapUserIdToTenantEntity()).collect(Collectors.toSet()), componentReference), revision, permissions);
}
Also used : ComponentReferenceEntity(org.apache.nifi.web.api.entity.ComponentReferenceEntity) PermissionsDTO(org.apache.nifi.web.api.dto.PermissionsDTO) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO)

Example 3 with ComponentReferenceEntity

use of org.apache.nifi.web.api.entity.ComponentReferenceEntity in project nifi by apache.

the class StandardNiFiServiceFacade method createComponentReferenceEntity.

private ComponentReferenceEntity createComponentReferenceEntity(final String resource) {
    ComponentReferenceEntity componentReferenceEntity = null;
    try {
        // get the component authorizable
        Authorizable componentAuthorizable = authorizableLookup.getAuthorizableFromResource(resource);
        // get the underlying base authorizable for the component reference
        if (componentAuthorizable instanceof EnforcePolicyPermissionsThroughBaseResource) {
            componentAuthorizable = ((EnforcePolicyPermissionsThroughBaseResource) componentAuthorizable).getBaseAuthorizable();
        }
        final ComponentReferenceDTO componentReference = dtoFactory.createComponentReferenceDto(componentAuthorizable);
        if (componentReference != null) {
            final PermissionsDTO componentReferencePermissions = dtoFactory.createPermissionsDto(componentAuthorizable);
            final RevisionDTO componentReferenceRevision = dtoFactory.createRevisionDTO(revisionManager.getRevision(componentReference.getId()));
            componentReferenceEntity = entityFactory.createComponentReferenceEntity(componentReference, componentReferenceRevision, componentReferencePermissions);
        }
    } catch (final ResourceNotFoundException e) {
    // component not found for the specified resource
    }
    return componentReferenceEntity;
}
Also used : EnforcePolicyPermissionsThroughBaseResource(org.apache.nifi.authorization.resource.EnforcePolicyPermissionsThroughBaseResource) ComponentReferenceEntity(org.apache.nifi.web.api.entity.ComponentReferenceEntity) PermissionsDTO(org.apache.nifi.web.api.dto.PermissionsDTO) Authorizable(org.apache.nifi.authorization.resource.Authorizable) ComponentReferenceDTO(org.apache.nifi.web.api.dto.ComponentReferenceDTO) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO)

Example 4 with ComponentReferenceEntity

use of org.apache.nifi.web.api.entity.ComponentReferenceEntity 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 5 with ComponentReferenceEntity

use of org.apache.nifi.web.api.entity.ComponentReferenceEntity 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);
}
Also used : ComponentReferenceEntity(org.apache.nifi.web.api.entity.ComponentReferenceEntity) PermissionsDTO(org.apache.nifi.web.api.dto.PermissionsDTO) Authorizable(org.apache.nifi.authorization.resource.Authorizable) AccessPolicyDTO(org.apache.nifi.web.api.dto.AccessPolicyDTO) AccessPolicy(org.apache.nifi.authorization.AccessPolicy) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO)

Aggregations

ComponentReferenceEntity (org.apache.nifi.web.api.entity.ComponentReferenceEntity)7 PermissionsDTO (org.apache.nifi.web.api.dto.PermissionsDTO)6 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)4 Authorizable (org.apache.nifi.authorization.resource.Authorizable)3 AccessPolicyDTO (org.apache.nifi.web.api.dto.AccessPolicyDTO)3 AccessPolicy (org.apache.nifi.authorization.AccessPolicy)2 EnforcePolicyPermissionsThroughBaseResource (org.apache.nifi.authorization.resource.EnforcePolicyPermissionsThroughBaseResource)2 TenantEntity (org.apache.nifi.web.api.entity.TenantEntity)2 Resource (org.apache.nifi.authorization.Resource)1 AccessPolicySummaryDTO (org.apache.nifi.web.api.dto.AccessPolicySummaryDTO)1 ComponentReferenceDTO (org.apache.nifi.web.api.dto.ComponentReferenceDTO)1