Search in sources :

Example 1 with ShadowAttributesType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAttributesType in project midpoint by Evolveum.

the class TestIntegrationObjectWrapperFactory method test150CreateWrapperShadow.

@Test
public void test150CreateWrapperShadow() throws Exception {
    final String TEST_NAME = "test150CreateWrapperShadow";
    TestUtil.displayTestTile(TEST_NAME);
    PrismObject<ShadowType> shadow = getShadowModel(accountJackOid);
    shadow.findReference(ShadowType.F_RESOURCE_REF).getValue().setObject(resourceDummy);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    Task task = taskManager.createTaskInstance(TEST_NAME);
    ObjectWrapperFactory factory = new ObjectWrapperFactory(getServiceLocator());
    ObjectWrapper<ShadowType> objectWrapper = factory.createObjectWrapper("shadow display name", "shadow description", shadow, ContainerStatus.MODIFYING, task);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    display("Wrapper after", objectWrapper);
    WrapperTestUtil.assertWrapper(objectWrapper, "shadow display name", "shadow description", shadow, ContainerStatus.MODIFYING);
    assertEquals("wrong number of containers in " + objectWrapper, 9, objectWrapper.getContainers().size());
    ContainerWrapper<ShadowAttributesType> attributesContainerWrapper = objectWrapper.findContainerWrapper(new ItemPath(ShadowType.F_ATTRIBUTES));
    PrismContainer<ShadowAttributesType> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
    WrapperTestUtil.assertWrapper(attributesContainerWrapper, "prismContainer.shadow.mainPanelDisplayName", new ItemPath(ShadowType.F_ATTRIBUTES), attributesContainer, true, ContainerStatus.MODIFYING);
    WrapperTestUtil.assertPropertyWrapper(attributesContainerWrapper, dummyResourceCtl.getAttributeFullnameQName(), USER_JACK_FULL_NAME);
    WrapperTestUtil.assertPropertyWrapper(attributesContainerWrapper, SchemaConstants.ICFS_NAME, USER_JACK_USERNAME);
    assertEquals("wrong number of items in " + attributesContainerWrapper, 16, attributesContainerWrapper.getItems().size());
    ContainerWrapper<ActivationType> activationContainerWrapper = objectWrapper.findContainerWrapper(new ItemPath(UserType.F_ACTIVATION));
    WrapperTestUtil.assertWrapper(activationContainerWrapper, "ShadowType.activation", UserType.F_ACTIVATION, shadow, ContainerStatus.MODIFYING);
    WrapperTestUtil.assertPropertyWrapper(activationContainerWrapper, ActivationType.F_ADMINISTRATIVE_STATUS, ActivationStatusType.ENABLED);
    WrapperTestUtil.assertPropertyWrapper(activationContainerWrapper, ActivationType.F_LOCKOUT_STATUS, null);
    assertEquals("Wrong attributes container wrapper readOnly", Boolean.FALSE, (Boolean) attributesContainerWrapper.isReadonly());
    ItemWrapper fullnameWrapper = attributesContainerWrapper.findPropertyWrapper(dummyResourceCtl.getAttributeFullnameQName());
    // Is this OK?
    assertEquals("Wrong attribute fullname readOnly", Boolean.FALSE, (Boolean) fullnameWrapper.isReadonly());
    assertEquals("Wrong attribute fullname visible", Boolean.TRUE, (Boolean) fullnameWrapper.isVisible());
    ItemDefinition fullNameDefinition = fullnameWrapper.getItemDefinition();
    display("fullname attribute definition", fullNameDefinition);
    assertEquals("Wrong attribute fullname definition.canRead", Boolean.TRUE, (Boolean) fullNameDefinition.canRead());
    assertEquals("Wrong attribute fullname definition.canAdd", Boolean.TRUE, (Boolean) fullNameDefinition.canAdd());
    assertEquals("Wrong attribute fullname definition.canModify", Boolean.TRUE, (Boolean) fullNameDefinition.canModify());
    // MID-3144
    if (fullNameDefinition.getDisplayOrder() == null || fullNameDefinition.getDisplayOrder() < 100 || fullNameDefinition.getDisplayOrder() > 400) {
        AssertJUnit.fail("Wrong fullname definition.displayOrder: " + fullNameDefinition.getDisplayOrder());
    }
    assertEquals("Wrong attribute fullname definition.displayName", "Full Name", fullNameDefinition.getDisplayName());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ShadowAttributesType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAttributesType) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) ItemWrapper(com.evolveum.midpoint.web.component.prism.ItemWrapper) ActivationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType) ObjectWrapperFactory(com.evolveum.midpoint.web.component.prism.ObjectWrapperFactory) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 2 with ShadowAttributesType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAttributesType in project midpoint by Evolveum.

