Search in sources :

Example 86 with NiFiUser

use of org.apache.nifi.authorization.user.NiFiUser in project nifi by apache.

the class RemoteProcessGroupAuditor method auditUpdateProcessGroupPortConfiguration.

private RemoteGroupPort auditUpdateProcessGroupPortConfiguration(ProceedingJoinPoint proceedingJoinPoint, RemoteProcessGroupPortDTO remoteProcessGroupPortDto, RemoteProcessGroup remoteProcessGroup, RemoteGroupPort remoteProcessGroupPort) throws Throwable {
    final Map<String, Object> previousValues = ConfigurationRecorder.capturePreviousValues(PORT_CONFIG_RECORDERS, remoteProcessGroupPort);
    // perform the underlying operation
    final RemoteGroupPort updatedRemoteProcessGroupPort = (RemoteGroupPort) proceedingJoinPoint.proceed();
    // get the current user
    NiFiUser user = NiFiUserUtils.getNiFiUser();
    if (user != null) {
        final Collection<ActionDetails> details = new ArrayList<>();
        // see if any property has changed
        ConfigurationRecorder.checkConfigured(PORT_CONFIG_RECORDERS, remoteProcessGroupPortDto, updatedRemoteProcessGroupPort, previousValues, details);
        final Date timestamp = new Date();
        final Collection<Action> actions = new ArrayList<>();
        // create the remote process group details
        final FlowChangeRemoteProcessGroupDetails remoteProcessGroupDetails = createFlowChangeDetails(remoteProcessGroup);
        // save the actions if necessary
        for (ActionDetails detail : details) {
            // create a configure action for each updated property
            FlowChangeAction remoteProcessGroupAction = createFlowChangeAction(user, timestamp, remoteProcessGroup, remoteProcessGroupDetails);
            remoteProcessGroupAction.setOperation(Operation.Configure);
            remoteProcessGroupAction.setActionDetails(detail);
            actions.add(remoteProcessGroupAction);
        }
        // ensure there are actions to record
        if (!actions.isEmpty()) {
            // save the actions
            saveActions(actions, logger);
        }
    }
    return updatedRemoteProcessGroupPort;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) ArrayList(java.util.ArrayList) FlowChangeRemoteProcessGroupDetails(org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails) Date(java.util.Date) ActionDetails(org.apache.nifi.action.details.ActionDetails) FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Example 87 with NiFiUser

use of org.apache.nifi.authorization.user.NiFiUser in project nifi by apache.

the class ReportingTaskAuditor method generateAuditRecord.

/**
 * Generates an audit record for the creation of a reporting task.
 *
 * @param reportingTask task
 * @param operation operation
 * @param actionDetails details
 * @return action
 */
public Action generateAuditRecord(ReportingTaskNode reportingTask, Operation operation, ActionDetails actionDetails) {
    FlowChangeAction action = null;
    // get the current user
    NiFiUser user = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (user != null) {
        // create the reporting task details
        FlowChangeExtensionDetails taskDetails = new FlowChangeExtensionDetails();
        taskDetails.setType(reportingTask.getComponentType());
        // create the reporting task action for adding this reporting task
        action = new FlowChangeAction();
        action.setUserIdentity(user.getIdentity());
        action.setOperation(operation);
        action.setTimestamp(new Date());
        action.setSourceId(reportingTask.getIdentifier());
        action.setSourceName(reportingTask.getName());
        action.setSourceType(Component.ReportingTask);
        action.setComponentDetails(taskDetails);
        if (actionDetails != null) {
            action.setActionDetails(actionDetails);
        }
    }
    return action;
}
Also used : NiFiUser(org.apache.nifi.authorization.user.NiFiUser) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) Date(java.util.Date) FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Example 88 with NiFiUser

use of org.apache.nifi.authorization.user.NiFiUser in project nifi by apache.

the class SnippetAuditor method generateAuditRecord.

/**
 * Generates an audit record for the creation of the specified funnel.
 */
private FlowChangeAction generateAuditRecord(String id, String name, Component type, Operation operation, Date timestamp) {
    FlowChangeAction action = null;
    // get the current user
    NiFiUser user = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (user != null) {
        // create the action for adding this funnel
        action = new FlowChangeAction();
        action.setUserIdentity(user.getIdentity());
        action.setOperation(operation);
        action.setTimestamp(timestamp);
        action.setSourceId(id);
        action.setSourceName(name);
        action.setSourceType(type);
    }
    return action;
}
Also used : NiFiUser(org.apache.nifi.authorization.user.NiFiUser) FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Example 89 with NiFiUser

use of org.apache.nifi.authorization.user.NiFiUser in project nifi by apache.

the class UserAuditor method generateAuditRecord.

/**
 * Generates an audit record for the creation of a user.
 *
 * @param user user
 * @param operation operation
 * @param actionDetails details
 * @return action
 */
