Search in sources :

Example 26 with ByteString

use of org.forgerock.opendj.ldap.ByteString in project admin-console-beta by connexta.

the class LdapTestDirectorySettings method checkReferencedUser.

boolean checkReferencedUser(Connection ldapConnection, SearchResultEntry group) {
    boolean hasReferencedMember = false;
    for (ByteString memberRef : group.getAttribute(settings.groupAttributeHoldingMember()).toArray()) {
        // This memberRef will be in the format:
        // memberAttributeReferencedInGroup + username + baseUserDN
        // Strip the baseUserDN and query for the remainder as a Filter
        // beneath the baseUserDN
        List<String> split = Arrays.asList(memberRef.toString().split(","));
        String userFilter = split.get(0);
        String checkUserBase = String.join(",", split.subList(1, split.size()));
        // found in a matched group
        if (checkUserBase.toUpperCase().endsWith(settings.baseUserDn().toUpperCase()) && userFilter.split("=")[0].equalsIgnoreCase(settings.memberAttributeReferencedInGroup())) {
            List<SearchResultEntry> foundMember = utils.getLdapQueryResults(ldapConnection, settings.baseUserDn(), userFilter, SearchScope.WHOLE_SUBTREE, 1);
            if (!foundMember.isEmpty()) {
                hasReferencedMember = true;
                break;
            }
        }
    }
    return hasReferencedMember;
}
Also used : ByteString(org.forgerock.opendj.ldap.ByteString) ByteString(org.forgerock.opendj.ldap.ByteString) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry)

Example 27 with ByteString

use of org.forgerock.opendj.ldap.ByteString in project admin-console-beta by connexta.

the class LdapQuery method performFunction.

@Override
public MapField.ListImpl performFunction() {
    List<SearchResultEntry> searchResults;
    List<MapField> convertedSearchResults = new ArrayList<>();
    try (LdapConnectionAttempt connectionAttempt = utils.bindUserToLdapConnection(conn, creds)) {
        addErrorMessages(connectionAttempt);
        if (containsErrorMsgs()) {
            return null;
        }
        searchResults = utils.getLdapQueryResults(connectionAttempt.getResult(), queryBase.getValue(), query.getValue(), SearchScope.WHOLE_SUBTREE, maxQueryResults.getValue() == null ? DEFAULT_MAX_QUERY_RESULTS : maxQueryResults.getValue());
        for (SearchResultEntry entry : searchResults) {
            MapField entryMap = new MapField();
            for (Attribute attri : entry.getAllAttributes()) {
                entryMap.put("name", entry.getName().toString());
                if (!attri.getAttributeDescriptionAsString().toLowerCase().contains("password")) {
                    List<String> attributeValueList = attri.parallelStream().map(ByteString::toString).collect(Collectors.toList());
                    String attributeValue = attributeValueList.size() == 1 ? attributeValueList.get(0) : attributeValueList.toString();
                    entryMap.put(attri.getAttributeDescriptionAsString(), attributeValue);
                }
            }
            convertedSearchResults.add(entryMap);
        }
    } catch (IOException e) {
        LOGGER.warn("Error closing LDAP connection", e);
    }
    return new MapField.ListImpl().addAll(convertedSearchResults);
}
Also used : Attribute(org.forgerock.opendj.ldap.Attribute) ArrayList(java.util.ArrayList) ByteString(org.forgerock.opendj.ldap.ByteString) IOException(java.io.IOException) LdapConnectionAttempt(org.codice.ddf.admin.ldap.commons.LdapConnectionAttempt) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry) MapField(org.codice.ddf.admin.common.fields.common.MapField)

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