use of com.evolveum.midpoint.prism.PrismContainerValue in project midpoint by Evolveum.
the class CredentialPolicyEvaluator method createDeleteHistoryDeltasIfNeeded.
// TODO: generalize for other credentials
private <F extends FocusType> void createDeleteHistoryDeltasIfNeeded(int historyLength, int addedValues, PrismContainer<R> currentCredentialContainer) throws SchemaException {
PrismContainer<PasswordHistoryEntryType> historyEntries = currentCredentialContainer.findOrCreateContainer(PasswordType.F_HISTORY_ENTRY);
List<PrismContainerValue<PasswordHistoryEntryType>> historyEntryValues = historyEntries.getValues();
if (historyEntries.size() == 0) {
return;
}
// We need to delete one more entry than intuitively expected - because we are computing from the history entries
// in the old object. In the new object there will be one new history entry for the changed password.
int numberOfHistoryEntriesToDelete = historyEntries.size() - historyLength + addedValues + 1;
for (int i = 0; i < numberOfHistoryEntriesToDelete; i++) {
ContainerDelta<PasswordHistoryEntryType> deleteHistoryDelta = ContainerDelta.createModificationDelete(new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_HISTORY_ENTRY), UserType.class, prismContext, historyEntryValues.get(i).clone());
context.getFocusContext().swallowToSecondaryDelta(deleteHistoryDelta);
}
}
use of com.evolveum.midpoint.prism.PrismContainerValue in project midpoint by Evolveum.
the class UserProfileServiceImpl method initializePrincipalFromAssignments.
private void initializePrincipalFromAssignments(MidPointPrincipal principal, PrismObject<SystemConfigurationType> systemConfiguration) throws SchemaException {
UserType userType = principal.getUser();
Collection<Authorization> authorizations = principal.getAuthorities();
List<AdminGuiConfigurationType> adminGuiConfigurations = new ArrayList<>();
Task task = taskManager.createTaskInstance(UserProfileServiceImpl.class.getName() + ".initializePrincipalFromAssignments");
OperationResult result = task.getResult();
principal.setApplicableSecurityPolicy(securityHelper.locateSecurityPolicy(userType.asPrismObject(), systemConfiguration, task, result));
if (!userType.getAssignment().isEmpty()) {
LensContext<UserType> lensContext = new LensContextPlaceholder<>(userType.asPrismObject(), prismContext);
AssignmentEvaluator.Builder<UserType> builder = new AssignmentEvaluator.Builder<UserType>().repository(repositoryService).focusOdo(new ObjectDeltaObject<>(userType.asPrismObject(), null, userType.asPrismObject())).channel(null).objectResolver(objectResolver).systemObjectCache(systemObjectCache).prismContext(prismContext).mappingFactory(mappingFactory).mappingEvaluator(mappingEvaluator).activationComputer(activationComputer).now(clock.currentTimeXMLGregorianCalendar()).loginMode(true).lensContext(lensContext);
AssignmentEvaluator<UserType> assignmentEvaluator = builder.build();
try {
RepositoryCache.enter();
for (AssignmentType assignmentType : userType.getAssignment()) {
try {
ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>();
assignmentIdi.setItemOld(LensUtil.createAssignmentSingleValueContainerClone(assignmentType));
assignmentIdi.recompute();
EvaluatedAssignment<UserType> assignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, userType, userType.toString(), task, result);
if (assignment.isValid()) {
authorizations.addAll(assignment.getAuthorizations());
adminGuiConfigurations.addAll(assignment.getAdminGuiConfigurations());
}
for (EvaluatedAssignmentTarget target : assignment.getRoles().getNonNegativeValues()) {
if (target.getTarget() != null && target.getTarget().asObjectable() instanceof UserType && DeputyUtils.isDelegationPath(target.getAssignmentPath())) {
List<OtherPrivilegesLimitationType> limitations = DeputyUtils.extractLimitations(target.getAssignmentPath());
principal.addDelegatorWithOtherPrivilegesLimitations(new DelegatorWithOtherPrivilegesLimitations((UserType) target.getTarget().asObjectable(), limitations));
}
}
} catch (SchemaException e) {
LOGGER.error("Schema violation while processing assignment of {}: {}; assignment: {}", userType, e.getMessage(), assignmentType, e);
} catch (ObjectNotFoundException e) {
LOGGER.error("Object not found while processing assignment of {}: {}; assignment: {}", userType, e.getMessage(), assignmentType, e);
} catch (ExpressionEvaluationException e) {
LOGGER.error("Evaluation error while processing assignment of {}: {}; assignment: {}", userType, e.getMessage(), assignmentType, e);
} catch (PolicyViolationException e) {
LOGGER.error("Policy violation while processing assignment of {}: {}; assignment: {}", userType, e.getMessage(), assignmentType, e);
}
}
} finally {
RepositoryCache.exit();
}
}
if (userType.getAdminGuiConfiguration() != null) {
// config from the user object should go last (to be applied as the last one)
adminGuiConfigurations.add(userType.getAdminGuiConfiguration());
}
principal.setAdminGuiConfiguration(AdminGuiConfigTypeUtil.compileAdminGuiConfiguration(adminGuiConfigurations, systemConfiguration));
}
use of com.evolveum.midpoint.prism.PrismContainerValue in project midpoint by Evolveum.
the class FilterContentEvaluator method evaluate.
public PipelineData evaluate(FilterContentExpressionType expression, PipelineData input, ExecutionContext context, OperationResult result) throws ScriptExecutionException {
List<ItemPath> keep = convert(expression.getKeep());
List<ItemPath> remove = convert(expression.getRemove());
if (keep.isEmpty() && remove.isEmpty()) {
// nothing to do here
return input;
}
for (PipelineItem pipelineItem : input.getData()) {
PrismValue value = pipelineItem.getValue();
if (!(value instanceof PrismContainerValue)) {
String message = "In 'select' commands in keep/remove mode, we can act only on prism container values, not on " + value;
if (context.isContinueOnAnyError()) {
LOGGER.error(message);
} else {
throw new ScriptExecutionException(message);
}
} else {
PrismContainerValue<?> pcv = (PrismContainerValue) value;
if (!keep.isEmpty()) {
pcv.keepPaths(keep);
} else {
pcv.removePaths(remove);
}
}
}
return input;
}
use of com.evolveum.midpoint.prism.PrismContainerValue in project midpoint by Evolveum.
the class AddAssignmentAspect method getApprovalRequestsFromFocusModify.
private List<ApprovalRequest<AssignmentType>> getApprovalRequestsFromFocusModify(PcpAspectConfigurationType config, PrismObject<?> focusOld, ObjectDelta<? extends ObjectType> change, ModelContext<?> modelContext, Task taskFromModel, OperationResult result) {
LOGGER.trace("Relevant assignments in focus modify delta:");
List<ApprovalRequest<AssignmentType>> approvalRequestList = new ArrayList<>();
Iterator<? extends ItemDelta> deltaIterator = change.getModifications().iterator();
final ItemPath ASSIGNMENT_PATH = new ItemPath(FocusType.F_ASSIGNMENT);
while (deltaIterator.hasNext()) {
ItemDelta delta = deltaIterator.next();
if (!ASSIGNMENT_PATH.equivalent(delta.getPath())) {
continue;
}
if (delta.getValuesToAdd() != null && !delta.getValuesToAdd().isEmpty()) {
Iterator<PrismContainerValue<AssignmentType>> valueIterator = delta.getValuesToAdd().iterator();
while (valueIterator.hasNext()) {
PrismContainerValue<AssignmentType> assignmentValue = valueIterator.next();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Assignment to add = {}", assignmentValue.debugDump());
}
ApprovalRequest<AssignmentType> req = processAssignmentToAdd(config, assignmentValue, modelContext, taskFromModel, result);
if (req != null) {
approvalRequestList.add(req);
valueIterator.remove();
}
}
}
if (delta.getValuesToReplace() != null && !delta.getValuesToReplace().isEmpty()) {
Iterator<PrismContainerValue<AssignmentType>> valueIterator = delta.getValuesToReplace().iterator();
while (valueIterator.hasNext()) {
PrismContainerValue<AssignmentType> assignmentValue = valueIterator.next();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Assignment to replace = {}", assignmentValue.debugDump());
}
if (existsEquivalentValue(focusOld, assignmentValue)) {
continue;
}
ApprovalRequest<AssignmentType> req = processAssignmentToAdd(config, assignmentValue, modelContext, taskFromModel, result);
if (req != null) {
approvalRequestList.add(req);
valueIterator.remove();
}
}
}
// let's sanitize the delta
if (delta.getValuesToAdd() != null && delta.getValuesToAdd().isEmpty()) {
// empty set of values to add is an illegal state
delta.resetValuesToAdd();
}
if (delta.getValuesToAdd() == null && delta.getValuesToReplace() == null && delta.getValuesToDelete() == null) {
deltaIterator.remove();
}
}
return approvalRequestList;
}
Aggregations