the class ShadowIntegrityCheckResultHandler method checkShadow.

private void checkShadow(ShadowCheckResult checkResult, PrismObject<ShadowType> shadow, Task workerTask, OperationResult result) throws SchemaException {
    ShadowType shadowType = shadow.asObjectable();
    ObjectReferenceType resourceRef = shadowType.getResourceRef();
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Checking shadow {} (resource {})", ObjectTypeUtil.toShortString(shadowType), resourceRef != null ? resourceRef.getOid() : "(null)");
    }
    statistics.incrementShadows();
    if (resourceRef == null) {
        checkResult.recordError(Statistics.NO_RESOURCE_OID, new SchemaException("No resourceRef"));
        fixNoResourceIfRequested(checkResult, Statistics.NO_RESOURCE_OID);
        applyFixes(checkResult, shadow, workerTask, result);
        return;
    }
    String resourceOid = resourceRef.getOid();
    if (resourceOid == null) {
        checkResult.recordError(Statistics.NO_RESOURCE_OID, new SchemaException("Null resource OID"));
        fixNoResourceIfRequested(checkResult, Statistics.NO_RESOURCE_OID);
        applyFixes(checkResult, shadow, workerTask, result);
        return;
    }
    PrismObject<ResourceType> resource = resources.get(resourceOid);
    if (resource == null) {
        statistics.incrementResources();
        try {
            resource = provisioningService.getObject(ResourceType.class, resourceOid, null, workerTask, result);
        } catch (ObjectNotFoundException e) {
            checkResult.recordError(Statistics.NO_RESOURCE, new ObjectNotFoundException("Resource object does not exist: " + e.getMessage(), e));
            fixNoResourceIfRequested(checkResult, Statistics.NO_RESOURCE);
            applyFixes(checkResult, shadow, workerTask, result);
            return;
        } catch (SchemaException e) {
            checkResult.recordError(Statistics.CANNOT_GET_RESOURCE, new SchemaException("Resource object has schema problems: " + e.getMessage(), e));
            return;
        } catch (CommonException | RuntimeException e) {
            checkResult.recordError(Statistics.CANNOT_GET_RESOURCE, new SystemException("Resource object cannot be fetched for some reason: " + e.getMessage(), e));
            return;
        }
        resources.put(resourceOid, resource);
    }
    checkResult.setResource(resource);
    ShadowKindType kind = shadowType.getKind();
    if (kind == null) {
        // TODO or simply assume account?
        checkResult.recordError(Statistics.NO_KIND_SPECIFIED, new SchemaException("No kind specified"));
        return;
    }
    if (checkExtraData) {
        checkOrFixShadowActivationConsistency(checkResult, shadow, fixExtraData);
    }
    PrismObject<ShadowType> fetchedShadow = null;
    if (checkFetch) {
        fetchedShadow = fetchShadow(checkResult, shadow, resource, workerTask, result);
        if (fetchedShadow != null) {
            shadow.setUserData(KEY_EXISTS_ON_RESOURCE, "true");
        }
    }
    if (checkOwners) {
        List<PrismObject<FocusType>> owners = searchOwners(shadow, result);
        if (owners != null) {
            shadow.setUserData(KEY_OWNERS, owners);
            if (owners.size() > 1) {
                checkResult.recordError(Statistics.MULTIPLE_OWNERS, new SchemaException("Multiple owners: " + owners));
            }
        }
        if (shadowType.getSynchronizationSituation() == SynchronizationSituationType.LINKED && (owners == null || owners.isEmpty())) {
            checkResult.recordError(Statistics.LINKED_WITH_NO_OWNER, new SchemaException("Linked shadow with no owner"));
        }
        if (shadowType.getSynchronizationSituation() != SynchronizationSituationType.LINKED && owners != null && !owners.isEmpty()) {
            checkResult.recordError(Statistics.NOT_LINKED_WITH_OWNER, new SchemaException("Shadow with an owner but not marked as linked (marked as " + shadowType.getSynchronizationSituation() + ")"));
        }
    }
    String intent = shadowType.getIntent();
    if (checkIntents && (intent == null || intent.isEmpty())) {
        checkResult.recordWarning(Statistics.NO_INTENT_SPECIFIED, "None or empty intent");
    }
    if (fixIntents && (intent == null || intent.isEmpty())) {
        doFixIntent(checkResult, fetchedShadow, shadow, resource, workerTask, result);
    }
    Pair<String, ShadowKindType> key = new ImmutablePair<>(resourceOid, kind);
    ObjectTypeContext context = contextMap.get(key);
    if (context == null) {
        context = new ObjectTypeContext();
        context.setResource(resource);
        RefinedResourceSchema resourceSchema;
        try {
            resourceSchema = RefinedResourceSchemaImpl.getRefinedSchema(context.getResource(), LayerType.MODEL, prismContext);
        } catch (SchemaException e) {
            checkResult.recordError(Statistics.CANNOT_GET_REFINED_SCHEMA, new SchemaException("Couldn't derive resource schema: " + e.getMessage(), e));
            return;
        }
        if (resourceSchema == null) {
            checkResult.recordError(Statistics.NO_RESOURCE_REFINED_SCHEMA, new SchemaException("No resource schema"));
            return;
        }
        context.setObjectClassDefinition(resourceSchema.getRefinedDefinition(kind, shadowType));
        if (context.getObjectClassDefinition() == null) {
            // TODO or warning only?
            checkResult.recordError(Statistics.NO_OBJECT_CLASS_REFINED_SCHEMA, new SchemaException("No refined object class definition for kind=" + kind + ", intent=" + intent));
            return;
        }
        contextMap.put(key, context);
    }
    try {
        provisioningService.applyDefinition(shadow, workerTask, result);
    } catch (SchemaException | ObjectNotFoundException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
        checkResult.recordError(Statistics.OTHER_FAILURE, new SystemException("Couldn't apply definition to shadow from repo", e));
        return;
    }
    Set<RefinedAttributeDefinition<?>> identifiers = new HashSet<>();
    Collection<? extends RefinedAttributeDefinition<?>> primaryIdentifiers = context.getObjectClassDefinition().getPrimaryIdentifiers();
    identifiers.addAll(primaryIdentifiers);
    identifiers.addAll(context.getObjectClassDefinition().getSecondaryIdentifiers());
    PrismContainer<ShadowAttributesType> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
    if (attributesContainer == null) {
        // might happen on unfinished shadows?
        checkResult.recordError(Statistics.OTHER_FAILURE, new SchemaException("No attributes container"));
        return;
    }
    for (RefinedAttributeDefinition<?> identifier : identifiers) {
        PrismProperty property = attributesContainer.getValue().findProperty(identifier.getName());
        if (property == null || property.size() == 0) {
            checkResult.recordWarning(Statistics.OTHER_FAILURE, "No value for identifier " + identifier.getName());
            continue;
        }
        if (property.size() > 1) {
            // we don't expect multi-valued identifiers
            checkResult.recordError(Statistics.OTHER_FAILURE, new SchemaException("Multi-valued identifier " + identifier.getName() + " with values " + property.getValues()));
            continue;
        }
        // size == 1
        String value = (String) property.getValue().getValue();
        if (value == null) {
            checkResult.recordWarning(Statistics.OTHER_FAILURE, "Null value for identifier " + identifier.getName());
            continue;
        }
        if (checkUniqueness) {
            if (!checkDuplicatesOnPrimaryIdentifiersOnly || primaryIdentifiers.contains(identifier)) {
                addIdentifierValue(checkResult, context, identifier.getName(), value, shadow);
            }
        }
        if (checkNormalization) {
            doCheckNormalization(checkResult, identifier, value, context);
        }
    }
    applyFixes(checkResult, shadow, workerTask, result);
}
Also used : ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) PrismObject(com.evolveum.midpoint.prism.PrismObject) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) RefinedAttributeDefinition(com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) HashSet(java.util.HashSet) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ShadowAttributesType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAttributesType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) CommonException(com.evolveum.midpoint.util.exception.CommonException) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)

