Search in sources :

Example 16 with LdapException

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

the class ApacheLdapProviderImpl method readStringAttribute.

public String readStringAttribute(final String entryDN, final String attribute) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
    activityPreCheck();
    getInputValidator().readStringAttribute(entryDN, attribute);
    try {
        final EntryCursor entries = connection.search(entryDN, ChaiConstant.FILTER_OBJECTCLASS_ANY, org.apache.directory.api.ldap.model.message.SearchScope.OBJECT, attribute);
        final Entry entry = entries.iterator().next();
        final Attribute attr = entry.get(attribute);
        return attr == null ? null : attr.getString();
    } catch (LdapException e) {
        throw ChaiOperationException.forErrorMessage(e.getMessage());
    }
}
Also used : EntryCursor(org.apache.directory.api.ldap.model.cursor.EntryCursor) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 17 with LdapException

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

the class ApacheLdapProviderImpl method writeStringAttribute.

public void writeStringAttribute(final String entryDN, final String attributeName, final Set<String> values, final boolean overwrite) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
    activityPreCheck();
    getInputValidator().writeStringAttribute(entryDN, attributeName, values, overwrite);
    try {
        final ModifyRequest modifyRequest = new ModifyRequestImpl();
        modifyRequest.setName(new Dn(entryDN));
        {
            final Modification modification = new DefaultModification();
            modification.setOperation(overwrite ? ModificationOperation.REPLACE_ATTRIBUTE : ModificationOperation.ADD_ATTRIBUTE);
            modification.setAttribute(new DefaultAttribute(attributeName, values.toArray(new String[values.size()])));
            modifyRequest.addModification(modification);
        }
        final ModifyResponse response = connection.modify(modifyRequest);
        processResponse(response);
    } catch (LdapException e) {
        throw ChaiOperationException.forErrorMessage(e.getMessage());
    }
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) ModifyRequestImpl(org.apache.directory.api.ldap.model.message.ModifyRequestImpl) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Dn(org.apache.directory.api.ldap.model.name.Dn) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse)

Example 18 with LdapException

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

the class LdapIdentityProvider method getGroup.

@Override
public ExternalGroup getGroup(@Nonnull String name) throws ExternalIdentityException {
    DebugTimer timer = new DebugTimer();
    LdapConnection connection = connect();
    timer.mark("connect");
    try {
        Entry entry = getEntry(connection, config.getGroupConfig(), name, config.getCustomAttributes());
        timer.mark("lookup");
        if (log.isDebugEnabled()) {
            log.debug("getGroup({}) {}", name, timer.getString());
        }
        if (entry != null) {
            return createGroup(entry, name);
        } else {
            return null;
        }
    } catch (LdapException | CursorException e) {
        throw lookupFailedException(e, timer);
    } finally {
        disconnect(connection);
    }
}
Also used : DebugTimer(org.apache.jackrabbit.oak.commons.DebugTimer) Entry(org.apache.directory.api.ldap.model.entry.Entry) SearchResultEntry(org.apache.directory.api.ldap.model.message.SearchResultEntry) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 19 with LdapException

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

the class LdifInputStreamLoader method execute.

/**
 * Opens the LDIF file and loads the entries into the context.
 *
 * @return The count of entries created.
 */
public int execute() {
    try {
        try {
            for (LdifEntry ldifEntry : new LdifReader(ldif)) {
                Dn dn = ldifEntry.getDn();
                if (ldifEntry.isEntry()) {
                    Entry entry = ldifEntry.getEntry();
                    try {
                        coreSession.lookup(dn);
                        LOG.debug("Found {}, will not create.", dn);
                    } catch (Exception e) {
                        try {
                            coreSession.add(new DefaultEntry(coreSession.getDirectoryService().getSchemaManager(), entry));
                            count++;
                            LOG.debug("Created {}.", dn);
                        } catch (LdapException e1) {
                            LOG.error("Could not create entry " + entry, e1);
                        }
                    }
                } else {
                    // modify
                    List<Modification> items = ldifEntry.getModifications();
                    try {
                        coreSession.modify(dn, items);
                        LOG.debug("Modified: " + dn + " with modificationItems: " + items);
                    } catch (LdapException e) {
                        LOG.debug("Could not modify: " + dn + " with modificationItems: " + items, e);
                    }
                }
            }
        } finally {
            ldif.close();
        }
    } catch (Exception ioe) {
        LOG.error(I18n.err(I18n.ERR_174), ioe);
    }
    return count;
}
Also used : Modification(org.apache.directory.api.ldap.model.entry.Modification) LdifReader(org.apache.directory.api.ldap.model.ldif.LdifReader) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Dn(org.apache.directory.api.ldap.model.name.Dn) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 20 with LdapException

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

the class SchemaEntityFactory method getLdapComparator.

/**
 * {@inheritDoc}
 */
@Override
public LdapComparator<?> getLdapComparator(SchemaManager schemaManager, Entry entry, Registries targetRegistries, String schemaName) throws LdapException {
    checkEntry(entry, SchemaConstants.COMPARATOR);
    // The Comparator OID
    String oid = getOid(entry, SchemaConstants.COMPARATOR, schemaManager.isStrict());
    // Get the schema
    if (!schemaManager.isSchemaLoaded(schemaName)) {
        // The schema is not loaded. We can't create the requested Comparator
        String msg = I18n.err(I18n.ERR_16022_CANNOT_ADD_CMP, entry.getDn().getName(), schemaName);
        LOG.warn(msg);
        throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
    }
    Schema schema = getSchema(schemaName, targetRegistries);
    if (schema == null) {
        // The schema is disabled. We still have to update the backend
        String msg = I18n.err(I18n.ERR_16023_CANNOT_ADD_CMP_IN_REGISTRY, entry.getDn().getName(), schemaName);
        LOG.info(msg);
        schema = schemaManager.getLoadedSchema(schemaName);
    }
    // The FQCN
    String fqcn = getFqcn(entry, SchemaConstants.COMPARATOR);
    // The ByteCode
    Attribute byteCode = entry.get(MetaSchemaConstants.M_BYTECODE_AT);
    try {
        // Class load the comparator
        LdapComparator<?> comparator = classLoadComparator(schemaManager, oid, fqcn, byteCode);
        // Update the common fields
        setSchemaObjectProperties(comparator, entry, schema);
        // return the resulting comparator
        return comparator;
    } catch (Exception e) {
        throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, e.getMessage(), e);
    }
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) InvocationTargetException(java.lang.reflect.InvocationTargetException) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Aggregations

LdapException (org.apache.directory.api.ldap.model.exception.LdapException)329 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)159 ArrayList (java.util.ArrayList)93 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)91 FinderException (org.apache.directory.fortress.core.FinderException)73 Entry (org.apache.directory.api.ldap.model.entry.Entry)63 Modification (org.apache.directory.api.ldap.model.entry.Modification)63 IOException (java.io.IOException)54 SearchCursor (org.apache.directory.api.ldap.model.cursor.SearchCursor)51 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)50 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)49 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 LdapAuthenticationException (org.apache.directory.api.ldap.model.exception.LdapAuthenticationException)25 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)25 DecoderException (org.apache.directory.api.asn1.DecoderException)22 LdapNoPermissionException (org.apache.directory.api.ldap.model.exception.LdapNoPermissionException)22 LdapOtherException (org.apache.directory.api.ldap.model.exception.LdapOtherException)22 ConnectException (java.net.ConnectException)21