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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations