Search in sources :

Example 26 with LdapConnection

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

the class PermDAO method findPermissionOperations.

List<Permission> findPermissionOperations(PermObj permObj) throws FinderException {
    List<Permission> permList = new ArrayList<>();
    LdapConnection ld = null;
    String permRoot = getRootDn(permObj.isAdmin(), permObj.getContextId());
    try {
        String permObjVal = encodeSafeText(permObj.getObjName(), GlobalIds.PERM_LEN);
        StringBuilder filterbuf = new StringBuilder();
        filterbuf.append(GlobalIds.FILTER_PREFIX);
        filterbuf.append(PERM_OP_OBJECT_CLASS_NAME);
        filterbuf.append(")(");
        filterbuf.append(GlobalIds.POBJ_NAME);
        filterbuf.append("=");
        filterbuf.append(permObjVal);
        filterbuf.append("))");
        ld = getAdminConnection();
        SearchCursor searchResults = search(ld, permRoot, SearchScope.SUBTREE, filterbuf.toString(), PERMISSION_OP_ATRS, false, GlobalIds.BATCH_SIZE);
        long sequence = 0;
        while (searchResults.next()) {
            permList.add(unloadPopLdapEntry(searchResults.getEntry(), sequence++, permObj.isAdmin()));
        }
    } catch (LdapException e) {
        String error = "findPermissions caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.PERM_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "findPermissions caught CursorException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.PERM_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return permList;
}
Also used : FinderException(org.apache.directory.fortress.core.FinderException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) Permission(org.apache.directory.fortress.core.model.Permission) 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 27 with LdapConnection

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

the class PermDAO method revoke.

/**
 * @param pOp
 * @param role
 * @throws org.apache.directory.fortress.core.UpdateException
 *
 * @throws org.apache.directory.fortress.core.FinderException
 */
void revoke(Permission pOp, Role role) throws UpdateException, FinderException {
    LdapConnection ld = null;
    String dn = getDn(pOp, pOp.getContextId());
    try {
        List<Modification> mods = new ArrayList<Modification>();
        mods.add(new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, ROLES, role.getName()));
        ld = getAdminConnection();
        modify(ld, dn, mods, pOp);
    } catch (LdapNoSuchAttributeException e) {
        String warning = "revoke perm object [" + pOp.getObjName() + "] operation [" + pOp.getOpName() + "] name [" + role.getName() + "] assignment does not exist.";
        throw new FinderException(GlobalErrIds.PERM_ROLE_NOT_EXIST, warning);
    } catch (LdapException e) {
        String error = "revoke perm object [" + pOp.getObjName() + "] operation [" + pOp.getOpName() + "] name [" + role.getName() + "] caught LdapException=" + e.getMessage();
        throw new UpdateException(GlobalErrIds.PERM_REVOKE_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) FinderException(org.apache.directory.fortress.core.FinderException) 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) LdapNoSuchAttributeException(org.apache.directory.api.ldap.model.exception.LdapNoSuchAttributeException)

Example 28 with LdapConnection

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

the class PermDAO method getPermAttributeSet.

PermissionAttributeSet getPermAttributeSet(PermissionAttributeSet permAttributeSet) throws FinderException {
    PermissionAttributeSet entity = null;
    LdapConnection ld = null;
    String dn = getDn(permAttributeSet, permAttributeSet.getContextId());
    try {
        ld = getAdminConnection();
        Entry findEntry = read(ld, dn, PERMISION_ATTRIBUTE_SET_ATRS);
        if (findEntry == null) {
            String warning = "getPermAttributeSet no entry found dn [" + dn + "]";
            throw new FinderException(GlobalErrIds.PERM_ATTRIBUTE_SET_NOT_FOUND, warning);
        }
        entity = unloadPASetLdapEntry(findEntry, 0);
        // find permission attributes for this set
        entity.setAttributes(this.findPermissionAttributes(entity));
    } catch (LdapNoSuchObjectException e) {
        String warning = "getPermAttributeSet COULD NOT FIND ENTRY for dn [" + dn + "]";
        throw new FinderException(GlobalErrIds.PERM_ATTRIBUTE_SET_NOT_FOUND, warning);
    } catch (LdapException e) {
        String error = "getPermAttributeSet dn [" + dn + "] caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.PERM_ATTRIBUTE_SET_NOT_FOUND, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return entity;
}
Also used : LdapNoSuchObjectException(org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException) PermissionAttributeSet(org.apache.directory.fortress.core.model.PermissionAttributeSet) 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 29 with LdapConnection

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

the class PermDAO method findAnyPermissions.

/**
 * Uses substring filters to allow any permission matching the passed in obj and op names.
 *
 * @param permission
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<Permission> findAnyPermissions(Permission permission) throws FinderException {
    List<Permission> permList = new ArrayList<>();
    LdapConnection ld = null;
    String permRoot = getRootDn(permission.isAdmin(), permission.getContextId());
    try {
        String permObjVal = encodeSafeText(permission.getObjName(), GlobalIds.PERM_LEN);
        String permOpVal = encodeSafeText(permission.getOpName(), GlobalIds.PERM_LEN);
        StringBuilder filterbuf = new StringBuilder();
        filterbuf.append(GlobalIds.FILTER_PREFIX);
        filterbuf.append(PERM_OP_OBJECT_CLASS_NAME);
        filterbuf.append(")(|");
        if (permObjVal != null && permObjVal != "") {
            filterbuf.append("(");
            filterbuf.append(GlobalIds.POBJ_NAME);
            filterbuf.append("=*");
            filterbuf.append(permObjVal);
            filterbuf.append("*)");
        }
        if (permOpVal != null && permOpVal != "") {
            filterbuf.append("(");
            filterbuf.append(GlobalIds.POP_NAME);
            filterbuf.append("=*");
            filterbuf.append(permOpVal);
            filterbuf.append("*)");
        }
        filterbuf.append("))");
        ld = getAdminConnection();
        SearchCursor searchResults = search(ld, permRoot, SearchScope.SUBTREE, filterbuf.toString(), PERMISSION_OP_ATRS, false, GlobalIds.BATCH_SIZE);
        long sequence = 0;
        while (searchResults.next()) {
            permList.add(unloadPopLdapEntry(searchResults.getEntry(), sequence++, permission.isAdmin()));
        }
    } catch (LdapException e) {
        String error = "findAnyPermissions caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.PERM_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "findAnyPermissions caught CursorException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.PERM_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return permList;
}
Also used : FinderException(org.apache.directory.fortress.core.FinderException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) Permission(org.apache.directory.fortress.core.model.Permission) 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 30 with LdapConnection

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

the class PermDAO method deleteAttributeSet.

/**
 * @param entity
 * @throws RemoveException
 */
void deleteAttributeSet(PermissionAttributeSet entity) throws RemoveException {
    LdapConnection ld = null;
    String dn = getDn(entity, entity.getContextId());
    try {
        ld = getAdminConnection();
        deleteRecursive(ld, dn, entity);
    } catch (LdapException e) {
        String error = "deleteAttributeSet name [" + entity.getName() + "]" + " caught LdapException=" + e.getMessage();
        throw new RemoveException(GlobalErrIds.PERM_ATTRIBUTE_SET_DELETE_FAILED, error, e);
    } catch (CursorException e) {
        String error = "deleteAttributeSet name [" + entity.getName() + "] " + " caught LdapException=" + e.getMessage();
        throw new RemoveException(GlobalErrIds.PERM_ATTRIBUTE_SET_DELETE_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
}
Also used : RemoveException(org.apache.directory.fortress.core.RemoveException) 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)

Aggregations

LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)178 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)164 ArrayList (java.util.ArrayList)89 FinderException (org.apache.directory.fortress.core.FinderException)73 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)63 Entry (org.apache.directory.api.ldap.model.entry.Entry)50 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 LdapNetworkConnection (org.apache.directory.ldap.client.api.LdapNetworkConnection)14 IOException (java.io.IOException)12 Permission (org.apache.directory.fortress.core.model.Permission)9 Dn (org.apache.directory.api.ldap.model.name.Dn)7 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)6 SecurityException (org.apache.directory.fortress.core.SecurityException)6