Search in sources :

Example 11 with ByteString

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);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Attribute(org.opends.server.types.Attribute) ByteString(org.forgerock.opendj.ldap.ByteString) ByteString(org.forgerock.opendj.ldap.ByteString) HashSet(java.util.HashSet)

Example 12 with ByteString

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;
}
Also used : SearchRequest(org.forgerock.opendj.ldap.requests.SearchRequest) Attribute(org.forgerock.opendj.ldap.Attribute) LinkedAttribute(org.forgerock.opendj.ldap.LinkedAttribute) ByteString(org.forgerock.opendj.ldap.ByteString) Connection(org.forgerock.opendj.ldap.Connection) ByteString(org.forgerock.opendj.ldap.ByteString) SearchResultReferenceIOException(org.forgerock.opendj.ldap.SearchResultReferenceIOException) ConnectionEntryReader(org.forgerock.opendj.ldif.ConnectionEntryReader) LDAPUrl(org.forgerock.opendj.ldap.LDAPUrl) LdapException(org.forgerock.opendj.ldap.LdapException) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry)

Example 13 with ByteString

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<>();
    }
}
Also used : Attribute(org.forgerock.opendj.ldap.Attribute) ByteString(org.forgerock.opendj.ldap.ByteString) ByteString(org.forgerock.opendj.ldap.ByteString) HashSet(java.util.HashSet)

Example 14 with ByteString

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);
}
Also used : Attribute(org.forgerock.opendj.ldap.Attribute) ByteString(org.forgerock.opendj.ldap.ByteString) ByteString(org.forgerock.opendj.ldap.ByteString) Attr(com.iplanet.services.ldap.Attr)

Example 15 with ByteString

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.");
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Attribute(org.forgerock.opendj.ldap.Attribute) ByteString(org.forgerock.opendj.ldap.ByteString) ByteString(org.forgerock.opendj.ldap.ByteString) HashSet(java.util.HashSet) ServiceAlreadyExistsException(com.sun.identity.sm.ServiceAlreadyExistsException)

Aggregations

ByteString (org.forgerock.opendj.ldap.ByteString)27 Attribute (org.forgerock.opendj.ldap.Attribute)22 SearchResultEntry (org.forgerock.opendj.ldap.responses.SearchResultEntry)16 LdapException (org.forgerock.opendj.ldap.LdapException)14 Connection (org.forgerock.opendj.ldap.Connection)12 HashSet (java.util.HashSet)11 ConnectionEntryReader (org.forgerock.opendj.ldif.ConnectionEntryReader)11 SearchResultReferenceIOException (org.forgerock.opendj.ldap.SearchResultReferenceIOException)8 IOException (java.io.IOException)6 Set (java.util.Set)5 Principal (java.security.Principal)4 ArrayList (java.util.ArrayList)4 BindRequest (org.forgerock.opendj.ldap.requests.BindRequest)4 SearchRequest (org.forgerock.opendj.ldap.requests.SearchRequest)4 BindResult (org.forgerock.opendj.ldap.responses.BindResult)4 AndFilter (org.springframework.ldap.filter.AndFilter)4 EqualsFilter (org.springframework.ldap.filter.EqualsFilter)4 LinkedHashSet (java.util.LinkedHashSet)3 SSOException (com.iplanet.sso.SSOException)2 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)2