use of org.apache.nifi.web.api.entity.ProcessorEntity in project nifi by apache.
the class ITProcessorAccessControl method createSnippetWithRestrictedComponent.
private Tuple<ProcessorEntity, SnippetEntity> createSnippetWithRestrictedComponent(final String restrictedClassName, final NiFiTestUser user) throws Exception {
final String processorUrl = helper.getBaseUrl() + "/process-groups/root/processors";
final String snippetUrl = helper.getBaseUrl() + "/snippets";
// create the processor
ProcessorDTO processor = new ProcessorDTO();
processor.setName("restricted");
processor.setType(restrictedClassName);
// create the revision
final RevisionDTO revision = new RevisionDTO();
revision.setClientId(READ_WRITE_CLIENT_ID);
revision.setVersion(0L);
// create the entity body
ProcessorEntity entity = new ProcessorEntity();
entity.setRevision(revision);
entity.setComponent(processor);
// perform the request as a user with read/write and restricted access
Response response = user.testPost(processorUrl, entity);
// ensure the request is successful
assertEquals(201, response.getStatus());
// get the response
final ProcessorEntity responseProcessorEntity = response.readEntity(ProcessorEntity.class);
// build the snippet for the copy/paste
final SnippetDTO snippet = new SnippetDTO();
snippet.setParentGroupId(responseProcessorEntity.getComponent().getParentGroupId());
snippet.getProcessors().put(responseProcessorEntity.getId(), responseProcessorEntity.getRevision());
// create the entity body
final SnippetEntity snippetEntity = new SnippetEntity();
snippetEntity.setSnippet(snippet);
// create the snippet
response = helper.getNoneUser().testPost(snippetUrl, snippetEntity);
// ensure the request failed... need either read or write to create snippet (not sure what snippet will be used for)
assertEquals(403, response.getStatus());
// create the snippet
response = helper.getReadWriteUser().testPost(snippetUrl, snippetEntity);
// ensure the request is successful
assertEquals(201, response.getStatus());
// get the response
return new Tuple<>(responseProcessorEntity, response.readEntity(SnippetEntity.class));
}
use of org.apache.nifi.web.api.entity.ProcessorEntity in project nifi by apache.
the class ITProcessorAccessControl method testReadUserPutProcessor.
/**
* Ensures the READ user cannot put a processor.
*
* @throws Exception ex
*/
@Test
public void testReadUserPutProcessor() throws Exception {
final ProcessorEntity entity = getRandomProcessor(helper.getReadUser());
assertTrue(entity.getPermissions().getCanRead());
assertFalse(entity.getPermissions().getCanWrite());
assertNotNull(entity.getComponent());
// attempt update the name
entity.getRevision().setClientId(READ_CLIENT_ID);
entity.getComponent().setName("Updated Name");
// perform the request
final Response response = updateProcessor(helper.getReadUser(), entity);
// ensure forbidden response
assertEquals(403, response.getStatus());
}
use of org.apache.nifi.web.api.entity.ProcessorEntity in project nifi by apache.
the class ITProcessorAccessControl method getRandomProcessor.
private ProcessorEntity getRandomProcessor(final NiFiTestUser user) throws Exception {
final String url = helper.getBaseUrl() + "/flow/process-groups/root";
// get the processors
final Response response = user.testGet(url);
// ensure the response was successful
assertEquals(200, response.getStatus());
// unmarshal
final ProcessGroupFlowEntity flowEntity = response.readEntity(ProcessGroupFlowEntity.class);
final FlowDTO flowDto = flowEntity.getProcessGroupFlow().getFlow();
final Set<ProcessorEntity> processors = flowDto.getProcessors();
// ensure the correct number of processors
assertFalse(processors.isEmpty());
// use the first processor as the target
Iterator<ProcessorEntity> processorIter = processors.iterator();
assertTrue(processorIter.hasNext());
return processorIter.next();
}
use of org.apache.nifi.web.api.entity.ProcessorEntity in project nifi by apache.
the class ITProcessorAccessControl method copyPasteExecuteCodeRestrictedProcessor.
private void copyPasteExecuteCodeRestrictedProcessor(final NiFiTestUser user) throws Exception {
final String copyUrl = helper.getBaseUrl() + "/process-groups/root/snippet-instance";
final Tuple<ProcessorEntity, SnippetEntity> tuple = createSnippetWithRestrictedComponent(ExecuteCodeRestrictedProcessor.class.getName(), user);
final SnippetEntity snippetEntity = tuple.getValue();
// build the copy/paste request
final CopySnippetRequestEntity copyRequest = new CopySnippetRequestEntity();
copyRequest.setSnippetId(snippetEntity.getSnippet().getId());
copyRequest.setOriginX(0.0);
copyRequest.setOriginY(0.0);
// create the snippet
Response response = helper.getReadWriteUser().testPost(copyUrl, copyRequest);
// ensure the request failed... need privileged users since snippet comprised of the restricted components
assertEquals(403, response.getStatus());
// perform the request as a user with read/write and only execute code restricted access
response = user.testPost(copyUrl, copyRequest);
// ensure the request is successful
assertEquals(201, response.getStatus());
final FlowEntity flowEntity = response.readEntity(FlowEntity.class);
// remove the restricted processors
deleteRestrictedComponent(tuple.getKey(), user);
deleteRestrictedComponent(flowEntity.getFlow().getProcessors().stream().findFirst().orElse(null), user);
}
use of org.apache.nifi.web.api.entity.ProcessorEntity in project nifi by apache.
the class ITProcessorAccessControl method verifyDelete.
private void verifyDelete(final NiFiTestUser user, final String clientId, final int responseCode) throws Exception {
final ProcessorEntity entity = createProcessor(helper, "Copy");
// create the entity body
final Map<String, String> queryParams = new HashMap<>();
queryParams.put("version", String.valueOf(entity.getRevision().getVersion()));
queryParams.put("clientId", clientId);
// perform the request
Response response = user.testDelete(entity.getUri(), queryParams);
// ensure the request is failed with a forbidden status code
assertEquals(responseCode, response.getStatus());
}
Aggregations