Search in sources :

Example 11 with LdapNoSuchObjectException

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

the class UserDAO method getUserRoles.

/**
 * @param userId
 * @return
 * @throws FinderException
 */
private List<UserRole> getUserRoles(String userId, String contextId) throws FinderException {
    List<UserRole> roles = null;
    LdapConnection ld = null;
    String userDn = getDn(userId, contextId);
    try {
        ld = getAdminConnection();
        Entry findEntry = read(ld, userDn, ROLE_ATR);
        roles = unloadUserRoles(findEntry, userId, contextId, null);
    } catch (LdapNoSuchObjectException e) {
        String warning = "getUserRoles COULD NOT FIND ENTRY for user [" + userId + "]";
        throw new FinderException(GlobalErrIds.USER_NOT_FOUND, warning);
    } catch (LdapException e) {
        String error = "getUserRoles [" + userDn + "]= caught LDAPException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.USER_READ_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return roles;
}
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) UserRole(org.apache.directory.fortress.core.model.UserRole) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 12 with LdapNoSuchObjectException

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

the class UserDAO method getUser.

/**
 * @param user
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
User getUser(User user, boolean isRoles) throws FinderException {
    User entity = null;
    LdapConnection ld = null;
    String userDn = getDn(user.getUserId(), user.getContextId());
    String[] uATTRS;
    if (isRoles) {
        // Retrieve the User's assigned RBAC and Admin Role attributes from directory.
        uATTRS = defaultAtrs;
    } else {
        // Do not retrieve the User's assigned RBAC and Admin Role attributes from directory.
        uATTRS = authnAtrs;
    }
    Entry findEntry = null;
    try {
        ld = getAdminConnection();
        findEntry = read(ld, userDn, uATTRS);
    } catch (LdapNoSuchObjectException e) {
        String warning = "getUser COULD NOT FIND ENTRY for user [" + user.getUserId() + "]";
        throw new FinderException(GlobalErrIds.USER_NOT_FOUND, warning);
    } catch (LdapException e) {
        String error = "getUser [" + userDn + "]= caught LDAPException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.USER_READ_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    try {
        if (findEntry != null) {
            entity = unloadLdapEntry(findEntry, 0, user.getContextId());
        }
    } catch (LdapInvalidAttributeValueException e) {
        entity = null;
    }
    if (entity == null) {
        String warning = "getUser userId [" + user.getUserId() + "] not found, Fortress rc=" + GlobalErrIds.USER_NOT_FOUND;
        throw new FinderException(GlobalErrIds.USER_NOT_FOUND, warning);
    }
    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) User(org.apache.directory.fortress.core.model.User) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 13 with LdapNoSuchObjectException

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

the class ExampleDAO method findByKey.

/**
 * @param name
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
public Example findByKey(String name) throws FinderException {
    Example entity = null;
    LdapConnection ld = null;
    String dn = SchemaConstants.CN_AT + "=" + name + "," + Config.getInstance().getProperty(EIds.EXAMPLE_ROOT);
    if (LOG.isDebugEnabled()) {
        LOG.debug("findByKey dn [" + dn + "]");
    }
    try {
        ld = getAdminConnection();
        Entry findEntry = read(ld, dn, EXAMPLE_ATRS);
        entity = getEntityFromLdapEntry(findEntry);
        if (entity == null) {
            String error = "findByKey could not find entry for example name [" + name + "]";
            LOG.error(error);
            throw new FinderException(EErrIds.EXAMPLE_NOT_FOUND, error);
        }
    } catch (LdapNoSuchObjectException e) {
        String error = "findByKey COULD NOT FIND ENTRY for example name [" + name + "]";
        throw new FinderException(GlobalErrIds.SSD_NOT_FOUND, error);
    } catch (LdapException e) {
        String error = "findByKey name [" + name + "] caught LDAPException=" + e;
        LOG.warn(error);
        throw new FinderException(EErrIds.EXAMPLE_READ_FAILED, error);
    } 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 14 with LdapNoSuchObjectException

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

the class UserDAO method getUserAdminRoles.

/**
 * @param user
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<UserAdminRole> getUserAdminRoles(User user) throws FinderException {
    List<UserAdminRole> roles = null;
    LdapConnection ld = null;
    String userDn = getDn(user.getUserId(), user.getContextId());
    try {
        ld = getAdminConnection();
        Entry findEntry = read(ld, userDn, AROLE_ATR);
        roles = unloadUserAdminRoles(findEntry, user.getUserId(), user.getContextId());
    } catch (LdapNoSuchObjectException e) {
        String warning = "getUserAdminRoles COULD NOT FIND ENTRY for user [" + user.getUserId() + "]";
        throw new FinderException(GlobalErrIds.USER_NOT_FOUND, warning);
    } catch (LdapException e) {
        String error = "getUserAdminRoles [" + userDn + "]= caught LDAPException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.USER_READ_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return roles;
}
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) UserAdminRole(org.apache.directory.fortress.core.model.UserAdminRole) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 15 with LdapNoSuchObjectException

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

the class UserDAO method getRoles.

/**
 * @param user
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<String> getRoles(User user) throws FinderException {
    List<String> roles = null;
    LdapConnection ld = null;
    String userDn = getDn(user.getUserId(), user.getContextId());
    try {
        ld = getAdminConnection();
        Entry findEntry = read(ld, userDn, ROLES);
        if (findEntry == null) {
            String warning = "getRoles userId [" + user.getUserId() + "] not found, Fortress rc=" + GlobalErrIds.USER_NOT_FOUND;
            throw new FinderException(GlobalErrIds.USER_NOT_FOUND, warning);
        }
        roles = getAttributes(findEntry, GlobalIds.USER_ROLE_ASSIGN);
    } catch (LdapNoSuchObjectException e) {
        String warning = "getRoles COULD NOT FIND ENTRY for user [" + user.getUserId() + "]";
        throw new FinderException(GlobalErrIds.USER_NOT_FOUND, warning);
    } catch (LdapException e) {
        String error = "getRoles [" + userDn + "]= caught LDAPException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.URLE_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return roles;
}
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)

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