Search in sources :

Example 41 with PrismPropertyValue

use of com.evolveum.midpoint.prism.PrismPropertyValue in project midpoint by Evolveum.

the class SynchronizationUtils method createSynchronizationSituationDescriptionDelta.

public static List<PropertyDelta<?>> createSynchronizationSituationDescriptionDelta(PrismObject object, SynchronizationSituationType situation, XMLGregorianCalendar timestamp, String sourceChannel, boolean full) {
    SynchronizationSituationDescriptionType syncSituationDescription = new SynchronizationSituationDescriptionType();
    syncSituationDescription.setSituation(situation);
    syncSituationDescription.setChannel(sourceChannel);
    syncSituationDescription.setTimestamp(timestamp);
    syncSituationDescription.setFull(full);
    List<PropertyDelta<?>> deltas = new ArrayList<PropertyDelta<?>>();
    PropertyDelta syncSituationDelta = PropertyDelta.createDelta(new ItemPath(ShadowType.F_SYNCHRONIZATION_SITUATION_DESCRIPTION), object.getDefinition());
    syncSituationDelta.addValueToAdd(new PrismPropertyValue(syncSituationDescription));
    deltas.add(syncSituationDelta);
    List<PrismPropertyValue<SynchronizationSituationDescriptionType>> oldSituationDescriptions = getSituationFromSameChannel(object, sourceChannel);
    if (oldSituationDescriptions != null && !oldSituationDescriptions.isEmpty()) {
        syncSituationDelta = PropertyDelta.createDelta(new ItemPath(ShadowType.F_SYNCHRONIZATION_SITUATION_DESCRIPTION), object.getDefinition());
        syncSituationDelta.addValuesToDelete(oldSituationDescriptions);
        deltas.add(syncSituationDelta);
    }
    return deltas;
}
Also used : ArrayList(java.util.ArrayList) SynchronizationSituationDescriptionType(com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationSituationDescriptionType) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 42 with PrismPropertyValue

use of com.evolveum.midpoint.prism.PrismPropertyValue in project midpoint by Evolveum.

the class CryptoUtil method checkEncrypted.

private static <T extends ObjectType> void checkEncrypted(PrismPropertyValue<?> pval) {
    Itemable item = pval.getParent();
    if (item == null) {
        return;
    }
    ItemDefinition itemDef = item.getDefinition();
    if (itemDef == null || itemDef.getTypeName() == null) {
        return;
    }
    if (itemDef.getTypeName().equals(ProtectedStringType.COMPLEX_TYPE)) {
        QName propName = item.getElementName();
        PrismPropertyValue<ProtectedStringType> psPval = (PrismPropertyValue<ProtectedStringType>) pval;
        ProtectedStringType ps = psPval.getValue();
        if (ps.getClearValue() != null) {
            throw new IllegalStateException("Unencrypted value in field " + propName);
        }
    } else if (itemDef.getTypeName().equals(NotificationConfigurationType.COMPLEX_TYPE)) {
        // this is really ugly hack needed because currently it is not possible to break NotificationConfigurationType into prism item [pm]
        NotificationConfigurationType ncfg = ((PrismPropertyValue<NotificationConfigurationType>) pval).getValue();
        if (ncfg.getMail() != null) {
            for (MailServerConfigurationType mscfg : ncfg.getMail().getServer()) {
                if (mscfg.getPassword() != null && mscfg.getPassword().getClearValue() != null) {
                    throw new IllegalStateException("Unencrypted value in mail server config password entry");
                }
            }
        }
        if (ncfg.getSms() != null) {
            for (SmsConfigurationType smscfg : ncfg.getSms()) {
                for (SmsGatewayConfigurationType gwcfg : smscfg.getGateway()) {
                    if (gwcfg.getPassword() != null && gwcfg.getPassword().getClearValue() != null) {
                        throw new IllegalStateException("Unencrypted value in SMS gateway config password entry");
                    }
                }
            }
        }
    }
}
Also used : NotificationConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.NotificationConfigurationType) Itemable(com.evolveum.midpoint.prism.Itemable) QName(javax.xml.namespace.QName) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) MailServerConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.MailServerConfigurationType) SmsGatewayConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SmsGatewayConfigurationType) SmsConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SmsConfigurationType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 43 with PrismPropertyValue

use of com.evolveum.midpoint.prism.PrismPropertyValue in project midpoint by Evolveum.

the class CryptoUtil method encryptValue.

