Search in sources :

Example 36 with AttributeType

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

the class DefaultAttributeTypeRegistry method unregister.

/**
 * {@inheritDoc}
 */
@Override
public AttributeType unregister(String numericOid) throws LdapException {
    try {
        AttributeType removed = super.unregister(numericOid);
        removeMappingFor(removed);
        // Deleting an AT which might be used as a superior means we have
        // to recursively update the descendant map. We also have to remove
        // the at.oid -> descendant relation
        oidToDescendantSet.remove(numericOid);
        // Now recurse if needed
        unregisterDescendants(removed, removed.getSuperior());
        return removed;
    } catch (LdapException ne) {
        throw new LdapNoSuchAttributeException(ne.getMessage(), ne);
    }
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapNoSuchAttributeException(org.apache.directory.api.ldap.model.exception.LdapNoSuchAttributeException)

Example 37 with AttributeType

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

the class OpenLdapSchemaParser method afterParse.

/**
 * Splits parsed schema descriptions and resolved
 * object identifier macros.
 *
 * @throws ParseException the parse exception
 */
private void afterParse() throws ParseException {
    objectClasses = new ArrayList<>();
    attributeTypes = new ArrayList<>();
    objectIdentifierMacros = new HashMap<>();
    // split parsed schema descriptions
    for (Object obj : schemaDescriptions) {
        if (obj instanceof OpenLdapObjectIdentifierMacro) {
            OpenLdapObjectIdentifierMacro oid = (OpenLdapObjectIdentifierMacro) obj;
            objectIdentifierMacros.put(oid.getName(), oid);
        } else if (obj instanceof AttributeType) {
            MutableAttributeType attributeType = (MutableAttributeType) obj;
            attributeTypes.add(attributeType);
        } else if (obj instanceof ObjectClass) {
            ObjectClass objectClass = (ObjectClass) obj;
            objectClasses.add(objectClass);
        }
    }
    if (isResolveObjectIdentifierMacros()) {
        // resolve object identifier macros
        for (OpenLdapObjectIdentifierMacro oid : objectIdentifierMacros.values()) {
            resolveObjectIdentifierMacro(oid);
        }
        // apply object identifier macros to object classes
        for (ObjectClass objectClass : objectClasses) {
            objectClass.setOid(getResolveOid(objectClass.getOid()));
        }
        // apply object identifier macros to attribute types
        for (MutableAttributeType attributeType : attributeTypes) {
            attributeType.setOid(getResolveOid(attributeType.getOid()));
            attributeType.setSyntaxOid(getResolveOid(attributeType.getSyntaxOid()));
        }
    }
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) OpenLdapObjectIdentifierMacro(org.apache.directory.api.ldap.model.schema.syntaxCheckers.OpenLdapObjectIdentifierMacro) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType)

Example 38 with AttributeType

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

the class SchemaBinaryAttributeDetector method isBinary.

/**
 * {@inheritDoc}
 */
@Override
public boolean isBinary(String attributeId) {
    String attrId = Strings.toLowerCaseAscii(attributeId);
    if (attrId.endsWith(";binary")) {
        return true;
    }
    if (schemaManager != null) {
        AttributeType attributeType = schemaManager.getAttributeType(attrId);
        if (attributeType == null) {
            return false;
        }
        LdapSyntax ldapSyntax = attributeType.getSyntax();
        return (ldapSyntax != null) && !ldapSyntax.isHumanReadable();
    }
    return false;
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax)

Example 39 with AttributeType

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

the class DefaultEntry method put.

/**
 * {@inheritDoc}
 */
public Attribute put(String upId, AttributeType attributeType, byte[]... values) throws LdapException {
    if (attributeType == null) {
        try {
            attributeType = getAttributeType(upId);
        } catch (Exception e) {
            String message = I18n.err(I18n.ERR_13231_NO_VALID_AT_FOR_THIS_ID);
            LOG.error(message);
            throw new IllegalArgumentException(message, e);
        }
    } else {
        if (!Strings.isEmpty(upId)) {
            AttributeType tempAT = getAttributeType(upId);
            if (!tempAT.equals(attributeType)) {
                String message = I18n.err(I18n.ERR_13229_ID_INCOMPATIBLE_WITH_AT, upId, attributeType);
                LOG.error(message);
                throw new IllegalArgumentException(message);
            }
        } else {
            upId = getUpId(upId, attributeType);
        }
    }
    if (attributeType.equals(objectClassAttributeType)) {
        String message = I18n.err(I18n.ERR_13227_NON_STRING_VALUE_NOT_ALLOWED);
        LOG.error(message);
        throw new UnsupportedOperationException(message);
    }
    Attribute attribute = new DefaultAttribute(upId, attributeType, values);
    return attributes.put(attributeType.getOid(), attribute);
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) LdapLdifException(org.apache.directory.api.ldap.model.ldif.LdapLdifException) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) IOException(java.io.IOException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 40 with AttributeType

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

the class DefaultEntry method removeAttributes.

/**
 * {@inheritDoc}
 */
@Override
public void removeAttributes(String... attributes) {
    if (attributes.length == 0) {
        return;
    }
    if (schemaManager == null) {
        for (String attribute : attributes) {
            Attribute attr = get(attribute);
            if (attr != null) {
                this.attributes.remove(attr.getId());
            } else {
                String message = I18n.err(I18n.ERR_13218_AT_DOES_NOT_EXIST, attribute);
                LOG.warn(message);
                continue;
            }
        }
    } else {
        for (String attribute : attributes) {
            AttributeType attributeType = null;
            try {
                attributeType = schemaManager.lookupAttributeTypeRegistry(attribute);
            } catch (LdapException ne) {
                LOG.warn(I18n.msg(I18n.MSG_13203_MISSING_ATTRIBUTE_IN_ENTRY, attribute));
                continue;
            }
            this.attributes.remove(attributeType.getOid());
        }
    }
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

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