Search in sources :

Example 26 with AttributeType

use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.

the class StringValueAttributeTypeTest method testInstanceOf.

/**
 * Test the instanceOf method
 */
@Test
public void testInstanceOf() throws LdapException {
    AttributeType attribute = EntryUtils.getIA5StringAttributeType();
    Value ssv = Value.createValue(attribute);
    assertTrue(ssv.isInstanceOf(attribute));
    attribute = EntryUtils.getBytesAttributeType();
    assertFalse(ssv.isInstanceOf(attribute));
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) Test(org.junit.Test)

Example 27 with AttributeType

use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.

the class ObjectClassHelper method buildMay.

/**
 * Build and check the MAY AT for this ObjectClass
 */
private static void buildMay(ObjectClass objectClass, List<Throwable> errors, Registries registries) {
    AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry();
    List<String> mayAttributeTypeOids = objectClass.getMayAttributeTypeOids();
    if (mayAttributeTypeOids != null) {
        objectClass.getMayAttributeTypes().clear();
        for (String mayAttributeTypeName : mayAttributeTypeOids) {
            try {
                AttributeType attributeType = atRegistry.lookup(mayAttributeTypeName);
                if (attributeType.isCollective()) {
                    // Collective Attributes are not allowed in MAY or MUST
                    String msg = I18n.err(I18n.ERR_13779_COLLECTIVE_NOT_ALLOWED_IN_MAY, mayAttributeTypeName, objectClass.getOid());
                    LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_COLLECTIVE_NOT_ALLOWED_IN_MAY, msg);
                    ldapSchemaException.setSourceObject(objectClass);
                    ldapSchemaException.setRelatedId(mayAttributeTypeName);
                    errors.add(ldapSchemaException);
                    LOG.info(msg);
                    continue;
                }
                if (objectClass.getMayAttributeTypes().contains(attributeType)) {
                    // Already registered : this is an error
                    String msg = I18n.err(I18n.ERR_13770_CANNOT_REGISTER_DUPLICATE_AT_IN_MAY, objectClass.getOid(), mayAttributeTypeName);
                    LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_DUPLICATE_AT_IN_MAY, msg);
                    ldapSchemaException.setSourceObject(objectClass);
                    ldapSchemaException.setRelatedId(mayAttributeTypeName);
                    errors.add(ldapSchemaException);
                    LOG.info(msg);
                    continue;
                }
                objectClass.getMayAttributeTypes().add(attributeType);
            } catch (LdapException ne) {
                // Cannot find the AT
                String msg = I18n.err(I18n.ERR_13771_CANNOT_REGISTER_AT_IN_MAY_DOES_NOT_EXIST, objectClass.getOid(), mayAttributeTypeName);
                LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_NONEXISTENT_MAY_AT, msg, ne);
                ldapSchemaException.setSourceObject(objectClass);
                ldapSchemaException.setRelatedId(mayAttributeTypeName);
                errors.add(ldapSchemaException);
                LOG.info(msg);
                continue;
            }
        }
    }
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) AttributeTypeRegistry(org.apache.directory.api.ldap.model.schema.registries.AttributeTypeRegistry)

Example 28 with AttributeType

use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.

the class ObjectClassHelper method addToRegistries.

/**
 * Inject the ObjectClass into the registries, updating the references to
 * other SchemaObject
 *
 * @param objectClass The ObjectClass to add to the Registries
 * @param errors The errors we got while adding the ObjectClass to the Registries
 * @param registries The Registries
 * @throws LdapException on failure
 */
