use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class ShadowCreator method createRepositoryShadow.
/**
* Create a copy of a resource object (or another shadow) that is suitable for repository storage.
*/
@NotNull
PrismObject<ShadowType> createRepositoryShadow(ProvisioningContext ctx, PrismObject<ShadowType> resourceObjectOrShadow) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException, EncryptionException {
ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(resourceObjectOrShadow);
PrismObject<ShadowType> repoShadow = resourceObjectOrShadow.clone();
ShadowType repoShadowType = repoShadow.asObjectable();
ResourceAttributeContainer repoAttributesContainer = ShadowUtil.getAttributesContainer(repoShadow);
repoShadowType.setPrimaryIdentifierValue(helper.determinePrimaryIdentifierValue(ctx, resourceObjectOrShadow));
CachingStategyType cachingStrategy = ProvisioningUtil.getCachingStrategy(ctx);
if (cachingStrategy == CachingStategyType.NONE) {
// Clean all repoShadow attributes and add only those that should be there
repoAttributesContainer.clear();
Collection<ResourceAttribute<?>> primaryIdentifiers = attributesContainer.getPrimaryIdentifiers();
for (PrismProperty<?> p : primaryIdentifiers) {
repoAttributesContainer.add(p.clone());
}
Collection<ResourceAttribute<?>> secondaryIdentifiers = attributesContainer.getSecondaryIdentifiers();
for (PrismProperty<?> p : secondaryIdentifiers) {
repoAttributesContainer.add(p.clone());
}
// Also add all the attributes that act as association identifiers.
// We will need them when the shadow is deleted (to remove the shadow from entitlements).
ResourceObjectDefinition objectDefinition = ctx.getObjectDefinitionRequired();
for (ResourceAssociationDefinition associationDef : objectDefinition.getAssociationDefinitions()) {
if (associationDef.getDirection() == ResourceObjectAssociationDirectionType.OBJECT_TO_SUBJECT) {
QName valueAttributeName = associationDef.getDefinitionBean().getValueAttribute();
if (repoAttributesContainer.findAttribute(valueAttributeName) == null) {
ResourceAttribute<Object> valueAttribute = attributesContainer.findAttribute(valueAttributeName);
if (valueAttribute != null) {
repoAttributesContainer.add(valueAttribute.clone());
}
}
}
}
repoShadowType.setCachingMetadata(null);
ProvisioningUtil.cleanupShadowActivation(repoShadowType);
} else if (cachingStrategy == CachingStategyType.PASSIVE) {
// Do not need to clear anything. Just store all attributes and add metadata.
CachingMetadataType cachingMetadata = new CachingMetadataType();
cachingMetadata.setRetrievalTimestamp(clock.currentTimeXMLGregorianCalendar());
repoShadowType.setCachingMetadata(cachingMetadata);
} else {
throw new ConfigurationException("Unknown caching strategy " + cachingStrategy);
}
helper.setKindIfNecessary(repoShadowType, ctx);
// setIntentIfNecessary(repoShadowType, objectClassDefinition);
// Store only password meta-data in repo - unless there is explicit caching
CredentialsType creds = repoShadowType.getCredentials();
if (creds != null) {
PasswordType passwordType = creds.getPassword();
if (passwordType != null) {
preparePasswordForStorage(passwordType, ctx);
ObjectReferenceType owner = ctx.getTask() != null ? ctx.getTask().getOwnerRef() : null;
ProvisioningUtil.addPasswordMetadata(passwordType, clock.currentTimeXMLGregorianCalendar(), owner);
}
// TODO: other credential types - later
}
// now
if (repoShadowType.getResourceRef() == null) {
repoShadowType.setResourceRef(ObjectTypeUtil.createObjectRef(ctx.getResource(), prismContext));
}
if (repoShadowType.getName() == null) {
repoShadowType.setName(new PolyStringType(ShadowUtil.determineShadowName(resourceObjectOrShadow)));
}
if (repoShadowType.getObjectClass() == null) {
repoShadowType.setObjectClass(attributesContainer.getDefinition().getTypeName());
}
if (repoShadowType.isProtectedObject() != null) {
repoShadowType.setProtectedObject(null);
}
helper.normalizeAttributes(repoShadow, ctx.getObjectDefinitionRequired());
return repoShadow;
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class ShadowedObjectConstruction method getAssociationDefinition.
@NotNull
private ResourceAssociationDefinition getAssociationDefinition(QName associationName) throws SchemaException {
ResourceObjectDefinition objectDefinition = ctx.getObjectDefinitionRequired();
ResourceAssociationDefinition rEntitlementAssociationDef = objectDefinition.findAssociationDefinition(associationName);
if (rEntitlementAssociationDef == null) {
LOGGER.trace("Entitlement association with name {} couldn't be found in {} {}\nresource shadow:\n{}\nrepo shadow:\n{}", associationName, objectDefinition, ctx.getDesc(), resourceObject.debugDumpLazily(1), repoShadow.debugDumpLazily(1));
LOGGER.trace("Full [refined] definition: {}", objectDefinition.debugDumpLazily());
throw new SchemaException("Entitlement association with name " + associationName + " couldn't be found in " + ctx);
}
return rEntitlementAssociationDef;
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class QueryHelper method applyMatchingRules.
/**
* Visit the query and normalize values (or set matching rules) as needed
*/
@Contract("null, _ -> null; !null, _ -> !null")
ObjectQuery applyMatchingRules(ObjectQuery originalQuery, ResourceObjectDefinition objectDef) {
if (originalQuery == null) {
return null;
}
ObjectQuery processedQuery = originalQuery.clone();
ObjectFilter filter = processedQuery.getFilter();
Visitor visitor = f -> {
try {
if (f instanceof EqualFilter) {
applyMatchingRuleToEqFilter((EqualFilter<?>) f, objectDef);
}
} catch (SchemaException e) {
throw new SystemException(e);
}
};
filter.accept(visitor);
return processedQuery;
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class AssignmentEditorDto method prepareAssignmentAttributes.
private List<ACAttributeDto> prepareAssignmentAttributes(AssignmentType assignment, PageBase pageBase) {
List<ACAttributeDto> acAtrList = new ArrayList<>();
if (assignment == null || assignment.getConstruction() == null || assignment.getConstruction().getAttribute() == null || assignment.getConstruction() == null) {
return acAtrList;
}
OperationResult result = new OperationResult(OPERATION_LOAD_ATTRIBUTES);
ConstructionType construction = assignment.getConstruction();
ObjectReferenceType resourceRef = construction.getResourceRef();
PrismObject<ResourceType> resource = resourceRef.asReferenceValue().getObject();
if (resource == null) {
resource = getReference(construction.getResourceRef(), result, pageBase);
}
try {
PrismContext prismContext = pageBase.getPrismContext();
ResourceSchema refinedSchema = ResourceSchemaFactory.getCompleteSchema(resource, LayerType.PRESENTATION);
ResourceObjectDefinition objectClassDefinition = refinedSchema.findObjectDefinition(ShadowKindType.ACCOUNT, construction.getIntent());
if (objectClassDefinition == null) {
return attributes;
}
PrismContainerDefinition<?> definition = objectClassDefinition.toResourceAttributeContainerDefinition();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Refined definition for {}\n{}", construction, definition.debugDump());
}
Collection<? extends ItemDefinition<?>> definitions = definition.getDefinitions();
for (ResourceAttributeDefinitionType attribute : assignment.getConstruction().getAttribute()) {
for (ItemDefinition attrDef : definitions) {
if (attrDef instanceof PrismPropertyDefinition) {
PrismPropertyDefinition propertyDef = (PrismPropertyDefinition) attrDef;
if (propertyDef.isOperational() || propertyDef.isIgnored()) {
continue;
}
if (ItemPathTypeUtil.asSingleNameOrFail(attribute.getRef()).equals(propertyDef.getItemName())) {
acAtrList.add(ACAttributeDto.createACAttributeDto(propertyDef, attribute, prismContext));
break;
}
}
}
}
result.recordSuccess();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Exception occurred during assignment attribute loading", ex);
result.recordFatalError(pageBase.createStringResource("AssignmentEditorDto.message.prepareAssignmentAttributes.fatalError").getString(), ex);
} finally {
result.recomputeStatus();
}
return acAtrList;
}
use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.
the class AssignmentEditorPanel method loadAttributes.
private List<ACAttributeDto> loadAttributes() {
AssignmentEditorDto dto = getModel().getObject();
OperationResult result = new OperationResult(OPERATION_LOAD_ATTRIBUTES);
List<ACAttributeDto> attributes = new ArrayList<>();
try {
ConstructionType construction = WebComponentUtil.getContainerValue(dto.getOldValue(), AssignmentType.F_CONSTRUCTION, ConstructionType.class);
if (construction == null) {
return attributes;
}
PrismObject<ResourceType> resource = getReference(construction.getResourceRef(), result);
PrismContext prismContext = getPageBase().getPrismContext();
ResourceSchema refinedSchema = ResourceSchemaFactory.getCompleteSchema(resource, LayerType.PRESENTATION);
ResourceObjectDefinition objectClassDefinition = refinedSchema.findObjectDefinition(ShadowKindType.ACCOUNT, construction.getIntent());
if (objectClassDefinition == null) {
return attributes;
}
PrismContainerDefinition definition = objectClassDefinition.toResourceAttributeContainerDefinition();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Refined definition for {}\n{}", construction, definition.debugDump());
}
Collection<ItemDefinition<?>> definitions = definition.getDefinitions();
for (ItemDefinition<?> attrDef : definitions) {
if (!(attrDef instanceof PrismPropertyDefinition)) {
// log skipping or something...
continue;
}
PrismPropertyDefinition<?> propertyDef = (PrismPropertyDefinition<?>) attrDef;
if (propertyDef.isOperational() || propertyDef.isIgnored()) {
continue;
}
attributes.add(ACAttributeDto.createACAttributeDto(propertyDef, findOrCreateValueConstruction(propertyDef), prismContext));
}
result.recordSuccess();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Exception occurred during assignment attribute loading", ex);
result.recordFatalError(createStringResource("AssignmentEditorPanel.message.loadAttributes.fatalError").getString(), ex);
} finally {
result.recomputeStatus();
}
attributes.sort((a1, a2) -> String.CASE_INSENSITIVE_ORDER.compare(a1.getName(), a2.getName()));
if (dto.getAttributes() != null && !dto.getAttributes().isEmpty()) {
for (ACAttributeDto assignmentAttribute : dto.getAttributes()) {
for (ACAttributeDto attributeDto : attributes) {
if (attributeDto.getName().equals(assignmentAttribute.getName())) {
attributes.set(attributes.indexOf(attributeDto), assignmentAttribute);
continue;
}
}
}
}
dto.setAttributes(attributes);
getPageBase().showResult(result, false);
return dto.getAttributes();
}
Aggregations