Search in sources :

Example 11 with FinderException

use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.

the class PermDAO method getPerm.

/**
 * @param permObj
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
PermObj getPerm(PermObj permObj) throws FinderException {
    PermObj entity = null;
    LdapConnection ld = null;
    String dn = GlobalIds.POBJ_NAME + "=" + permObj.getObjName() + "," + getRootDn(permObj.isAdmin(), permObj.getContextId());
    try {
        ld = getAdminConnection();
        Entry findEntry = read(ld, dn, PERMISION_OBJ_ATRS);
        if (findEntry == null) {
            String warning = "getPerm Obj no entry found dn [" + dn + "]";
            throw new FinderException(GlobalErrIds.PERM_OBJ_NOT_FOUND, warning);
        }
        entity = unloadPobjLdapEntry(findEntry, 0, permObj.isAdmin());
    } catch (LdapNoSuchObjectException e) {
        String warning = "getPerm Obj COULD NOT FIND ENTRY for dn [" + dn + "]";
        throw new FinderException(GlobalErrIds.PERM_OBJ_NOT_FOUND, warning);
    } catch (LdapException e) {
        String error = "getPerm Obj dn [" + dn + "] caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.PERM_READ_OBJ_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return entity;
}
Also used : LdapNoSuchObjectException(org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException) FinderException(org.apache.directory.fortress.core.FinderException) PermObj(org.apache.directory.fortress.core.model.PermObj) 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 12 with FinderException

use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.

the class PermDAO method getPerm.

/**
 * @param permission
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
Permission getPerm(Permission permission) throws FinderException {
    Permission entity = null;
    LdapConnection ld = null;
    String dn = getOpRdn(permission.getOpName(), permission.getObjId()) + "," + GlobalIds.POBJ_NAME + "=" + permission.getObjName() + "," + getRootDn(permission.isAdmin(), permission.getContextId());
    try {
        ld = getAdminConnection();
        Entry findEntry = read(ld, dn, PERMISSION_OP_ATRS);
        if (findEntry == null) {
            String warning = "getPerm no entry found dn [" + dn + "]";
            throw new FinderException(GlobalErrIds.PERM_OP_NOT_FOUND, warning);
        }
        entity = unloadPopLdapEntry(findEntry, 0, permission.isAdmin());
    } catch (LdapNoSuchObjectException e) {
        String warning = "getPerm Op COULD NOT FIND ENTRY for dn [" + dn + "]";
        throw new FinderException(GlobalErrIds.PERM_OP_NOT_FOUND, warning);
    } catch (LdapException e) {
        String error = "getUser [" + dn + "] caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.PERM_READ_OP_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return entity;
}
Also used : 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) Permission(org.apache.directory.fortress.core.model.Permission) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 13 with FinderException

use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.

the class PermDAO method findPermissions.

/**
 * @param session
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<Permission> findPermissions(Session session, boolean isAdmin) throws FinderException {
    List<Permission> permList = new ArrayList<>();
    LdapConnection ld = null;
    String permRoot = getRootDn(isAdmin, session.getContextId());
    try {
        StringBuilder filterbuf = new StringBuilder();
        filterbuf.append(GlobalIds.FILTER_PREFIX);
        filterbuf.append(PERM_OP_OBJECT_CLASS_NAME);
        filterbuf.append(")(|");
        if (!session.isGroupSession()) {
            filterbuf.append("(");
            filterbuf.append(USERS);
            filterbuf.append("=");
            filterbuf.append(session.getUserId());
            filterbuf.append(")");
        }
        Set<String> roles;
        if (isAdmin) {
            roles = AdminRoleUtil.getInheritedRoles(session.getAdminRoles(), session.getContextId());
        } else {
            roles = RoleUtil.getInstance().getInheritedRoles(session.getRoles(), session.getContextId());
        }
        if (CollectionUtils.isNotEmpty(roles)) {
            for (String uRole : roles) {
                filterbuf.append("(");
                filterbuf.append(ROLES);
                filterbuf.append("=");
                filterbuf.append(uRole);
                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++, isAdmin));
        }
    } catch (LdapException e) {
        String error = "findPermissions user [" + session.getUserId() + "] caught LdapException in PermDAO.findPermissions=" + e.getMessage();
        throw new FinderException(GlobalErrIds.PERM_SESS_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "findPermissions user [" + session.getUserId() + "] caught CursorException in PermDAO.findPermissions=" + e.getMessage();
        throw new FinderException(GlobalErrIds.PERM_SESS_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 14 with FinderException

use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.

the class PermP method remove.

/**
 * Remove the Admin Role assignment attribute from all Admin permssions.  This method is called by DelAdminMgrImpl
 * when the AdminRole is being deleted.
 *
 * @param role contains the name of AdminRole targeted for attribute removal.
 * @throws SecurityException in the event of DAO search error.
 */
void remove(AdminRole role) throws SecurityException {
    List<Permission> list;
    try {
        list = search(role);
        for (Permission perm : list) {
            perm.setAdmin(true);
            revoke(perm, role);
        }
    } catch (FinderException fe) {
        String error = "remove admin role [" + role.getName() + "] caught FinderException=" + fe;
        throw new SecurityException(GlobalErrIds.PERM_BULK_ADMINROLE_REVOKE_FAILED, error, fe);
    }
}
Also used : FinderException(org.apache.directory.fortress.core.FinderException) Permission(org.apache.directory.fortress.core.model.Permission) SecurityException(org.apache.directory.fortress.core.SecurityException)

Example 15 with FinderException

use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.

the class PolicyDAO method getPolicy.

/**
 * @param policy
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
PwPolicy getPolicy(PwPolicy policy) throws FinderException {
    PwPolicy entity = null;
    LdapConnection ld = null;
    String dn = getDn(policy);
    try {
        ld = getAdminConnection();
        Entry findEntry = read(ld, dn, PASSWORD_POLICY_ATRS);
        entity = unloadLdapEntry(findEntry, 0);
    } catch (LdapNoSuchObjectException e) {
        String warning = "getPolicy Obj COULD NOT FIND ENTRY for dn [" + dn + "]";
        throw new FinderException(GlobalErrIds.PSWD_NOT_FOUND, warning);
    } catch (LdapException e) {
        String error = "getPolicy name [" + policy.getName() + "] caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.PSWD_READ_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return entity;
}
Also used : 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) PwPolicy(org.apache.directory.fortress.core.model.PwPolicy) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Aggregations

FinderException (org.apache.directory.fortress.core.FinderException)80 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)72 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)72 ArrayList (java.util.ArrayList)49 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)48 SearchCursor (org.apache.directory.api.ldap.model.cursor.SearchCursor)48 Entry (org.apache.directory.api.ldap.model.entry.Entry)22 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)21 LdapNoSuchObjectException (org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException)17 Permission (org.apache.directory.fortress.core.model.Permission)10 User (org.apache.directory.fortress.core.model.User)8 SecurityException (org.apache.directory.fortress.core.SecurityException)7 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)6 Modification (org.apache.directory.api.ldap.model.entry.Modification)6 UpdateException (org.apache.directory.fortress.core.UpdateException)6 Role (org.apache.directory.fortress.core.model.Role)6 UserRole (org.apache.directory.fortress.core.model.UserRole)6 OrgUnit (org.apache.directory.fortress.core.model.OrgUnit)5 AdminRole (org.apache.directory.fortress.core.model.AdminRole)4 RoleConstraint (org.apache.directory.fortress.core.model.RoleConstraint)4