public static void addToRegistries(ObjectClass objectClass, List<Throwable> errors, Registries registries) throws LdapException {
    if (registries != null) {
        try {
            objectClass.unlock();
            // The superiors
            buildSuperiors(objectClass, errors, registries);
            // The MAY AttributeTypes
            buildMay(objectClass, errors, registries);
            // The MUST AttributeTypes
            buildMust(objectClass, errors, registries);
            /**
             * Add the OC references (using and usedBy) :
             * OC -> AT (MAY and MUST)
             * OC -> OC (SUPERIORS)
             */
            for (AttributeType mayAttributeType : objectClass.getMayAttributeTypes()) {
                registries.addReference(objectClass, mayAttributeType);
            }
            for (AttributeType mustAttributeType : objectClass.getMustAttributeTypes()) {
                registries.addReference(objectClass, mustAttributeType);
            }
            for (ObjectClass superiorObjectClass : objectClass.getSuperiors()) {
                registries.addReference(objectClass, superiorObjectClass);
            }
        } finally {
            objectClass.lock();
        }
    }
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType)

Example 29 with AttributeType

use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.

the class ObjectClassHelper method removeFromRegistries.

/**
 * Remove the ObjectClass from the registries, updating the references to
 * other SchemaObject.
 *
 * If one of the referenced SchemaObject does not exist (SUPERIORS, MAY, MUST),
 * an exception is thrown.
 *
 * @param objectClass The ObjectClass to remove fro the registries
 * @param errors The errors we got while removing the ObjectClass from the registries
 * @param registries The Registries
 * @throws LdapException If the ObjectClass is not valid
 */
public static void removeFromRegistries(ObjectClass objectClass, List<Throwable> errors, Registries registries) throws LdapException {
    if (registries != null) {
        ObjectClassRegistry objectClassRegistry = registries.getObjectClassRegistry();
        // Unregister this ObjectClass into the Descendant map
        objectClassRegistry.unregisterDescendants(objectClass, objectClass.getSuperiors());
        /**
         * Remove the OC references (using and usedBy) :
         * OC -> AT (for MAY and MUST)
         * OC -> OC
         */
        if (objectClass.getMayAttributeTypes() != null) {
            for (AttributeType may : objectClass.getMayAttributeTypes()) {
                registries.delReference(objectClass, may);
            }
        }
        if (objectClass.getMustAttributeTypes() != null) {
            for (AttributeType must : objectClass.getMustAttributeTypes()) {
                registries.delReference(objectClass, must);
            }
        }
        if (objectClass.getSuperiors() != null) {
            for (ObjectClass superior : objectClass.getSuperiors()) {
                registries.delReference(objectClass, superior);
            }
        }
    }
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) ObjectClassRegistry(org.apache.directory.api.ldap.model.schema.registries.ObjectClassRegistry)

Example 30 with AttributeType

use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.

the class Registries method resolve.

private void resolve(ObjectClass objectClass, List<Throwable> errors) {
    // This set is used to avoid having more than one error
    // for an ObjectClass. It's mandatory when processing
    // the Superiors, as they may be broken and referenced more than once.
    Set<String> processed = new HashSet<>();
    // Store the ObjectClass itself in the processed, to avoid cycle
    processed.add(objectClass.getOid());
    // Call the recursive method, as we may have superiors to deal with
    resolveRecursive(objectClass, processed, errors);
    // Check that the MAY and MUST AT are consistent (no AT in MAY and in MUST
    // in one of its superior
    List<AttributeType> musts = getMustRecursive(new ArrayList<AttributeType>(), new HashSet<ObjectClass>(), objectClass);
    if (musts != null) {
        for (AttributeType may : objectClass.getMayAttributeTypes()) {
            if (musts.contains(may)) {
                // This is not allowed.
                LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_DUPLICATE_AT_IN_MAY_AND_MUST);
                ldapSchemaException.setSourceObject(objectClass);
                ldapSchemaException.setOtherObject(may);
                errors.add(ldapSchemaException);
            }
        }
    }
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) HashSet(java.util.HashSet)

Aggregations

AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)135 Test (org.junit.Test)68 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)42 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)25 ParseException (java.text.ParseException)15 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)15 Value (org.apache.directory.api.ldap.model.entry.Value)15 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)11 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)11 HashSet (java.util.HashSet)10 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)10 ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)10 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)9 IOException (java.io.IOException)7 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)7 Before (org.junit.Before)7 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)6 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)6 ArrayList (java.util.ArrayList)5 Dn (org.apache.directory.api.ldap.model.name.Dn)4