Search in sources :

Example 86 with Nullable

use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.

the class JVMDefaultTrustManager method loadKeyStore.

/**
 * Attempts to load the contents of the specified file as a Java keystore.
 *
 * @param  f  The file from which to load the keystore data.
 *
 * @return  The keystore that was loaded from the specified file.
 *
 * @throws  CertificateException  If a problem occurs while trying to load the
 */
@Nullable()
private static KeyStore loadKeyStore(@NotNull final File f) throws CertificateException {
    if ((!f.exists()) || (!f.isFile())) {
        return null;
    }
    CertificateException firstGetInstanceException = null;
    CertificateException firstLoadException = null;
    for (final String keyStoreType : new String[] { "JKS", "PKCS12" }) {
        final KeyStore keyStore;
        try {
            keyStore = CryptoHelper.getKeyStore(keyStoreType, null, true);
        } catch (final Exception e) {
            Debug.debugException(e);
            if (firstGetInstanceException == null) {
                firstGetInstanceException = new CertificateException(ERR_JVM_DEFAULT_TRUST_MANAGER_CANNOT_INSTANTIATE_KEYSTORE.get(keyStoreType, StaticUtils.getExceptionMessage(e)), e);
            }
            continue;
        }
        try (FileInputStream inputStream = new FileInputStream(f)) {
            keyStore.load(inputStream, null);
        } catch (final Exception e) {
            Debug.debugException(e);
            if (firstLoadException == null) {
                firstLoadException = new CertificateException(ERR_JVM_DEFAULT_TRUST_MANAGER_CANNOT_ERROR_LOADING_KEYSTORE.get(f.getAbsolutePath(), StaticUtils.getExceptionMessage(e)), e);
            }
            continue;
        }
        return keyStore;
    }
    if (firstLoadException != null) {
        throw firstLoadException;
    }
    throw firstGetInstanceException;
}
Also used : CertificateException(java.security.cert.CertificateException) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) KeyStore(java.security.KeyStore) CertificateNotYetValidException(java.security.cert.CertificateNotYetValidException) CertificateExpiredException(java.security.cert.CertificateExpiredException) CertificateException(java.security.cert.CertificateException) FileInputStream(java.io.FileInputStream) Nullable(com.unboundid.util.Nullable)

Example 87 with Nullable

use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.

the class InMemoryDirectoryServer method searchForEntry.

/**
 * {@inheritDoc}
 * <BR><BR>
 * This method may be used regardless of whether the server is listening for
 * client connections, and regardless of whether search operations are allowed
 * in the server.
 */
@Override()
@Nullable()
public SearchResultEntry searchForEntry(@NotNull final SearchRequest searchRequest) throws LDAPSearchException {
    final ArrayList<Control> requestControlList = new ArrayList<>(searchRequest.getControlList());
    requestControlList.add(new Control(InMemoryRequestHandler.OID_INTERNAL_OPERATION_REQUEST_CONTROL, false));
    final SearchRequest r;
    if ((searchRequest.getSizeLimit() == 1) && (searchRequest.getSearchResultListener() == null)) {
        r = searchRequest;
    } else {
        r = new SearchRequest(searchRequest.getBaseDN(), searchRequest.getScope(), searchRequest.getDereferencePolicy(), 1, searchRequest.getTimeLimitSeconds(), searchRequest.typesOnly(), searchRequest.getFilter(), searchRequest.getAttributes());
        r.setFollowReferrals(InternalSDKHelper.followReferralsInternal(r));
        r.setReferralConnector(InternalSDKHelper.getReferralConnectorInternal(r));
        r.setResponseTimeoutMillis(searchRequest.getResponseTimeoutMillis(null));
        r.setControls(requestControlList);
    }
    final SearchResult result;
    try {
        result = search(r);
    } catch (final LDAPSearchException lse) {
        Debug.debugException(lse);
        if (lse.getResultCode() == ResultCode.NO_SUCH_OBJECT) {
            return null;
        }
        throw lse;
    }
    if (result.getEntryCount() == 0) {
        return null;
    } else {
        return result.getSearchEntries().get(0);
    }
}
Also used : SearchRequest(com.unboundid.ldap.sdk.SearchRequest) ReadOnlySearchRequest(com.unboundid.ldap.sdk.ReadOnlySearchRequest) Control(com.unboundid.ldap.sdk.Control) ArrayList(java.util.ArrayList) LDAPSearchException(com.unboundid.ldap.sdk.LDAPSearchException) SearchResult(com.unboundid.ldap.sdk.SearchResult) Nullable(com.unboundid.util.Nullable)

