Search in sources :

Example 16 with AccessDeniedException

use of org.apache.nifi.authorization.AccessDeniedException in project nifi by apache.

the class TestPartitionedWriteAheadEventStore method testGetSpecificEventIds.

@Test
public void testGetSpecificEventIds() throws IOException {
    final RepositoryConfiguration config = createConfig();
    final PartitionedWriteAheadEventStore store = new PartitionedWriteAheadEventStore(config, writerFactory, readerFactory, EventReporter.NO_OP, new EventFileManager());
    store.initialize();
    final int numEvents = 20;
    final List<ProvenanceEventRecord> events = new ArrayList<>(numEvents);
    for (int i = 0; i < numEvents; i++) {
        final ProvenanceEventRecord event = createEvent();
        store.addEvents(Collections.singleton(event));
        events.add(event);
    }
    final EventAuthorizer allowEvenNumberedEventIds = new EventAuthorizer() {

        @Override
        public boolean isAuthorized(final ProvenanceEventRecord event) {
            return event.getEventId() % 2 == 0L;
        }

        @Override
        public void authorize(ProvenanceEventRecord event) throws AccessDeniedException {
            if (!isAuthorized(event)) {
                throw new AccessDeniedException();
            }
        }
    };
    final List<Long> evenEventIds = new ArrayList<>();
    final List<Long> oddEventIds = new ArrayList<>();
    final List<Long> allEventIds = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        final Long id = Long.valueOf(i);
        allEventIds.add(id);
        if (i % 2 == 0) {
            evenEventIds.add(id);
        } else {
            oddEventIds.add(id);
        }
    }
    final List<ProvenanceEventRecord> storedEvents = store.getEvents(evenEventIds, allowEvenNumberedEventIds, EventTransformer.EMPTY_TRANSFORMER);
    assertEquals(numEvents / 2, storedEvents.size());
    for (int i = 0; i < storedEvents.size(); i++) {
        assertEquals(events.get(i * 2), storedEvents.get(i));
    }
    assertTrue(store.getEvents(oddEventIds, allowEvenNumberedEventIds, EventTransformer.EMPTY_TRANSFORMER).isEmpty());
    final List<ProvenanceEventRecord> allStoredEvents = store.getEvents(allEventIds, EventAuthorizer.GRANT_ALL, EventTransformer.EMPTY_TRANSFORMER);
    assertEquals(events, allStoredEvents);
}
Also used : AccessDeniedException(org.apache.nifi.authorization.AccessDeniedException) EventAuthorizer(org.apache.nifi.provenance.authorization.EventAuthorizer) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) StandardProvenanceEventRecord(org.apache.nifi.provenance.StandardProvenanceEventRecord) ArrayList(java.util.ArrayList) AtomicLong(java.util.concurrent.atomic.AtomicLong) RepositoryConfiguration(org.apache.nifi.provenance.RepositoryConfiguration) Test(org.junit.Test)

Example 17 with AccessDeniedException

use of org.apache.nifi.authorization.AccessDeniedException in project nifi by apache.

the class TestPartitionedWriteAheadEventStore method testGetEventsWithMinIdAndCountWithAuthorizer.

@Test
public void testGetEventsWithMinIdAndCountWithAuthorizer() throws IOException {
    final RepositoryConfiguration config = createConfig();
    final PartitionedWriteAheadEventStore store = new PartitionedWriteAheadEventStore(config, writerFactory, readerFactory, EventReporter.NO_OP, new EventFileManager());
    store.initialize();
    final int numEvents = 20;
    final List<ProvenanceEventRecord> events = new ArrayList<>(numEvents);
    for (int i = 0; i < numEvents; i++) {
        final ProvenanceEventRecord event = createEvent();
        store.addEvents(Collections.singleton(event));
        events.add(event);
    }
    final EventAuthorizer allowEventNumberedEventIds = new EventAuthorizer() {

        @Override
        public boolean isAuthorized(final ProvenanceEventRecord event) {
            return event.getEventId() % 2 == 0L;
        }

        @Override
        public void authorize(ProvenanceEventRecord event) throws AccessDeniedException {
            if (!isAuthorized(event)) {
                throw new AccessDeniedException();
            }
        }
    };
    final List<ProvenanceEventRecord> storedEvents = store.getEvents(0, 20, allowEventNumberedEventIds, EventTransformer.EMPTY_TRANSFORMER);
    assertEquals(numEvents / 2, storedEvents.size());
    for (int i = 0; i < storedEvents.size(); i++) {
        assertEquals(events.get(i * 2), storedEvents.get(i));
    }
}
Also used : AccessDeniedException(org.apache.nifi.authorization.AccessDeniedException) EventAuthorizer(org.apache.nifi.provenance.authorization.EventAuthorizer) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) StandardProvenanceEventRecord(org.apache.nifi.provenance.StandardProvenanceEventRecord) ArrayList(java.util.ArrayList) RepositoryConfiguration(org.apache.nifi.provenance.RepositoryConfiguration) Test(org.junit.Test)

