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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations