Skip to content

Commit

Permalink
Create PoC for associated objects inbounds
Browse files Browse the repository at this point in the history
Very experimental code for inbound mappings for associated objects.
Now it can do a basic import. Very fragile! Other tests are probably
broken as well.
  • Loading branch information
mederly committed Apr 5, 2024
1 parent bb0b90e commit 632b41b
Show file tree
Hide file tree
Showing 122 changed files with 2,788 additions and 1,735 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public AssociatedResourceObjectTypeDefinitionConfigItem(

@Override
public @NotNull String localDescription() {
var displayName = value().getDisplayName();
return "associated object type '%s' %sdefinition".formatted(
value().getIntent(), displayName != null ? "(" + displayName + ") " : "");
return "associated " + super.localDescription();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,4 @@ public ResourceObjectTypeDefinitionConfigItem(
@NotNull ConfigurationItem<ResourceObjectTypeDefinitionType> original) {
super(original);
}

@Override
public @NotNull String localDescription() {
var displayName = value().getDisplayName();
return "associated object type '%s' %sdefinition".formatted(
value().getIntent(), displayName != null ? "(" + displayName + ") " : "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ default void assertAttached() {
}
//endregion

/** Call {@link #getPrismObjectDefinition()} for the cached version. */
default @NotNull PrismObjectDefinition<ShadowType> toPrismObjectDefinition() {
return ObjectFactory.constructObjectDefinition(
toResourceAttributeContainerDefinition(),
Expand Down Expand Up @@ -598,4 +599,9 @@ default void assertAttached() {

/** Returns both attribute and association definitions. */
@NotNull Collection<? extends ShadowItemDefinition<?, ?>> getShadowItemDefinitions();

default boolean hasInboundMappings() {
return getShadowItemDefinitions().stream()
.anyMatch(ShadowItemDefinition::hasInboundMapping);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package com.evolveum.midpoint.schema.processor;

import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CapabilityType;
Expand Down Expand Up @@ -129,6 +130,18 @@ default boolean matchesKind(@Nullable ShadowKindType kind) {
throw new UnsupportedOperationException("Dynamic references are not supported for archetypeRef; in " + this);
}

// TEMPORARY
default @Nullable ItemPath getFocusItemPath() {
var focusSpec = getDefinitionBean().getFocus();
return focusSpec != null && focusSpec.getItemPath() != null ? focusSpec.getItemPath().getItemPath() : null;
}

// TEMPORARY
default @Nullable String getAssignmentSubtype() {
var focusSpec = getDefinitionBean().getFocus();
return focusSpec != null ? focusSpec.getAssignmentSubtype() : null;
}

/** Returns true if there is "synchronization reactions" definition section here (even if it's empty). */
boolean hasSynchronizationReactionsDefinition();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ private void parseProtected() throws SchemaException, ConfigurationException {
if (protectedPatternBeans.isEmpty()) {
return;
}
var prismObjectDef = definition.toPrismObjectDefinition();
var prismObjectDef = definition.getPrismObjectDefinition();
for (ResourceObjectPatternType protectedPatternBean : protectedPatternBeans) {
definition.addProtectedObjectPattern(
convertToPattern(protectedPatternBean, prismObjectDef));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private static SystemException alreadyChecked(ConfigurationException e) {
// We apply the prism shadow definition for (representative) target object to the shadowRef definition.
var shadowRefDef = Objects.requireNonNull(def.findReferenceDefinition(ShadowAssociationValueType.F_SHADOW_REF)).clone();
shadowRefDef.mutator().setTargetObjectDefinition(
getTargetObjectDefinition().toPrismObjectDefinition());
getTargetObjectDefinition().getPrismObjectDefinition());
def.mutator().replaceDefinition(
ShadowAssociationValueType.F_SHADOW_REF,
shadowRefDef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javax.xml.namespace.QName;

import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;

import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -146,11 +147,15 @@ public ShadowAssociationValue cloneComplex(CloneStrategy strategy) {
}

/** Target object or its reference. TODO better name. */
public ShadowType getShadowBean() {
public @NotNull ShadowType getShadowBean() {
var shadowRef = stateNonNull(asContainerable().getShadowRef(), "No shadowRef in %s", this);
return (ShadowType) stateNonNull(shadowRef.getObjectable(), "No shadow in %s", this);
}

public @NotNull AbstractShadow getShadow() {
return AbstractShadow.of(getShadowBean());
}

public QName getTargetObjectClassName() {
return getAttributesContainerRequired().getDefinitionRequired().getTypeName();
}
Expand Down Expand Up @@ -190,7 +195,7 @@ public QName getTargetObjectClassName() {
return stateNonNull(getShadowIfPresent(), "No shadow in %s", this);
}

private @NotNull ResourceObjectDefinition getAssociatedObjectDefinition() {
public @NotNull ResourceObjectDefinition getAssociatedObjectDefinition() {
return getShadowRequired().getObjectDefinition();
}

Expand All @@ -205,4 +210,17 @@ public void setShadow(@NotNull AbstractShadow shadow) {
.identifiersOnly(false);
// TODO check consistence
}

@Override
protected boolean appendExtraHeaderDump(StringBuilder sb, int indent, boolean wasIndent) {
wasIndent = super.appendExtraHeaderDump(sb, indent, wasIndent);
if (!wasIndent) {
DebugUtil.indentDebugDump(sb, indent);
} else {
sb.append("; ");
}
// TODO this should be a part of ShadowType dumping; but that code is automatically generated for now
sb.append(getAssociatedObjectDefinition());
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ default boolean hasOutboundMapping() {
*/
@NotNull List<InboundMappingType> getInboundMappingBeans();

default boolean hasInboundMapping() {
return !getInboundMappingBeans().isEmpty();
}

/**
* Drives behavior of strong and normal mappings for this attribute.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.util.*;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.prism.util.CloneUtil;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -113,11 +115,10 @@ public abstract class ShadowItemDefinitionImpl<
ShadowItemDefinitionImpl(@NotNull ND nativeDefinition, @NotNull CB customizationBean, boolean forcedIgnored)
throws SchemaException {
assert nativeDefinition.isImmutable();
assert customizationBean.isImmutable();

this.currentLayer = DEFAULT_LAYER;
this.nativeDefinition = nativeDefinition;
this.customizationBean = customizationBean;
this.customizationBean = CloneUtil.toImmutable(customizationBean);
this.limitationsMap = computeLimitationsMap(forcedIgnored);
this.accessOverride = new PropertyAccessType();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import java.util.Comparator;

import static com.evolveum.midpoint.util.MiscUtil.stateNonNull;

/**
* Wraps both {@link SynchronizationActionType} and {@link AbstractSynchronizationActionType}.
*/
Expand Down Expand Up @@ -64,6 +66,11 @@ public ObjectReferenceType getObjectTemplateRef() {

public abstract @Nullable Class<? extends AbstractSynchronizationActionType> getNewDefinitionBeanClass();

public @NotNull Class<? extends AbstractSynchronizationActionType> getNewDefinitionBeanClassRequired() {
return stateNonNull(getNewDefinitionBeanClass(),
"Action definition bean class not present in %s", this);
}

@VisibleForTesting
public abstract @Nullable AbstractSynchronizationActionType getNewDefinitionBean();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ default void checkAttributeDefinitions() {
AbstractShadow clone();

default void applyDefinition(@NotNull ResourceObjectDefinition newDefinition) throws SchemaException {
// This causes problems with embedded associations
//getPrismObject().applyDefinition(newDefinition.getPrismObjectDefinition(), false);
getAttributesContainer().applyDefinition(
newDefinition.toResourceAttributeContainerDefinition());
checkConsistence();
Expand Down Expand Up @@ -310,6 +312,10 @@ default PolyStringType getName() {
"No object class in %s", this);
}

default boolean isClassified() {
return ShadowUtil.isClassified(getBean());
}

default boolean isProtectedObject() {
return BooleanUtils.isTrue(getBean().isProtectedObject());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.evolveum.midpoint.authentication.api.util.AuthenticationModuleNameConstants;
import com.evolveum.midpoint.authentication.impl.util.ModuleType;
import com.evolveum.midpoint.model.api.correlator.CandidateOwner;
import com.evolveum.midpoint.model.api.correlator.CandidateOwnersMap;
import com.evolveum.midpoint.model.api.correlator.CandidateOwners;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

Expand All @@ -25,7 +25,7 @@ public class CorrelationModuleAuthenticationImpl extends ModuleAuthenticationImp
private List<CorrelationModuleConfigurationType> correlators;
private int currentProcessingCorrelator;

private CandidateOwnersMap candidateOwners = new CandidateOwnersMap();
private CandidateOwners candidateOwners = new CandidateOwners();
private final List<ObjectType> owners = new ArrayList<>();

private FocusType preFocus;
Expand Down Expand Up @@ -77,16 +77,12 @@ public boolean isEmptyCorrelatorsList() {
return CollectionUtils.isEmpty(correlators);
}

public void rewriteCandidateOwners(CandidateOwnersMap map) {
candidateOwners.clear();
candidateOwners.mergeWith(map);
public void rewriteCandidateOwners(CandidateOwners newOwners) {
candidateOwners.replaceWith(newOwners);
}

public Set<String> getCandidateOids() {
return candidateOwners.values()
.stream()
.map(CandidateOwner::getOid)
.collect(Collectors.toSet());
return candidateOwners.getCandidateOids();
}

public void rewriteOwner(ObjectType owner) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipalManager;
import com.evolveum.midpoint.model.api.correlation.CompleteCorrelationResult;
import com.evolveum.midpoint.model.api.correlation.CorrelationService;
import com.evolveum.midpoint.model.api.correlator.CandidateOwnersMap;
import com.evolveum.midpoint.model.api.correlator.CandidateOwners;
import com.evolveum.midpoint.schema.CorrelatorDiscriminator;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.security.api.*;
Expand Down Expand Up @@ -96,8 +96,8 @@ public Authentication doAuthenticate(
return authentication;
}

CandidateOwnersMap ownersMap = correlationResult.getCandidateOwnersMap();
correlationModuleAuthentication.rewriteCandidateOwners(ownersMap);
CandidateOwners owners = correlationResult.getCandidateOwnersMap();
correlationModuleAuthentication.rewriteCandidateOwners(owners);

return authentication;
} catch (Exception e) {
Expand Down Expand Up @@ -125,11 +125,11 @@ private boolean candidateOwnerExist(CompleteCorrelationResult correlationResult)
return correlationResult.getCandidateOwnersMap() != null && !correlationResult.getCandidateOwnersMap().isEmpty();
}

private void rewriteCandidatesToOwners(@NotNull CandidateOwnersMap candidateOwnersMap,
private void rewriteCandidatesToOwners(@NotNull CandidateOwners candidateOwners,
CorrelationModuleAuthenticationImpl correlationModuleAuthentication) {
correlationModuleAuthentication.clearOwners();
candidateOwnersMap.values()
.forEach(c -> correlationModuleAuthentication.addOwnerIfNotExist(c.getObject()));
candidateOwners.objectBasedValues()
.forEach(c -> correlationModuleAuthentication.addOwnerIfNotExist(c.getValue()));
}

private void isOwnersNumberUnderRestriction(CorrelationModuleAuthenticationImpl correlationModuleAuthentication) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2010-2024 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.model.api.correlation;

import java.io.Serializable;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CorrelationSituationType;

public abstract class AbstractCorrelationResult<C extends Containerable> implements Serializable, DebugDumpable {

/** What is the result of the correlation? */
@NotNull final CorrelationSituationType situation;

/** The correlated owner. Non-null if and only if {@link #situation} is {@link CorrelationSituationType#EXISTING_OWNER}. */
@Nullable final C owner;

AbstractCorrelationResult(@NotNull CorrelationSituationType situation, @Nullable C owner) {
this.situation = situation;
this.owner = owner;
}

public @NotNull CorrelationSituationType getSituation() {
return situation;
}

public @Nullable C getOwner() {
return owner;
}
}

0 comments on commit 632b41b

Please sign in to comment.