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;
}
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);
}
}
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;
}
}
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));
}
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;
}
Aggregations