Search in sources :

Example 16 with LdapNoSuchObjectException

use of org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException in project directory-fortress-core by apache.

the class PermDAO method grant.

/**
 * @param pOp
 * @param role
 * @throws org.apache.directory.fortress.core.UpdateException
 *
 * @throws org.apache.directory.fortress.core.FinderException
 */
void grant(Permission pOp, Role role) throws UpdateException {
    LdapConnection ld = null;
    String dn = getDn(pOp, pOp.getContextId());
    try {
        List<Modification> mods = new ArrayList<Modification>();
        mods.add(new DefaultModification(ModificationOperation.ADD_ATTRIBUTE, ROLES, role.getName()));
        ld = getAdminConnection();
        modify(ld, dn, mods, pOp);
    } catch (LdapAttributeInUseException e) {
        String warning = "grant perm object [" + pOp.getObjName() + "] operation [" + pOp.getOpName() + "] role [" + role.getName() + "] assignment already exists, Fortress rc=" + GlobalErrIds.PERM_ROLE_EXIST;
        throw new UpdateException(GlobalErrIds.PERM_ROLE_EXIST, warning);
    } catch (LdapNoSuchObjectException e) {
        String warning = "grant perm object [" + pOp.getObjName() + "] operation [" + pOp.getOpName() + "] role [" + role.getName() + "] perm not found, Fortress rc=" + GlobalErrIds.PERM_OP_NOT_FOUND;
        throw new UpdateException(GlobalErrIds.PERM_OP_NOT_FOUND, warning);
    } catch (LdapException e) {
        String error = "grant perm object [" + pOp.getObjName() + "] operation [" + pOp.getOpName() + "] name [" + role.getName() + "]  caught LdapException=" + e.getMessage();
        throw new UpdateException(GlobalErrIds.PERM_GRANT_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
}
Also used : LdapNoSuchObjectException(org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException) 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) LdapAttributeInUseException(org.apache.directory.api.ldap.model.exception.LdapAttributeInUseException) 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 17 with LdapNoSuchObjectException

use of org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException in project directory-fortress-core by apache.

the class AdminRoleDAO method getRole.

/**
 * This method will retrieve the AdminRole from {@link GlobalIds#ADMIN_ROLE_ROOT} container by name.
 *
 * @param adminRole maps to {@link AdminRole#name}.
 * @return AdminRole back to client.
 * @throws FinderException in the event LDAP errors occur.
 */
AdminRole getRole(AdminRole adminRole) throws FinderException {
    AdminRole entity = null;
    LdapConnection ld = null;
    String dn = getDn(adminRole);
    try {
        ld = getAdminConnection();
        Entry findEntry = read(ld, dn, ROLE_ATRS);
        if (findEntry != null) {
            entity = unloadLdapEntry(findEntry, 0, adminRole.getContextId());
        }
        if (entity == null) {
            String warning = "getRole name [" + adminRole.getName() + "] no entry found dn [" + dn + "]";
            throw new FinderException(GlobalErrIds.ARLE_NOT_FOUND, warning);
        }
    } catch (LdapNoSuchObjectException e) {
        String warning = "getRole name [" + adminRole.getName() + "] Obj COULD NOT FIND ENTRY for dn [" + dn + "]";
        throw new FinderException(GlobalErrIds.ARLE_NOT_FOUND, warning, e);
    } catch (LdapException e) {
        String error = "getRole dn [" + dn + "] LEXCD=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ARLE_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) AdminRole(org.apache.directory.fortress.core.model.AdminRole) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 18 with LdapNoSuchObjectException

use of org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException in project directory-fortress-core by apache.

the class RoleDAO method getRole.

/**
 * @param role
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
Role getRole(Role role) throws FinderException {
    Role entity = null;
    LdapConnection ld = null;
    String dn = getDn(role.getName(), role.getContextId());
    try {
        ld = getAdminConnection();
        Entry findEntry = read(ld, dn, ROLE_ATRS);
        if (findEntry != null) {
            entity = unloadLdapEntry(findEntry, 0, role.getContextId());
        }
        if (entity == null) {
            String warning = "getRole no entry found dn [" + dn + "]";
            throw new FinderException(GlobalErrIds.ROLE_NOT_FOUND, warning);
        }
    } catch (LdapNoSuchObjectException e) {
        String warning = "getRole Obj COULD NOT FIND ENTRY for dn [" + dn + "]";
        throw new FinderException(GlobalErrIds.ROLE_NOT_FOUND, warning);
    } catch (LdapException e) {
        String error = "getRole dn [" + dn + "] LEXCD=" + e;
        throw new FinderException(GlobalErrIds.ROLE_READ_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return entity;
}
Also used : Role(org.apache.directory.fortress.core.model.Role) 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 19 with LdapNoSuchObjectException

use of org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException in project directory-fortress-core by apache.

the class GroupDAO method get.

/**
 * @param group
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
Group get(Group group) throws FinderException {
    Group entity = null;
    LdapConnection ld = null;
    String dn = getDn(group.getName(), group.getContextId());
    try {
        ld = getAdminConnection();
        Entry findEntry = read(ld, dn, GROUP_ATRS);
        if (findEntry == null) {
            String warning = "No Group entry found dn [" + dn + "]";
            throw new FinderException(GlobalErrIds.GROUP_NOT_FOUND, warning);
        }
        entity = unloadLdapEntry(findEntry, 0);
    } catch (LdapNoSuchObjectException e) {
        String warning = "read Obj COULD NOT FIND ENTRY for dn [" + dn + "]";
        throw new FinderException(GlobalErrIds.GROUP_NOT_FOUND, warning, e);
    } catch (LdapException e) {
        String error = "read dn [" + dn + "] LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.GROUP_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) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 20 with LdapNoSuchObjectException

use of org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException in project directory-fortress-core by apache.

the class ConfigDAO method getConfig.

/**
 * @param name
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
Properties getConfig(String name) throws FinderException {
    Properties props = null;
    LdapConnection ld = null;
    String dn = getDn(name);
    LOG.info("getConfig dn [{}]", dn);
    try {
        ld = getAdminConnection();
        Entry findEntry = read(ld, dn, CONFIG_ATRS);
        props = PropUtil.getProperties(getAttributes(findEntry, GlobalIds.PROPS));
    } catch (LdapNoSuchObjectException e) {
        String warning = "getConfig COULD NOT FIND ENTRY for dn [" + dn + "]";
        throw new FinderException(GlobalErrIds.USER_NOT_FOUND, warning, e);
    } catch (LdapException e) {
        String error = "getConfig dn [" + dn + "] caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.FT_CONFIG_READ_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return props;
}
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) Properties(java.util.Properties) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Aggregations

LdapNoSuchObjectException (org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException)21 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)19 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)19 Entry (org.apache.directory.api.ldap.model.entry.Entry)17 FinderException (org.apache.directory.fortress.core.FinderException)17 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)16 LdapAttributeInUseException (org.apache.directory.api.ldap.model.exception.LdapAttributeInUseException)3 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)2 Modification (org.apache.directory.api.ldap.model.entry.Modification)2 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)2 Permission (org.apache.directory.fortress.core.model.Permission)2 AuthenticationException (javax.naming.AuthenticationException)1 AuthenticationNotSupportedException (javax.naming.AuthenticationNotSupportedException)1 CommunicationException (javax.naming.CommunicationException)1 ContextNotEmptyException (javax.naming.ContextNotEmptyException)1 InvalidNameException (javax.naming.InvalidNameException)1 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)1 NameNotFoundException (javax.naming.NameNotFoundException)1