if (typeConfig.isMembershipAttributeDN())
{
//TODO: use direct LDAP query instaed of other find method and add attributesFilter
relationships.add(new LDAPIdentityObjectRelationshipImpl(null, ldapIO, findIdentityObject(ctx, memberRef)));
}
else
{
//TODO: if relationships are not refered with DNs and only names its not possible to map
//TODO: them to proper IdentityType and keep name uniqnes per type. Workaround needed
throw new NotYetImplementedException("LDAP limitation. If relationship targets are not refered with FQDNs " +
"and only names, it's not possible to map them to proper IdentityType and keep name uniqnes per type. " +
"Workaround needed");
}
//break;
}
}
}
// if not parent then all parent entries need to be found
else
{
// Search in all other type contexts
for (IdentityObjectType parentType : configuration.getConfiguredTypes())
{
checkIOType(parentType);
LDAPIdentityObjectTypeConfiguration parentTypeConfiguration = getTypeConfiguration(ctx, parentType);
List<String> allowedTypes = Arrays.asList(parentTypeConfiguration.getAllowedMembershipTypes());
// Check if given identity type can be parent
if (!allowedTypes.contains(identity.getIdentityType().getName()))
{
continue;
}
String nameFilter = "*";
//Filter by name
Control[] requestControls = null;
StringBuilder af = new StringBuilder();
// Add filter to search only parents of the given entry
af.append("(")
.append(parentTypeConfiguration.getMembershipAttributeName())
.append("=");
if (parentTypeConfiguration.isMembershipAttributeDN())
{
af.append(ldapIO.getDn());
}
else
{
//TODO: this doesn't make much sense unless parent/child are same identity types and resides in the same LDAP context
af.append(ldapIO.getName());
}
af.append(")");
String filter = parentTypeConfiguration.getEntrySearchFilter();
List<SearchResult> sr = null;
String[] entryCtxs = parentTypeConfiguration.getCtxDNs();
if (filter != null && filter.length() > 0)
{
Object[] filterArgs = {nameFilter};
sr = searchIdentityObjects(ctx,
entryCtxs,
"(&(" + filter + ")" + af.toString() + ")",
filterArgs,
new String[]{parentTypeConfiguration.getIdAttributeName()},
requestControls);
}
else
{
filter = "(".concat(parentTypeConfiguration.getIdAttributeName()).concat("=").concat(nameFilter).concat(")");
sr = searchIdentityObjects(ctx,
entryCtxs,
"(&(" + filter + ")" + af.toString() + ")",
null,
new String[]{parentTypeConfiguration.getIdAttributeName()},
requestControls);
}
for (SearchResult res : sr)
{
LdapContext ldapCtx = (LdapContext)res.getObject();
String dn = ldapCtx.getNameInNamespace();
relationships.add(new LDAPIdentityObjectRelationshipImpl(null, createIdentityObjectInstance(ctx, parentType, res.getAttributes(), dn), ldapIO));
}
}
}