Example 3 with ShadowAttributesType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAttributesType in project midpoint by Evolveum.

the class TestRefinedSchema method assertAccountShadow.

private void assertAccountShadow(PrismObject<ShadowType> accObject, PrismObject<ResourceType> resource, PrismContext prismContext) throws SchemaException, JAXBException {
    ResourceType resourceType = resource.asObjectable();
    QName objectClassQName = new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "AccountObjectClass");
    PrismAsserts.assertPropertyValue(accObject, ShadowType.F_NAME, createPolyString("jack"));
    PrismAsserts.assertPropertyValue(accObject, ShadowType.F_OBJECT_CLASS, objectClassQName);
    PrismAsserts.assertPropertyValue(accObject, ShadowType.F_INTENT, SchemaConstants.INTENT_DEFAULT);
    PrismContainer<?> attributes = accObject.findOrCreateContainer(SchemaConstants.C_ATTRIBUTES);
    assertEquals("Wrong type of <attributes> definition in account", ResourceAttributeContainerDefinitionImpl.class, attributes.getDefinition().getClass());
    ResourceAttributeContainerDefinition attrDef = (ResourceAttributeContainerDefinition) attributes.getDefinition();
    assertAttributeDefs(attrDef, resourceType, null, LayerType.MODEL);
    PrismAsserts.assertPropertyValue(attributes, SchemaTestConstants.ICFS_NAME, "uid=jack,ou=People,dc=example,dc=com");
    PrismAsserts.assertPropertyValue(attributes, getAttrQName(resource, "cn"), "Jack Sparrow");
    PrismAsserts.assertPropertyValue(attributes, getAttrQName(resource, "givenName"), "Jack");
    PrismAsserts.assertPropertyValue(attributes, getAttrQName(resource, "sn"), "Sparrow");
    PrismAsserts.assertPropertyValue(attributes, getAttrQName(resource, "uid"), "jack");
    assertEquals("JAXB class name doesn't match (1)", ShadowType.class, accObject.getCompileTimeClass());
    accObject.checkConsistence();
    ShadowType accObjectType = accObject.asObjectable();
    assertEquals("Wrong JAXB name", createPolyStringType("jack"), accObjectType.getName());
    assertEquals("Wrong JAXB objectClass", objectClassQName, accObjectType.getObjectClass());
    ShadowAttributesType attributesType = accObjectType.getAttributes();
    assertNotNull("null ResourceObjectShadowAttributesType (JAXB)", attributesType);
    List<Object> attributeElements = attributesType.getAny();
    TestUtil.assertElement(attributeElements, SchemaTestConstants.ICFS_NAME, "uid=jack,ou=People,dc=example,dc=com");
    TestUtil.assertElement(attributeElements, getAttrQName(resource, "cn"), "Jack Sparrow");
    TestUtil.assertElement(attributeElements, getAttrQName(resource, "givenName"), "Jack");
    TestUtil.assertElement(attributeElements, getAttrQName(resource, "sn"), "Sparrow");
    TestUtil.assertElement(attributeElements, getAttrQName(resource, "uid"), "jack");
    String accString = PrismTestUtil.serializeObjectToString(accObjectType.asPrismObject());
    System.out.println("Result of JAXB marshalling:\n" + accString);
    accObject.checkConsistence(true, true, ConsistencyCheckScope.THOROUGH);
}
Also used : QName(javax.xml.namespace.QName) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ShadowAttributesType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAttributesType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 4 with ShadowAttributesType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAttributesType in project midpoint by Evolveum.

