Search in sources :

Example 26 with PolyStringType

use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.

the class ShadowManager method createRepositoryShadow.

/**
	 * Create a copy of a shadow that is suitable for repository storage. 
	 */
private PrismObject<ShadowType> createRepositoryShadow(ProvisioningContext ctx, PrismObject<ShadowType> shadow) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
    ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(shadow);
    PrismObject<ShadowType> repoShadow = shadow.clone();
    ShadowType repoShadowType = repoShadow.asObjectable();
    ResourceAttributeContainer repoAttributesContainer = ShadowUtil.getAttributesContainer(repoShadow);
    CachingStategyType cachingStrategy = ProvisioningUtil.getCachingStrategy(ctx);
    if (cachingStrategy == CachingStategyType.NONE) {
        // Clean all repoShadow attributes and add only those that should be
        // there
        repoAttributesContainer.clear();
        Collection<ResourceAttribute<?>> primaryIdentifiers = attributesContainer.getPrimaryIdentifiers();
        for (PrismProperty<?> p : primaryIdentifiers) {
            repoAttributesContainer.add(p.clone());
        }
        Collection<ResourceAttribute<?>> secondaryIdentifiers = attributesContainer.getSecondaryIdentifiers();
        for (PrismProperty<?> p : secondaryIdentifiers) {
            repoAttributesContainer.add(p.clone());
        }
        // Also add all the attributes that act as association identifiers.
        // We will need them when the shadow is deleted (to remove the shadow from entitlements).
        RefinedObjectClassDefinition objectClassDefinition = ctx.getObjectClassDefinition();
        for (RefinedAssociationDefinition associationDef : objectClassDefinition.getAssociationDefinitions()) {
            if (associationDef.getResourceObjectAssociationType().getDirection() == ResourceObjectAssociationDirectionType.OBJECT_TO_SUBJECT) {
                QName valueAttributeName = associationDef.getResourceObjectAssociationType().getValueAttribute();
                if (repoAttributesContainer.findAttribute(valueAttributeName) == null) {
                    ResourceAttribute<Object> valueAttribute = attributesContainer.findAttribute(valueAttributeName);
                    if (valueAttribute != null) {
                        repoAttributesContainer.add(valueAttribute.clone());
                    }
                }
            }
        }
        repoShadowType.setCachingMetadata(null);
        ProvisioningUtil.cleanupShadowActivation(repoShadowType);
    } else if (cachingStrategy == CachingStategyType.PASSIVE) {
        // Do not need to clear anything. Just store all attributes and add metadata.
        CachingMetadataType cachingMetadata = new CachingMetadataType();
        cachingMetadata.setRetrievalTimestamp(clock.currentTimeXMLGregorianCalendar());
        repoShadowType.setCachingMetadata(cachingMetadata);
    } else {
        throw new ConfigurationException("Unknown caching strategy " + cachingStrategy);
    }
    setKindIfNecessary(repoShadowType, ctx.getObjectClassDefinition());
    //        setIntentIfNecessary(repoShadowType, objectClassDefinition);
    // Store only password meta-data in repo
    CredentialsType creds = repoShadowType.getCredentials();
    if (creds != null) {
        PasswordType passwordType = creds.getPassword();
        if (passwordType != null) {
            ProvisioningUtil.cleanupShadowPassword(passwordType);
            PrismObject<UserType> owner = null;
            if (ctx.getTask() != null) {
                owner = ctx.getTask().getOwner();
            }
            ProvisioningUtil.addPasswordMetadata(passwordType, clock.currentTimeXMLGregorianCalendar(), owner);
        }
    // TODO: other credential types - later
    }
    // convert to the resource reference.
    if (repoShadowType.getResource() != null) {
        repoShadowType.setResource(null);
        repoShadowType.setResourceRef(ObjectTypeUtil.createObjectRef(ctx.getResource()));
    }
    // now
    if (repoShadowType.getResourceRef() == null) {
        repoShadowType.setResourceRef(ObjectTypeUtil.createObjectRef(ctx.getResource()));
    }
    if (repoShadowType.getName() == null) {
        repoShadowType.setName(new PolyStringType(ShadowUtil.determineShadowName(shadow)));
    }
    if (repoShadowType.getObjectClass() == null) {
        repoShadowType.setObjectClass(attributesContainer.getDefinition().getTypeName());
    }
    if (repoShadowType.isProtectedObject() != null) {
        repoShadowType.setProtectedObject(null);
    }
    normalizeAttributes(repoShadow, ctx.getObjectClassDefinition());
    return repoShadow;
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) QName(javax.xml.namespace.QName) ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) RefinedAssociationDefinition(com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) PrismObject(com.evolveum.midpoint.prism.PrismObject) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute)

Example 27 with PolyStringType

use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.

the class PropertyRestriction method checkValueType.

