Newer
Older
LdapDAO.checkLdapResult(e.getResultCode());
* Returns a member user identified by the X500Principal only. The
* returned object has the fields required by the LdapGroupDAO.
* Note that this method binds as a proxy user and not as the
* @param userDN
* @return
* @throws UserNotFoundException
* @throws LDAPException
*/
User<X500Principal> getX500User(DN userDN)
throws UserNotFoundException, LDAPException, TransientException
Filter.createEqualityFilter(LDAP_ENTRYDN,
Jeff Burke
committed
userDN.toNormalizedString());
Jeff Burke
committed
new SearchRequest(config.getUsersDN(), SearchScope.ONE,
filter, firstLastAttribs);
getReadOnlyConnection().searchForEntry(searchRequest);
Jeff Burke
committed
String msg = "User not found " + userDN;
logger.debug(msg);
throw new UserNotFoundException(msg);
}
User<X500Principal> user = new User<X500Principal>(
new X500Principal(searchResult.getAttributeValue(
String princ = searchResult.getAttributeValue(
if (princ != null)
{
user.getIdentities().add(new HttpPrincipal(princ));
}
String fname = searchResult.getAttributeValue(LDAP_FIRST_NAME);
String lname = searchResult.getAttributeValue(LDAP_LAST_NAME);
user.details.add(new PersonalDetails(fname, lname));
DN getUserDN(User<? extends Principal> user)
throws UserNotFoundException, TransientException
Jeff Burke
committed
String searchField = userLdapAttrib.get(user.getUserID().getClass());
Jeff Burke
committed
"Unsupported principal type " + user.getUserID().getClass());
// change the DN to be in the 'java' format
Jeff Burke
committed
Filter filter;
if (user.getUserID() instanceof X500Principal)
{
X500Principal orderedPrincipal = AuthenticationUtil.getOrderedForm(
Jeff Burke
committed
(X500Principal) user.getUserID());
filter = Filter.createEqualityFilter(searchField, orderedPrincipal.toString());
Jeff Burke
committed
filter = Filter.createEqualityFilter(searchField, user.getUserID().getName());
Jeff Burke
committed
logger.debug("search filter: " + filter);
SearchResultEntry searchResult = null;
try
{
Jeff Burke
committed
SearchRequest searchRequest = new SearchRequest(
config.getUsersDN(), SearchScope.ONE, filter, LDAP_ENTRYDN);
searchResult = getReadOnlyConnection().searchForEntry(searchRequest);
LdapDAO.checkLdapResult(e.getResultCode());
String msg = "User not found " + user.getUserID().getName();
logger.debug(msg);
throw new UserNotFoundException(msg);
}
return searchResult.getAttributeValueAsDN(LDAP_ENTRYDN);
}
Jeff Burke
committed
protected DN getUserDN(final String userID, final String usersDN)
throws LDAPException, TransientException
Jeff Burke
committed
return new DN(LDAP_UID + "=" + userID + "," + usersDN);
}
catch (LDAPException e)
{
logger.debug("getUserDN Exception: " + e, e);
LdapDAO.checkLdapResult(e.getResultCode());
}
throw new IllegalArgumentException(userID + " not a valid user ID");
}
private void addAttribute(List<Attribute> attributes, final String name, final String value)
{
if (value != null && !value.isEmpty())
{
attributes.add(new Attribute(name, value));
}
private void addModification(List<Modification> mods, final String name, final String value)
{
if (value != null && !value.isEmpty())
{
mods.add(new Modification(ModificationType.REPLACE, name, value));
}
else
{
mods.add(new Modification(ModificationType.REPLACE, name));
}
}
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
/**
* Checks the Ldap result code, and if the result is not SUCCESS,
* throws an appropriate exception. This is the place to decide on
* mapping between ldap errors and exception types
*
* @param code The code returned from an LDAP request.
* @throws TransientException
* @throws UserAlreadyExistsException
*/
protected static void checkUserLDAPResult(final ResultCode code)
throws TransientException, UserAlreadyExistsException
{
if (code == ResultCode.ENTRY_ALREADY_EXISTS)
{
throw new UserAlreadyExistsException("User already exists.");
}
else
{
LdapDAO.checkLdapResult(code);
}
}
* Method to return a randomly generated user numeric ID. The default
* implementation returns a value between 10000 and Integer.MAX_VALUE.
* Services that support a different mechanism for generating numeric
* IDs override this method.
* @return
*/
protected int genNextNumericId()
{
Random rand = new Random();
return rand.nextInt(Integer.MAX_VALUE - 10000) + 10000;
}