Search in sources :

Example 61 with LdapConnection

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

the class OrganizationalUnitDAO method create.

/**
 * @param oe
 * @throws org.apache.directory.fortress.core.CreateException
 */
void create(OrganizationalUnit oe) throws CreateException {
    LdapConnection ld = null;
    String nodeDn = SchemaConstants.OU_AT + "=" + oe.getName() + ",";
    if (StringUtils.isNotEmpty(oe.getParent())) {
        nodeDn += SchemaConstants.OU_AT + "=" + oe.getParent() + ",";
    }
    nodeDn += getRootDn(oe.getContextId());
    try {
        LOG.info("create container dn [{}]", nodeDn);
        Entry myEntry = new DefaultEntry(nodeDn, SchemaConstants.OBJECT_CLASS, SchemaConstants.ORGANIZATIONAL_UNIT_OC, SchemaConstants.OU_AT, oe.getName(), SchemaConstants.DESCRIPTION_AT, oe.getDescription());
        ld = getAdminConnection();
        add(ld, myEntry);
    } catch (LdapException e) {
        String error = "create container node dn [" + nodeDn + "] caught LdapException=" + e;
        throw new CreateException(GlobalErrIds.CNTR_CREATE_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
}
Also used : 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) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) CreateException(org.apache.directory.fortress.core.CreateException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 62 with LdapConnection

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

the class SdDAO method getSD.

/**
 * @param sdSet
 * @return
 * @throws FinderException
 */
SDSet getSD(SDSet sdSet) throws FinderException {
    SDSet entity = null;
    LdapConnection ld = null;
    String dn = getDn(sdSet.getName(), sdSet.getContextId());
    try {
        ld = getAdminConnection();
        Entry findEntry = read(ld, dn, SD_SET_ATRS);
        if (findEntry == null) {
            String warning = "getSD no entry found dn [" + dn + "]";
            throw new FinderException(GlobalErrIds.SSD_NOT_FOUND, warning);
        }
        entity = unloadLdapEntry(findEntry, 0);
    } catch (LdapNoSuchObjectException e) {
        String warning = "getSD Obj COULD NOT FIND ENTRY for dn [" + dn + "]";
        throw new FinderException(GlobalErrIds.SSD_NOT_FOUND, warning);
    } catch (LdapException e) {
        String error = "getSSD dn [" + dn + "] LEXCD=" + e;
        int errCode;
        if (sdSet.getType() == SDSet.SDType.DYNAMIC) {
            errCode = GlobalErrIds.DSD_READ_FAILED;
        } else {
            errCode = GlobalErrIds.SSD_READ_FAILED;
        }
        throw new FinderException(errCode, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return entity;
}
Also used : SDSet(org.apache.directory.fortress.core.model.SDSet) LdapNoSuchObjectException(org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException) FinderException(org.apache.directory.fortress.core.FinderException) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 63 with LdapConnection

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

the class SdDAO method search.

/**
 * Given an SSD name and type, find matching object in the directory.
 * @param sdset requires name and type.
 * @return List of matching SDSets.
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<SDSet> search(SDSet sdset) throws FinderException {
    List<SDSet> sdList = new ArrayList<>();
    LdapConnection ld = null;
    String ssdRoot = getSdRoot(sdset.getContextId());
    String objectClass = SSD_OBJECT_CLASS_NM;
    if (sdset.getType() == SDSet.SDType.DYNAMIC) {
        objectClass = DSD_OBJECT_CLASS_NM;
    }
    try {
        String searchVal = encodeSafeText(sdset.getName(), GlobalIds.ROLE_LEN);
        String filter = GlobalIds.FILTER_PREFIX + objectClass + ")(" + SD_SET_NM + "=" + searchVal + "*))";
        ld = getAdminConnection();
        SearchCursor searchResults = search(ld, ssdRoot, SearchScope.SUBTREE, filter, SD_SET_ATRS, false, GlobalIds.BATCH_SIZE);
        long sequence = 0;
        while (searchResults.next()) {
            sdList.add(unloadLdapEntry(searchResults.getEntry(), sequence++));
        }
    } catch (LdapException e) {
        String error = "search sdset name [" + sdset.getName() + "] type [" + sdset.getType() + "] caught LdapException=" + e.getMessage();
        int errCode;
        if (sdset.getType() == SDSet.SDType.DYNAMIC) {
            errCode = GlobalErrIds.DSD_SEARCH_FAILED;
        } else {
            errCode = GlobalErrIds.SSD_SEARCH_FAILED;
        }
        throw new FinderException(errCode, error, e);
    } catch (CursorException e) {
        String error = "search sdset name [" + sdset.getName() + "] type [" + sdset.getType() + "] caught CursorException=" + e.getMessage();
        int errCode;
        if (sdset.getType() == SDSet.SDType.DYNAMIC) {
            errCode = GlobalErrIds.DSD_SEARCH_FAILED;
        } else {
            errCode = GlobalErrIds.SSD_SEARCH_FAILED;
        }
        throw new FinderException(errCode, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return sdList;
}
Also used : SDSet(org.apache.directory.fortress.core.model.SDSet) FinderException(org.apache.directory.fortress.core.FinderException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) ArrayList(java.util.ArrayList) SearchCursor(org.apache.directory.api.ldap.model.cursor.SearchCursor) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 64 with LdapConnection

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

the class SdDAO method search.

/**
 * @param role
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<SDSet> search(Role role, SDSet.SDType type) throws FinderException {
    List<SDSet> sdList = new ArrayList<>();
    LdapConnection ld = null;
    String ssdRoot = getSdRoot(role.getContextId());
    String objectClass = SSD_OBJECT_CLASS_NM;
    if (type == SDSet.SDType.DYNAMIC) {
        objectClass = DSD_OBJECT_CLASS_NM;
    }
    try {
        String roleVal = encodeSafeText(role.getName(), GlobalIds.ROLE_LEN);
        StringBuilder filterbuf = new StringBuilder();
        filterbuf.append(GlobalIds.FILTER_PREFIX);
        filterbuf.append(objectClass);
        filterbuf.append(")(");
        // Include any parents target role may have:
        Set<String> roles = RoleUtil.getInstance().getAscendants(role.getName(), role.getContextId());
        if (CollectionUtils.isNotEmpty(roles)) {
            filterbuf.append("|(");
            filterbuf.append(ROLES);
            filterbuf.append("=");
            filterbuf.append(roleVal);
            filterbuf.append(")");
            for (String uRole : roles) {
                filterbuf.append("(");
                filterbuf.append(ROLES);
                filterbuf.append("=");
                filterbuf.append(uRole);
                filterbuf.append(")");
            }
            filterbuf.append(")");
        } else {
            filterbuf.append(ROLES);
            filterbuf.append("=");
            filterbuf.append(roleVal);
            filterbuf.append(")");
        }
        filterbuf.append(")");
        ld = getAdminConnection();
        SearchCursor searchResults = search(ld, ssdRoot, SearchScope.SUBTREE, filterbuf.toString(), SD_SET_ATRS, false, GlobalIds.BATCH_SIZE);
        long sequence = 0;
        while (searchResults.next()) {
            sdList.add(unloadLdapEntry(searchResults.getEntry(), sequence++));
        }
    } catch (LdapException e) {
        String error = "search role [" + role.getName() + "] type [" + type + "] caught LdapException=" + e.getMessage();
        int errCode;
        if (type == SDSet.SDType.DYNAMIC) {
            errCode = GlobalErrIds.DSD_SEARCH_FAILED;
        } else {
            errCode = GlobalErrIds.SSD_SEARCH_FAILED;
        }
        throw new FinderException(errCode, error, e);
    } catch (CursorException e) {
        String error = "search role [" + role.getName() + "] type [" + type + "] caught CursorException=" + e.getMessage();
        int errCode;
        if (type == SDSet.SDType.DYNAMIC) {
            errCode = GlobalErrIds.DSD_SEARCH_FAILED;
        } else {
            errCode = GlobalErrIds.SSD_SEARCH_FAILED;
        }
        throw new FinderException(errCode, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return sdList;
}
Also used : SDSet(org.apache.directory.fortress.core.model.SDSet) FinderException(org.apache.directory.fortress.core.FinderException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) ArrayList(java.util.ArrayList) SearchCursor(org.apache.directory.api.ldap.model.cursor.SearchCursor) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 65 with LdapConnection

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

the class SuffixDAO method create.

/**
 * @param se
 * @throws org.apache.directory.fortress.core.CreateException
 */
void create(Suffix se) throws CreateException {
    LdapConnection ld = null;
    String nodeDn = getDn(se);
    try {
        LOG.info("create suffix dn [{}]", nodeDn);
        Entry myEntry = new DefaultEntry(nodeDn);
        myEntry.add(SchemaConstants.OBJECT_CLASS_AT, SUFFIX_OBJ_CLASS);
        myEntry.add(SchemaConstants.DC_AT, se.getName());
        myEntry.add(SchemaConstants.O_AT, se.getDescription());
        ld = getAdminConnection();
        add(ld, myEntry);
    } catch (LdapException e) {
        String error = "create container node dn [" + nodeDn + "] caught LDAPException=" + e.getMessage();
        throw new CreateException(GlobalErrIds.SUFX_CREATE_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
}
Also used : 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) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) CreateException(org.apache.directory.fortress.core.CreateException) 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