public Action generateAuditRecord(User user, Operation operation, ActionDetails actionDetails) {
    FlowChangeAction action = null;
    // get the current user
    NiFiUser niFiUser = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (niFiUser != null) {
        // create the user action for adding this user
        action = new FlowChangeAction();
        action.setUserIdentity(niFiUser.getIdentity());
        action.setOperation(operation);
        action.setTimestamp(new Date());
        action.setSourceId(user.getIdentifier());
        action.setSourceName(user.getIdentity());
        action.setSourceType(Component.User);
        if (actionDetails != null) {
            action.setActionDetails(actionDetails);
        }
    }
    return action;
}
Also used : NiFiUser(org.apache.nifi.authorization.user.NiFiUser) Date(java.util.Date) FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Example 90 with NiFiUser

use of org.apache.nifi.authorization.user.NiFiUser in project nifi by apache.

the class UserGroupAuditor method updateUserAdvice.

/**
 * Audits the configuration of a single user.
 *
 * @param proceedingJoinPoint join point
 * @param userGroupDTO dto
 * @param userGroupDAO dao
 * @return node
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.UserGroupDAO+) && " + "execution(org.apache.nifi.authorization.Group updateUserGroup(org.apache.nifi.web.api.dto.UserGroupDTO)) && " + "args(userGroupDTO) && " + "target(userGroupDAO)")
public Group updateUserAdvice(ProceedingJoinPoint proceedingJoinPoint, UserGroupDTO userGroupDTO, UserGroupDAO userGroupDAO) throws Throwable {
    // determine the initial values for each property/setting that's changing
    Group user = userGroupDAO.getUserGroup(userGroupDTO.getId());
    final Map<String, String> values = extractConfiguredPropertyValues(user, userGroupDTO);
    // update the user state
    final Group updatedUserGroup = (Group) proceedingJoinPoint.proceed();
    // if no exceptions were thrown, add the user group action...
    user = userGroupDAO.getUserGroup(updatedUserGroup.getIdentifier());
    // get the current user
    NiFiUser niFiUser = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (niFiUser != null) {
        // determine the updated values
        Map<String, String> updatedValues = extractConfiguredPropertyValues(user, userGroupDTO);
        // create a user action
        Date actionTimestamp = new Date();
        Collection<Action> actions = new ArrayList<>();
        // go through each updated value
        for (String property : updatedValues.keySet()) {
            String newValue = updatedValues.get(property);
            String oldValue = values.get(property);
            Operation operation = null;
            // determine the type of operation
            if (oldValue == null || newValue == null || !newValue.equals(oldValue)) {
                operation = Operation.Configure;
            }
            // create a configuration action accordingly
            if (operation != null) {
                final FlowChangeConfigureDetails actionDetails = new FlowChangeConfigureDetails();
                actionDetails.setName(property);
                actionDetails.setValue(newValue);
                actionDetails.setPreviousValue(oldValue);
                // create a configuration action
                FlowChangeAction configurationAction = new FlowChangeAction();
                configurationAction.setUserIdentity(niFiUser.getIdentity());
                configurationAction.setOperation(operation);
                configurationAction.setTimestamp(actionTimestamp);
                configurationAction.setSourceId(user.getIdentifier());
                configurationAction.setSourceName(user.getName());
                configurationAction.setSourceType(Component.UserGroup);
                configurationAction.setActionDetails(actionDetails);
                actions.add(configurationAction);
            }
        }
        // ensure there are actions to record
        if (!actions.isEmpty()) {
            // save the actions
            saveActions(actions, logger);
        }
    }
    return updatedUserGroup;
}
Also used : Group(org.apache.nifi.authorization.Group) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) FlowChangeConfigureDetails(org.apache.nifi.action.details.FlowChangeConfigureDetails) ArrayList(java.util.ArrayList) Operation(org.apache.nifi.action.Operation) Date(java.util.Date) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Around(org.aspectj.lang.annotation.Around)

Aggregations

NiFiUser (org.apache.nifi.authorization.user.NiFiUser)127 Date (java.util.Date)47 FlowChangeAction (org.apache.nifi.action.FlowChangeAction)42 ArrayList (java.util.ArrayList)33 Authorizable (org.apache.nifi.authorization.resource.Authorizable)32 Action (org.apache.nifi.action.Action)29 HashMap (java.util.HashMap)27 Map (java.util.Map)26 AccessDeniedException (org.apache.nifi.authorization.AccessDeniedException)26 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)26 IOException (java.io.IOException)25 Set (java.util.Set)25 ScheduledState (org.apache.nifi.controller.ScheduledState)25 Collectors (java.util.stream.Collectors)24 UUID (java.util.UUID)23 ControllerServiceState (org.apache.nifi.controller.service.ControllerServiceState)22 AffectedComponentDTO (org.apache.nifi.web.api.dto.AffectedComponentDTO)22 DtoFactory (org.apache.nifi.web.api.dto.DtoFactory)22 AffectedComponentEntity (org.apache.nifi.web.api.entity.AffectedComponentEntity)22 ProcessorEntity (org.apache.nifi.web.api.entity.ProcessorEntity)22