use of com.evolveum.midpoint.util.exception.ConfigurationException in project midpoint by Evolveum.
the class AbstractLdapHierarchyTest method reconcileAllUsers.
protected void reconcileAllUsers() throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
final Task task = createTask("reconcileAllUsers");
OperationResult result = task.getResult();
ResultHandler<UserType> handler = new ResultHandler<UserType>() {
@Override
public boolean handle(PrismObject<UserType> object, OperationResult parentResult) {
try {
display("reconciling " + object);
reconcileUser(object.getOid(), task, parentResult);
} catch (SchemaException | PolicyViolationException | ExpressionEvaluationException | ObjectNotFoundException | ObjectAlreadyExistsException | CommunicationException | ConfigurationException | SecurityViolationException e) {
throw new SystemException(e.getMessage(), e);
}
return true;
}
};
display("Reconciling all users");
modelService.searchObjectsIterative(UserType.class, null, handler, null, task, result);
}
use of com.evolveum.midpoint.util.exception.ConfigurationException in project midpoint by Evolveum.
the class Construction method resolveTarget.
private ResourceType resolveTarget(String sourceDescription, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
// SearchFilterType filter = targetRef.getFilter();
ExpressionVariables variables = Utils.getDefaultExpressionVariables(getFocusOdo().getNewObject().asObjectable(), null, null, null);
if (assignmentPathVariables == null) {
assignmentPathVariables = LensUtil.computeAssignmentPathVariables(getAssignmentPath());
}
Utils.addAssignmentPathVariables(assignmentPathVariables, variables);
LOGGER.info("Expression variables for filter evaluation: {}", variables);
ObjectFilter origFilter = QueryConvertor.parseFilter(getConstructionType().getResourceRef().getFilter(), ResourceType.class, getPrismContext());
LOGGER.info("Orig filter {}", origFilter);
ObjectFilter evaluatedFilter = ExpressionUtil.evaluateFilterExpressions(origFilter, variables, getMappingFactory().getExpressionFactory(), getPrismContext(), " evaluating resource filter expression ", task, result);
LOGGER.info("evaluatedFilter filter {}", evaluatedFilter);
if (evaluatedFilter == null) {
throw new SchemaException("The OID is null and filter could not be evaluated in assignment targetRef in " + getSource());
}
final Collection<PrismObject<ResourceType>> results = new ArrayList<>();
ResultHandler<ResourceType> handler = (object, parentResult) -> {
LOGGER.info("Found object {}", object);
return results.add(object);
};
getObjectResolver().searchIterative(ResourceType.class, ObjectQuery.createObjectQuery(evaluatedFilter), null, handler, task, result);
if (org.apache.commons.collections.CollectionUtils.isEmpty(results)) {
throw new IllegalArgumentException("Got no target from repository, filter:" + evaluatedFilter + ", class:" + ResourceType.class + " in " + sourceDescription);
}
if (results.size() > 1) {
throw new IllegalArgumentException("Got more than one target from repository, filter:" + evaluatedFilter + ", class:" + ResourceType.class + " in " + sourceDescription);
}
PrismObject<ResourceType> target = results.iterator().next();
// assignmentType.getTargetRef().setOid(target.getOid());
return target.asObjectable();
}
use of com.evolveum.midpoint.util.exception.ConfigurationException in project midpoint by Evolveum.
the class Clockwork method click.
public <F extends ObjectType> HookOperationMode click(LensContext<F> context, Task task, OperationResult result) throws SchemaException, PolicyViolationException, ExpressionEvaluationException, ObjectNotFoundException, ObjectAlreadyExistsException, CommunicationException, ConfigurationException, SecurityViolationException {
if (context.getDebugListener() == null) {
context.setDebugListener(debugListener);
}
try {
XMLGregorianCalendar now = clock.currentTimeXMLGregorianCalendar();
// We need to determine focus before auditing. Otherwise we will not know user
// for the accounts (unless there is a specific delta for it).
// This is ugly, but it is the easiest way now (TODO: cleanup).
contextLoader.determineFocusContext((LensContext<? extends FocusType>) context, result);
ModelState state = context.getState();
if (state == ModelState.INITIAL) {
if (debugListener != null) {
debugListener.beforeSync(context);
}
metadataManager.applyRequestMetadata(context, now, task, result);
context.getStats().setRequestTimestamp(now);
// We need to do this BEFORE projection. If we would do that after projection
// there will be secondary changes that are not part of the request.
audit(context, AuditEventStage.REQUEST, task, result);
}
boolean recompute = false;
if (!context.isFresh()) {
LOGGER.trace("Context is not fresh -- forcing cleanup and recomputation");
recompute = true;
} else if (context.getExecutionWave() > context.getProjectionWave()) {
// should not occur
LOGGER.warn("Execution wave is greater than projection wave -- forcing cleanup and recomputation");
recompute = true;
}
if (recompute) {
context.cleanup();
projector.project(context, "PROJECTOR (" + state + ")", task, result);
} else if (context.getExecutionWave() == context.getProjectionWave()) {
LOGGER.trace("Running projector for current execution wave");
projector.resume(context, "PROJECTOR (" + state + ")", task, result);
} else {
LOGGER.trace("Skipping projection because the context is fresh and projection for current wave has already run");
}
if (!context.isRequestAuthorized()) {
authorizeContextRequest(context, task, result);
}
LensUtil.traceContext(LOGGER, "CLOCKWORK (" + state + ")", "before processing", true, context, false);
if (InternalsConfig.consistencyChecks) {
try {
context.checkConsistence();
} catch (IllegalStateException e) {
throw new IllegalStateException(e.getMessage() + " in clockwork, state=" + state, e);
}
}
if (InternalsConfig.encryptionChecks && !ModelExecuteOptions.isNoCrypt(context.getOptions())) {
context.checkEncrypted();
}
switch(state) {
case INITIAL:
processInitialToPrimary(context, task, result);
break;
case PRIMARY:
processPrimaryToSecondary(context, task, result);
break;
case SECONDARY:
processSecondary(context, task, result);
break;
case FINAL:
HookOperationMode mode = processFinal(context, task, result);
if (debugListener != null) {
debugListener.afterSync(context);
}
return mode;
}
result.recomputeStatus();
result.cleanupResult();
return invokeHooks(context, task, result);
} catch (CommunicationException | ConfigurationException | ExpressionEvaluationException | ObjectNotFoundException | PolicyViolationException | SchemaException | SecurityViolationException | RuntimeException | ObjectAlreadyExistsException e) {
processClockworkException(context, e, task, result);
throw e;
}
}
use of com.evolveum.midpoint.util.exception.ConfigurationException in project midpoint by Evolveum.
the class SynchronizationServiceImpl method executeActions.
private <F extends FocusType> void executeActions(SynchronizationReactionType reactionDef, LensContext<F> context, SynchronizationSituation<F> situation, BeforeAfterType order, ResourceType resource, boolean logDebug, Task task, OperationResult parentResult) throws ConfigurationException, SchemaException {
for (SynchronizationActionType actionDef : reactionDef.getAction()) {
if ((actionDef.getOrder() == null && order == BeforeAfterType.BEFORE) || (actionDef.getOrder() != null && actionDef.getOrder() == order)) {
String handlerUri = actionDef.getHandlerUri();
if (handlerUri == null) {
handlerUri = actionDef.getRef();
}
if (handlerUri == null) {
LOGGER.error("Action definition in resource {} doesn't contain handler URI", resource);
throw new ConfigurationException("Action definition in resource " + resource + " doesn't contain handler URI");
}
Action action = actionManager.getActionInstance(handlerUri);
if (action == null) {
LOGGER.warn("Couldn't create action with uri '{}' in resource {}, skipping action.", new Object[] { handlerUri, resource });
continue;
}
// TODO: legacy userTemplate
Map<QName, Object> parameters = null;
if (actionDef.getParameters() != null) {
// TODO: process parameters
// parameters = actionDef.getParameters().getAny();
}
if (logDebug) {
LOGGER.debug("SYNCHRONIZATION: ACTION: Executing: {}.", new Object[] { action.getClass() });
} else {
LOGGER.trace("SYNCHRONIZATION: ACTION: Executing: {}.", new Object[] { action.getClass() });
}
action.handle(context, situation, parameters, task, parentResult);
}
}
}
use of com.evolveum.midpoint.util.exception.ConfigurationException in project midpoint by Evolveum.
the class SynchronizationServiceImpl method determineFocusClass.
private <F extends FocusType> Class<F> determineFocusClass(ObjectSynchronizationType synchronizationPolicy, ResourceType resource) throws ConfigurationException {
if (synchronizationPolicy == null) {
throw new IllegalStateException("synchronizationPolicy is null");
}
QName focusTypeQName = synchronizationPolicy.getFocusType();
if (focusTypeQName == null) {
return (Class<F>) UserType.class;
}
ObjectTypes objectType = ObjectTypes.getObjectTypeFromTypeQName(focusTypeQName);
if (objectType == null) {
throw new ConfigurationException("Unknown focus type " + focusTypeQName + " in synchronization policy in " + resource);
}
return (Class<F>) objectType.getClassDefinition();
}
Aggregations