use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class AbstractSecurityTest method assertDeleteDeny.
protected <O extends ObjectType> void assertDeleteDeny(Class<O> type, String oid, ModelExecuteOptions options) throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
Task task = taskManager.createTaskInstance(AbstractSecurityTest.class.getName() + ".assertDeleteDeny");
OperationResult result = task.getResult();
ObjectDelta<O> delta = ObjectDelta.createDeleteDelta(type, oid, prismContext);
try {
logAttempt("delete", type, oid, null);
modelService.executeChanges(MiscSchemaUtil.createCollection(delta), options, task, result);
failDeny("delete", type, oid, null);
} catch (SecurityViolationException e) {
// this is expected
logDeny("delete", type, oid, null);
result.computeStatus();
TestUtil.assertFailure(result);
} catch (ObjectNotFoundException e) {
// MID-3221
// still consider OK ... for now
logError("delete", type, oid, null);
result.computeStatus();
TestUtil.assertFailure(result);
}
}
use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class ResourceObjectReferenceResolver method fetchResourceObject.
public PrismObject<ShadowType> fetchResourceObject(ProvisioningContext ctx, Collection<? extends ResourceAttribute<?>> identifiers, AttributesToReturn attributesToReturn, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
ResourceType resource = ctx.getResource();
ConnectorInstance connector = ctx.getConnector(ReadCapabilityType.class, parentResult);
RefinedObjectClassDefinition objectClassDefinition = ctx.getObjectClassDefinition();
try {
if (!ResourceTypeUtil.isReadCapabilityEnabled(resource)) {
throw new UnsupportedOperationException("Resource does not support 'read' operation");
}
ResourceObjectIdentification identification = ResourceObjectIdentification.create(objectClassDefinition, identifiers);
identification = resolvePrimaryIdentifiers(ctx, identification, parentResult);
identification.validatePrimaryIdenfiers();
return connector.fetchObject(ShadowType.class, identification, attributesToReturn, ctx, parentResult);
} catch (ObjectNotFoundException e) {
parentResult.recordFatalError("Object not found. Identifiers: " + identifiers + ". Reason: " + e.getMessage(), e);
throw new ObjectNotFoundException("Object not found. identifiers=" + identifiers + ", objectclass=" + PrettyPrinter.prettyPrint(objectClassDefinition.getTypeName()) + ": " + e.getMessage(), e);
} catch (CommunicationException e) {
parentResult.recordFatalError("Error communication with the connector " + connector + ": " + e.getMessage(), e);
throw e;
} catch (GenericFrameworkException e) {
parentResult.recordFatalError("Generic error in the connector " + connector + ". Reason: " + e.getMessage(), e);
throw new GenericConnectorException("Generic error in the connector " + connector + ". Reason: " + e.getMessage(), e);
} catch (SchemaException ex) {
parentResult.recordFatalError("Can't get resource object, schema error: " + ex.getMessage(), ex);
throw ex;
} catch (ExpressionEvaluationException ex) {
parentResult.recordFatalError("Can't get resource object, expression error: " + ex.getMessage(), ex);
throw ex;
} catch (ConfigurationException e) {
parentResult.recordFatalError(e);
throw e;
}
}
use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class ResourceObjectReferenceResolver method resolve.
PrismObject<ShadowType> resolve(ProvisioningContext ctx, ResourceObjectReferenceType resourceObjectReference, QName objectClass, final String desc, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
if (resourceObjectReference == null) {
return null;
}
ObjectReferenceType shadowRef = resourceObjectReference.getShadowRef();
if (shadowRef != null && shadowRef.getOid() != null) {
if (resourceObjectReference.getResolutionFrequency() == null || resourceObjectReference.getResolutionFrequency() == ResourceObjectReferenceResolutionFrequencyType.ONCE) {
PrismObject<ShadowType> shadow = repositoryService.getObject(ShadowType.class, shadowRef.getOid(), null, result);
return shadow;
}
} else if (resourceObjectReference.getResolutionFrequency() == ResourceObjectReferenceResolutionFrequencyType.NEVER) {
throw new ObjectNotFoundException("No shadowRef OID in " + desc + " and resolution frequency set to NEVER");
}
if (resourceObjectReference.getObjectClass() != null) {
objectClass = resourceObjectReference.getObjectClass();
if (objectClass.getNamespaceURI() == null) {
objectClass = new QName(ResourceTypeUtil.getResourceNamespace(ctx.getResource()), objectClass.getLocalPart());
}
}
ProvisioningContext subctx = ctx.spawn(objectClass);
// Use "raw" definitions from the original schema to avoid endless loops
subctx.setUseRefinedDefinition(false);
subctx.assertDefinition();
ObjectQuery refQuery = QueryJaxbConvertor.createObjectQuery(ShadowType.class, resourceObjectReference.getFilter(), prismContext);
ObjectFilter baseFilter = ObjectQueryUtil.createResourceAndObjectClassFilter(ctx.getResource().getOid(), objectClass, prismContext);
ObjectFilter filter = AndFilter.createAnd(baseFilter, refQuery.getFilter());
ObjectQuery query = ObjectQuery.createObjectQuery(filter);
// TODO: implement "repo" search strategies
Collection<SelectorOptions<GetOperationOptions>> options = null;
final Holder<ShadowType> shadowHolder = new Holder<>();
ShadowHandler<ShadowType> handler = new ShadowHandler<ShadowType>() {
@Override
public boolean handle(ShadowType shadow) {
if (shadowHolder.getValue() != null) {
throw new IllegalStateException("More than one search results for " + desc);
}
shadowHolder.setValue(shadow);
return true;
}
};
shadowCache.searchObjectsIterative(subctx, query, options, handler, true, result);
// TODO: implement storage of OID (ONCE search frequency)
ShadowType shadowType = shadowHolder.getValue();
return shadowType == null ? null : shadowType.asPrismObject();
}
use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class ShadowManager method findOrAddShadowFromChangeGlobalContext.
public PrismObject<ShadowType> findOrAddShadowFromChangeGlobalContext(ProvisioningContext globalCtx, Change change, OperationResult parentResult) throws SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ObjectNotFoundException, ExpressionEvaluationException {
// Try to locate existing shadow in the repository
List<PrismObject<ShadowType>> accountList = searchShadowByIdenifiers(globalCtx, change, parentResult);
if (accountList.size() > 1) {
String message = "Found more than one shadow with the identifier " + change.getIdentifiers() + ".";
LOGGER.error(message);
parentResult.recordFatalError(message);
throw new IllegalArgumentException(message);
}
PrismObject<ShadowType> newShadow = null;
if (accountList.isEmpty()) {
if (change.getObjectDelta() == null || change.getObjectDelta().getChangeType() != ChangeType.DELETE) {
newShadow = createNewShadowFromChange(globalCtx, change, parentResult);
try {
ConstraintsChecker.onShadowAddOperation(newShadow.asObjectable());
String oid = repositoryService.addObject(newShadow, null, parentResult);
newShadow.setOid(oid);
if (change.getObjectDelta() != null && change.getObjectDelta().getOid() == null) {
change.getObjectDelta().setOid(oid);
}
} catch (ObjectAlreadyExistsException e) {
parentResult.recordFatalError("Can't add " + SchemaDebugUtil.prettyPrint(newShadow) + " to the repository. Reason: " + e.getMessage(), e);
throw new IllegalStateException(e.getMessage(), e);
}
LOGGER.debug("Added new shadow (from global change): {}", newShadow);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Added new shadow (from global change):\n{}", newShadow.debugDump());
}
}
} else {
// Account was found in repository
newShadow = accountList.get(0);
if (change.getObjectDelta() != null && change.getObjectDelta().getChangeType() == ChangeType.DELETE) {
Collection<? extends ItemDelta> deadDeltas = PropertyDelta.createModificationReplacePropertyCollection(ShadowType.F_DEAD, newShadow.getDefinition(), true);
try {
ConstraintsChecker.onShadowModifyOperation(deadDeltas);
repositoryService.modifyObject(ShadowType.class, newShadow.getOid(), deadDeltas, parentResult);
} catch (ObjectAlreadyExistsException e) {
parentResult.recordFatalError("Can't add " + SchemaDebugUtil.prettyPrint(newShadow) + " to the repository. Reason: " + e.getMessage(), e);
throw new IllegalStateException(e.getMessage(), e);
} catch (ObjectNotFoundException e) {
parentResult.recordWarning("Shadow " + SchemaDebugUtil.prettyPrint(newShadow) + " was probably deleted from the repository in the meantime. Exception: " + e.getMessage(), e);
return null;
}
}
}
return newShadow;
}
use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class ShadowManager method findOrAddShadowFromChange.
// beware, may return null if an shadow that was to be marked as DEAD, was deleted in the meantime
public PrismObject<ShadowType> findOrAddShadowFromChange(ProvisioningContext ctx, Change change, OperationResult parentResult) throws SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ObjectNotFoundException, ExpressionEvaluationException {
// Try to locate existing shadow in the repository
List<PrismObject<ShadowType>> accountList = searchShadowByIdenifiers(ctx, change, parentResult);
if (accountList.size() > 1) {
String message = "Found more than one shadow with the identifier " + change.getIdentifiers() + ".";
LOGGER.error(message);
parentResult.recordFatalError(message);
throw new IllegalArgumentException(message);
}
PrismObject<ShadowType> newShadow = null;
if (accountList.isEmpty()) {
if (change.getObjectDelta() == null || change.getObjectDelta().getChangeType() != ChangeType.DELETE) {
newShadow = createNewShadowFromChange(ctx, change, parentResult);
try {
ConstraintsChecker.onShadowAddOperation(newShadow.asObjectable());
String oid = repositoryService.addObject(newShadow, null, parentResult);
newShadow.setOid(oid);
if (change.getObjectDelta() != null && change.getObjectDelta().getOid() == null) {
change.getObjectDelta().setOid(oid);
}
} catch (ObjectAlreadyExistsException e) {
parentResult.recordFatalError("Can't add " + SchemaDebugUtil.prettyPrint(newShadow) + " to the repository. Reason: " + e.getMessage(), e);
throw new IllegalStateException(e.getMessage(), e);
}
LOGGER.debug("Added new shadow (from change): {}", newShadow);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Added new shadow (from change):\n{}", newShadow.debugDump());
}
}
} else {
// Account was found in repository
newShadow = accountList.get(0);
if (change.getObjectDelta() != null && change.getObjectDelta().getChangeType() == ChangeType.DELETE) {
Collection<? extends ItemDelta> deadDeltas = PropertyDelta.createModificationReplacePropertyCollection(ShadowType.F_DEAD, newShadow.getDefinition(), true);
try {
ConstraintsChecker.onShadowModifyOperation(deadDeltas);
repositoryService.modifyObject(ShadowType.class, newShadow.getOid(), deadDeltas, parentResult);
} catch (ObjectAlreadyExistsException e) {
parentResult.recordFatalError("Can't add " + SchemaDebugUtil.prettyPrint(newShadow) + " to the repository. Reason: " + e.getMessage(), e);
throw new IllegalStateException(e.getMessage(), e);
} catch (ObjectNotFoundException e) {
parentResult.recordWarning("Shadow " + SchemaDebugUtil.prettyPrint(newShadow) + " was probably deleted from the repository in the meantime. Exception: " + e.getMessage(), e);
return null;
}
}
}
return newShadow;
}
Aggregations