use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.
the class ManageCertificates method getKeystorePath.
/**
* Retrieves the path to the target key store file.
*
* @param keystoreArgumentName The name of the argument used to specify the
* path to the target key store.
*
* @return The path to the target keystore file, or {@code null} if no
* keystore path was configured.
*/
@Nullable()
private File getKeystorePath(@NotNull final String keystoreArgumentName) {
final FileArgument keystoreArgument = subCommandParser.getFileArgument(keystoreArgumentName);
if ((keystoreArgument != null) && keystoreArgument.isPresent()) {
return keystoreArgument.getValue();
}
final BooleanArgument useJVMDefaultTrustStoreArgument = subCommandParser.getBooleanArgument("useJVMDefaultTrustStore");
if ((useJVMDefaultTrustStoreArgument != null) && useJVMDefaultTrustStoreArgument.isPresent()) {
return JVM_DEFAULT_CACERTS_FILE;
}
return null;
}
use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.
the class ManageCertificates method getIssuerCertificate.
/**
* Attempts to retrieve the issuer certificate for the provided certificate
* from the given keystore or the JVM-default trust store.
*
* @param certificate The certificate for which to retrieve the
* issuer certificate.
* @param keystore The keystore in which to look for the
* issuer certificate.
* @param jvmDefaultTrustStoreRef A reference that will be used to hold the
* JVM-default trust store if it is obtained
* in the process of retrieving the issuer
* certificate.
* @param missingIssuerRef A reference that will be updated with the
* DN of a missing issuer certificate, if any
* certificate in the chain cannot be
* located. This must not be {@code null}.
*
* @return The issuer certificate for the provided certificate, or
* {@code null} if the issuer certificate could not be retrieved.
*
* @throws Exception If a problem is encountered while trying to retrieve
* the issuer certificate.
*/
@Nullable()
private static X509Certificate getIssuerCertificate(@NotNull final X509Certificate certificate, @NotNull final KeyStore keystore, @NotNull final AtomicReference<KeyStore> jvmDefaultTrustStoreRef, @NotNull final AtomicReference<DN> missingIssuerRef) throws Exception {
final DN subjectDN = certificate.getSubjectDN();
final DN issuerDN = certificate.getIssuerDN();
if (subjectDN.equals(issuerDN)) {
// This means that the certificate is self-signed, so there is no issuer.
return null;
}
// See if we can find the issuer certificate in the provided keystore.
X509Certificate issuerCertificate = getIssuerCertificate(certificate, keystore);
if (issuerCertificate != null) {
return issuerCertificate;
}
// See if we can get the JVM-default trust store.
KeyStore jvmDefaultTrustStore = jvmDefaultTrustStoreRef.get();
if (jvmDefaultTrustStore == null) {
if (JVM_DEFAULT_CACERTS_FILE == null) {
missingIssuerRef.set(issuerDN);
return null;
}
final String[] keystoreTypes = { CryptoHelper.KEY_STORE_TYPE_JKS, CryptoHelper.KEY_STORE_TYPE_PKCS_12, BouncyCastleFIPSHelper.FIPS_KEY_STORE_TYPE };
for (final String keystoreType : keystoreTypes) {
final KeyStore ks = CryptoHelper.getKeyStore(keystoreType);
try (FileInputStream inputStream = new FileInputStream(JVM_DEFAULT_CACERTS_FILE)) {
ks.load(inputStream, null);
jvmDefaultTrustStore = ks;
jvmDefaultTrustStoreRef.set(jvmDefaultTrustStore);
break;
} catch (final Exception e) {
Debug.debugException(e);
}
}
}
if (jvmDefaultTrustStore != null) {
issuerCertificate = getIssuerCertificate(certificate, jvmDefaultTrustStore);
}
if (issuerCertificate == null) {
missingIssuerRef.set(issuerDN);
}
return issuerCertificate;
}
use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.
the class ModifyDNRequest method processAsync.
/**
* Sends this modify DN request to the directory server over the provided
* connection and returns the message ID for the request.
*
* @param connection The connection to use to communicate with the
* directory server.
* @param resultListener The async result listener that is to be notified
* when the response is received. It may be
* {@code null} only if the result is to be processed
* by this class.
*
* @return The async request ID created for the operation, or {@code null} if
* the provided {@code resultListener} is {@code null} and the
* operation will not actually be processed asynchronously.
*
* @throws LDAPException If a problem occurs while sending the request.
*/
@Nullable()
AsyncRequestID processAsync(@NotNull final LDAPConnection connection, @Nullable final AsyncResultListener resultListener) throws LDAPException {
// Create the LDAP message.
messageID = connection.nextMessageID();
final LDAPMessage message = new LDAPMessage(messageID, this, getControls());
// If the provided async result listener is {@code null}, then we'll use
// this class as the message acceptor. Otherwise, create an async helper
// and use it as the message acceptor.
final AsyncRequestID asyncRequestID;
final long timeout = getResponseTimeoutMillis(connection);
if (resultListener == null) {
asyncRequestID = null;
connection.registerResponseAcceptor(messageID, this);
} else {
final AsyncHelper helper = new AsyncHelper(connection, OperationType.MODIFY_DN, messageID, resultListener, getIntermediateResponseListener());
connection.registerResponseAcceptor(messageID, helper);
asyncRequestID = helper.getAsyncRequestID();
if (timeout > 0L) {
final Timer timer = connection.getTimer();
final AsyncTimeoutTimerTask timerTask = new AsyncTimeoutTimerTask(helper);
timer.schedule(timerTask, timeout);
asyncRequestID.setTimerTask(timerTask);
}
}
// Send the request to the server.
try {
Debug.debugLDAPRequest(Level.INFO, this, messageID, connection);
final LDAPConnectionLogger logger = connection.getConnectionOptions().getConnectionLogger();
if (logger != null) {
logger.logModifyDNRequest(connection, messageID, this);
}
connection.getConnectionStatistics().incrementNumModifyDNRequests();
connection.sendMessage(message, timeout);
return asyncRequestID;
} catch (final LDAPException le) {
Debug.debugException(le);
connection.deregisterResponseAcceptor(messageID);
throw le;
}
}
use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.
the class ModifyRequest method processAsync.
/**
* Sends this modify request to the directory server over the provided
* connection and returns the message ID for the request.
*
* @param connection The connection to use to communicate with the
* directory server.
* @param resultListener The async result listener that is to be notified
* when the response is received. It may be
* {@code null} only if the result is to be processed
* by this class.
*
* @return The async request ID created for the operation, or {@code null} if
* the provided {@code resultListener} is {@code null} and the
* operation will not actually be processed asynchronously.
*
* @throws LDAPException If a problem occurs while sending the request.
*/
@Nullable()
AsyncRequestID processAsync(@NotNull final LDAPConnection connection, @Nullable final AsyncResultListener resultListener) throws LDAPException {
// Create the LDAP message.
messageID = connection.nextMessageID();
final LDAPMessage message = new LDAPMessage(messageID, this, getControls());
// If the provided async result listener is {@code null}, then we'll use
// this class as the message acceptor. Otherwise, create an async helper
// and use it as the message acceptor.
final AsyncRequestID asyncRequestID;
final long timeout = getResponseTimeoutMillis(connection);
if (resultListener == null) {
asyncRequestID = null;
connection.registerResponseAcceptor(messageID, this);
} else {
final AsyncHelper helper = new AsyncHelper(connection, OperationType.MODIFY, messageID, resultListener, getIntermediateResponseListener());
connection.registerResponseAcceptor(messageID, helper);
asyncRequestID = helper.getAsyncRequestID();
if (timeout > 0L) {
final Timer timer = connection.getTimer();
final AsyncTimeoutTimerTask timerTask = new AsyncTimeoutTimerTask(helper);
timer.schedule(timerTask, timeout);
asyncRequestID.setTimerTask(timerTask);
}
}
// Send the request to the server.
try {
Debug.debugLDAPRequest(Level.INFO, this, messageID, connection);
final LDAPConnectionLogger logger = connection.getConnectionOptions().getConnectionLogger();
if (logger != null) {
logger.logModifyRequest(connection, messageID, this);
}
connection.getConnectionStatistics().incrementNumModifyRequests();
connection.sendMessage(message, timeout);
return asyncRequestID;
} catch (final LDAPException le) {
Debug.debugException(le);
connection.deregisterResponseAcceptor(messageID);
throw le;
}
}
use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.
the class SearchRequest method processAsync.
/**
* Sends this search request to the directory server over the provided
* connection and returns the message ID for the request.
*
* @param connection The connection to use to communicate with the
* directory server.
* @param resultListener The async result listener that is to be notified
* when the response is received. It may be
* {@code null} only if the result is to be processed
* by this class.
*
* @return The async request ID created for the operation, or {@code null} if
* the provided {@code resultListener} is {@code null} and the
* operation will not actually be processed asynchronously.
*
* @throws LDAPException If a problem occurs while sending the request.
*/
@Nullable()
AsyncRequestID processAsync(@NotNull final LDAPConnection connection, @Nullable final AsyncSearchResultListener resultListener) throws LDAPException {
// Create the LDAP message.
messageID = connection.nextMessageID();
final LDAPMessage message = new LDAPMessage(messageID, this, getControls());
// If the provided async result listener is {@code null}, then we'll use
// this class as the message acceptor. Otherwise, create an async helper
// and use it as the message acceptor.
final AsyncRequestID asyncRequestID;
final long timeout = getResponseTimeoutMillis(connection);
if (resultListener == null) {
asyncRequestID = null;
connection.registerResponseAcceptor(messageID, this);
} else {
final AsyncSearchHelper helper = new AsyncSearchHelper(connection, messageID, resultListener, getIntermediateResponseListener());
connection.registerResponseAcceptor(messageID, helper);
asyncRequestID = helper.getAsyncRequestID();
if (timeout > 0L) {
final Timer timer = connection.getTimer();
final AsyncTimeoutTimerTask timerTask = new AsyncTimeoutTimerTask(helper);
timer.schedule(timerTask, timeout);
asyncRequestID.setTimerTask(timerTask);
}
}
// Send the request to the server.
try {
Debug.debugLDAPRequest(Level.INFO, this, messageID, connection);
final LDAPConnectionLogger logger = connection.getConnectionOptions().getConnectionLogger();
if (logger != null) {
logger.logSearchRequest(connection, messageID, this);
}
connection.getConnectionStatistics().incrementNumSearchRequests();
connection.sendMessage(message, timeout);
return asyncRequestID;
} catch (final LDAPException le) {
Debug.debugException(le);
connection.deregisterResponseAcceptor(messageID);
throw le;
}
}
Aggregations