Skip to content

Commit

Permalink
Introduce PolyString attributes in the repository
Browse files Browse the repository at this point in the history
This commit brings in storing normalizable shadow attributes, i.e.,
those that have a matching/normalization rule defined, as PolyStrings.
Previously, these were stored as plain strings in their normalized form.
That was OK for searching, but is no longer suitable for full attribute
caching.

Major changes:

- Added NormalizationAwareResourceAttributeDefinition that supports
handling of these attributes. Also, the structure of classes related
to attribute definitions was changed: RawResourceAttributeDefinition
is not an interface, but a concrete class instead. The delegation
to rawDefinition in ResourceAttributeDefinition is no longer based on
the generic delegator (to increase clarity).
RawResourceObjectClassDefinition is gone.

- Furthered differentiation of shadow objects in provisioning-impl:
RawRepoShadow, RepoShadow, ResourceObject, ExistingResourceObject,
in order to know exactly the data structure we work with. The same
was done for the tests. Added convenience methods for retrieving
AbstractShadow instances in ProvisioningService. Goal: code clarity,
contract enforcement (also via increased consistency checking).

- Restructured processing of acquired shadows in provisioning
(classification, shadow update, combining shadow + resource object)
to ShadowPostProcessor. Goal: removing duplicate code.

Minor and/or unrelated changes:

- Fixed listing all dead shadows in lookupShadowByIndexedPrimaryIdValue
(this led to e.g. problems described in MID-9328).

- Renamed RepoShadowFinder back to ShadowFinder (to facilitate
backporting of fixes from 4.9 to 4.8 and earlier).

- The findAttributeDefinition method is now "<T> T" instead of "<?>".

- Consistence checks are now turned on for provisioning-impl tests.

- QShadowMapping: not retrieving index-only attributes on modifications.
This is a temporary change that is to be discussed.

- Adaptation to changes induced by
0213195e58a5c37826fd630d613c7dba57df9e5d in prism.

Related to MID-2119 (shadow caching).

Work in progress. Some changes are experimental/temporary.
Many tests currently fail.
  • Loading branch information
