Skip to content

Commit

Permalink
fix for MID-7122 -> shadow password delta is always replace
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Dec 6, 2021
1 parent 00ff930 commit 8016220
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ public boolean isProcessMetadataFor(ItemPath path) throws SchemaException {
return metadataItemProcessingSpec.isFullProcessing(path);
}

@NotNull
public PrismObject<?> getObject() {
return object;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
import java.util.Collection;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.gui.impl.prism.panel.MetadataContainerPanel;

import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.springframework.stereotype.Component;

import com.evolveum.midpoint.gui.api.factory.wrapper.ItemWrapperFactory;
Expand Down Expand Up @@ -129,10 +133,26 @@ protected PrismContainerValue<C> createNewValue(PrismContainer<C> item) {
@Override
protected PrismContainerWrapper<C> createWrapperInternal(PrismContainerValueWrapper<?> parent, PrismContainer<C> childContainer,
ItemStatus status, WrapperContext ctx) {

status = recomputeStatus(childContainer, status, ctx);
return new PrismContainerWrapperImpl<>(parent, childContainer, status);
}

private ItemStatus recomputeStatus(PrismContainer<C> containerWrapper, ItemStatus defaultStatus, WrapperContext ctx) {
if (isShadowCredentialsOrPassword(containerWrapper.getDefinition(), ctx)) {
return ItemStatus.NOT_CHANGED;
}
return defaultStatus;
}

private boolean isShadowCredentialsOrPassword(PrismContainerDefinition<C> childItemDef, WrapperContext ctx) {
PrismObject<?> object = ctx.getObject();
if (object == null || !ShadowType.class.equals(object.getCompileTimeClass())) {
return false;
}
QName typeName = childItemDef.getTypeName();
return QNameUtil.match(typeName, CredentialsType.COMPLEX_TYPE) || QNameUtil.match(typeName, PasswordType.COMPLEX_TYPE);
}

@Override
public void registerWrapperPanel(PrismContainerWrapper<C> wrapper) {
if (wrapper.isMetadata()) {
Expand All @@ -144,6 +164,9 @@ public void registerWrapperPanel(PrismContainerWrapper<C> wrapper) {

@Override
public PrismContainerValueWrapper<C> createContainerValueWrapper(PrismContainerWrapper<C> objectWrapper, PrismContainerValue<C> objectValue, ValueStatus status, WrapperContext context) {
if (isShadowCredentialsOrPassword(objectValue.getDefinition(), context)) {
status = ValueStatus.NOT_CHANGED;
}
return new PrismContainerValueWrapperImpl<>(objectWrapper, objectValue, status);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ protected PrismContainerWrapper<ShadowAssociationType> createWrapperInternal(Pri
LOGGER.debug("Association for {} is not supported", childContainer.getComplexTypeDefinition().getTypeClass());
return super.createWrapperInternal(parent, childContainer, status, ctx);
}

ShadowType shadow = (ShadowType) ctx.getObject().asObjectable();
PrismObject<?> object = ctx.getObject();
if (object == null) {
return super.createWrapperInternal(parent, childContainer, status, ctx);
}
ShadowType shadow = (ShadowType) object.asObjectable();
PrismObject<ResourceType> resource = loadResource(shadow, ctx);
if (resource == null) {
return super.createWrapperInternal(parent, childContainer, status, ctx);
Expand Down Expand Up @@ -167,6 +170,9 @@ private Collection<RefinedAssociationDefinition> loadRefinedAssociationDefinitio

private boolean isNotShadow(WrapperContext ctx, OperationResult parentResult) {
PrismObject<?> object = ctx.getObject();
if (object == null) {
return true;
}
ObjectType objectType = (ObjectType) object.asObjectable();
if (!(objectType instanceof ShadowType)) {
parentResult.recordFatalError("Something very strange happened. Association container in the" + objectType.getClass().getSimpleName() + "?");
Expand Down

0 comments on commit 8016220

Please sign in to comment.