{
log.debug("findUserByUserName(): username = " + userName);
if (userName == null)
{
throw new IdentityException("User name canot be null");
}
String filter = "(".concat(getUidAttributeID()).concat("=").concat(userName).concat(")");
log.debug("Search filter: " + filter);
List sr = searchUsers(filter, null);
if (sr.size() > 1)
{
throw new IdentityException("Found more than one user with id: " + userName + "" +
"Posible data inconsistency");
}
SearchResult res = (SearchResult)sr.iterator().next();
ctx = (Context)res.getObject();
String dn = ctx.getNameInNamespace();
User user = createUserInstance(res.getAttributes(), dn);
ctx.close();
return user;
}
catch (NoSuchElementException e)
{
log.debug("No user found with name: " + userName, e);
}
catch (NamingException e)
{
throw new IdentityException("User search failed.", e);
}
finally
{
try
{
if (ctx != null)
{
ctx.close();
}
}
catch (NamingException e)
{
throw new IdentityException("Failed to close LDAP connection", e);
}
}
throw new NoSuchUserException("No user found with name: " + userName);
}