private static <T extends ObjectType> void encryptValue(Protector protector, PrismPropertyValue<?> pval) throws EncryptionException {
    Itemable item = pval.getParent();
    if (item == null) {
        return;
    }
    ItemDefinition itemDef = item.getDefinition();
    if (itemDef == null || itemDef.getTypeName() == null) {
        return;
    }
    if (itemDef.getTypeName().equals(ProtectedStringType.COMPLEX_TYPE)) {
        QName propName = item.getElementName();
        PrismPropertyValue<ProtectedStringType> psPval = (PrismPropertyValue<ProtectedStringType>) pval;
        ProtectedStringType ps = psPval.getValue();
        encryptProtectedStringType(protector, ps, propName.getLocalPart());
        if (pval.getParent() == null) {
            pval.setParent(item);
        }
    } else if (itemDef.getTypeName().equals(NotificationConfigurationType.COMPLEX_TYPE)) {
        // this is really ugly hack needed because currently it is not possible to break NotificationConfigurationType into prism item [pm]
        NotificationConfigurationType ncfg = ((PrismPropertyValue<NotificationConfigurationType>) pval).getValue();
        if (ncfg.getMail() != null) {
            for (MailServerConfigurationType mscfg : ncfg.getMail().getServer()) {
                encryptProtectedStringType(protector, mscfg.getPassword(), "mail server password");
            }
        }
        if (ncfg.getSms() != null) {
            for (SmsConfigurationType smscfg : ncfg.getSms()) {
                for (SmsGatewayConfigurationType gwcfg : smscfg.getGateway()) {
                    encryptProtectedStringType(protector, gwcfg.getPassword(), "sms gateway password");
                }
            }
        }
    }
}
Also used : NotificationConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.NotificationConfigurationType) Itemable(com.evolveum.midpoint.prism.Itemable) QName(javax.xml.namespace.QName) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) MailServerConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.MailServerConfigurationType) SmsGatewayConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SmsGatewayConfigurationType) SmsConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SmsConfigurationType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 44 with PrismPropertyValue

use of com.evolveum.midpoint.prism.PrismPropertyValue in project midpoint by Evolveum.

the class TestJaxbSanity method testUnmarshallAndEqualsResource.

@Test
public void testUnmarshallAndEqualsResource() throws JAXBException, SchemaException, FileNotFoundException {
    System.out.println("\n\n ===[testUnmarshallAndEqualsResource]===\n");
    // GIVEN
    ResourceType resource1Type = JaxbTestUtil.getInstance().unmarshalObject(new File(RESOURCE_OPENDJ_FILENAME), ResourceType.class);
    assertNotNull(resource1Type);
    System.out.println("Resource1 " + resource1Type.asPrismObject().debugDump());
    PrismObject resource1 = resource1Type.asPrismObject();
    ResourceType resource2Type = JaxbTestUtil.getInstance().unmarshalObject(new File(RESOURCE_OPENDJ_FILENAME), ResourceType.class);
    assertNotNull(resource2Type);
    System.out.println("Resource2 " + resource2Type.asPrismObject().debugDump());
    PrismObject resource2 = resource2Type.asPrismObject();
    // WHEN, THEN
    ObjectDelta<ResourceType> objectDelta = resource1.diff(resource2);
    System.out.println("Resource delta:");
    System.out.println(objectDelta.debugDump());
    assertTrue("Resource delta is not empty", objectDelta.isEmpty());
    assertTrue("Resource not equal", resource1Type.equals(resource2Type));
    System.out.println("HASH");
    System.out.println(resource1Type.hashCode());
    System.out.println(resource2Type.hashCode());
    assertTrue("Resource hashcode does not match", resource1Type.hashCode() == resource2Type.hashCode());
    PrismPropertyValue<Object> pv1 = new PrismPropertyValue<Object>(resource1Type.getConnectorConfiguration());
    PrismPropertyValue<Object> pv2 = new PrismPropertyValue<Object>(resource2Type.getConnectorConfiguration());
    assertTrue("Real property values not equal", pv1.equalsRealValue(pv2));
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismObject(com.evolveum.midpoint.prism.PrismObject) File(java.io.File) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) Test(org.testng.annotations.Test)

Example 45 with PrismPropertyValue

use of com.evolveum.midpoint.prism.PrismPropertyValue in project midpoint by Evolveum.

the class TestMappingTime method testNoReferenceTime.

@Test
public void testNoReferenceTime() throws Exception {
    final String TEST_NAME = "testNoReferenceTime";
    System.out.println("===[ " + TEST_NAME + "]===");
    // GIVEN
    PrismObject<UserType> userOld = evaluator.getUserOld();
    userOld.asObjectable().getActivation().setDisableTimestamp(null);
    Mapping.Builder<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> builder = evaluator.createMappingBuilder(MAPPING_TIME_ACTIVATION, TEST_NAME, "title", null, userOld);
    builder.setNow(TIME_PAST);
    PrismPropertyDefinition<Boolean> existenceDef = new PrismPropertyDefinitionImpl<>(ExpressionConstants.OUTPUT_ELEMENT_NAME, DOMUtil.XSD_BOOLEAN, evaluator.getPrismContext());
    builder.setDefaultTargetDefinition(existenceDef);
    Mapping<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> mapping = builder.build();
    OperationResult opResult = new OperationResult(TEST_NAME);
    // WHEN
    mapping.evaluate(null, opResult);
    // THEN
    PrismValueDeltaSetTriple<PrismPropertyValue<Boolean>> outputTriple = mapping.getOutputTriple();
    assertNullTriple(outputTriple);
    assertNextRecompute(mapping, null);
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismPropertyDefinitionImpl(com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) Test(org.testng.annotations.Test)

Aggregations

PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)176 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)93 Test (org.testng.annotations.Test)83 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)81 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)81 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)60 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)43 QName (javax.xml.namespace.QName)35 PrismObject (com.evolveum.midpoint.prism.PrismObject)29 PrismPropertyDefinitionImpl (com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl)19 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)17 ArrayList (java.util.ArrayList)16 Task (com.evolveum.midpoint.task.api.Task)12 ExpressionEvaluationContext (com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext)11 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)10 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)9 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)9 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)8 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)8 File (java.io.File)8