use of org.apache.nifi.action.Operation in project nifi by apache.
the class ProcessorAuditor method updateProcessorAdvice.
/**
* Audits the configuration of a single processor.
*
* @param proceedingJoinPoint join point
* @param processorDTO dto
* @param processorDAO dao
* @return node
* @throws Throwable ex
*/
@Around("within(org.apache.nifi.web.dao.ProcessorDAO+) && " + "execution(org.apache.nifi.controller.ProcessorNode updateProcessor(org.apache.nifi.web.api.dto.ProcessorDTO)) && " + "args(processorDTO) && " + "target(processorDAO)")
public ProcessorNode updateProcessorAdvice(ProceedingJoinPoint proceedingJoinPoint, ProcessorDTO processorDTO, ProcessorDAO processorDAO) throws Throwable {
// determine the initial values for each property/setting that's changing
ProcessorNode processor = processorDAO.getProcessor(processorDTO.getId());
final Map<String, String> values = extractConfiguredPropertyValues(processor, processorDTO);
final ScheduledState scheduledState = processor.getScheduledState();
// update the processor state
final ProcessorNode updatedProcessor = (ProcessorNode) proceedingJoinPoint.proceed();
// if no exceptions were thrown, add the processor action...
processor = processorDAO.getProcessor(updatedProcessor.getIdentifier());
// get the current user
NiFiUser user = NiFiUserUtils.getNiFiUser();
// ensure the user was found
if (user != null) {
// determine the updated values
Map<String, String> updatedValues = extractConfiguredPropertyValues(processor, processorDTO);
// create the processor details
FlowChangeExtensionDetails processorDetails = new FlowChangeExtensionDetails();
processorDetails.setType(processor.getComponentType());
// create a processor 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) {
// clear the value if this property is sensitive
final PropertyDescriptor propertyDescriptor = processor.getProcessor().getPropertyDescriptor(property);
if (propertyDescriptor != null && propertyDescriptor.isSensitive()) {
if (newValue != null) {
newValue = "********";
}
if (oldValue != null) {
oldValue = "********";
}
} else if (ANNOTATION_DATA.equals(property)) {
if (newValue != null) {
newValue = "<annotation data not shown>";
}
if (oldValue != null) {
oldValue = "<annotation data not shown>";
}
}
final FlowChangeConfigureDetails actionDetails = new FlowChangeConfigureDetails();
actionDetails.setName(property);
actionDetails.setValue(newValue);
actionDetails.setPreviousValue(oldValue);
// create a configuration action
FlowChangeAction configurationAction = new FlowChangeAction();
configurationAction.setUserIdentity(user.getIdentity());
configurationAction.setOperation(operation);
configurationAction.setTimestamp(actionTimestamp);
configurationAction.setSourceId(processor.getIdentifier());
configurationAction.setSourceName(processor.getName());
configurationAction.setSourceType(Component.Processor);
configurationAction.setComponentDetails(processorDetails);
configurationAction.setActionDetails(actionDetails);
actions.add(configurationAction);
}
}
// determine the new executing state
final ScheduledState updatedScheduledState = processor.getScheduledState();
// determine if the running state has changed and its not disabled
if (scheduledState != updatedScheduledState) {
// create a processor action
FlowChangeAction processorAction = new FlowChangeAction();
processorAction.setUserIdentity(user.getIdentity());
processorAction.setTimestamp(new Date());
processorAction.setSourceId(processor.getIdentifier());
processorAction.setSourceName(processor.getName());
processorAction.setSourceType(Component.Processor);
processorAction.setComponentDetails(processorDetails);
// set the operation accordingly
if (ScheduledState.RUNNING.equals(updatedScheduledState)) {
processorAction.setOperation(Operation.Start);
} else if (ScheduledState.DISABLED.equals(updatedScheduledState)) {
processorAction.setOperation(Operation.Disable);
} else {
// state is now stopped... consider the previous state
if (ScheduledState.RUNNING.equals(scheduledState)) {
processorAction.setOperation(Operation.Stop);
} else if (ScheduledState.DISABLED.equals(scheduledState)) {
processorAction.setOperation(Operation.Enable);
}
}
actions.add(processorAction);
}
// ensure there are actions to record
if (!actions.isEmpty()) {
// save the actions
saveActions(actions, logger);
}
}
return updatedProcessor;
}
use of org.apache.nifi.action.Operation in project nifi by apache.
the class ReportingTaskAuditor method updateReportingTaskAdvice.
/**
* Audits the configuration of a reporting task.
*
* @param proceedingJoinPoint joinpoint
* @param reportingTaskDTO dto
* @param reportingTaskDAO dao
* @return object
* @throws Throwable ex
*/
@Around("within(org.apache.nifi.web.dao.ReportingTaskDAO+) && " + "execution(org.apache.nifi.controller.ReportingTaskNode updateReportingTask(org.apache.nifi.web.api.dto.ReportingTaskDTO)) && " + "args(reportingTaskDTO) && " + "target(reportingTaskDAO)")
public Object updateReportingTaskAdvice(ProceedingJoinPoint proceedingJoinPoint, ReportingTaskDTO reportingTaskDTO, ReportingTaskDAO reportingTaskDAO) throws Throwable {
// determine the initial values for each property/setting thats changing
ReportingTaskNode reportingTask = reportingTaskDAO.getReportingTask(reportingTaskDTO.getId());
final Map<String, String> values = extractConfiguredPropertyValues(reportingTask, reportingTaskDTO);
final ScheduledState scheduledState = reportingTask.getScheduledState();
// update the reporting task state
final ReportingTaskNode updatedReportingTask = (ReportingTaskNode) proceedingJoinPoint.proceed();
// if no exceptions were thrown, add the reporting task action...
reportingTask = reportingTaskDAO.getReportingTask(updatedReportingTask.getIdentifier());
// get the current user
final NiFiUser user = NiFiUserUtils.getNiFiUser();
// ensure the user was found
if (user != null) {
// determine the updated values
Map<String, String> updatedValues = extractConfiguredPropertyValues(reportingTask, reportingTaskDTO);
// create the reporting task details
FlowChangeExtensionDetails taskDetails = new FlowChangeExtensionDetails();
taskDetails.setType(reportingTask.getComponentType());
// create a reporting task 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) {
// clear the value if this property is sensitive
final PropertyDescriptor propertyDescriptor = reportingTask.getReportingTask().getPropertyDescriptor(property);
if (propertyDescriptor != null && propertyDescriptor.isSensitive()) {
if (newValue != null) {
newValue = "********";
}
if (oldValue != null) {
oldValue = "********";
}
} else if (ANNOTATION_DATA.equals(property)) {
if (newValue != null) {
newValue = "<annotation data not shown>";
}
if (oldValue != null) {
oldValue = "<annotation data not shown>";
}
}
final FlowChangeConfigureDetails actionDetails = new FlowChangeConfigureDetails();
actionDetails.setName(property);
actionDetails.setValue(newValue);
actionDetails.setPreviousValue(oldValue);
// create a configuration action
FlowChangeAction configurationAction = new FlowChangeAction();
configurationAction.setUserIdentity(user.getIdentity());
configurationAction.setOperation(operation);
configurationAction.setTimestamp(actionTimestamp);
configurationAction.setSourceId(reportingTask.getIdentifier());
configurationAction.setSourceName(reportingTask.getName());
configurationAction.setSourceType(Component.ReportingTask);
configurationAction.setComponentDetails(taskDetails);
configurationAction.setActionDetails(actionDetails);
actions.add(configurationAction);
}
}
// determine the new executing state
final ScheduledState updatedScheduledState = reportingTask.getScheduledState();
// determine if the running state has changed and its not disabled
if (scheduledState != updatedScheduledState) {
// create a reporting task action
FlowChangeAction taskAction = new FlowChangeAction();
taskAction.setUserIdentity(user.getIdentity());
taskAction.setTimestamp(new Date());
taskAction.setSourceId(reportingTask.getIdentifier());
taskAction.setSourceName(reportingTask.getName());
taskAction.setSourceType(Component.ReportingTask);
taskAction.setComponentDetails(taskDetails);
// set the operation accordingly
if (ScheduledState.RUNNING.equals(updatedScheduledState)) {
taskAction.setOperation(Operation.Start);
} else if (ScheduledState.DISABLED.equals(updatedScheduledState)) {
taskAction.setOperation(Operation.Disable);
} else {
// state is now stopped... consider the previous state
if (ScheduledState.RUNNING.equals(scheduledState)) {
taskAction.setOperation(Operation.Stop);
} else if (ScheduledState.DISABLED.equals(scheduledState)) {
taskAction.setOperation(Operation.Enable);
}
}
actions.add(taskAction);
}
// ensure there are actions to record
if (!actions.isEmpty()) {
// save the actions
saveActions(actions, logger);
}
}
return updatedReportingTask;
}
use of org.apache.nifi.action.Operation in project nifi by apache.
the class UserAuditor method updateUserAdvice.
/**
* Audits the configuration of a single user.
*
* @param proceedingJoinPoint join point
* @param userDTO dto
* @param userDAO dao
* @return node
* @throws Throwable ex
*/
@Around("within(org.apache.nifi.web.dao.UserDAO+) && " + "execution(org.apache.nifi.authorization.User updateUser(org.apache.nifi.web.api.dto.UserDTO)) && " + "args(userDTO) && " + "target(userDAO)")
public User updateUserAdvice(ProceedingJoinPoint proceedingJoinPoint, UserDTO userDTO, UserDAO userDAO) throws Throwable {
// determine the initial values for each property/setting that's changing
User user = userDAO.getUser(userDTO.getId());
final Map<String, String> values = extractConfiguredPropertyValues(user, userDTO);
// update the user state
final User updatedUser = (User) proceedingJoinPoint.proceed();
// if no exceptions were thrown, add the user action...
user = userDAO.getUser(updatedUser.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, userDTO);
// 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.getIdentity());
configurationAction.setSourceType(Component.User);
configurationAction.setActionDetails(actionDetails);
actions.add(configurationAction);
}
}
// ensure there are actions to record
if (!actions.isEmpty()) {
// save the actions
saveActions(actions, logger);
}
}
return updatedUser;
}
use of org.apache.nifi.action.Operation in project nifi by apache.
the class StandardActionDAO method findActions.
@Override
public History findActions(HistoryQuery historyQuery) throws DataAccessException {
// get the sort column
String sortColumn = "ACTION_TIMESTAMP";
if (StringUtils.isNotBlank(historyQuery.getSortColumn())) {
String rawColumnName = historyQuery.getSortColumn();
if (!columnMap.containsKey(rawColumnName)) {
throw new IllegalArgumentException(String.format("Unrecognized column name '%s'.", rawColumnName));
}
sortColumn = columnMap.get(rawColumnName);
}
// get the sort order
String sortOrder = "desc";
if (StringUtils.isNotBlank(historyQuery.getSortOrder())) {
sortOrder = historyQuery.getSortOrder();
}
History actionResult = new History();
Collection<Action> actions = new ArrayList<>();
PreparedStatement statement = null;
ResultSet rs = null;
try {
List<String> where = new ArrayList<>();
// append the start time
if (historyQuery.getStartDate() != null) {
where.add("ACTION_TIMESTAMP >= ?");
}
// append the end time
if (historyQuery.getEndDate() != null) {
where.add("ACTION_TIMESTAMP <= ?");
}
// append the user id as necessary
if (historyQuery.getUserIdentity() != null) {
where.add("UPPER(IDENTITY) LIKE ?");
}
// append the source id as necessary
if (historyQuery.getSourceId() != null) {
where.add("SOURCE_ID = ?");
}
String sql = SELECT_ACTION_COUNT;
if (!where.isEmpty()) {
sql += " WHERE " + StringUtils.join(where, " AND ");
}
// get the total number of actions
statement = connection.prepareStatement(sql);
int paramIndex = 1;
// set the start date as necessary
if (historyQuery.getStartDate() != null) {
statement.setTimestamp(paramIndex++, new java.sql.Timestamp(historyQuery.getStartDate().getTime()));
}
// set the end date as necessary
if (historyQuery.getEndDate() != null) {
statement.setTimestamp(paramIndex++, new java.sql.Timestamp(historyQuery.getEndDate().getTime()));
}
// set the user id as necessary
if (historyQuery.getUserIdentity() != null) {
statement.setString(paramIndex++, "%" + historyQuery.getUserIdentity().toUpperCase() + "%");
}
// set the source id as necessary
if (historyQuery.getSourceId() != null) {
statement.setString(paramIndex, historyQuery.getSourceId());
}
// execute the statement
rs = statement.executeQuery();
// ensure there are results
if (rs.next()) {
actionResult.setTotal(rs.getInt("ACTION_COUNT"));
} else {
throw new DataAccessException("Unable to determine total action count.");
}
sql = SELECT_ACTIONS;
if (!where.isEmpty()) {
sql += " WHERE " + StringUtils.join(where, " AND ");
}
// append the sort criteria
sql += (" ORDER BY " + sortColumn + " " + sortOrder);
// append the offset and limit
sql += " LIMIT ? OFFSET ?";
// close the previous statement
statement.close();
// create the statement
statement = connection.prepareStatement(sql);
paramIndex = 1;
// set the start date as necessary
if (historyQuery.getStartDate() != null) {
statement.setTimestamp(paramIndex++, new java.sql.Timestamp(historyQuery.getStartDate().getTime()));
}
// set the end date as necessary
if (historyQuery.getEndDate() != null) {
statement.setTimestamp(paramIndex++, new java.sql.Timestamp(historyQuery.getEndDate().getTime()));
}
// set the user id as necessary
if (historyQuery.getUserIdentity() != null) {
statement.setString(paramIndex++, "%" + historyQuery.getUserIdentity().toUpperCase() + "%");
}
// set the source id as necessary
if (historyQuery.getSourceId() != null) {
statement.setString(paramIndex++, historyQuery.getSourceId());
}
// set the limit
statement.setInt(paramIndex++, historyQuery.getCount());
// set the offset according to the currented page calculated above
statement.setInt(paramIndex, historyQuery.getOffset());
// execute the query
rs = statement.executeQuery();
// create each corresponding action
while (rs.next()) {
final Integer actionId = rs.getInt("ID");
final Operation operation = Operation.valueOf(rs.getString("OPERATION"));
final Component component = Component.valueOf(rs.getString("SOURCE_TYPE"));
FlowChangeAction action = new FlowChangeAction();
action.setId(actionId);
action.setUserIdentity(rs.getString("IDENTITY"));
action.setOperation(Operation.valueOf(rs.getString("OPERATION")));
action.setTimestamp(new Date(rs.getTimestamp("ACTION_TIMESTAMP").getTime()));
action.setSourceId(rs.getString("SOURCE_ID"));
action.setSourceName(rs.getString("SOURCE_NAME"));
action.setSourceType(Component.valueOf(rs.getString("SOURCE_TYPE")));
// get the component details if appropriate
ComponentDetails componentDetails = null;
if (Component.Processor.equals(component) || Component.ControllerService.equals(component) || Component.ReportingTask.equals(component)) {
componentDetails = getExtensionDetails(actionId);
} else if (Component.RemoteProcessGroup.equals(component)) {
componentDetails = getRemoteProcessGroupDetails(actionId);
}
if (componentDetails != null) {
action.setComponentDetails(componentDetails);
}
// get the action details if appropriate
ActionDetails actionDetails = null;
if (Operation.Move.equals(operation)) {
actionDetails = getMoveDetails(actionId);
} else if (Operation.Configure.equals(operation)) {
actionDetails = getConfigureDetails(actionId);
} else if (Operation.Connect.equals(operation) || Operation.Disconnect.equals(operation)) {
actionDetails = getConnectDetails(actionId);
} else if (Operation.Purge.equals(operation)) {
actionDetails = getPurgeDetails(actionId);
}
// set the action details
if (actionDetails != null) {
action.setActionDetails(actionDetails);
}
// add the action
actions.add(action);
}
// populate the action result
actionResult.setActions(actions);
} catch (SQLException sqle) {
throw new DataAccessException(sqle);
} finally {
RepositoryUtils.closeQuietly(rs);
RepositoryUtils.closeQuietly(statement);
}
return actionResult;
}
use of org.apache.nifi.action.Operation in project nifi by apache.
the class AccessPolicyAuditor method updateAccessPolicyAdvice.
/**
* Audits the configuration of a single policy.
*
* @param proceedingJoinPoint join point
* @param accessPolicyDTO dto
* @param accessPolicyDAO dao
* @return node
* @throws Throwable ex
*/
@Around("within(org.apache.nifi.web.dao.AccessPolicyDAO+) && " + "execution(org.apache.nifi.authorization.AccessPolicy updateAccessPolicy(org.apache.nifi.web.api.dto.AccessPolicyDTO)) && " + "args(accessPolicyDTO) && " + "target(accessPolicyDAO)")
public AccessPolicy updateAccessPolicyAdvice(ProceedingJoinPoint proceedingJoinPoint, AccessPolicyDTO accessPolicyDTO, AccessPolicyDAO accessPolicyDAO) throws Throwable {
// determine the initial values for each property/setting that's changing
AccessPolicy accessPolicy = accessPolicyDAO.getAccessPolicy(accessPolicyDTO.getId());
final Map<String, String> values = extractConfiguredPropertyValues(accessPolicy, accessPolicyDTO);
// update the policy state
final AccessPolicy updatedAccessPolicy = (AccessPolicy) proceedingJoinPoint.proceed();
// if no exceptions were thrown, add the policy action...
accessPolicy = accessPolicyDAO.getAccessPolicy(updatedAccessPolicy.getIdentifier());
// get the current user
NiFiUser user = NiFiUserUtils.getNiFiUser();
// ensure the user was found
if (user != null) {
// determine the updated values
Map<String, String> updatedValues = extractConfiguredPropertyValues(accessPolicy, accessPolicyDTO);
// create a policy 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(user.getIdentity());
configurationAction.setOperation(operation);
configurationAction.setTimestamp(actionTimestamp);
configurationAction.setSourceId(accessPolicy.getIdentifier());
configurationAction.setSourceName(formatPolicyName(accessPolicy));
configurationAction.setSourceType(Component.AccessPolicy);
configurationAction.setActionDetails(actionDetails);
actions.add(configurationAction);
}
}
// ensure there are actions to record
if (!actions.isEmpty()) {
// save the actions
saveActions(actions, logger);
}
}
return updatedAccessPolicy;
}
Aggregations