Search in sources :

Example 51 with ResourceNotFoundException

use of org.apache.nifi.web.ResourceNotFoundException in project nifi by apache.

the class StandardControllerServiceDAO method getControllerServices.

@Override
public Set<ControllerServiceNode> getControllerServices(final String groupId, final boolean includeAncestorGroups, final boolean includeDescendantGroups) {
    if (groupId == null) {
        return flowController.getRootControllerServices();
    } else {
        final String searchId = groupId.equals(ROOT_GROUP_ID_ALIAS) ? flowController.getRootGroupId() : groupId;
        final ProcessGroup procGroup = flowController.getGroup(flowController.getRootGroupId()).findProcessGroup(searchId);
        if (procGroup == null) {
            throw new ResourceNotFoundException("Could not find Process Group with ID " + groupId);
        }
        final Set<ControllerServiceNode> serviceNodes = procGroup.getControllerServices(includeAncestorGroups);
        if (includeDescendantGroups) {
            serviceNodes.addAll(procGroup.findAllControllerServices());
        }
        return serviceNodes;
    }
}
Also used : ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException)

Example 52 with ResourceNotFoundException

use of org.apache.nifi.web.ResourceNotFoundException in project nifi by apache.

the class StandardInputPortDAO method locatePort.

private Port locatePort(final String portId) {
    final ProcessGroup rootGroup = flowController.getGroup(flowController.getRootGroupId());
    Port port = rootGroup.findInputPort(portId);
    if (port == null) {
        port = rootGroup.findOutputPort(portId);
    }
    if (port == null) {
        throw new ResourceNotFoundException(String.format("Unable to find port with id '%s'.", portId));
    } else {
        return port;
    }
}
Also used : Port(org.apache.nifi.connectable.Port) RootGroupPort(org.apache.nifi.remote.RootGroupPort) ProcessGroup(org.apache.nifi.groups.ProcessGroup) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException)

Example 53 with ResourceNotFoundException

use of org.apache.nifi.web.ResourceNotFoundException in project nifi by apache.

the class StandardOutputPortDAO method locatePort.

private Port locatePort(final String portId) {
    final ProcessGroup rootGroup = flowController.getGroup(flowController.getRootGroupId());
    final Port port = rootGroup.findOutputPort(portId);
    if (port == null) {
        throw new ResourceNotFoundException(String.format("Unable to find port with id '%s'.", portId));
    } else {
        return port;
    }
}
Also used : Port(org.apache.nifi.connectable.Port) RootGroupPort(org.apache.nifi.remote.RootGroupPort) ProcessGroup(org.apache.nifi.groups.ProcessGroup) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException)

Example 54 with ResourceNotFoundException

use of org.apache.nifi.web.ResourceNotFoundException in project nifi by apache.

the class StandardPolicyBasedAuthorizerDAO method deleteUser.

@Override
public User deleteUser(final String userId) {
    if (userGroupProvider instanceof ConfigurableUserGroupProvider) {
        final ConfigurableUserGroupProvider configurableUserGroupProvider = (ConfigurableUserGroupProvider) userGroupProvider;
        final User user = getUser(userId);
        final User removedUser = configurableUserGroupProvider.deleteUser(user);
        // ensure the user was removed
        if (removedUser == null) {
            throw new ResourceNotFoundException(String.format("Unable to find user with id '%s'.", userId));
        }
        // remove any references to the user being deleted from policies if possible
        if (accessPolicyProvider instanceof ConfigurableAccessPolicyProvider) {
            for (AccessPolicy policy : accessPolicyProvider.getAccessPolicies()) {
                final ConfigurableAccessPolicyProvider configurableAccessPolicyProvider = (ConfigurableAccessPolicyProvider) accessPolicyProvider;
                // ensure this policy contains a reference to the user and this policy is configurable (check proactively to prevent an exception)
                if (policy.getUsers().contains(removedUser.getIdentifier()) && configurableAccessPolicyProvider.isConfigurable(policy)) {
                    final AccessPolicy.Builder builder = new AccessPolicy.Builder(policy).removeUser(removedUser.getIdentifier());
                    configurableAccessPolicyProvider.updateAccessPolicy(builder.build());
                }
            }
        }
        return removedUser;
    } else {
        throw new IllegalStateException(MSG_NON_CONFIGURABLE_USERS);
    }
}
Also used : User(org.apache.nifi.authorization.User) ConfigurableUserGroupProvider(org.apache.nifi.authorization.ConfigurableUserGroupProvider) ConfigurableAccessPolicyProvider(org.apache.nifi.authorization.ConfigurableAccessPolicyProvider) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) AccessPolicy(org.apache.nifi.authorization.AccessPolicy)

