if (credential == null)
{
throw new IllegalArgumentException();
}
LDAPIdentityObjectImpl ldapIO = getSafeLDAPIO(ctx, identityObject);
if (supportedFeatures.isCredentialSupported(ldapIO.getIdentityType(),credential.getType()))
{
String passwordString = null;
// Handle generic impl
if (credential.getValue() != null)
{
//TODO: support for empty password should be configurable
passwordString = credential.getValue().toString();
}
else
{
throw new IdentityException("Null password value");
}
String attributeName = getTypeConfiguration(ctx, ldapIO.getIdentityType()).getPasswordAttributeName();
if (attributeName == null)
{
throw new IdentityException("IdentityType doesn't have passwordAttributeName option set: "
+ ldapIO.getIdentityType().getName());
}
LdapContext ldapContext = getLDAPContext(ctx);
try
{
//TODO: maybe perform a schema check if this attribute is allowed for such entry
Attributes attrs = new BasicAttributes(true);
Attribute attr = new BasicAttribute(attributeName);
attr.add(passwordString);
attrs.put(attr);
ldapContext.modifyAttributes(ldapIO.getDn(), DirContext.REPLACE_ATTRIBUTE,attrs);
}
catch (NamingException e)
{
throw new IdentityException("Cannot set identity password value.", e);
}