mederly committed Dec 11, 2023
1 parent 6e1066b commit faad391
Show file tree
Hide file tree
Showing 253 changed files with 7,203 additions and 5,668 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
* @author katka
*
*/
public interface ItemWrapper<I extends Item, VW extends PrismValueWrapper> extends ItemDefinition<I>, Revivable, DebugDumpable, Serializable {
public interface ItemWrapper<I extends Item<?, ?>, VW extends PrismValueWrapper>
extends ItemDefinition<I>, Revivable, DebugDumpable, Serializable {


String debugDump(int indent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3388,7 +3388,7 @@ public static Class<? extends PageBase> resolveSelfPage() {
return null;
}

public static <I extends Item> PrismObject<LookupTableType> findLookupTable(ItemDefinition<I> definition, PageBase page) {
public static <I extends Item<?, ?>> PrismObject<LookupTableType> findLookupTable(ItemDefinition<I> definition, PageBase page) {
PrismReferenceValue valueEnumerationRef = definition.getValueEnumerationRef();
return findLookupTable(valueEnumerationRef, page);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public PrismContainerWrapper<ConnectorConfigurationType> createWrapper(PrismCont
}

// childItem = definitionFixed.instantiate();
childItem.applyDefinition(definitionFixed, true);
childItem.applyDefinition(definitionFixed);
// parent.getNewValue().addReplaceExisting(childItem);
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ protected void applySecurityConstraints(PrismObject<O> object, WrapperContext co

try {
PrismObjectDefinition<O> objectDef = getModelInteractionService().getEditObjectDefinition(object, phase, task, result);
object.applyDefinition(objectDef, true);
object.applyDefinition(objectDef);
} catch (SchemaException | ConfigurationException | ObjectNotFoundException | ExpressionEvaluationException
| CommunicationException | SecurityViolationException e) {
LOGGER.error("Exception while applying security constraints: {}", e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
/**
* @author katka
*/
public abstract class ItemWrapperImpl<I extends Item, VW extends PrismValueWrapper> implements ItemWrapper<I, VW>, Serializable {
public abstract class ItemWrapperImpl<I extends Item<?, ?>, VW extends PrismValueWrapper>
implements ItemWrapper<I, VW>, Serializable {

private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -485,7 +486,7 @@ public boolean canBeDefinitionOf(I item) {
}

@Override
public boolean canBeDefinitionOf(PrismValue pvalue) {
public boolean canBeDefinitionOf(@NotNull PrismValue pvalue) {
return getItemDefinition().canBeDefinitionOf(pvalue);
}

Expand Down Expand Up @@ -700,20 +701,22 @@ public void removeAll(ModelServiceLocator locator) throws SchemaException {
}
}

@SuppressWarnings({ "rawtypes", "unchecked" })
private void removeValue(VW valueWrapper) {
Item rawItem = getItem(); // using not parameterized version to make compiler happy
switch (valueWrapper.getStatus()) {
case ADDED:
case MODIFIED:
values.remove(valueWrapper);
getItem().remove(valueWrapper.getOldValue());
getItem().remove(valueWrapper.getNewValue());
rawItem.remove(valueWrapper.getOldValue());
rawItem.remove(valueWrapper.getNewValue());
break;
case NOT_CHANGED:
// if (isSingleValue()) {
// valueWrapper.setRealValue(null);
// valueWrapper.setStatus(ValueStatus.MODIFIED);
// } else {
getItem().remove(valueWrapper.getNewValue());
rawItem.remove(valueWrapper.getNewValue());
valueWrapper.setStatus(ValueStatus.DELETED);
// }
break;
Expand All @@ -724,7 +727,8 @@ private void removeValue(VW valueWrapper) {

@Override
public <PV extends PrismValue> void add(PV newValue, ModelServiceLocator locator) throws SchemaException {
getItem().add(newValue);
//noinspection unchecked,rawtypes
((Item) getItem()).add(newValue);
VW newItemValue = WebPrismUtil.createNewValueWrapper(this, newValue, locator);
values.add(newItemValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public QName getMatchingRuleQName() {
}

@Override
public @NotNull MatchingRule<T> getMatchingRule() throws SchemaException {
public @NotNull MatchingRule<T> getMatchingRule() {
return getItemDefinition().getMatchingRule();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package com.evolveum.midpoint.gui.impl.prism.wrapper;

import java.io.Serial;
import java.util.List;
import java.util.Optional;

Expand All @@ -29,7 +30,7 @@
*/
public class ResourceAttributeWrapperImpl<T> extends PrismPropertyWrapperImpl<T> implements ResourceAttributeWrapper<T> {

private static final long serialVersionUID = 1L;
@Serial private static final long serialVersionUID = 1L;

public ResourceAttributeWrapperImpl(PrismContainerValueWrapper<?> parent, ResourceAttribute<T> item, ItemStatus status) {
super(parent, item, status);
Expand Down Expand Up @@ -283,6 +284,11 @@ public String getFrameworkAttributeName() {
return getRefinedAttributeDefinition().getFrameworkAttributeName();
}

@Override
public boolean hasRefinements() {
return getRefinedAttributeDefinition().hasRefinements();
}

@Override
public @NotNull LayerType getCurrentLayer() {
return getRefinedAttributeDefinition().getCurrentLayer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public boolean canBeDefinitionOf(PrismContainer<ValueMetadataType> item) {
}

@Override
public boolean canBeDefinitionOf(PrismValue pvalue) {
public boolean canBeDefinitionOf(@NotNull PrismValue pvalue) {
return metadataValueWrapper.canBeDefinitionOf(pvalue);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

package com.evolveum.midpoint.init;

import com.evolveum.midpoint.schema.constants.MidPointConstants;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.schema.util.SchemaDebugUtil;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;

Expand All @@ -20,7 +19,7 @@ public class InfraInitialSetup {
private static final Trace LOGGER = TraceManager.getTrace(InfraInitialSetup.class);

public void init() {
PrettyPrinter.setDefaultNamespacePrefix(MidPointConstants.NS_MIDPOINT_PUBLIC_PREFIX);
SchemaDebugUtil.initializePrettyPrinter();
// Make sure that JUL is loaded in the main classloader
java.util.logging.Logger logger = java.util.logging.Logger.getLogger(InfraInitialSetup.class.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ protected UserType load() {
PrismObject<UserType> user = WebModelServiceUtils.loadObject(UserType.class, principal.getOid(), PagePostAuthentication.this, task, task.getResult());
try {
PrismObjectDefinition<UserType> userDef = getModelInteractionService().getEditObjectDefinition(user, null, task, task.getResult());
if (userDef != null) {
user.applyDefinition(userDef, true);
}
user.applyDefinition(userDef, true);
} catch (SchemaException | ConfigurationException | ObjectNotFoundException | ExpressionEvaluationException
| CommunicationException | SecurityViolationException e) {
//TODO: nothing critical even by the error. for now just log it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.io.IOException;
import javax.xml.datatype.XMLGregorianCalendar;

import com.evolveum.midpoint.schema.util.SchemaDebugUtil;

import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import org.xml.sax.SAXException;
Expand Down Expand Up @@ -44,7 +46,7 @@ public abstract class AbstractActivationComputerTest extends AbstractUnitTest {

@BeforeSuite
public void setup() throws SchemaException, SAXException, IOException {
PrettyPrinter.setDefaultNamespacePrefix(MidPointConstants.NS_MIDPOINT_PUBLIC_PREFIX);
SchemaDebugUtil.initializePrettyPrinter();
PrismTestUtil.resetPrismContext(MidPointPrismContextFactory.FACTORY);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,33 @@

package com.evolveum.midpoint.common;

import static org.assertj.core.api.Assertions.assertThat;

import static com.evolveum.midpoint.prism.util.PrismTestUtil.getPrismContext;

import java.io.File;
import java.io.IOException;
import java.util.Locale;

import org.testng.AssertJUnit;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import org.xml.sax.SAXException;

import com.evolveum.midpoint.common.configuration.api.MidpointConfiguration;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.midpoint.schema.MidPointPrismContextFactory;
import com.evolveum.midpoint.schema.constants.MidPointConstants;
import com.evolveum.midpoint.schema.util.SchemaDebugUtil;
import com.evolveum.midpoint.tools.testng.AbstractUnitTest;
import com.evolveum.midpoint.util.LocalizableMessage;
import com.evolveum.midpoint.util.LocalizableMessageBuilder;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.exception.SchemaException;

import com.evolveum.midpoint.xml.ns._public.common.common_3.CaseType;

import org.testng.AssertJUnit;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import org.xml.sax.SAXException;

import java.io.File;
import java.io.IOException;
import java.util.Locale;

import static com.evolveum.midpoint.prism.util.PrismTestUtil.getPrismContext;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Created by Viliam Repan (lazyman).
*/
Expand All @@ -50,7 +48,7 @@ public class LocalizationTest extends AbstractUnitTest {

@BeforeSuite
public void setup() throws SchemaException, SAXException, IOException {
PrettyPrinter.setDefaultNamespacePrefix(MidPointConstants.NS_MIDPOINT_PUBLIC_PREFIX);
SchemaDebugUtil.initializePrettyPrinter();
PrismTestUtil.resetPrismContext(MidPointPrismContextFactory.FACTORY);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package com.evolveum.midpoint.common;

import static com.evolveum.midpoint.schema.constants.SchemaConstants.ICFS_PASSWORD;
import static com.evolveum.midpoint.schema.util.task.work.SpecificWorkDefinitionUtil.*;

import static java.util.Collections.singleton;
Expand All @@ -31,6 +32,7 @@
import com.evolveum.midpoint.schema.constants.SchemaConstants;

import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.schema.util.SchemaDebugUtil;
import com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType;

import org.testng.Assert;
Expand Down Expand Up @@ -77,7 +79,7 @@ public class TestCryptoUtil extends AbstractUnitTest {

@BeforeSuite
public void setup() throws SchemaException, SAXException, IOException {
PrettyPrinter.setDefaultNamespacePrefix(MidPointConstants.NS_MIDPOINT_PUBLIC_PREFIX);
SchemaDebugUtil.initializePrettyPrinter();
PrismTestUtil.resetPrismContext(MidPointPrismContextFactory.FACTORY);
protector = createProtector();
}
Expand Down Expand Up @@ -167,8 +169,7 @@ public void test127EncryptAddAccountTaskManuallyConstructedLegacy() throws Excep
shadow.asPrismObject().add(attributes);

MutablePrismPropertyDefinition<ProtectedStringType> passwordDef = prismContext.definitionFactory()
.createPropertyDefinition(
new QName(SchemaConstants.NS_ICF_SCHEMA, "password"), ProtectedStringType.COMPLEX_TYPE);
.createPropertyDefinition(ICFS_PASSWORD, ProtectedStringType.COMPLEX_TYPE);
PrismProperty<ProtectedStringType> password = passwordDef.instantiate();
ProtectedStringType passwordRealValue = new ProtectedStringType();
passwordRealValue.setClearValue(PASSWORD_PLAINTEXT);
Expand Down Expand Up @@ -206,16 +207,15 @@ public void test128EncryptAddAccountTaskManuallyConstructedNew() throws Exceptio
.name("test128")
.asPrismObject();

ShadowType shadow = new ShadowType(prismContext)
ShadowType shadow = new ShadowType()
.name("some-shadow");
PrismContainerDefinition<Containerable> attributesDef = shadow.asPrismObject().getDefinition()
.findContainerDefinition(ShadowType.F_ATTRIBUTES);
PrismContainer<?> attributes = attributesDef.instantiate();
shadow.asPrismObject().add(attributes);

MutablePrismPropertyDefinition<ProtectedStringType> passwordDef = prismContext.definitionFactory()
.createPropertyDefinition(
new QName(SchemaConstants.NS_ICF_SCHEMA, "password"), ProtectedStringType.COMPLEX_TYPE);
.createPropertyDefinition(ICFS_PASSWORD, ProtectedStringType.COMPLEX_TYPE);
PrismProperty<ProtectedStringType> password = passwordDef.instantiate();
ProtectedStringType passwordRealValue = new ProtectedStringType();
passwordRealValue.setClearValue(PASSWORD_PLAINTEXT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

import java.io.IOException;
import java.util.List;

import com.evolveum.midpoint.schema.util.SchemaDebugUtil;

import jakarta.xml.bind.JAXBElement;
import javax.xml.namespace.QName;

Expand Down Expand Up @@ -37,7 +40,7 @@ public class TestStaticValues extends AbstractUnitTest {

@BeforeSuite
public void setup() throws SchemaException, SAXException, IOException {
PrettyPrinter.setDefaultNamespacePrefix(MidPointConstants.NS_MIDPOINT_PUBLIC_PREFIX);
SchemaDebugUtil.initializePrettyPrinter();
PrismTestUtil.resetPrismContext(MidPointPrismContextFactory.FACTORY);
}

Expand Down

0 comments on commit faad391

Please sign in to comment.