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);
}
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));
}
}
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.");
}
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.");
}
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");
}
Aggregations