Example 18 with AccessDeniedException

use of org.apache.nifi.authorization.AccessDeniedException in project nifi by apache.

the class VolatileProvenanceRepository method retrieveLineageSubmission.

@Override
public ComputeLineageSubmission retrieveLineageSubmission(String lineageIdentifier, final NiFiUser user) {
    final ComputeLineageSubmission submission = lineageSubmissionMap.get(lineageIdentifier);
    final String userId = submission.getSubmitterIdentity();
    if (user == null && userId == null) {
        return submission;
    }
    if (user == null) {
        throw new AccessDeniedException("Cannot retrieve Provenance Lineage Submission because no user id was provided in the lineage request.");
    }
    if (userId == null || userId.equals(user.getIdentity())) {
        return submission;
    }
    throw new AccessDeniedException("Cannot retrieve Provenance Lineage Submission because " + user.getIdentity() + " is not the user who submitted the request.");
}
Also used : AccessDeniedException(org.apache.nifi.authorization.AccessDeniedException) ComputeLineageSubmission(org.apache.nifi.provenance.lineage.ComputeLineageSubmission)

Example 19 with AccessDeniedException

use of org.apache.nifi.authorization.AccessDeniedException in project nifi by apache.

the class PersistentProvenanceRepository method retrieveQuerySubmission.

@Override
public QuerySubmission retrieveQuerySubmission(final String queryIdentifier, final NiFiUser user) {
    final QuerySubmission submission = querySubmissionMap.get(queryIdentifier);
    final String userId = submission.getSubmitterIdentity();
    if (user == null && userId == null) {
        return submission;
    }
    if (user == null) {
        throw new AccessDeniedException("Cannot retrieve Provenance Query Submission because no user id was provided in the provenance request.");
    }
    if (userId == null || userId.equals(user.getIdentity())) {
        return submission;
    }
    throw new AccessDeniedException("Cannot retrieve Provenance Query Submission because " + user.getIdentity() + " is not the user who submitted the request.");
}
Also used : AccessDeniedException(org.apache.nifi.authorization.AccessDeniedException) QuerySubmission(org.apache.nifi.provenance.search.QuerySubmission)

Example 20 with AccessDeniedException

use of org.apache.nifi.authorization.AccessDeniedException in project nifi by apache.

the class LuceneEventIndex method retrieveLineageSubmission.

@Override
public AsyncLineageSubmission retrieveLineageSubmission(final String lineageIdentifier, final NiFiUser user) {
    final AsyncLineageSubmission submission = lineageSubmissionMap.get(lineageIdentifier);
    final String userId = submission.getSubmitterIdentity();
    if (user == null && userId == null) {
        return submission;
    }
    if (user == null) {
        throw new AccessDeniedException("Cannot retrieve Provenance Lineage Submission because no user id was provided");
    }
    if (userId == null || userId.equals(user.getIdentity())) {
        return submission;
    }
    throw new AccessDeniedException("Cannot retrieve Provenance Lineage Submission because " + user.getIdentity() + " is not the user who submitted the request");
}
Also used : AccessDeniedException(org.apache.nifi.authorization.AccessDeniedException) AsyncLineageSubmission(org.apache.nifi.provenance.AsyncLineageSubmission)

Aggregations

AccessDeniedException (org.apache.nifi.authorization.AccessDeniedException)26 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)12 ApiOperation (io.swagger.annotations.ApiOperation)6 ApiResponses (io.swagger.annotations.ApiResponses)6 QuerySubmission (org.apache.nifi.provenance.search.QuerySubmission)6 Test (org.junit.Test)6 URI (java.net.URI)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Consumes (javax.ws.rs.Consumes)5 Produces (javax.ws.rs.Produces)5 ProvenanceEventRecord (org.apache.nifi.provenance.ProvenanceEventRecord)5 RepositoryConfiguration (org.apache.nifi.provenance.RepositoryConfiguration)5 StandardProvenanceEventRecord (org.apache.nifi.provenance.StandardProvenanceEventRecord)5 EventAuthorizer (org.apache.nifi.provenance.authorization.EventAuthorizer)5 IOException (java.io.IOException)4 Path (javax.ws.rs.Path)4 Collections (java.util.Collections)3 List (java.util.List)3 Map (java.util.Map)3