Search in sources :

Example 11 with ShadowAttributesType

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

the class AbstractTestForExchangeConnector method createAddressBookPolicy.

protected String createAddressBookPolicy(String name, Collection<String> addressLists, String gal, String oab, String rooms) 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_ADDRESS_BOOK_POLICY);
    shadow.setKind(ShadowKindType.GENERIC);
    shadow.setIntent("address-book-policy");
    ShadowAttributesType attributes = new ShadowAttributesType();
    attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_ICFS, "name"), name, doc));
    for (String addressList : addressLists) {
        attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_RI, "AddressLists"), addressList, doc));
    }
    attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_RI, "GlobalAddressList"), gal, doc));
    attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_RI, "OfflineAddressBook"), oab, doc));
    attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_RI, "RoomList"), rooms, 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 12 with ShadowAttributesType

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

the class AbstractTestForExchangeConnector method prepareShadowType.

// additionalAttributes: e.g. "OfflineAddressBook" -> "OAB123"
private ShadowType prepareShadowType(String givenName, String sn, String name, String recipientType, String overrideMail, String samAccountName, String upn, Map<String, Object> additionalAttributes) {
    if (samAccountName == null) {
        samAccountName = sn.toLowerCase();
    }
    Document doc = ModelClientUtil.getDocumnent();
    ShadowType user = new ShadowType();
    user.setName(ModelClientUtil.createPolyStringType(name, doc));
    user.setResourceRef(createObjectReferenceType(ResourceType.class, getResourceOid()));
    user.setObjectClass(OC_ACCOUNT);
    user.setKind(ShadowKindType.ACCOUNT);
    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, "givenName"), givenName, doc));
    attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_RI, "sn"), sn, doc));
    attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_RI, "RecipientType"), recipientType, doc));
    attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_RI, "sAMAccountName"), samAccountName, doc));
    if (overrideMail != null) {
        attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_RI, "EmailAddressPolicyEnabled"), "true", doc));
        attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_RI, "EmailAddresses"), overrideMail, doc));
    }
    if (upn != null) {
        attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_RI, "userPrincipalName"), upn, doc));
    }
    if (additionalAttributes != null) {
        for (Map.Entry<String, Object> entry : additionalAttributes.entrySet()) {
            if (entry.getValue() instanceof Collection) {
                for (Object value : (Collection) entry.getValue()) {
                    addAttribute(attributes, entry.getKey(), value, doc);
                }
            } else {
                addAttribute(attributes, entry.getKey(), entry.getValue(), doc);
            }
        }
    }
    user.setAttributes(attributes);
    return user;
}
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) Collection(java.util.Collection) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) Document(org.w3c.dom.Document) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with ShadowAttributesType

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

the class AbstractTestForExchangeConnector method createOfflineAddressBook.

protected String createOfflineAddressBook(String name, String addressList, String tenantName) 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_OFFLINE_ADDRESS_BOOK);
    shadow.setKind(ShadowKindType.GENERIC);
    shadow.setIntent("offline-address-book");
    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, "AddressLists"), addressList, doc));
    //attributes.getAny().add(ModelClientUtil.createTextElement(new QName(NS_RI, "_TenantName"), tenantName, 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 14 with ShadowAttributesType

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

the class TestExchangeConnectorLow method test210ModifyingNonexistingPowerShellObject.

@Test
public void test210ModifyingNonexistingPowerShellObject() throws Exception {
    // create shadow with non-existing GUID
    System.out.println("Creating shadow with non-existing GUID...");
    Document doc = ModelClientUtil.getDocumnent();
    String name = "Wrong GUID shadow";
    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_ICFS, "uid"), "wrong-GUID", doc));
    shadow.setAttributes(attributes);
    String oid = createObject(ShadowType.class, shadow, createRaw());
    System.out.println("Done, reading it back...");
    ShadowType shadowReadAgain = getObjectNoFetch(ShadowType.class, oid);
    dumpAttributes(shadowReadAgain);
    System.out.println("Now launching modifyObject operation...");
    //Class objectType, String oid, String path, ModificationTypeType modType, Object value, ModelExecuteOptionsType optionsType, boolean assertSuccess
    ObjectDeltaOperationType odo = modifyObject(ShadowType.class, oid, "attributes/DomainType", ModificationTypeType.REPLACE, "InternalRelay", null, false);
    OperationResultType r = odo.getExecutionResult();
    System.out.println("Done: " + r.getStatus() + ":" + r.getMessage());
    OperationResultType found = findOperationResult(r, new OperationResultMatcher() {

        @Override
        public boolean match(OperationResultType r) {
            return r.getDetails() != null && r.getDetails().contains("UnknownUidException");
        }
    });
    AssertJUnit.assertNotNull("UnknownUidException was not detected", found);
    System.out.println("======================================================================================================");
    System.out.println("Details: " + found.getDetails());
}
Also used : ObjectDeltaOperationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) 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) Test(org.testng.annotations.Test)

