Search in sources :

Example 96 with LdapException

use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.

the class StoreSearchResultAttributeValue method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<SearchResultEntryDecorator> container) {
    SearchResultEntryDecorator searchResultEntry = container.getMessage();
    TLV tlv = container.getCurrentTLV();
    // Store the value
    Object value = null;
    try {
        if (tlv.getLength() == 0) {
            searchResultEntry.addAttributeValue("");
            LOG.debug("The attribute value is null");
        } else {
            if (container.isBinary(searchResultEntry.getCurrentAttribute().getId())) {
                value = tlv.getValue().getData();
                if (IS_DEBUG) {
                    LOG.debug("Attribute value {}", Strings.dumpBytes((byte[]) value));
                }
            } else {
                value = Strings.utf8ToString(tlv.getValue().getData());
                LOG.debug("Attribute value {}", value);
            }
            searchResultEntry.addAttributeValue(value);
        }
    } catch (LdapException le) {
    // Just swallow the exception, it can't occur here
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
}
Also used : SearchResultEntryDecorator(org.apache.directory.api.ldap.codec.decorators.SearchResultEntryDecorator) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 97 with LdapException

use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.

the class AttributeUtils method toEntry.

/**
 * Convert a BasicAttributes or a AttributesImpl to an Entry
 *
 * @param attributes the BasicAttributes or AttributesImpl instance to convert
 * @param dn The Dn which is needed by the Entry
 * @return An instance of a Entry object
 *
 * @throws LdapException If we get an invalid attribute
 */
public static Entry toEntry(Attributes attributes, Dn dn) throws LdapException {
    if (attributes instanceof BasicAttributes) {
        try {
            Entry entry = new DefaultEntry(dn);
            for (NamingEnumeration<? extends javax.naming.directory.Attribute> attrs = attributes.getAll(); attrs.hasMoreElements(); ) {
                javax.naming.directory.Attribute attr = attrs.nextElement();
                Attribute entryAttribute = toApiAttribute(attr);
                if (entryAttribute != null) {
                    entry.put(entryAttribute);
                }
            }
            return entry;
        } catch (LdapException ne) {
            throw new LdapInvalidAttributeTypeException(ne.getMessage(), ne);
        }
    } else {
        return null;
    }
}
Also used : BasicAttributes(javax.naming.directory.BasicAttributes) BasicAttribute(javax.naming.directory.BasicAttribute) LdapInvalidAttributeTypeException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeTypeException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 98 with LdapException

use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.

the class DefaultAttribute method isValid.

/**
 * {@inheritDoc}
 */
@Override
public boolean isValid(AttributeType attributeType) throws LdapInvalidAttributeValueException {
    LdapSyntax syntax = attributeType.getSyntax();
    if (syntax == null) {
        return false;
    }
    SyntaxChecker syntaxChecker = syntax.getSyntaxChecker();
    if (syntaxChecker == null) {
        return false;
    }
    // Check that we can have no value for this attributeType
    if (values.isEmpty()) {
        return syntaxChecker.isValidSyntax(null);
    }
    // Check that we can't have more than one value if the AT is single-value
    if ((attributeType.isSingleValued()) && (values.size() > 1)) {
        return false;
    }
    // Now check the values
    for (Value value : values) {
        try {
            if (!value.isValid(syntaxChecker)) {
                return false;
            }
        } catch (LdapException le) {
            return false;
        }
    }
    return true;
}
Also used : SyntaxChecker(org.apache.directory.api.ldap.model.schema.SyntaxChecker) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 99 with LdapException

use of org.apache.directory.api.ldap.model.exception.LdapException 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 100 with LdapException

use of org.apache.directory.api.ldap.model.exception.LdapException 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

LdapException (org.apache.directory.api.ldap.model.exception.LdapException)361 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)161 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)111 ArrayList (java.util.ArrayList)94 FinderException (org.apache.directory.fortress.core.FinderException)73 Modification (org.apache.directory.api.ldap.model.entry.Modification)70 Entry (org.apache.directory.api.ldap.model.entry.Entry)68 IOException (java.io.IOException)57 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)57 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)53 SearchCursor (org.apache.directory.api.ldap.model.cursor.SearchCursor)51 UpdateException (org.apache.directory.fortress.core.UpdateException)41 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)35 Dn (org.apache.directory.api.ldap.model.name.Dn)34 SEPASecurityException (it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException)29 LdapAuthenticationException (org.apache.directory.api.ldap.model.exception.LdapAuthenticationException)25 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)25 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)23 DecoderException (org.apache.directory.api.asn1.DecoderException)22 LdapNoPermissionException (org.apache.directory.api.ldap.model.exception.LdapNoPermissionException)22