use of org.apache.nifi.action.Action 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.Action in project nifi by apache.
the class UserGroupAuditor method removeUserAdvice.
/**
* Audits the removal of a user via deleteUser().
*
* @param proceedingJoinPoint join point
* @param userGroupId user id
* @param userGroupDAO dao
* @throws Throwable ex
*/
@Around("within(org.apache.nifi.web.dao.UserGroupDAO+) && " + "execution(org.apache.nifi.authorization.Group deleteUserGroup(java.lang.String)) && " + "args(userGroupId) && " + "target(userGroupDAO)")
public Group removeUserAdvice(ProceedingJoinPoint proceedingJoinPoint, String userGroupId, UserGroupDAO userGroupDAO) throws Throwable {
// get the user group before removing it
Group userGroup = userGroupDAO.getUserGroup(userGroupId);
// remove the user group
final Group removedUserGroup = (Group) proceedingJoinPoint.proceed();
// if no exceptions were thrown, add removal actions...
// audit the user removal
final Action action = generateAuditRecord(userGroup, Operation.Remove);
// save the actions
if (action != null) {
saveAction(action, logger);
}
return removedUserGroup;
}
use of org.apache.nifi.action.Action in project nifi by apache.
the class TestRemoteProcessGroupAuditor method testConfigureProxyPasswordClear.
@Test
public void testConfigureProxyPasswordClear() throws Throwable {
final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();
when(existingRPG.getProxyPassword()).thenReturn("proxy-password");
final RemoteProcessGroupDTO inputRPGDTO = defaultInput();
inputRPGDTO.setProxyPassword(null);
final Collection<Action> actions = updateProcessGroupConfiguration(inputRPGDTO, existingRPG);
assertEquals(1, actions.size());
final Action action = actions.iterator().next();
assertEquals(Operation.Configure, action.getOperation());
assertConfigureDetails(action.getActionDetails(), "Proxy Password", SENSITIVE_VALUE_MASK, "");
}
use of org.apache.nifi.action.Action in project nifi by apache.
the class TestRemoteProcessGroupAuditor method testConfigureProxyPort.
@Test
public void testConfigureProxyPort() throws Throwable {
final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();
final RemoteProcessGroupDTO inputRPGDTO = defaultInput();
inputRPGDTO.setProxyPort(3128);
final Collection<Action> actions = updateProcessGroupConfiguration(inputRPGDTO, existingRPG);
assertEquals(1, actions.size());
final Action action = actions.iterator().next();
assertEquals(Operation.Configure, action.getOperation());
assertConfigureDetails(action.getActionDetails(), "Proxy Port", existingRPG.getProxyPort(), inputRPGDTO.getProxyPort());
}
use of org.apache.nifi.action.Action in project nifi by apache.
the class TestRemoteProcessGroupAuditor method testConfigureTransportProtocol.
@Test
public void testConfigureTransportProtocol() throws Throwable {
final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();
when(existingRPG.getTransportProtocol()).thenReturn(SiteToSiteTransportProtocol.RAW);
final RemoteProcessGroupDTO inputRPGDTO = defaultInput();
inputRPGDTO.setTransportProtocol("HTTP");
final Collection<Action> actions = updateProcessGroupConfiguration(inputRPGDTO, existingRPG);
assertEquals(1, actions.size());
final Action action = actions.iterator().next();
assertEquals(Operation.Configure, action.getOperation());
assertConfigureDetails(action.getActionDetails(), "Transport Protocol", existingRPG.getTransportProtocol().name(), inputRPGDTO.getTransportProtocol());
}
Aggregations