IdentityObjectType type,
Map<String, String[]> attributes) throws IdentityException
{
if (name == null)
{
throw new IdentityException("Name cannot be null");
}
checkIOType(type);
if (log.isLoggable(Level.FINER))
{
log.finer(toString() + ".createIdentityObject with name: " + name + " and type: " + type.getName());
}
LdapContext ldapContext = getLDAPContext(invocationCtx);
try
{
// If there are many contexts specified in the configuration the first one is used
LdapContext ctx = (LdapContext)ldapContext.lookup(getTypeConfiguration(invocationCtx, type).getCtxDNs()[0]);
//We store new entry using set of attributes. This should give more flexibility then
//extending identity object from ContextDir - configure what objectClass place there
Attributes attrs = new BasicAttributes(true);
//create attribute using provided configuration
Map<String, String[]> attributesToAdd = getTypeConfiguration(invocationCtx, type).getCreateEntryAttributeValues();
//merge
if (attributes != null)
{
for (Map.Entry<String, String[]> entry : attributes.entrySet())
{
if (!attributesToAdd.containsKey(entry.getKey()))
{
attributesToAdd.put(entry.getKey(), entry.getValue());
}
else
{
List<String> list1 = Arrays.asList(attributesToAdd.get(entry.getKey()));
List<String> list2 = Arrays.asList(entry.getValue());
list1.addAll(list2);
String[] vals = list1.toArray(new String[list1.size()]);
attributesToAdd.put(entry.getKey(), vals);
}
}
}
//attributes
for (Iterator it1 = attributesToAdd.keySet().iterator(); it1.hasNext();)
{
String attributeName = (String)it1.next();
Attribute attr = new BasicAttribute(attributeName);
String[] attributeValues = attributesToAdd.get(attributeName);
//values
for (String attrValue : attributeValues)
{
attr.add(attrValue);
}
attrs.put(attr);
}
// Make it RFC 2253 compliant
LdapName validLDAPName = new LdapName(getTypeConfiguration(invocationCtx, type).getIdAttributeName().concat("=").concat(name));
log.finer("creating ldap entry for: " + validLDAPName + "; " + attrs);
ctx.createSubcontext(validLDAPName, attrs);
}
catch (Exception e)
{
throw new IdentityException("Failed to create identity object", e);
}
finally
{
try
{
ldapContext.close();
}
catch (NamingException e)
{
throw new IdentityException("Failed to close LDAP connection", e);
}
}
return findIdentityObject(invocationCtx, name, type);