ArrayList<IdentityObjectAttribute> filteredAttrs = new ArrayList<IdentityObjectAttribute>();
ArrayList<IdentityObjectAttribute> leftAttrs = new ArrayList<IdentityObjectAttribute>();
IdentityObjectAttribute[] attributesToAdd = null;
IdentityStore toStore = resolveIdentityStore(identity);
IdentityStoreInvocationContext targetCtx = resolveInvocationContext(toStore, invocationCtx);
// Put supported attrs to the main store
if (toStore != defaultAttributeStore)
{
Set<String> supportedAttrs = toStore.getSupportedAttributeNames(targetCtx, identity.getIdentityType());
// Filter out supported and not supported attributes
for (IdentityObjectAttribute entry : attributes)
{
if (supportedAttrs.contains(entry.getName()))
{
filteredAttrs.add(entry);
}
else
{
leftAttrs.add(entry);
}
}
toStore.addAttributes(targetCtx, identity, filteredAttrs.toArray(new IdentityObjectAttribute[filteredAttrs.size()]));
attributesToAdd = leftAttrs.toArray(new IdentityObjectAttribute[leftAttrs.size()]);
}
else
{
attributesToAdd = attributes;
}
IdentityStoreInvocationContext defaultCtx = resolveInvocationContext(defaultAttributeStore, invocationCtx);
if (isAllowNotDefinedAttributes())
{
defaultAttributeStore.addAttributes(defaultCtx, identity, attributesToAdd);
}