Search in sources :

Example 16 with AuthorizationAccessException

use of org.apache.nifi.authorization.exception.AuthorizationAccessException in project nifi by apache.

the class AbstractPolicyBasedAuthorizer method checkInheritability.

/**
 * Returns whether the proposed fingerprint is inheritable.
 *
 * @param proposedFingerprint the proposed fingerprint
 * @throws AuthorizationAccessException if there was an unexpected error performing the operation
 * @throws UninheritableAuthorizationsException if the proposed fingerprint was uninheritable
 */
@Override
public final void checkInheritability(String proposedFingerprint) throws AuthorizationAccessException, UninheritableAuthorizationsException {
    try {
        // ensure we understand the proposed fingerprint
        parsePoliciesUsersAndGroups(proposedFingerprint);
    } catch (final AuthorizationAccessException e) {
        throw new UninheritableAuthorizationsException("Unable to parse proposed fingerprint: " + e);
    }
    final List<User> users = getSortedUsers();
    final List<Group> groups = getSortedGroups();
    final List<AccessPolicy> accessPolicies = getSortedAccessPolicies();
    // ensure we're in a state to inherit
    if (!users.isEmpty() || !groups.isEmpty() || !accessPolicies.isEmpty()) {
        throw new UninheritableAuthorizationsException("Proposed fingerprint is not inheritable because the current Authorizations is not empty..");
    }
}
Also used : UninheritableAuthorizationsException(org.apache.nifi.authorization.exception.UninheritableAuthorizationsException) AuthorizationAccessException(org.apache.nifi.authorization.exception.AuthorizationAccessException)

Example 17 with AuthorizationAccessException

use of org.apache.nifi.authorization.exception.AuthorizationAccessException in project nifi-minifi by apache.

the class MiNiFiServer method start.

public void start() {
    try {
        logger.info("Loading Flow...");
        FlowFileEventRepository flowFileEventRepository = new RingBufferEventRepository(5);
        AuditService auditService = new StandardAuditService();
        Authorizer authorizer = new Authorizer() {

            @Override
            public AuthorizationResult authorize(AuthorizationRequest request) throws AuthorizationAccessException {
                return AuthorizationResult.approved();
            }

            @Override
            public void initialize(AuthorizerInitializationContext initializationContext) throws AuthorizerCreationException {
            // do nothing
            }

            @Override
            public void onConfigured(AuthorizerConfigurationContext configurationContext) throws AuthorizerCreationException {
            // do nothing
            }

            @Override
            public void preDestruction() throws AuthorizerDestructionException {
            // do nothing
            }
        };
        final String sensitivePropAlgorithmVal = props.getProperty(StringEncryptor.NF_SENSITIVE_PROPS_ALGORITHM);
        final String sensitivePropProviderVal = props.getProperty(StringEncryptor.NF_SENSITIVE_PROPS_PROVIDER);
        final String sensitivePropValueNifiPropVar = props.getProperty(StringEncryptor.NF_SENSITIVE_PROPS_KEY, DEFAULT_SENSITIVE_PROPS_KEY);
        StringEncryptor encryptor = StringEncryptor.createEncryptor(sensitivePropAlgorithmVal, sensitivePropProviderVal, sensitivePropValueNifiPropVar);
        VariableRegistry variableRegistry = new FileBasedVariableRegistry(props.getVariableRegistryPropertiesPaths());
        BulletinRepository bulletinRepository = new VolatileBulletinRepository();
        FlowController flowController = FlowController.createStandaloneInstance(flowFileEventRepository, props, authorizer, auditService, encryptor, bulletinRepository, variableRegistry, new StandardFlowRegistryClient());
        flowService = StandardFlowService.createStandaloneInstance(flowController, props, encryptor, // revision manager
        null, authorizer);
        // start and load the flow
        flowService.start();
        flowService.load(null);
        flowController.onFlowInitialized(true);
        flowController.getGroup(flowController.getRootGroupId()).startProcessing();
        this.flowController = flowController;
        logger.info("Flow loaded successfully.");
    } catch (Exception e) {
        // ensure the flow service is terminated
        if (flowService != null && flowService.isRunning()) {
            flowService.stop(false);
        }
        startUpFailure(new Exception("Unable to load flow due to: " + e, e));
    }
}
Also used : VolatileBulletinRepository(org.apache.nifi.events.VolatileBulletinRepository) VolatileBulletinRepository(org.apache.nifi.events.VolatileBulletinRepository) BulletinRepository(org.apache.nifi.reporting.BulletinRepository) AuthorizationRequest(org.apache.nifi.authorization.AuthorizationRequest) FileBasedVariableRegistry(org.apache.nifi.util.FileBasedVariableRegistry) VariableRegistry(org.apache.nifi.registry.VariableRegistry) StatusRequestException(org.apache.nifi.minifi.status.StatusRequestException) AuthorizerCreationException(org.apache.nifi.authorization.exception.AuthorizerCreationException) AuthorizerDestructionException(org.apache.nifi.authorization.exception.AuthorizerDestructionException) AuthorizationAccessException(org.apache.nifi.authorization.exception.AuthorizationAccessException) RingBufferEventRepository(org.apache.nifi.controller.repository.metrics.RingBufferEventRepository) FlowFileEventRepository(org.apache.nifi.controller.repository.FlowFileEventRepository) Authorizer(org.apache.nifi.authorization.Authorizer) StringEncryptor(org.apache.nifi.encrypt.StringEncryptor) FlowController(org.apache.nifi.controller.FlowController) AuthorizerInitializationContext(org.apache.nifi.authorization.AuthorizerInitializationContext) StandardFlowRegistryClient(org.apache.nifi.registry.flow.StandardFlowRegistryClient) StandardAuditService(org.apache.nifi.admin.service.impl.StandardAuditService) AuditService(org.apache.nifi.admin.service.AuditService) StandardAuditService(org.apache.nifi.admin.service.impl.StandardAuditService) AuthorizerConfigurationContext(org.apache.nifi.authorization.AuthorizerConfigurationContext) FileBasedVariableRegistry(org.apache.nifi.util.FileBasedVariableRegistry)

Aggregations

AuthorizationAccessException (org.apache.nifi.authorization.exception.AuthorizationAccessException)17 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 DocumentBuilder (javax.xml.parsers.DocumentBuilder)6 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 StringWriter (java.io.StringWriter)5 Document (org.w3c.dom.Document)5 Element (org.w3c.dom.Element)5 XMLStreamException (javax.xml.stream.XMLStreamException)4 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)4 AuthorizerCreationException (org.apache.nifi.authorization.exception.AuthorizerCreationException)4 Node (org.w3c.dom.Node)4 NodeList (org.w3c.dom.NodeList)4 SAXException (org.xml.sax.SAXException)4 KeyManagementException (java.security.KeyManagementException)2 KeyStoreException (java.security.KeyStoreException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 UnrecoverableKeyException (java.security.UnrecoverableKeyException)2 CertificateException (java.security.cert.CertificateException)2