Search in sources :

Example 6 with AuditService

use of org.apache.nifi.admin.service.AuditService in project nifi by apache.

the class TestRemoteProcessGroupAuditor method updateProcessGroupInputPortConfiguration.

@SuppressWarnings("unchecked")
private Collection<Action> updateProcessGroupInputPortConfiguration(RemoteProcessGroupPortDTO inputRPGPortDTO, RemoteGroupPort existingRPGPort) throws Throwable {
    final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();
    final RemoteProcessGroupAuditor auditor = new RemoteProcessGroupAuditor();
    final ProceedingJoinPoint joinPoint = mock(ProceedingJoinPoint.class);
    final String remoteProcessGroupId = "remote-process-group-id";
    inputRPGPortDTO.setId(remoteProcessGroupId);
    inputRPGPortDTO.setTargetId(remoteProcessGroupId);
    final String targetUrl = "http://localhost:8080/nifi";
    when(existingRPG.getIdentifier()).thenReturn(remoteProcessGroupId);
    when(existingRPG.getTargetUri()).thenReturn(targetUrl);
    final RemoteProcessGroupDAO remoteProcessGroupDAO = mock(RemoteProcessGroupDAO.class);
    when(remoteProcessGroupDAO.getRemoteProcessGroup(remoteProcessGroupId)).thenReturn(existingRPG);
    when(existingRPG.getInputPort(eq(inputRPGPortDTO.getId()))).thenReturn(existingRPGPort);
    // Setup updatedRPGPort mock based on inputRPGPortDTO.
    final RemoteGroupPort updatedRPGPort = mock(RemoteGroupPort.class);
    final String portName = existingRPGPort.getName();
    when(updatedRPGPort.getName()).thenReturn(portName);
    if (inputRPGPortDTO.isTransmitting() != null) {
        when(updatedRPGPort.isRunning()).thenReturn(inputRPGPortDTO.isTransmitting());
    }
    when(updatedRPGPort.getMaxConcurrentTasks()).thenReturn(inputRPGPortDTO.getConcurrentlySchedulableTaskCount());
    when(updatedRPGPort.isUseCompression()).thenReturn(inputRPGPortDTO.getUseCompression());
    final BatchSettingsDTO batchSettings = inputRPGPortDTO.getBatchSettings();
    if (batchSettings != null) {
        when(updatedRPGPort.getBatchCount()).thenReturn(batchSettings.getCount());
        when(updatedRPGPort.getBatchSize()).thenReturn(batchSettings.getSize());
        when(updatedRPGPort.getBatchDuration()).thenReturn(batchSettings.getDuration());
    }
    when(joinPoint.proceed()).thenReturn(updatedRPGPort);
    // Capture added actions so that those can be asserted later.
    final AuditService auditService = mock(AuditService.class);
    final AtomicReference<Collection<Action>> addedActions = new AtomicReference<>();
    doAnswer(invocation -> {
        Collection<Action> actions = invocation.getArgumentAt(0, Collection.class);
        addedActions.set(actions);
        return null;
    }).when(auditService).addActions(any());
    auditor.setAuditService(auditService);
    auditor.auditUpdateProcessGroupInputPortConfiguration(joinPoint, remoteProcessGroupId, inputRPGPortDTO, remoteProcessGroupDAO);
    final Collection<Action> actions = addedActions.get();
    // Assert common action values.
    if (actions != null) {
        actions.forEach(action -> {
            assertEquals(remoteProcessGroupId, action.getSourceId());
            assertEquals("user-id", action.getUserIdentity());
            assertEquals(targetUrl, ((RemoteProcessGroupDetails) action.getComponentDetails()).getUri());
            assertNotNull(action.getTimestamp());
        });
    }
    return actions;
}
Also used : BatchSettingsDTO(org.apache.nifi.web.api.dto.BatchSettingsDTO) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Action(org.apache.nifi.action.Action) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) AtomicReference(java.util.concurrent.atomic.AtomicReference) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Collection(java.util.Collection) RemoteProcessGroupDAO(org.apache.nifi.web.dao.RemoteProcessGroupDAO) AuditService(org.apache.nifi.admin.service.AuditService)

Example 7 with AuditService

use of org.apache.nifi.admin.service.AuditService 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

AuditService (org.apache.nifi.admin.service.AuditService)7 FlowFileEventRepository (org.apache.nifi.controller.repository.FlowFileEventRepository)4 BulletinRepository (org.apache.nifi.reporting.BulletinRepository)4 Before (org.junit.Before)4 HashMap (java.util.HashMap)3 MockPolicyBasedAuthorizer (org.apache.nifi.authorization.MockPolicyBasedAuthorizer)3 MockProvenanceRepository (org.apache.nifi.provenance.MockProvenanceRepository)3 FileBasedVariableRegistry (org.apache.nifi.registry.variable.FileBasedVariableRegistry)3 Collection (java.util.Collection)2 LinkedHashSet (java.util.LinkedHashSet)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Action (org.apache.nifi.action.Action)2 AccessPolicy (org.apache.nifi.authorization.AccessPolicy)2 AuthorizationRequest (org.apache.nifi.authorization.AuthorizationRequest)2 Authorizer (org.apache.nifi.authorization.Authorizer)2 Group (org.apache.nifi.authorization.Group)2 User (org.apache.nifi.authorization.User)2 FlowController (org.apache.nifi.controller.FlowController)2 StringEncryptor (org.apache.nifi.encrypt.StringEncryptor)2 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)2