use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method getLinkRefOid.
protected <F extends FocusType> String getLinkRefOid(PrismObject<F> focus, String resourceOid, ShadowKindType kind, String intent) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
F focusType = focus.asObjectable();
for (ObjectReferenceType linkRefType : focusType.getLinkRef()) {
String linkTargetOid = linkRefType.getOid();
assertFalse("No linkRef oid", StringUtils.isBlank(linkTargetOid));
PrismObject<ShadowType> account = getShadowModel(linkTargetOid, GetOperationOptions.createNoFetch(), false);
ShadowType shadowType = account.asObjectable();
if (kind != null && !kind.equals(shadowType.getKind())) {
continue;
}
if (!MiscUtil.equals(intent, shadowType.getIntent())) {
continue;
}
if (resourceOid.equals(shadowType.getResourceRef().getOid())) {
// This is noFetch. Therefore there is no fetchResult
return linkTargetOid;
}
}
AssertJUnit.fail("Linked shadow for resource " + resourceOid + ", kind " + kind + " and intent " + intent + " not found in " + focus);
// Never reached. But compiler complains about missing return
return null;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.
the class ProvisioningTestUtil method checkRepoShadow.
public static void checkRepoShadow(PrismObject<ShadowType> repoShadow, ShadowKindType kind, Integer expectedNumberOfAttributes) {
ShadowType repoShadowType = repoShadow.asObjectable();
assertNotNull("No OID in repo shadow " + repoShadow, repoShadowType.getOid());
assertNotNull("No name in repo shadow " + repoShadow, repoShadowType.getName());
assertNotNull("No objectClass in repo shadow " + repoShadow, repoShadowType.getObjectClass());
assertEquals("Wrong kind in repo shadow " + repoShadow, kind, repoShadowType.getKind());
PrismContainer<Containerable> attributesContainer = repoShadow.findContainer(ShadowType.F_ATTRIBUTES);
assertNotNull("No attributes in repo shadow " + repoShadow, attributesContainer);
Collection<Item<?, ?>> attributes = attributesContainer.getValue().getItems();
assertFalse("Empty attributes in repo shadow " + repoShadow, attributes.isEmpty());
if (expectedNumberOfAttributes != null) {
assertEquals("Unexpected number of attributes in repo shadow " + repoShadow, (int) expectedNumberOfAttributes, attributes.size());
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.
the class KindIntentFilterHelper method processEvent.
public boolean processEvent(Event event, BaseEventHandlerType eventHandlerConfig) {
if (eventHandlerConfig.getObjectKind().isEmpty() && eventHandlerConfig.getObjectIntent().isEmpty()) {
return true;
}
if (!(event instanceof ResourceObjectEvent)) {
// or should we return false?
return true;
}
ResourceObjectEvent resourceObjectEvent = (ResourceObjectEvent) event;
logStart(LOGGER, event, eventHandlerConfig, eventHandlerConfig.getStatus());
boolean retval = true;
if (!eventHandlerConfig.getObjectKind().isEmpty()) {
retval = false;
for (ShadowKindType shadowKindType : eventHandlerConfig.getObjectKind()) {
if (shadowKindType == null) {
LOGGER.warn("Filtering on null shadowKindType; filter = " + eventHandlerConfig);
} else if (resourceObjectEvent.isShadowKind(shadowKindType)) {
retval = true;
break;
}
}
}
if (retval) {
// now check the intent
if (!eventHandlerConfig.getObjectIntent().isEmpty()) {
retval = false;
for (String intent : eventHandlerConfig.getObjectIntent()) {
if (intent == null) {
LOGGER.warn("Filtering on null intent; filter = " + eventHandlerConfig);
} else if (resourceObjectEvent.isShadowIntent(intent)) {
retval = true;
break;
}
}
}
}
logEnd(LOGGER, event, eventHandlerConfig, retval);
return retval;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.
the class EntitlementConverter method collectEntitlementsAsObjectOperationDelete.
// endregion
// region Delete
// ///////
// DELETE
// ///////
/**
* This is somehow different that all the other methods. We are not following the content of a shadow or delta.
* We are following the definitions. This is to avoid the need to read the object that is going to be deleted.
* In fact, the object should not be there any more, but we still want to clean up entitlement membership
* based on the information from the shadow.
*
* @param <T> Type of the association (referencing) attribute
*/
<T> void collectEntitlementsAsObjectOperationDelete(Map<ResourceObjectDiscriminator, ResourceObjectOperations> roMap, PrismObject<ShadowType> subjectShadow, ProvisioningContext subjectCtx, OperationResult result) throws SchemaException, CommunicationException, ObjectNotFoundException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
ResourceObjectDefinition subjectDef = subjectCtx.getObjectDefinitionRequired();
Collection<ResourceAssociationDefinition> associationDefs = subjectDef.getAssociationDefinitions();
if (associationDefs.isEmpty()) {
LOGGER.trace("No associations in deleted shadow, nothing to do");
return;
}
ResourceAttributeContainer subjectAttributesContainer = ShadowUtil.getAttributesContainer(subjectShadow);
for (ResourceAssociationDefinition associationDef : associationDefs) {
if (associationDef.getDirection() != ResourceObjectAssociationDirectionType.OBJECT_TO_SUBJECT) {
// We can ignore these. They will die together with the object. No need to explicitly delete them.
LOGGER.trace("Ignoring subject-to-object association in deleted shadow");
continue;
}
if (!associationDef.requiresExplicitReferentialIntegrity()) {
LOGGER.trace("Ignoring association in deleted shadow because it does not require explicit" + " referential integrity assurance");
continue;
}
if (associationDef.getAuxiliaryObjectClass() != null && !subjectDef.hasAuxiliaryObjectClass(associationDef.getAuxiliaryObjectClass())) {
LOGGER.trace("Ignoring association in deleted shadow because subject does not have {} auxiliary object class", associationDef.getAuxiliaryObjectClass());
continue;
}
QName associationName = associationDef.getName();
ShadowKindType entitlementKind = associationDef.getKind();
for (String entitlementIntent : associationDef.getIntents()) {
// TODO deduplicate the code
// TODO error handling
ProvisioningContext entitlementCtx = subjectCtx.spawnForKindIntent(entitlementKind, entitlementIntent);
ResourceObjectDefinition entitlementDef = entitlementCtx.getObjectDefinitionRequired();
QName assocAttrName = associationDef.getDefinitionBean().getAssociationAttribute();
QName valueAttrName = associationDef.getDefinitionBean().getValueAttribute();
schemaCheck(assocAttrName != null, "No association attribute defined in entitlement association '%s' in %s", associationName, subjectCtx);
schemaCheck(valueAttrName != null, "No value attribute defined in entitlement association '%s' in %s", associationName, subjectCtx);
// noinspection unchecked
ResourceAttributeDefinition<T> assocAttrDef = (ResourceAttributeDefinition<T>) entitlementDef.findAttributeDefinitionRequired(assocAttrName, () -> " in entitlement association '" + associationName + "' in " + entitlementCtx + " [association attribute]");
final ResourceAttribute<T> valueAttr = subjectAttributesContainer.findAttribute(valueAttrName);
if (valueAttr == null || valueAttr.isEmpty()) {
// Although we cannot really remedy the situation now, we at least throw an error so the problem is detected.
throw new SchemaException("Value attribute " + valueAttrName + " has no value; attribute defined in entitlement " + "association '" + associationName + "' in " + subjectCtx);
}
if (valueAttr.size() > 1) {
throw new SchemaException("Value attribute " + valueAttrName + " has no more than one value; attribute defined" + " in entitlement association '" + associationName + "' in " + subjectCtx);
}
ResourceAttributeDefinition<T> valueAttrDef = valueAttr.getDefinition();
PrismPropertyValue<T> valueAttrValue = valueAttr.getAnyValue();
ObjectQuery query = createEntitlementQuery(valueAttrValue, valueAttrDef, assocAttrDef, associationDef);
AttributesToReturn attributesToReturn = ProvisioningUtil.createAttributesToReturn(entitlementCtx);
SearchHierarchyConstraints searchHierarchyConstraints = determineSearchHierarchyConstraints(entitlementCtx, result);
ObjectHandler handler = (ucfObject, lResult) -> {
PrismObject<ShadowType> entitlementShadow = ucfObject.getResourceObject();
Collection<? extends ResourceAttribute<?>> primaryIdentifiers = ShadowUtil.getPrimaryIdentifiers(entitlementShadow);
ResourceObjectDiscriminator disc = new ResourceObjectDiscriminator(entitlementDef.getTypeName(), primaryIdentifiers);
ResourceObjectOperations operations = roMap.get(disc);
if (operations == null) {
operations = new ResourceObjectOperations();
roMap.put(disc, operations);
operations.setResourceObjectContext(entitlementCtx);
Collection<? extends ResourceAttribute<?>> allIdentifiers = ShadowUtil.getAllIdentifiers(entitlementShadow);
operations.setAllIdentifiers(allIdentifiers);
}
PropertyDelta<T> attributeDelta = null;
for (Operation operation : operations.getOperations()) {
if (operation instanceof PropertyModificationOperation) {
PropertyModificationOperation<?> propOp = (PropertyModificationOperation<?>) operation;
if (propOp.getPropertyDelta().getElementName().equals(assocAttrName)) {
// noinspection unchecked
attributeDelta = (PropertyDelta<T>) propOp.getPropertyDelta();
}
}
}
if (attributeDelta == null) {
attributeDelta = assocAttrDef.createEmptyDelta(ItemPath.create(ShadowType.F_ATTRIBUTES, assocAttrName));
PropertyModificationOperation<?> attributeModification = new PropertyModificationOperation<>(attributeDelta);
attributeModification.setMatchingRuleQName(associationDef.getMatchingRule());
operations.add(attributeModification);
}
attributeDelta.addValuesToDelete(valueAttr.getClonedValues());
LOGGER.trace("Association in deleted shadow delta:\n{}", attributeDelta.debugDumpLazily());
return true;
};
try {
LOGGER.trace("Searching for associations in deleted shadow, query: {}", query);
ConnectorInstance connector = subjectCtx.getConnector(ReadCapabilityType.class, result);
connector.search(entitlementDef, query, handler, attributesToReturn, null, searchHierarchyConstraints, UcfFetchErrorReportingMethod.EXCEPTION, subjectCtx.getUcfExecutionContext(), result);
} catch (TunnelException e) {
throw (SchemaException) e.getCause();
} catch (GenericFrameworkException e) {
throw new GenericConnectorException(e.getMessage(), e);
}
}
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.
the class AssociationFromLinkExpressionEvaluator method selectMatchingShadows.
private void selectMatchingShadows(List<String> candidateShadowsOidList, PrismContainer<ShadowAssociationType> output, String resourceOid, ShadowKindType kind, String intent, QName assocName, ExpressionEvaluationContext context, OperationResult result) {
S_AtomicFilterExit filter = prismContext.queryFor(ShadowType.class).id(candidateShadowsOidList.toArray(new String[0])).and().item(ShadowType.F_RESOURCE_REF).ref(resourceOid).and().item(ShadowType.F_KIND).eq(kind);
if (intent != null) {
filter = filter.and().item(ShadowType.F_INTENT).eq(intent);
}
ObjectQuery query = filter.build();
try {
List<PrismObject<ShadowType>> objects = objectResolver.searchObjects(ShadowType.class, query, createNoFetchReadOnlyCollection(), context.getTask(), result);
for (PrismObject<ShadowType> object : objects) {
PrismContainerValue<ShadowAssociationType> newValue = output.createNewValue();
ShadowAssociationType shadowAssociationType = newValue.asContainerable();
shadowAssociationType.setName(assocName);
toAssociation(object, shadowAssociationType);
}
} catch (CommonException e) {
throw new SystemException("Couldn't search for relevant shadows: " + e.getMessage(), e);
}
}
Aggregations