Example 88 with Nullable

use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.

the class InMemoryRequestHandler method getMissingAttributeValues.

/**
 * Retrieves a list of all provided attribute values which are missing from
 * the specified entry.  The target attribute may or may not contain
 * additional values.
 *
 * @param  dn               The DN of the entry to examine.
 * @param  attributeName    The attribute expected to be present in the target
 *                          entry with the given values.
 * @param  attributeValues  The values expected to be present in the target
 *                          entry.
 *
 * @return  A list containing all of the provided values which were not found
 *          in the entry, an empty list if all provided attribute values were
 *          found, or {@code null} if the target entry does not exist.
 *
 * @throws  LDAPException  If a problem is encountered while trying to
 *                         communicate with the directory server.
 */
@Nullable()
public List<String> getMissingAttributeValues(@NotNull final String dn, @NotNull final String attributeName, @NotNull final Collection<String> attributeValues) throws LDAPException {
    synchronized (entryMap) {
        final Entry e = getEntry(dn);
        if (e == null) {
            return null;
        }
        final Schema schema = schemaRef.get();
        final List<String> missingValues = new ArrayList<>(attributeValues.size());
        for (final String value : attributeValues) {
            final Filter f = Filter.createEqualityFilter(attributeName, value);
            if (!f.matchesEntry(e, schema)) {
                missingValues.add(value);
            }
        }
        return missingValues;
    }
}
Also used : ChangeLogEntry(com.unboundid.ldap.sdk.ChangeLogEntry) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry) Entry(com.unboundid.ldap.sdk.Entry) ReadOnlyEntry(com.unboundid.ldap.sdk.ReadOnlyEntry) Filter(com.unboundid.ldap.sdk.Filter) Schema(com.unboundid.ldap.sdk.schema.Schema) ArrayList(java.util.ArrayList) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Nullable(com.unboundid.util.Nullable)

Example 89 with Nullable

use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.

the class InMemoryRequestHandler method handlePostReadControl.

/**
 * Checks to see if the provided control map includes a post-read request
 * control, and if so then generates the appropriate response control that
 * should be returned to the client.
 *
 * @param  m  The map of request controls, indexed by OID.
 * @param  e  The entry as it appeared before the operation.
 *
 * @return  The post-read response control that should be returned to the
 *          client, or {@code null} if there is none.
 */
@Nullable()
private PostReadResponseControl handlePostReadControl(@NotNull final Map<String, Control> m, @NotNull final Entry e) {
    final PostReadRequestControl c = (PostReadRequestControl) m.get(PostReadRequestControl.POST_READ_REQUEST_OID);
    if (c == null) {
        return null;
    }
    final SearchEntryParer parer = new SearchEntryParer(Arrays.asList(c.getAttributes()), schemaRef.get());
    final Entry trimmedEntry = parer.pareEntry(e);
    return new PostReadResponseControl(new ReadOnlyEntry(trimmedEntry));
}
Also used : ReadOnlyEntry(com.unboundid.ldap.sdk.ReadOnlyEntry) ChangeLogEntry(com.unboundid.ldap.sdk.ChangeLogEntry) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry) Entry(com.unboundid.ldap.sdk.Entry) ReadOnlyEntry(com.unboundid.ldap.sdk.ReadOnlyEntry) PostReadResponseControl(com.unboundid.ldap.sdk.controls.PostReadResponseControl) PostReadRequestControl(com.unboundid.ldap.sdk.controls.PostReadRequestControl) Nullable(com.unboundid.util.Nullable)

