Skip to content

Commit

Permalink
Storing password metadata (MID-2282)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Apr 9, 2015
1 parent 71aa0cd commit 7cd5213
Show file tree
Hide file tree
Showing 12 changed files with 343 additions and 71 deletions.
Expand Up @@ -256,7 +256,7 @@ DD findItemDelta(ItemPath propertyPath, Class<DD> deltaType, Class<I> itemType)
}
}

public <IV extends PrismValue,ID extends ItemDefinition> PartiallyResolvedDelta<IV,ID> findPartial(ItemPath propertyPath) {
public <IV extends PrismValue,ID extends ItemDefinition> Collection<PartiallyResolvedDelta<IV,ID>> findPartial(ItemPath propertyPath) {
if (changeType == ChangeType.ADD) {
PartiallyResolvedItem<IV,ID> partialValue = objectToAdd.findPartial(propertyPath);
if (partialValue == null || partialValue.getItem() == null) {
Expand All @@ -265,20 +265,23 @@ public <IV extends PrismValue,ID extends ItemDefinition> PartiallyResolvedDelta<
Item<IV,ID> item = partialValue.getItem();
ItemDelta<IV,ID> itemDelta = item.createDelta();
itemDelta.addValuesToAdd(item.getClonedValues());
return new PartiallyResolvedDelta<IV,ID>(itemDelta, partialValue.getResidualPath());
Collection<PartiallyResolvedDelta<IV,ID>> deltas = new ArrayList<>(1);
deltas.add(new PartiallyResolvedDelta<IV,ID>(itemDelta, partialValue.getResidualPath()));
return deltas;
} else if (changeType == ChangeType.MODIFY) {
Collection<PartiallyResolvedDelta<IV,ID>> deltas = new ArrayList<>();
for (ItemDelta<?,?> modification: modifications) {
CompareResult compareComplex = modification.getPath().compareComplex(propertyPath);
if (compareComplex == CompareResult.EQUIVALENT) {
return new PartiallyResolvedDelta<IV,ID>((ItemDelta<IV,ID>)modification, null);
} else if (compareComplex == CompareResult.SUPERPATH) {
return new PartiallyResolvedDelta<IV,ID>((ItemDelta<IV,ID>)modification, null);
deltas.add(new PartiallyResolvedDelta<IV,ID>((ItemDelta<IV,ID>)modification, null));
} else if (compareComplex == CompareResult.SUBPATH) {
return new PartiallyResolvedDelta<IV,ID>((ItemDelta<IV,ID>)modification,
propertyPath.remainder(modification.getPath()));
deltas.add(new PartiallyResolvedDelta<IV,ID>((ItemDelta<IV,ID>)modification, null));
} else if (compareComplex == CompareResult.SUPERPATH) {
deltas.add(new PartiallyResolvedDelta<IV,ID>((ItemDelta<IV,ID>)modification,
modification.getPath().remainder(propertyPath)));
}
}
return null;
return deltas;
} else {
return null;
}
Expand Down
Expand Up @@ -18,12 +18,14 @@
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.PrismValue;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.DebugUtil;

/**
* @author semancik
*
*/
public class PartiallyResolvedDelta<V extends PrismValue,D extends ItemDefinition> {
public class PartiallyResolvedDelta<V extends PrismValue,D extends ItemDefinition> implements DebugDumpable {

private ItemDelta<V,D> delta;
private ItemPath residualPath;
Expand Down Expand Up @@ -80,6 +82,22 @@ public boolean equals(Object obj) {
return false;
return true;
}

@Override
public String debugDump() {
return debugDump(0);
}

@Override
public String debugDump(int indent) {
StringBuilder sb = new StringBuilder();
DebugUtil.indentDebugDump(sb, indent);
sb.append("PartiallyResolvedDelta\n");
DebugUtil.debugDumpWithLabel(sb, "delta", delta, indent + 1);
sb.append("\n");
DebugUtil.debugDumpWithLabel(sb, "residual path", residualPath==null?"null":residualPath.toString(), indent + 1);
return sb.toString();
}

@Override
public String toString() {
Expand Down
Expand Up @@ -424,6 +424,28 @@ public static IdItemPathSegment getFirstIdSegment(ItemPath itemPath) {
return null;
}

public static NameItemPathSegment getFirstNameSegment(ItemPath itemPath) {
if (itemPath == null) {
return null;
}
ItemPathSegment first = itemPath.first();
if (first instanceof NameItemPathSegment) {
return (NameItemPathSegment)first;
}
if (first instanceof IdItemPathSegment) {
return getFirstNameSegment(itemPath.rest());
}
return null;
}

public static QName getFirstName(ItemPath itemPath) {
NameItemPathSegment nameSegment = getFirstNameSegment(itemPath);
if (nameSegment == null) {
return null;
}
return nameSegment.getName();
}

public static ItemPath pathRestStartingWithName(ItemPath path) {
ItemPathSegment pathSegment = path.first();
if (pathSegment instanceof NameItemPathSegment) {
Expand All @@ -435,6 +457,15 @@ public static ItemPath pathRestStartingWithName(ItemPath path) {
}
}

public boolean containsName(QName name) {
for (ItemPathSegment segment: segments) {
if (segment instanceof NameItemPathSegment && ((NameItemPathSegment)segment).getName().equals(name)) {
return true;
}
}
return false;
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
Expand Down
10 changes: 10 additions & 0 deletions infra/schema/src/main/resources/xml/ns/public/common/common-3.xsd
Expand Up @@ -2406,6 +2406,16 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="metadata" type="tns:MetadataType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Timestamps and general metadata describing the credential change.
</xsd:documentation>
<xsd:appinfo>
<a:operational>true</a:operational>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:long" use="optional"/>
</xsd:complexType>
Expand Down
Expand Up @@ -858,7 +858,7 @@ void logDeltaExecution(ObjectDelta<T> objectDelta, LensContext<F> context,
sb.append(" delta of ").append(objectDelta.getObjectTypeClass().getSimpleName());
sb.append(" ]---------------------\n");
DebugUtil.debugDumpLabel(sb, "Channel", 0);
sb.append(" ").append(getChannel(context, task)).append("\n");
sb.append(" ").append(LensUtil.getChannel(context, task)).append("\n");
if (context != null) {
DebugUtil.debugDumpLabel(sb, "Wave", 0);
sb.append(" ").append(context.getExecutionWave()).append("\n");
Expand Down Expand Up @@ -1041,47 +1041,24 @@ private <T extends ObjectType, F extends ObjectType> void executeModification(Ob
}

private <T extends ObjectType, F extends ObjectType> void applyMetadata(LensContext<F> context, Task task, T objectTypeToAdd, OperationResult result) throws SchemaException {
MetadataType metaData = new MetadataType();
String channel = getChannel(context, task);
metaData.setCreateChannel(channel);
metaData.setCreateTimestamp(clock.currentTimeXMLGregorianCalendar());
if (task.getOwner() != null) {
metaData.setCreatorRef(ObjectTypeUtil.createObjectRef(task.getOwner()));
}
MetadataType metaData = LensUtil.createCreateMetadata(context, clock.currentTimeXMLGregorianCalendar(), task);
if (workflowManager != null) {
metaData.getCreateApproverRef().addAll(workflowManager.getApprovedBy(task, result));
}

objectTypeToAdd.setMetadata(metaData);
}

private <F extends ObjectType> String getChannel(LensContext<F> context, Task task){
if (context != null && context.getChannel() != null){
return context.getChannel();
} else if (task.getChannel() != null){
return task.getChannel();
}
return null;
}


private <T extends ObjectType, F extends ObjectType> void applyMetadata(ObjectDelta<T> change, LensElementContext<T> objectContext,
Class objectTypeClass, Task task, LensContext<F> context, OperationResult result) throws SchemaException {
String channel = getChannel(context, task);

PrismObjectDefinition def = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(objectTypeClass);
String channel = LensUtil.getChannel(context, task);

if (channel != null) {
PropertyDelta delta = PropertyDelta.createModificationReplaceProperty((new ItemPath(ObjectType.F_METADATA, MetadataType.F_MODIFY_CHANNEL)), def, channel);
((Collection) change.getModifications()).add(delta);
}
PropertyDelta delta = PropertyDelta.createModificationReplaceProperty((new ItemPath(ObjectType.F_METADATA, MetadataType.F_MODIFY_TIMESTAMP)), def, XmlTypeConverter.createXMLGregorianCalendar(System.currentTimeMillis()));
((Collection) change.getModifications()).add(delta);
if (task.getOwner() != null) {
ReferenceDelta refDelta = ReferenceDelta.createModificationReplace((new ItemPath(ObjectType.F_METADATA,
MetadataType.F_MODIFIER_REF)), def, task.getOwner().getOid());
((Collection) change.getModifications()).add(refDelta);
}
PrismObjectDefinition<T> def = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(objectTypeClass);

((Collection) change.getModifications()).addAll(LensUtil.createModifyMetadataDeltas(context, new ItemPath(ObjectType.F_METADATA), def, clock.currentTimeXMLGregorianCalendar(), task));

List<PrismReferenceValue> approverReferenceValues = new ArrayList<PrismReferenceValue>();

if (workflowManager != null) {
Expand Down
Expand Up @@ -55,14 +55,17 @@
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple;
import com.evolveum.midpoint.prism.delta.PropertyDelta;
import com.evolveum.midpoint.prism.delta.ReferenceDelta;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.provisioning.api.ProvisioningService;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.constants.ExpressionConstants;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.schema.util.ShadowUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.DOMUtil;
Expand All @@ -87,6 +90,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.LayerType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MappingStrengthType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MetadataType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectPolicyConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType;
Expand Down Expand Up @@ -1281,4 +1285,42 @@ public static AssignmentType getAssignmentType(ItemDeltaItem<PrismContainerValue
return ((PrismContainer<AssignmentType>)assignmentIdi.getItemNew()).getValue(0).asContainerable();
}
}

public static <F extends ObjectType> MetadataType createCreateMetadata(LensContext<F> context, XMLGregorianCalendar now, Task task) {
MetadataType metaData = new MetadataType();
String channel = getChannel(context, task);
metaData.setCreateChannel(channel);
metaData.setCreateTimestamp(now);
if (task.getOwner() != null) {
metaData.setCreatorRef(ObjectTypeUtil.createObjectRef(task.getOwner()));
}
return metaData;
}

public static <F extends ObjectType, T extends ObjectType> Collection<? extends ItemDelta<?,?>> createModifyMetadataDeltas(LensContext<F> context,
ItemPath metadataPath, PrismObjectDefinition<T> def, XMLGregorianCalendar now, Task task) {
Collection<? extends ItemDelta<?,?>> deltas = new ArrayList<>();
String channel = getChannel(context, task);
if (channel != null) {
PropertyDelta<String> delta = PropertyDelta.createModificationReplaceProperty(metadataPath.subPath(MetadataType.F_MODIFY_CHANNEL), def, channel);
((Collection)deltas).add(delta);
}
PropertyDelta<XMLGregorianCalendar> delta = PropertyDelta.createModificationReplaceProperty(metadataPath.subPath(MetadataType.F_MODIFY_TIMESTAMP), def, now);
((Collection)deltas).add(delta);
if (task.getOwner() != null) {
ReferenceDelta refDelta = ReferenceDelta.createModificationReplace(
metadataPath.subPath(MetadataType.F_MODIFIER_REF), def, task.getOwner().getOid());
((Collection)deltas).add(refDelta);
}
return deltas;
}

public static <F extends ObjectType> String getChannel(LensContext<F> context, Task task) {
if (context != null && context.getChannel() != null){
return context.getChannel();
} else if (task.getChannel() != null){
return task.getChannel();
}
return null;
}
}

0 comments on commit 7cd5213

Please sign in to comment.