use of com.evolveum.midpoint.util.exception.ConfigurationException in project midpoint by Evolveum.
the class ProjectionCredentialsProcessor method processProjectionPasswordMapping.
private <F extends FocusType> void processProjectionPasswordMapping(LensContext<F> context, final LensProjectionContext projCtx, final ValuePolicyType passwordPolicy, XMLGregorianCalendar now, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
LensFocusContext<F> focusContext = context.getFocusContext();
PrismObject<F> userNew = focusContext.getObjectNew();
if (userNew == null) {
// This must be a user delete or something similar. No point in proceeding
LOGGER.trace("userNew is null, skipping credentials processing");
return;
}
PrismObjectDefinition<ShadowType> accountDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ShadowType.class);
PrismPropertyDefinition<ProtectedStringType> projPasswordPropertyDefinition = accountDefinition.findPropertyDefinition(SchemaConstants.PATH_PASSWORD_VALUE);
ResourceShadowDiscriminator rsd = projCtx.getResourceShadowDiscriminator();
RefinedObjectClassDefinition refinedProjDef = projCtx.getStructuralObjectClassDefinition();
if (refinedProjDef == null) {
LOGGER.trace("No RefinedObjectClassDefinition, therefore also no password outbound definition, skipping credentials processing for projection {}", rsd);
return;
}
List<MappingType> outboundMappingTypes = refinedProjDef.getPasswordOutbound();
if (outboundMappingTypes == null || outboundMappingTypes.isEmpty()) {
LOGGER.trace("No outbound password mapping for {}, skipping credentials processing", rsd);
return;
}
// HACK
if (!projCtx.isDoReconciliation() && !projCtx.isAdd() && !isActivated(outboundMappingTypes, focusContext.getDelta())) {
LOGGER.trace("Outbound password mappings not activated for type {}, skipping credentials processing", rsd);
return;
}
final ObjectDelta<ShadowType> projDelta = projCtx.getDelta();
final PropertyDelta<ProtectedStringType> projPasswordDelta;
if (projDelta != null && projDelta.getChangeType() == MODIFY) {
projPasswordDelta = projDelta.findPropertyDelta(SchemaConstants.PATH_PASSWORD_VALUE);
} else {
projPasswordDelta = null;
}
checkExistingDeltaSanity(projCtx, projPasswordDelta);
boolean evaluateWeak = getEvaluateWeak(projCtx);
final ItemDeltaItem<PrismPropertyValue<PasswordType>, PrismPropertyDefinition<ProtectedStringType>> userPasswordIdi = focusContext.getObjectDeltaObject().findIdi(SchemaConstants.PATH_PASSWORD_VALUE);
StringPolicyResolver stringPolicyResolver = new StringPolicyResolver() {
@Override
public void setOutputPath(ItemPath outputPath) {
}
@Override
public void setOutputDefinition(ItemDefinition outputDefinition) {
}
@Override
public StringPolicyType resolve() {
if (passwordPolicy == null) {
return null;
}
return passwordPolicy.getStringPolicy();
}
};
MappingInitializer<PrismPropertyValue<ProtectedStringType>, PrismPropertyDefinition<ProtectedStringType>> initializer = (builder) -> {
builder.defaultTargetDefinition(projPasswordPropertyDefinition);
builder.defaultSource(new Source<>(userPasswordIdi, ExpressionConstants.VAR_INPUT));
builder.stringPolicyResolver(stringPolicyResolver);
return builder;
};
MappingOutputProcessor<PrismPropertyValue<ProtectedStringType>> processor = (mappingOutputPath, outputStruct) -> {
PrismValueDeltaSetTriple<PrismPropertyValue<ProtectedStringType>> outputTriple = outputStruct.getOutputTriple();
if (outputTriple == null) {
LOGGER.trace("Credentials 'password' expression resulted in null output triple, skipping credentials processing for {}", rsd);
return false;
}
boolean projectionIsNew = projDelta != null && (projDelta.getChangeType() == ChangeType.ADD || projCtx.getSynchronizationPolicyDecision() == SynchronizationPolicyDecision.ADD);
Collection<PrismPropertyValue<ProtectedStringType>> newValues = outputTriple.getPlusSet();
if (projectionIsNew) {
newValues = outputTriple.getNonNegativeValues();
} else {
newValues = outputTriple.getPlusSet();
}
if (!canGetCleartext(newValues)) {
ObjectDelta<ShadowType> projectionPrimaryDelta = projCtx.getPrimaryDelta();
if (projectionPrimaryDelta != null) {
PropertyDelta<ProtectedStringType> passwordPrimaryDelta = projectionPrimaryDelta.findPropertyDelta(SchemaConstants.PATH_PASSWORD_VALUE);
if (passwordPrimaryDelta != null) {
// We have only hashed value coming from the mapping. There are not very useful
// for provisioning. But we have primary projection delta - and that is very likely
// to be better.
// Skip all password mappings in this case. Primary delta trumps everything.
// No weak, normal or even strong mapping can change that.
// We need to disregard even strong mapping in this case. If we would heed the strong
// mapping then account initialization won't be possible.
LOGGER.trace("We have primary password delta in projection, skipping credentials processing");
return false;
}
}
}
return true;
};
mappingEvaluator.evaluateOutboundMapping(context, projCtx, outboundMappingTypes, SchemaConstants.PATH_PASSWORD_VALUE, SchemaConstants.PATH_PASSWORD_VALUE, initializer, processor, now, true, evaluateWeak, "password mapping", task, result);
}
use of com.evolveum.midpoint.util.exception.ConfigurationException in project midpoint by Evolveum.
the class DiscoverConnectorsExecutor method rebindResources.
private void rebindResources(Map<String, String> rebindMap, ExecutionContext context, OperationResult result) throws ScriptExecutionException {
List<PrismObject<ResourceType>> resources;
try {
resources = modelService.searchObjects(ResourceType.class, null, null, null, result);
} catch (SchemaException | ConfigurationException | ObjectNotFoundException | CommunicationException | SecurityViolationException | ExpressionEvaluationException e) {
throw new ScriptExecutionException("Couldn't list resources: " + e.getMessage(), e);
}
for (PrismObject<ResourceType> resource : resources) {
if (resource.asObjectable().getConnectorRef() != null) {
String connectorOid = resource.asObjectable().getConnectorRef().getOid();
String newOid = rebindMap.get(connectorOid);
if (newOid != null) {
String msg = "resource " + resource + " from connector " + connectorOid + " to new one: " + newOid;
LOGGER.info("Rebinding " + msg);
ReferenceDelta refDelta = ReferenceDelta.createModificationReplace(ResourceType.F_CONNECTOR_REF, resource.getDefinition(), newOid);
ObjectDelta<ResourceType> objDelta = ObjectDelta.createModifyDelta(resource.getOid(), refDelta, ResourceType.class, prismContext);
operationsHelper.applyDelta(objDelta, context, result);
context.println("Rebound " + msg);
}
}
}
}
use of com.evolveum.midpoint.util.exception.ConfigurationException in project midpoint by Evolveum.
the class ModelObjectResolver method getObject.
public <T extends ObjectType> T getObject(Class<T> clazz, String oid, Collection<SelectorOptions<GetOperationOptions>> options, Task task, OperationResult result) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
T objectType = null;
try {
PrismObject<T> object = null;
ObjectTypes.ObjectManager manager = ObjectTypes.getObjectManagerForClass(clazz);
final GetOperationOptions rootOptions = SelectorOptions.findRootOptions(options);
switch(manager) {
case PROVISIONING:
object = provisioning.getObject(clazz, oid, options, task, result);
if (object == null) {
throw new SystemException("Got null result from provisioning.getObject while looking for " + clazz.getSimpleName() + " with OID " + oid + "; using provisioning implementation " + provisioning.getClass().getName());
}
break;
case TASK_MANAGER:
object = taskManager.getObject(clazz, oid, options, result);
if (object == null) {
throw new SystemException("Got null result from taskManager.getObject while looking for " + clazz.getSimpleName() + " with OID " + oid + "; using task manager implementation " + taskManager.getClass().getName());
}
if (workflowManager != null && TaskType.class.isAssignableFrom(clazz) && !GetOperationOptions.isRaw(rootOptions) && !GetOperationOptions.isNoFetch(rootOptions)) {
workflowManager.augmentTaskObject(object, options, task, result);
}
break;
default:
object = cacheRepositoryService.getObject(clazz, oid, options, result);
if (object == null) {
throw new SystemException("Got null result from repository.getObject while looking for " + clazz.getSimpleName() + " with OID " + oid + "; using repository implementation " + cacheRepositoryService.getClass().getName());
}
}
objectType = object.asObjectable();
if (!clazz.isInstance(objectType)) {
throw new ObjectNotFoundException("Bad object type returned for referenced oid '" + oid + "'. Expected '" + clazz + "', but was '" + (objectType == null ? "null" : objectType.getClass()) + "'.");
}
if (hookRegistry != null) {
for (ReadHook hook : hookRegistry.getAllReadHooks()) {
hook.invoke(object, options, task, result);
}
}
} catch (SystemException | ObjectNotFoundException | CommunicationException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException ex) {
result.recordFatalError(ex);
throw ex;
} catch (RuntimeException | Error ex) {
LoggingUtils.logException(LOGGER, "Error resolving object with oid {}, expected type was {}.", ex, oid, clazz);
throw new SystemException("Error resolving object with oid '" + oid + "': " + ex.getMessage(), ex);
} finally {
result.computeStatus();
}
return objectType;
}
use of com.evolveum.midpoint.util.exception.ConfigurationException in project midpoint by Evolveum.
the class ModelCrudService method modifyObject.
/**
* <p>
* Modifies object using relative change description.
* </p>
* <p>
* Must fail if user with provided OID does not exists. Must fail if any of
* the described changes cannot be applied. Should be atomic.
* </p>
* <p>
* If two or more modify operations are executed in parallel, the operations
* should be merged. In case that the operations are in conflict (e.g. one
* operation adding a value and the other removing the same value), the
* result is not deterministic.
* </p>
* <p>
* The operation may fail if the modified object does not conform to the
* underlying schema of the storage system or the schema enforced by the
* implementation.
* </p>
*
* @param parentResult
* parent OperationResult (in/out)
* @throws ObjectNotFoundException
* specified object does not exist
* @throws SchemaException
* resulting object would violate the schema
* @throws ExpressionEvaluationException
* evaluation of expression associated with the object has failed
* @throws CommunicationException
* @throws ObjectAlreadyExistsException
* If the account or another "secondary" object already exists and cannot be created
* @throws PolicyViolationException
* Policy violation was detected during processing of the object
* @throws IllegalArgumentException
* wrong OID format, described change is not applicable
* @throws SystemException
* unknown error from underlying layers or other unexpected
* state
*/
public <T extends ObjectType> void modifyObject(Class<T> type, String oid, Collection<? extends ItemDelta> modifications, ModelExecuteOptions options, Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, ObjectAlreadyExistsException, PolicyViolationException, SecurityViolationException {
Validate.notNull(modifications, "Object modification must not be null.");
Validate.notEmpty(oid, "Change oid must not be null or empty.");
Validate.notNull(parentResult, "Result type must not be null.");
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Modifying object with oid {}", oid);
LOGGER.trace(DebugUtil.debugDump(modifications));
}
if (modifications.isEmpty()) {
LOGGER.warn("Calling modifyObject with empty modificaiton set");
return;
}
ItemDelta.checkConsistence(modifications, ConsistencyCheckScope.THOROUGH);
// TODO: check definitions, but tolerate missing definitions in <attributes>
OperationResult result = parentResult.createSubresult(MODIFY_OBJECT);
result.addCollectionOfSerializablesAsParam("modifications", modifications);
RepositoryCache.enter();
try {
ObjectDelta<T> objectDelta = (ObjectDelta<T>) ObjectDelta.createModifyDelta(oid, modifications, type, prismContext);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(objectDelta);
modelService.executeChanges(deltas, options, task, result);
result.computeStatus();
} catch (ExpressionEvaluationException ex) {
LOGGER.error("model.modifyObject failed: {}", ex.getMessage(), ex);
result.recordFatalError(ex);
throw ex;
} catch (ObjectNotFoundException ex) {
LOGGER.error("model.modifyObject failed: {}", ex.getMessage(), ex);
result.recordFatalError(ex);
throw ex;
} catch (SchemaException ex) {
ModelUtils.recordFatalError(result, ex);
throw ex;
} catch (ConfigurationException ex) {
ModelUtils.recordFatalError(result, ex);
throw ex;
} catch (SecurityViolationException ex) {
ModelUtils.recordFatalError(result, ex);
throw ex;
} catch (RuntimeException ex) {
ModelUtils.recordFatalError(result, ex);
throw ex;
} finally {
RepositoryCache.exit();
}
}
use of com.evolveum.midpoint.util.exception.ConfigurationException in project midpoint by Evolveum.
the class OrgMemberPanel method deleteManagerConfirmPerformed.
private void deleteManagerConfirmPerformed(FocusType manager, AjaxRequestTarget target) {
getPageBase().hideMainPopup(target);
OperationResult parentResult = new OperationResult("Remove manager");
Task task = getPageBase().createSimpleTask("Remove manager");
try {
ObjectDelta delta = ObjectDelta.createDeleteDelta(manager.asPrismObject().getCompileTimeClass(), manager.getOid(), getPageBase().getPrismContext());
getPageBase().getModelService().executeChanges(WebComponentUtil.createDeltaCollection(delta), null, task, parentResult);
parentResult.computeStatus();
} catch (SchemaException | ObjectAlreadyExistsException | ObjectNotFoundException | ExpressionEvaluationException | CommunicationException | ConfigurationException | PolicyViolationException | SecurityViolationException e) {
parentResult.recordFatalError("Failed to remove manager " + e.getMessage(), e);
LoggingUtils.logUnexpectedException(LOGGER, "Failed to remove manager", e);
getPageBase().showResult(parentResult);
}
target.add(getPageBase().getFeedbackPanel());
}
Aggregations