use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType in project midpoint by Evolveum.
the class DependencyProcessor method determineProjectionWaveDeprovision.
private <F extends ObjectType> LensProjectionContext determineProjectionWaveDeprovision(LensContext<F> context, LensProjectionContext projectionContext, ResourceObjectTypeDependencyType inDependency, List<ResourceObjectTypeDependencyType> depPath) throws PolicyViolationException {
if (depPath == null) {
depPath = new ArrayList<ResourceObjectTypeDependencyType>();
}
int determinedWave = 0;
int determinedOrder = 0;
// This needs to go in the reverse. We need to figure out who depends on us.
for (DependencyAndSource ds : findReverseDependecies(context, projectionContext)) {
LensProjectionContext dependencySourceContext = ds.sourceProjectionContext;
ResourceObjectTypeDependencyType outDependency = ds.dependency;
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("DEP(rev): {}", outDependency);
}
if (inDependency != null && isHigerOrder(outDependency, inDependency)) {
// otherwise we can end up in endless loop even for legal dependencies.
continue;
}
checkForCircular(depPath, outDependency);
depPath.add(outDependency);
ResourceShadowDiscriminator refDiscr = new ResourceShadowDiscriminator(outDependency, projectionContext.getResource().getOid(), projectionContext.getKind());
dependencySourceContext = determineProjectionWave(context, dependencySourceContext, outDependency, depPath);
if (dependencySourceContext.getWave() + 1 > determinedWave) {
determinedWave = dependencySourceContext.getWave() + 1;
if (outDependency.getOrder() == null) {
determinedOrder = 0;
} else {
determinedOrder = outDependency.getOrder();
}
}
depPath.remove(outDependency);
}
LensProjectionContext resultAccountContext = projectionContext;
if (projectionContext.getWave() >= 0 && projectionContext.getWave() != determinedWave) {
// therefore there is a circular dependency. Therefore we need to create another context to split it.
if (!projectionContext.isDelete()) {
resultAccountContext = createAnotherContext(context, projectionContext, determinedOrder);
}
}
// LOGGER.trace("Wave for {}: {}", resultAccountContext.getResourceAccountType(), wave);
resultAccountContext.setWave(determinedWave);
return resultAccountContext;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType in project midpoint by Evolveum.
the class CredentialsProcessor method transformFocusExectionDelta.
/**
* Called from ChangeExecutor. Will modify the execution deltas to hash or remove credentials if needed.
*/
public <O extends ObjectType> ObjectDelta<O> transformFocusExectionDelta(LensContext<O> context, ObjectDelta<O> focusDelta) throws SchemaException, EncryptionException {
LensFocusContext<O> focusContext = context.getFocusContext();
SecurityPolicyType securityPolicy = focusContext.getSecurityPolicy();
if (securityPolicy == null) {
return focusDelta;
}
CredentialsPolicyType credsType = securityPolicy.getCredentials();
if (credsType == null) {
return focusDelta;
}
ObjectDelta<O> transformedDelta = focusDelta.clone();
transformFocusExectionDeltaCredential(context, credsType, credsType.getPassword(), SchemaConstants.PATH_PASSWORD_VALUE, transformedDelta);
return transformedDelta;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType in project midpoint by Evolveum.
the class SearchEvaluator method evaluate.
public <T extends ObjectType> PipelineData evaluate(SearchExpressionType searchExpression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
Validate.notNull(searchExpression.getType());
boolean noFetch = expressionHelper.getArgumentAsBoolean(searchExpression.getParameter(), PARAM_NO_FETCH, input, context, false, "search", globalResult);
@SuppressWarnings({ "unchecked", "raw" }) Class<T> objectClass = (Class<T>) ObjectTypes.getObjectTypeFromTypeQName(searchExpression.getType()).getClassDefinition();
ObjectQuery objectQuery = null;
if (searchExpression.getQuery() != null) {
try {
objectQuery = QueryJaxbConvertor.createObjectQuery(objectClass, searchExpression.getQuery(), prismContext);
} catch (SchemaException e) {
throw new ScriptExecutionException("Couldn't parse object query due to schema exception", e);
}
} else if (searchExpression.getSearchFilter() != null) {
// todo resolve variable references in the filter
objectQuery = new ObjectQuery();
try {
ObjectFilter filter = QueryConvertor.parseFilter(searchExpression.getSearchFilter(), objectClass, prismContext);
objectQuery.setFilter(filter);
} catch (SchemaException e) {
throw new ScriptExecutionException("Couldn't parse object filter due to schema exception", e);
}
}
final String variableName = searchExpression.getVariable();
final PipelineData oldVariableValue = variableName != null ? context.getVariable(variableName) : null;
final PipelineData outputData = PipelineData.createEmpty();
final MutableBoolean atLeastOne = new MutableBoolean(false);
ResultHandler<T> handler = (object, parentResult) -> {
context.checkTaskStop();
atLeastOne.setValue(true);
if (searchExpression.getScriptingExpression() != null) {
if (variableName != null) {
context.setVariable(variableName, PipelineData.create(object.getValue()));
}
JAXBElement<?> childExpression = searchExpression.getScriptingExpression();
try {
outputData.addAllFrom(scriptingExpressionEvaluator.evaluateExpression((ScriptingExpressionType) childExpression.getValue(), PipelineData.create(object.getValue()), context, globalResult));
globalResult.setSummarizeSuccesses(true);
globalResult.summarize();
} catch (ScriptExecutionException e) {
// todo think about this
if (context.isContinueOnAnyError()) {
LoggingUtils.logUnexpectedException(LOGGER, "Exception when evaluating item from search result list.", e);
} else {
throw new SystemException(e);
}
}
} else {
outputData.addValue(object.getValue());
}
return true;
};
try {
Collection<SelectorOptions<GetOperationOptions>> options = operationsHelper.createGetOptions(searchExpression.getOptions(), noFetch);
modelService.searchObjectsIterative(objectClass, objectQuery, handler, options, context.getTask(), globalResult);
} catch (SchemaException | ObjectNotFoundException | SecurityViolationException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
// TODO continue on any error?
throw new ScriptExecutionException("Couldn't execute searchObjects operation: " + e.getMessage(), e);
}
if (atLeastOne.isFalse()) {
String matching = objectQuery != null ? "matching " : "";
// temporary hack, this will be configurable
context.println("Warning: no " + matching + searchExpression.getType().getLocalPart() + " object found");
}
if (variableName != null) {
context.setVariable(variableName, oldVariableValue);
}
return outputData;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType in project midpoint by Evolveum.
the class AssignExecutor method execute.
@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
boolean raw = getParamRaw(expression, input, context, globalResult);
boolean dryRun = getParamDryRun(expression, input, context, globalResult);
ActionParameterValueType resourceParameterValue = expressionHelper.getArgument(expression.getParameter(), PARAM_RESOURCE, false, false, NAME);
ActionParameterValueType roleParameterValue = expressionHelper.getArgument(expression.getParameter(), PARAM_ROLE, false, false, NAME);
Collection<ObjectReferenceType> resources;
if (resourceParameterValue != null) {
PipelineData data = expressionHelper.evaluateParameter(resourceParameterValue, null, input, context, globalResult);
resources = data.getDataAsReferences(ResourceType.COMPLEX_TYPE);
} else {
resources = null;
}
Collection<ObjectReferenceType> roles;
if (roleParameterValue != null) {
PipelineData data = expressionHelper.evaluateParameter(roleParameterValue, null, input, context, globalResult);
roles = data.getDataAsReferences(RoleType.COMPLEX_TYPE);
} else {
roles = null;
}
if (resources == null && roles == null) {
throw new ScriptExecutionException("Nothing to assign: neither resource nor role specified");
}
for (PipelineItem item : input.getData()) {
PrismValue value = item.getValue();
OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
context.checkTaskStop();
if (value instanceof PrismObjectValue && ((PrismObjectValue) value).asObjectable() instanceof FocusType) {
PrismObject<? extends ObjectType> prismObject = ((PrismObjectValue) value).asPrismObject();
ObjectType objectType = prismObject.asObjectable();
long started = operationsHelper.recordStart(context, objectType);
Throwable exception = null;
try {
operationsHelper.applyDelta(createDelta(objectType, resources, roles), operationsHelper.createExecutionOptions(raw), dryRun, context, result);
operationsHelper.recordEnd(context, objectType, started, null);
} catch (Throwable ex) {
operationsHelper.recordEnd(context, objectType, started, ex);
exception = processActionException(ex, NAME, value, context);
}
context.println((exception != null ? "Attempted to modify " : "Modified ") + prismObject.toString() + rawDrySuffix(raw, dryRun) + exceptionSuffix(exception));
} else {
//noinspection ThrowableNotThrown
processActionException(new ScriptExecutionException("Item is not a PrismObject of FocusType"), NAME, value, context);
}
operationsHelper.trimAndCloneResult(result, globalResult, context);
}
// TODO updated objects?
return input;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType in project midpoint by Evolveum.
the class AssignExecutor method createDelta.
private ObjectDelta createDelta(ObjectType objectType, Collection<ObjectReferenceType> resources, Collection<ObjectReferenceType> roles) throws ScriptExecutionException {
List<AssignmentType> assignments = new ArrayList<>();
if (roles != null) {
for (ObjectReferenceType roleRef : roles) {
AssignmentType assignmentType = new AssignmentType();
assignmentType.setTargetRef(roleRef);
assignments.add(assignmentType);
}
}
if (resources != null) {
for (ObjectReferenceType resourceRef : resources) {
AssignmentType assignmentType = new AssignmentType();
ConstructionType constructionType = new ConstructionType();
constructionType.setResourceRef(resourceRef);
assignmentType.setConstruction(constructionType);
assignments.add(assignmentType);
}
}
ObjectDelta delta = ObjectDelta.createEmptyModifyDelta(objectType.getClass(), objectType.getOid(), prismContext);
try {
delta.addModificationAddContainer(FocusType.F_ASSIGNMENT, assignments.toArray(new AssignmentType[0]));
} catch (SchemaException e) {
throw new ScriptExecutionException("Couldn't prepare modification to add resource/role assignments", e);
}
return delta;
}
Aggregations