Example 55 with ResourceNotFoundException

use of org.apache.nifi.web.ResourceNotFoundException in project nifi by apache.

the class StandardPolicyBasedAuthorizerDAO method deleteUserGroup.

@Override
public Group deleteUserGroup(final String userGroupId) {
    if (userGroupProvider instanceof ConfigurableUserGroupProvider) {
        final ConfigurableUserGroupProvider configurableUserGroupProvider = (ConfigurableUserGroupProvider) userGroupProvider;
        final Group group = getUserGroup(userGroupId);
        final Group removedGroup = configurableUserGroupProvider.deleteGroup(group);
        // ensure the user was removed
        if (removedGroup == null) {
            throw new ResourceNotFoundException(String.format("Unable to find user group with id '%s'.", removedGroup));
        }
        // remove any references to the user group being deleted from policies if possible
        if (accessPolicyProvider instanceof ConfigurableAccessPolicyProvider) {
            for (AccessPolicy policy : accessPolicyProvider.getAccessPolicies()) {
                final ConfigurableAccessPolicyProvider configurableAccessPolicyProvider = (ConfigurableAccessPolicyProvider) accessPolicyProvider;
                // ensure this policy contains a reference to the user group and this policy is configurable (check proactively to prevent an exception)
                if (policy.getGroups().contains(removedGroup.getIdentifier()) && configurableAccessPolicyProvider.isConfigurable(policy)) {
                    final AccessPolicy.Builder builder = new AccessPolicy.Builder(policy).removeGroup(removedGroup.getIdentifier());
                    configurableAccessPolicyProvider.updateAccessPolicy(builder.build());
                }
            }
        }
        return removedGroup;
    } else {
        throw new IllegalStateException(MSG_NON_CONFIGURABLE_USERS);
    }
}
Also used : Group(org.apache.nifi.authorization.Group) ConfigurableUserGroupProvider(org.apache.nifi.authorization.ConfigurableUserGroupProvider) ConfigurableAccessPolicyProvider(org.apache.nifi.authorization.ConfigurableAccessPolicyProvider) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) AccessPolicy(org.apache.nifi.authorization.AccessPolicy)

Aggregations

ResourceNotFoundException (org.apache.nifi.web.ResourceNotFoundException)59 ProcessGroup (org.apache.nifi.groups.ProcessGroup)22 Authorizable (org.apache.nifi.authorization.resource.Authorizable)16 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)16 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)12 Connection (org.apache.nifi.connectable.Connection)10 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)10 IOException (java.io.IOException)9 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)7 ApiOperation (io.swagger.annotations.ApiOperation)6 ApiResponses (io.swagger.annotations.ApiResponses)6 Consumes (javax.ws.rs.Consumes)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 AuthorizationResult (org.apache.nifi.authorization.AuthorizationResult)5 DataAuthorizable (org.apache.nifi.authorization.resource.DataAuthorizable)5 FlowFileQueue (org.apache.nifi.controller.queue.FlowFileQueue)5 ProcessGroupStatus (org.apache.nifi.controller.status.ProcessGroupStatus)5 RemoteProcessGroupStatus (org.apache.nifi.controller.status.RemoteProcessGroupStatus)5 HashMap (java.util.HashMap)4