Example 15 with ShadowAttributesType

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

the class ShadowIntegrityCheckResultHandler method reportOrFixUniqueness.

private String reportOrFixUniqueness(Task task, OperationResult result) {
    StringBuilder details = new StringBuilder();
    StringBuilder stat = new StringBuilder();
    for (Map.Entry<Pair<String, ShadowKindType>, ObjectTypeContext> entry : contextMap.entrySet()) {
        String resourceOid = entry.getKey().getLeft();
        ShadowKindType kind = entry.getKey().getRight();
        ObjectTypeContext ctx = entry.getValue();
        PrismObject<ResourceType> resource = resources.get(resourceOid);
        if (resource == null) {
            // should not happen
            LOGGER.error("No resource for {}", resourceOid);
            continue;
        }
        for (Map.Entry<QName, Map<String, List<PrismObject<ShadowType>>>> idValEntry : ctx.getIdentifierValueMap().entrySet()) {
            QName identifier = idValEntry.getKey();
            boolean first = true;
            for (Map.Entry<String, List<PrismObject<ShadowType>>> valListEntry : idValEntry.getValue().entrySet()) {
                List<PrismObject<ShadowType>> shadows = valListEntry.getValue();
                if (shadows.size() <= 1) {
                    continue;
                }
                if (first) {
                    details.append("Duplicates for ").append(ObjectTypeUtil.toShortString(resource));
                    details.append(", kind = ").append(kind);
                    details.append(", identifier = ").append(identifier).append(":\n");
                    first = false;
                }
                details.append(" - value: ").append(valListEntry.getKey()).append(", shadows: ").append(shadows.size()).append("\n");
                List<PrismObject<ShadowType>> shadowsToConsider = new ArrayList<>();
                for (PrismObject<ShadowType> shadow : shadows) {
                    details.append("   - ").append(ObjectTypeUtil.toShortString(shadow));
                    details.append("; sync situation = ").append(shadow.asObjectable().getSynchronizationSituation()).append("\n");
                    PrismContainer<ShadowAttributesType> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
                    if (attributesContainer != null && !attributesContainer.isEmpty()) {
                        for (Item item : attributesContainer.getValue().getItems()) {
                            details.append("     - ").append(item.getElementName().getLocalPart()).append(" = ");
                            details.append(item.getRealValues());
                            details.append("\n");
                        }
                    }
                    if (duplicateShadowsDeleted.contains(shadow.getOid())) {
                        details.append("     (already deleted)\n");
                    } else {
                        shadowsToConsider.add(shadow);
                    }
                }
                if (fixUniqueness && shadowsToConsider.size() > 1) {
                    DuplicateShadowsTreatmentInstruction instruction = duplicateShadowsResolver.determineDuplicateShadowsTreatment(shadowsToConsider);
                    deleteShadows(instruction, details, task, result);
                }
            }
        }
    }
    stat.append("Duplicate shadows detected: ").append(duplicateShadowsDetected.size());
    if (fixUniqueness) {
        stat.append(", deleted: ").append(duplicateShadowsDeleted.size());
    // TODO report the duplicates that remain
    }
    // there can be many 'search owner' subresults
    result.summarize();
    return stat.toString() + "\n" + details.toString();
}
Also used : QName(javax.xml.namespace.QName) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) 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) Item(com.evolveum.midpoint.prism.Item) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair)

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