String dnSlice = extractSlice(userDN, nameParser, startIndex,
endIndex);
int dotIndex = attributeId.indexOf(".");
if (dotIndex > -1) {
Attributes nestedAttrs = ctx.getAttributes(dnSlice, null);
Attribute attr = nestedAttrs.get(attributeId
.substring(dotIndex + 1));
if (attr != null && attr.size() > 0) {
if (attr.size() == 1) {
userPrincipal.putCustomProperty(option.getKey().substring(
CUSTOM_PROPERTY_OPT.length()), attr.get());
} else {
List<Object> values = new ArrayList<Object>();
for (NamingEnumeration<?> avne = attr.getAll(); avne
.hasMore();) {
values.add(avne.next());
}
userPrincipal.putCustomProperty(option.getKey().substring(
CUSTOM_PROPERTY_OPT.length()), values);
}
}
} else {
userPrincipal.putCustomProperty(option.getKey().substring(
CUSTOM_PROPERTY_OPT.length()), dnSlice);
}
} else {
Attribute attr = attrs.get(attributeId);
if (attr != null && attr.size() > 0) {
if (attr.size() == 1) {
userPrincipal.putCustomProperty(option.getKey().substring(
CUSTOM_PROPERTY_OPT.length()), extractSlice((String) attr
.get(), nameParser, startIndex, endIndex));
} else {
List<Object> values = new ArrayList<Object>();
for (NamingEnumeration<?> avne = attr.getAll(); avne.hasMore();) {
values.add(extractSlice((String) avne.next(), nameParser,
startIndex, endIndex));
}
userPrincipal.putCustomProperty(option.getKey().substring(
CUSTOM_PROPERTY_OPT.length()), values);
}
}
}
} else {
if ("DN".equalsIgnoreCase(attributeId)) {
userPrincipal.putCustomProperty(option.getKey().substring(
CUSTOM_PROPERTY_OPT.length()), userDN);
} else {
Attribute attr = attrs.get(attributeId);
if (attr != null && attr.size() > 0) {
if (attr.size() == 1) {
userPrincipal.putCustomProperty(option.getKey().substring(
CUSTOM_PROPERTY_OPT.length()), attr.get());
} else {
List<Object> values = new ArrayList<Object>();
for (NamingEnumeration<?> avne = attr.getAll(); avne.hasMore();) {
values.add(avne.next());
}
userPrincipal.putCustomProperty(option.getKey().substring(
CUSTOM_PROPERTY_OPT.length()), values);
}