private Object checkValueType(Object value, ValueFilter filter) throws QueryException {
    Class expectedType = linkDefinition.getTargetDefinition().getJaxbClass();
    if (expectedType == null || value == null) {
        // nothing to check here
        return value;
    }
    if (expectedType.isPrimitive()) {
        expectedType = ClassUtils.primitiveToWrapper(expectedType);
    }
    //attempt to fix value type for polystring (if it was string in filter we create polystring from it)
    if (PolyString.class.equals(expectedType) && (value instanceof String)) {
        LOGGER.debug("Trying to query PolyString value but filter contains String '{}'.", filter);
        String orig = (String) value;
        value = new PolyString(orig, context.getPrismContext().getDefaultPolyStringNormalizer().normalize(orig));
    }
    //attempt to fix value type for polystring (if it was polystringtype in filter we create polystring from it)
    if (PolyString.class.equals(expectedType) && (value instanceof PolyStringType)) {
        LOGGER.debug("Trying to query PolyString value but filter contains PolyStringType '{}'.", filter);
        PolyStringType type = (PolyStringType) value;
        value = new PolyString(type.getOrig(), type.getNorm());
    }
    if (String.class.equals(expectedType) && (value instanceof QName)) {
        //eg. shadow/objectClass
        value = RUtil.qnameToString((QName) value);
    }
    if (value instanceof RawType) {
        // MID-3850: but it's quite a workaround. Maybe we should treat RawType's earlier than this.
        try {
            return ((RawType) value).getParsedRealValue(expectedType);
        } catch (SchemaException e) {
            throw new QueryException("Couldn't parse value " + value + " as " + expectedType + ": " + e.getMessage(), e);
        }
    }
    if (!expectedType.isAssignableFrom(value.getClass())) {
        throw new QueryException("Value should be type of '" + expectedType + "' but it's '" + value.getClass() + "', filter '" + filter + "'.");
    }
    return value;
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) QName(javax.xml.namespace.QName) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType)

Example 28 with PolyStringType

use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.

the class AddGetObjectTest method test990AddResourceWithEmptyConnectorConfiguration.

@Test
public void test990AddResourceWithEmptyConnectorConfiguration() throws Exception {
    OperationResult result = new OperationResult("test990AddResourceWithEmptyConnectorConfiguration");
    PrismObject<ResourceType> prismResource = PrismTestUtil.getPrismContext().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ResourceType.class).instantiate();
    PolyStringType name = new PolyStringType();
    name.setOrig("Test Resource");
    name.setNorm("test resource");
    prismResource.asObjectable().setName(name);
    prismResource.findOrCreateContainer(ResourceType.F_CONNECTOR_CONFIGURATION).findOrCreateContainer(SchemaConstants.ICF_CONFIGURATION_PROPERTIES).createNewValue();
    System.out.println("Original data before saving: " + prismResource.debugDump());
    String oid = repositoryService.addObject(prismResource, null, result);
    PrismObject<ResourceType> fetchedResource = repositoryService.getObject(ResourceType.class, oid, null, result);
    System.out.println("Original data after saving: " + prismResource.debugDump());
    System.out.println("Fetched data: " + fetchedResource.debugDump());
    AssertJUnit.assertEquals(prismResource, fetchedResource);
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 29 with PolyStringType

use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.

the class AuditEventRecord method setInitiatorAndLoginParameter.

public void setInitiatorAndLoginParameter(PrismObject<UserType> initiator) {
    setInitiator(initiator);
    String parameter = null;
    if (initiator != null) {
        PolyStringType name = initiator.asObjectable().getName();
        if (name != null) {
            parameter = name.getOrig();
        }
    }
    setParameter(parameter);
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType)

Example 30 with PolyStringType

use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.

the class AbstractAdLdapMultidomainTest method test515AddOrgGroupMeleeIslandPirates.

/**
	 * Create role under the Melee Island org. This creates group in the orgstruct.
	 */
@Test
public void test515AddOrgGroupMeleeIslandPirates() throws Exception {
    final String TEST_NAME = "test515AddOrgGroupMeleeIslandPirates";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<RoleType> role = instantiateObject(RoleType.class);
    RoleType roleType = role.asObjectable();
    roleType.setName(new PolyStringType(GROUP_MELEE_ISLAND_PIRATES_NAME));
    AssignmentType metaroleAssignment = new AssignmentType();
    ObjectReferenceType metaroleRef = new ObjectReferenceType();
    metaroleRef.setOid(ROLE_META_ORG_GROUP_OID);
    metaroleRef.setType(RoleType.COMPLEX_TYPE);
    metaroleAssignment.setTargetRef(metaroleRef);
    roleType.getAssignment().add(metaroleAssignment);
    AssignmentType orgAssignment = new AssignmentType();
    ObjectReferenceType orgRef = new ObjectReferenceType();
    orgRef.setOid(orgMeleeIslandOid);
    orgRef.setType(OrgType.COMPLEX_TYPE);
    orgAssignment.setTargetRef(orgRef);
    roleType.getAssignment().add(orgAssignment);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    addObject(role, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    roleMeleeIslandPiratesOid = role.getOid();
    // TODO: assert LDAP object
    Entry entryOrgGroup = assertLdapOrgGroup(GROUP_MELEE_ISLAND_PIRATES_NAME, GROUP_MELEE_ISLAND_NAME);
    PrismObject<RoleType> roleAfter = getObject(RoleType.class, roleMeleeIslandPiratesOid);
    display("Role after", roleAfter);
    groupMeleeIslandPiratesOid = getSingleLinkOid(roleAfter);
    PrismObject<ShadowType> shadow = getShadowModel(groupMeleeIslandPiratesOid);
    display("Shadow (model)", shadow);
//        assertLdapConnectorInstances(2);
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) Task(com.evolveum.midpoint.task.api.Task) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Aggregations

PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)94 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)28 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)26 Test (org.testng.annotations.Test)23 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)20 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)14 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)12 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)12 QName (javax.xml.namespace.QName)11 Task (com.evolveum.midpoint.task.api.Task)10 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)10 File (java.io.File)10 PrismObject (com.evolveum.midpoint.prism.PrismObject)9 OrgType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)8 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)7 ArrayList (java.util.ArrayList)7 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)5 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)4 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)4 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)4