use of com.evolveum.midpoint.common.ResourceObjectPattern in project midpoint by Evolveum.
the class RefinedObjectClassDefinitionImpl method parseProtected.
private static void parseProtected(RefinedObjectClassDefinition rAccountDef, ResourceObjectTypeDefinitionType accountTypeDefType) throws SchemaException {
for (ResourceObjectPatternType protectedType : accountTypeDefType.getProtected()) {
ResourceObjectPattern protectedPattern = convertToPattern(protectedType, rAccountDef);
rAccountDef.getProtectedObjectPatterns().add(protectedPattern);
}
}
use of com.evolveum.midpoint.common.ResourceObjectPattern in project midpoint by Evolveum.
the class RefinedObjectClassDefinitionImpl method convertToPattern.
private static ResourceObjectPattern convertToPattern(ResourceObjectPatternType patternType, RefinedObjectClassDefinition rAccountDef) throws SchemaException {
ResourceObjectPattern resourceObjectPattern = new ResourceObjectPattern(rAccountDef);
SearchFilterType filterType = patternType.getFilter();
if (filterType != null) {
ObjectFilter filter = QueryConvertor.parseFilter(filterType, rAccountDef.getObjectDefinition());
resourceObjectPattern.addFilter(filter);
return resourceObjectPattern;
}
// Deprecated
if (patternType.getName() != null) {
RefinedAttributeDefinition attributeDefinition = rAccountDef.findAttributeDefinition(new QName(SchemaConstants.NS_ICF_SCHEMA, "name"));
if (attributeDefinition == null) {
throw new SchemaException("No ICF NAME attribute in schema as specified in the definition of protected objects (this is deprecated syntax anyway, convert it to filter)");
}
ResourceAttribute<String> attr = attributeDefinition.instantiate();
attr.setRealValue(patternType.getName());
resourceObjectPattern.addIdentifier(attr);
} else if (patternType.getUid() != null) {
RefinedAttributeDefinition attributeDefinition = rAccountDef.findAttributeDefinition(new QName(SchemaConstants.NS_ICF_SCHEMA, "uid"));
if (attributeDefinition == null) {
throw new SchemaException("No ICF UID attribute in schema as specified in the definition of protected objects (this is deprecated syntax anyway, convert it to filter)");
}
ResourceAttribute<String> attr = attributeDefinition.instantiate();
attr.setRealValue(patternType.getUid());
resourceObjectPattern.addIdentifier(attr);
} else {
throw new SchemaException("No filter and no deprecated name/uid in resource object pattern");
}
return resourceObjectPattern;
}
use of com.evolveum.midpoint.common.ResourceObjectPattern in project midpoint by Evolveum.
the class TestRefinedSchema method testProtectedAccount.
@Test
public void testProtectedAccount() throws JAXBException, SchemaException, SAXException, IOException {
System.out.println("\n===[ testProtectedAccount ]===\n");
// GIVEN
PrismContext prismContext = createInitializedPrismContext();
PrismObject<ResourceType> resource = prismContext.parseObject(RESOURCE_COMPLEX_FILE);
ResourceType resourceType = resource.asObjectable();
RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.parse(resourceType, prismContext);
assertNotNull("Refined schema is null", rSchema);
assertFalse("No account definitions", rSchema.getRefinedDefinitions(ShadowKindType.ACCOUNT).isEmpty());
RefinedObjectClassDefinition rAccount = rSchema.getRefinedDefinition(ShadowKindType.ACCOUNT, (String) null);
// WHEN
Collection<ResourceObjectPattern> protectedAccounts = rAccount.getProtectedObjectPatterns();
// THEN
assertNotNull("Null protectedAccounts", protectedAccounts);
assertFalse("Empty protectedAccounts", protectedAccounts.isEmpty());
assertEquals("Unexpected number of protectedAccounts", 2, protectedAccounts.size());
Iterator<ResourceObjectPattern> iterator = protectedAccounts.iterator();
assertDeprecatedProtectedAccount("first protected account", iterator.next(), "uid=idm,ou=Administrators,dc=example,dc=com", rAccount);
assertDeprecatedProtectedAccount("second protected account", iterator.next(), "uid=root,ou=Administrators,dc=example,dc=com", rAccount);
}
Aggregations