the class AbstractTestForExchangeConnector method createDistributionGroup.

protected String createDistributionGroup(String name, String primaryAddress, Collection<String> members, String ou, String displayName, String valueForFilter) throws FaultMessage {
    Document doc = ModelClientUtil.getDocumnent();
    ShadowType shadow = new ShadowType();
    shadow.setName(ModelClientUtil.createPolyStringType(name, doc));
    shadow.setResourceRef(createObjectReferenceType(ResourceType.class, getResourceOid()));
    shadow.setObjectClass(OC_DISTRIBUTION_GROUP);
    shadow.setKind(ShadowKindType.GENERIC);
    shadow.setIntent("distribution-group");
    ShadowAttributesType attributes = new ShadowAttributesType();
    attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_ICFS, "name"), name, doc));
    attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_RI, "Type"), "Security", doc));
    attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_RI, "PrimarySmtpAddress"), primaryAddress, doc));
    for (String member : members) {
        attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_RI, "Members"), member, doc));
    }
    attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_RI, "OrganizationalUnit"), ou, doc));
    attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_RI, "DisplayName"), displayName, doc));
    attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_RI, "HiddenFromAddressListsEnabled"), "true", doc));
    attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_RI, "CustomAttribute1"), valueForFilter, doc));
    attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_RI, "BypassSecurityGroupManagerCheck"), "true", doc));
    shadow.setAttributes(attributes);
    return createShadow(shadow);
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) ShadowAttributesType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAttributesType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) Document(org.w3c.dom.Document)

