use of org.forgerock.opendj.ldap.ByteString in project OpenAM by OpenRock.
the class EmbeddedSearchResultIterator method convertLDAPAttributeSetToMap.
static Map<String, Set<String>> convertLDAPAttributeSetToMap(List<Attribute> attributes) {
Map<String, Set<String>> answer = null;
if (CollectionUtils.isNotEmpty(attributes)) {
for (Attribute attr : attributes) {
if (attr != null) {
Set<String> strValues = new HashSet<>();
for (ByteString anAttr : attr) {
strValues.add(anAttr.toString());
}
if (answer == null) {
answer = new CaseInsensitiveHashMap<>(10);
}
answer.put(attr.getName(), strValues);
}
}
}
return (answer);
}
use of org.forgerock.opendj.ldap.ByteString in project OpenAM by OpenRock.
the class DJLDAPv3Repo method getGroupMembers.
/**
* Returns the DNs of the members of this group. If the MemberURL attribute has been configured, then this
* will also try to retrieve dynamic group members using the memberURL.
*
* @param dn The DN of the group to query.
* @return The DNs of the members.
* @throws IdRepoException If there is an error while trying to retrieve the members.
*/
private Set<String> getGroupMembers(String dn) throws IdRepoException {
Set<String> results = new HashSet<String>();
Connection conn = null;
String[] attrs;
if (memberURLAttr != null) {
attrs = new String[] { uniqueMemberAttr, memberURLAttr };
} else {
attrs = new String[] { uniqueMemberAttr };
}
try {
conn = connectionFactory.getConnection();
SearchResultEntry entry = conn.searchSingleEntry(LDAPRequests.newSingleEntrySearchRequest(dn, attrs));
Attribute attr = entry.getAttribute(uniqueMemberAttr);
if (attr != null) {
results.addAll(LDAPUtils.getAttributeValuesAsStringSet(attr));
} else if (memberURLAttr != null) {
attr = entry.getAttribute(memberURLAttr);
if (attr != null) {
for (ByteString byteString : attr) {
LDAPUrl url = LDAPUrl.valueOf(byteString.toString());
SearchRequest searchRequest = LDAPRequests.newSearchRequest(url.getName(), url.getScope(), url.getFilter(), DN_ATTR);
searchRequest.setTimeLimit(defaultTimeLimit);
searchRequest.setSizeLimit(defaultSizeLimit);
ConnectionEntryReader reader = conn.search(searchRequest);
while (reader.hasNext()) {
if (reader.isEntry()) {
results.add(reader.readEntry().getName().toString());
} else {
//ignore search result references
reader.readReference();
}
}
}
}
}
} catch (LdapException ere) {
DEBUG.error("An error occurred while retrieving group members for " + dn, ere);
handleErrorResult(ere);
} catch (SearchResultReferenceIOException srrioe) {
//should never ever happen...
DEBUG.error("Got reference instead of entry", srrioe);
throw newIdRepoException(IdRepoErrorCode.SEARCH_FAILED, CLASS_NAME);
} finally {
IOUtils.closeIfNotNull(conn);
}
return results;
}
use of org.forgerock.opendj.ldap.ByteString in project OpenAM by OpenRock.
the class UmaLabelsStore method getResourceSetIds.
private Set<String> getResourceSetIds(SearchResultEntry searchResult) throws SearchResultReferenceIOException, LdapException {
final Attribute attribute = searchResult.getAttribute(RESOURCE_SET_ATTR);
if (attribute != null) {
final Iterator<ByteString> resourceSets = attribute.iterator();
Set<String> resourceSetIds = new HashSet<>();
while (resourceSets.hasNext()) {
resourceSetIds.add(resourceSets.next().toString());
}
return resourceSetIds;
} else {
return new HashSet<>();
}
}
use of org.forgerock.opendj.ldap.ByteString in project OpenAM by OpenRock.
the class StaticGroup method getMembers.
/**
* Get members of the group.
*
* @param level
* Nesting level
* @return SearchResults for members of the group
* @exception Not
* thrown by this class
* @supported.api
*
*/
public SearchResults getMembers(int level) throws UMSException {
Attr attr = getAttribute(MEMBER_ATTR_NAME);
if (attr == null) {
return null;
}
if (level == LEVEL_ALL) {
level = getMaxNestingLevel();
}
if (level == LEVEL_DIRECT) {
return new SearchResults(getAttribute(MEMBER_ATTR_NAME));
}
Attr nestedMembers = new Attr(MEMBER_ATTR_NAME);
Attribute la = attr.toLDAPAttribute();
Iterator<ByteString> iterator = la.iterator();
while (iterator.hasNext()) {
String memberdn = iterator.next().toString();
PersistentObject entry = null;
try {
// entry = getUMSSession().getObject(new Guid(memberdn));
entry = UMSObject.getObject(getPrincipal(), new Guid(memberdn));
} catch (UMSException ignore) {
}
if (entry != null && entry instanceof StaticGroup) {
SearchResults r = ((StaticGroup) entry).getMembers(level - 1);
while (r.hasMoreElements()) {
PersistentObject member = null;
try {
member = r.next();
nestedMembers.addValue(member.getDN());
} catch (UMSException ignore) {
}
}
} else {
nestedMembers.addValue(memberdn);
}
entry = null;
}
return new SearchResults(nestedMembers);
}
use of org.forgerock.opendj.ldap.ByteString in project OpenAM by OpenRock.
the class SMSRepositoryMig method createSMSEntry.
private static void createSMSEntry(SMSFlatFileObject smsFlatFileObject, String dn, Iterable<Attribute> attrs) throws Exception {
// Convert attrs from LDAPAttributeSet to a Map needed by SMSObject.
Map<String, Set<String>> attrsMap = new HashMap<>();
for (Attribute attribute : attrs) {
String attrName = attribute.getAttributeDescriptionAsString();
Set<String> attrVals = new HashSet<>();
for (ByteString value : attribute) {
attrVals.add(value.toString());
}
attrsMap.put(attrName, attrVals);
}
try {
smsFlatFileObject.create(null, dn, attrsMap);
} catch (ServiceAlreadyExistsException e) {
System.out.println("Warning: '" + dn + "' already exists.");
}
}
Aggregations