Search in sources :

Example 1 with ResourceObjectPattern

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);
    }
}
Also used : ResourceObjectPattern(com.evolveum.midpoint.common.ResourceObjectPattern)

Example 2 with ResourceObjectPattern

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;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ResourceObjectPattern(com.evolveum.midpoint.common.ResourceObjectPattern) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QName(javax.xml.namespace.QName) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter)

Example 3 with 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);
}
Also used : ResourceObjectPattern(com.evolveum.midpoint.common.ResourceObjectPattern) PrismContext(com.evolveum.midpoint.prism.PrismContext) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) Test(org.testng.annotations.Test)

Aggregations

ResourceObjectPattern (com.evolveum.midpoint.common.ResourceObjectPattern)3 PrismContext (com.evolveum.midpoint.prism.PrismContext)1 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)1 SearchFilterType (com.evolveum.prism.xml.ns._public.query_3.SearchFilterType)1 QName (javax.xml.namespace.QName)1 Test (org.testng.annotations.Test)1