Example 90 with Nullable

use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.

the class InMemoryRequestHandler method getReferralURLs.

/**
 * Retrieves the referral URLs that should be used for the provided target DN
 * based on the given referral entry.
 *
 * @param  targetDN       The target DN from the associated operation.
 * @param  referralEntry  The entry containing the smart referral.
 *
 * @return  The referral URLs that should be returned.
 */
@Nullable()
private static List<String> getReferralURLs(@NotNull final DN targetDN, @NotNull final Entry referralEntry) {
    final String[] refs = referralEntry.getAttributeValues("ref");
    if (refs == null) {
        return null;
    }
    final RDN[] retainRDNs;
    try {
        // If the target DN equals the referral entry DN, or if it's not
        // subordinate to the referral entry, then the URLs should be returned
        // as-is.
        final DN parsedEntryDN = referralEntry.getParsedDN();
        if (targetDN.equals(parsedEntryDN) || (!targetDN.isDescendantOf(parsedEntryDN, true))) {
            return Arrays.asList(refs);
        }
        final RDN[] targetRDNs = targetDN.getRDNs();
        final RDN[] refEntryRDNs = referralEntry.getParsedDN().getRDNs();
        retainRDNs = new RDN[targetRDNs.length - refEntryRDNs.length];
        System.arraycopy(targetRDNs, 0, retainRDNs, 0, retainRDNs.length);
    } catch (final LDAPException le) {
        Debug.debugException(le);
        return Arrays.asList(refs);
    }
    final List<String> refList = new ArrayList<>(refs.length);
    for (final String ref : refs) {
        try {
            final LDAPURL url = new LDAPURL(ref);
            final RDN[] refRDNs = url.getBaseDN().getRDNs();
            final RDN[] newRefRDNs = new RDN[retainRDNs.length + refRDNs.length];
            System.arraycopy(retainRDNs, 0, newRefRDNs, 0, retainRDNs.length);
            System.arraycopy(refRDNs, 0, newRefRDNs, retainRDNs.length, refRDNs.length);
            final DN newBaseDN = new DN(newRefRDNs);
            final LDAPURL newURL = new LDAPURL(url.getScheme(), url.getHost(), url.getPort(), newBaseDN, null, null, null);
            refList.add(newURL.toString());
        } catch (final LDAPException le) {
            Debug.debugException(le);
            refList.add(ref);
        }
    }
    return refList;
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) LDAPURL(com.unboundid.ldap.sdk.LDAPURL) ArrayList(java.util.ArrayList) RDN(com.unboundid.ldap.sdk.RDN) DN(com.unboundid.ldap.sdk.DN) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) RDN(com.unboundid.ldap.sdk.RDN) Nullable(com.unboundid.util.Nullable)

Aggregations

Nullable (com.unboundid.util.Nullable)149 ArrayList (java.util.ArrayList)47 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)42 Entry (com.unboundid.ldap.sdk.Entry)30 LDAPException (com.unboundid.ldap.sdk.LDAPException)30 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)21 Attribute (com.unboundid.ldap.sdk.Attribute)21 ASN1Element (com.unboundid.asn1.ASN1Element)20 Filter (com.unboundid.ldap.sdk.Filter)20 SearchResult (com.unboundid.ldap.sdk.SearchResult)18 IOException (java.io.IOException)16 ReadOnlyEntry (com.unboundid.ldap.sdk.ReadOnlyEntry)14 File (java.io.File)14 DN (com.unboundid.ldap.sdk.DN)12 ArgumentException (com.unboundid.util.args.ArgumentException)10 RDN (com.unboundid.ldap.sdk.RDN)9 LDIFException (com.unboundid.ldif.LDIFException)8 ChangeLogEntry (com.unboundid.ldap.sdk.ChangeLogEntry)7 Modification (com.unboundid.ldap.sdk.Modification)7 LDIFModifyChangeRecord (com.unboundid.ldif.LDIFModifyChangeRecord)7