Search in sources :

Example 51 with LdapConnection

use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.

the class ConfigDAO method remove.

/**
 * @param name
 * @throws org.apache.directory.fortress.core.RemoveException
 */
void remove(String name) throws RemoveException {
    LdapConnection ld = null;
    String dn = getDn(name);
    LOG.info("remove dn [{}]", dn);
    try {
        ld = getAdminConnection();
        delete(ld, dn);
    } catch (LdapException e) {
        String error = "remove dn [" + dn + "] LDAPException=" + e.getMessage();
        throw new RemoveException(GlobalErrIds.FT_CONFIG_DELETE_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
}
Also used : RemoveException(org.apache.directory.fortress.core.RemoveException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 52 with LdapConnection

use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.

the class ConfigDAO method update.

/**
 * @param name
 * @param props
 * @return
 * @throws org.apache.directory.fortress.core.UpdateException
 */
Properties update(String name, Properties props) throws UpdateException {
    LdapConnection ld = null;
    String dn = getDn(name);
    LOG.info("update dn [{}]", dn);
    try {
        List<Modification> mods = new ArrayList<Modification>();
        if (PropUtil.isNotEmpty(props)) {
            loadProperties(props, mods, GlobalIds.PROPS, true);
        }
        ld = getAdminConnection();
        if (mods.size() > 0) {
            ld = getAdminConnection();
            modify(ld, dn, mods);
        }
    } catch (LdapException e) {
        String error = "update dn [" + dn + "] caught LDAPException=" + e.getMessage();
        throw new UpdateException(GlobalErrIds.FT_CONFIG_UPDATE_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return props;
}
Also used : Modification(org.apache.directory.api.ldap.model.entry.Modification) ArrayList(java.util.ArrayList) UpdateException(org.apache.directory.fortress.core.UpdateException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 53 with LdapConnection

use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.

the class ConfigDAO method create.

/**
 * @param name
 * @param props
 * @return
 * @throws org.apache.directory.fortress.core.CreateException
 */
Properties create(String name, Properties props) throws CreateException {
    LdapConnection ld = null;
    String dn = getDn(name);
    LOG.info("create dn [{}]", dn);
    try {
        Entry myEntry = new DefaultEntry(dn);
        myEntry.add(SchemaConstants.OBJECT_CLASS_AT, CONFIG_OBJ_CLASS);
        ld = getAdminConnection();
        myEntry.add(SchemaConstants.CN_AT, name);
        loadProperties(props, myEntry, GlobalIds.PROPS);
        add(ld, myEntry);
    } catch (LdapEntryAlreadyExistsException e) {
        String warning = "create config dn [" + dn + "] caught LdapEntryAlreadyExistsException=" + e.getMessage() + " msg=" + e.getMessage();
        throw new CreateException(GlobalErrIds.FT_CONFIG_ALREADY_EXISTS, warning, e);
    } catch (LdapException e) {
        String error;
        error = "create config dn [" + dn + "] caught LDAPException=" + e.getMessage();
        LOG.error(error, e);
        throw new CreateException(GlobalErrIds.FT_CONFIG_CREATE_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return props;
}
Also used : LdapEntryAlreadyExistsException(org.apache.directory.api.ldap.model.exception.LdapEntryAlreadyExistsException) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) CreateException(org.apache.directory.fortress.core.CreateException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 54 with LdapConnection

use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.

the class ConfigDAO method remove.

/**
 * @param name
 * @param props
 * @return
 * @throws org.apache.directory.fortress.core.UpdateException
 */
Properties remove(String name, Properties props) throws UpdateException {
    LdapConnection ld = null;
    String dn = getDn(name);
    LOG.info("remove props dn [{}]", dn);
    try {
        List<Modification> mods = new ArrayList<Modification>();
        if (PropUtil.isNotEmpty(props)) {
            removeProperties(props, mods, GlobalIds.PROPS);
        }
        if (mods.size() > 0) {
            ld = getAdminConnection();
            modify(ld, dn, mods);
        }
    } catch (LdapException e) {
        String error = "remove props dn [" + dn + "] caught LDAPException=" + e.getMessage();
        throw new UpdateException(GlobalErrIds.FT_CONFIG_DELETE_PROPS_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return props;
}
Also used : Modification(org.apache.directory.api.ldap.model.entry.Modification) ArrayList(java.util.ArrayList) UpdateException(org.apache.directory.fortress.core.UpdateException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 55 with LdapConnection

use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.

the class GroupDAO method update.

/**
 * @param group
 * @return
 * @throws org.apache.directory.fortress.core.CreateException
 */
Group update(Group group) throws FinderException, UpdateException {
    LdapConnection ld = null;
    String nodeDn = getDn(group.getName(), group.getContextId());
    try {
        LOG.debug("update group dn [{}]", nodeDn);
        List<Modification> mods = new ArrayList<Modification>();
        if (StringUtils.isNotEmpty(group.getDescription())) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants.DESCRIPTION_AT, group.getDescription()));
        }
        if (StringUtils.isNotEmpty(group.getProtocol())) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, GROUP_PROTOCOL_ATTR_IMPL, group.getProtocol()));
        }
        loadAttrs(group.getMembers(), mods, SchemaConstants.MEMBER_AT);
        loadProperties(group.getProperties(), mods, GROUP_PROPERTY_ATTR_IMPL, true, '=');
        if (mods.size() > 0) {
            ld = getAdminConnection();
            modify(ld, nodeDn, mods, group);
        }
    } catch (LdapException e) {
        String error = "update group node dn [" + nodeDn + "] caught LDAPException=" + e.getMessage();
        throw new UpdateException(GlobalErrIds.GROUP_UPDATE_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return get(group);
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) ArrayList(java.util.ArrayList) UpdateException(org.apache.directory.fortress.core.UpdateException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Aggregations

LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)180 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)166 ArrayList (java.util.ArrayList)90 FinderException (org.apache.directory.fortress.core.FinderException)73 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)65 Entry (org.apache.directory.api.ldap.model.entry.Entry)52 SearchCursor (org.apache.directory.api.ldap.model.cursor.SearchCursor)49 Modification (org.apache.directory.api.ldap.model.entry.Modification)43 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)41 UpdateException (org.apache.directory.fortress.core.UpdateException)41 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)37 LdapNoSuchObjectException (org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException)20 CreateException (org.apache.directory.fortress.core.CreateException)17 RemoveException (org.apache.directory.fortress.core.RemoveException)17 IOException (java.io.IOException)14 LdapNetworkConnection (org.apache.directory.ldap.client.api.LdapNetworkConnection)14 Permission (org.apache.directory.fortress.core.model.Permission)9 Dn (org.apache.directory.api.ldap.model.name.Dn)7 EntryCursor (org.apache.directory.api.ldap.model.cursor.EntryCursor)6 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)6