Example 5 with ShadowAttributesType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAttributesType in project midpoint by Evolveum.

the class AbstractTestForExchangeConnector method createAcceptedDomain.

protected String createAcceptedDomain(String name, String domainName, String domainType) throws FaultMessage {
    Document doc = ModelClientUtil.getDocumnent();
    ShadowType shadow = new ShadowType();
    shadow.setName(ModelClientUtil.createPolyStringType(name, doc));
    shadow.setResourceRef(createObjectReferenceType(ResourceType.class, getResourceOid()));
    shadow.setObjectClass(OC_ACCEPTED_DOMAIN);
    shadow.setKind(ShadowKindType.GENERIC);
    shadow.setIntent("custom-accepted-domain");
    ShadowAttributesType attributes = new ShadowAttributesType();
    attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_ICFS, "name"), name, doc));
    attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_RI, "DomainName"), domainName, doc));
    attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_RI, "DomainType"), domainType, doc));
    shadow.setAttributes(attributes);
    return createShadow(shadow);
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) ShadowAttributesType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAttributesType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) Document(org.w3c.dom.Document)

Aggregations

ShadowAttributesType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAttributesType)15 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)13 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)12 QName (javax.xml.namespace.QName)11 Document (org.w3c.dom.Document)9 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 HashMap (java.util.HashMap)3 Test (org.testng.annotations.Test)3 ObjectDeltaOperationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType)2 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)2 ShadowKindType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)2 Map (java.util.Map)2 JAXBElement (javax.xml.bind.JAXBElement)2 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)2 Element (org.w3c.dom.Element)2 RefinedAttributeDefinition (com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition)1 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)1 Item (com.evolveum.midpoint.prism.Item)1 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)1 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)1