use of com.unboundid.util.ssl.SSLUtil in project cas by apereo.
the class ActiveDirectoryWebAuthnCredentialRepositoryTests method getUsername.
@Override
@SneakyThrows
protected String getUsername() {
val uid = super.getUsername();
val bindInit = new BindConnectionInitializer("CN=admin,CN=Users,DC=cas,DC=example,DC=org", new Credential("P@ssw0rd"));
val sslUtil = new SSLUtil(null, new TrustAllTrustManager());
val socketFactory = sslUtil.createSSLSocketFactory();
@Cleanup val c = new LDAPConnection(socketFactory, "localhost", 10636, bindInit.getBindDn(), bindInit.getBindCredential().getString());
c.add(getLdif(uid));
val mod = new Modification(ModificationType.REPLACE, "streetAddress", " ");
c.modify(String.format("CN=%s,CN=Users,DC=cas,DC=example,DC=org", uid), mod);
return uid;
}
use of com.unboundid.util.ssl.SSLUtil in project cas by apereo.
the class ActiveDirectoryGoogleAuthenticatorTokenCredentialRepositoryTests method getUsernameUnderTest.
@Override
@SneakyThrows
protected String getUsernameUnderTest() {
val uid = "aham";
val bindInit = new BindConnectionInitializer("CN=admin,CN=Users,DC=cas,DC=example,DC=org", new Credential("P@ssw0rd"));
val sslUtil = new SSLUtil(null, new TrustAllTrustManager());
val socketFactory = sslUtil.createSSLSocketFactory();
@Cleanup val c = new LDAPConnection(socketFactory, "localhost", 10636, bindInit.getBindDn(), bindInit.getBindCredential().getString());
val mod = new Modification(ModificationType.REPLACE, "streetAddress", " ");
c.modify(String.format("CN=%s,CN=Users,DC=cas,DC=example,DC=org", uid), mod);
return uid;
}
use of com.unboundid.util.ssl.SSLUtil in project zm-mailbox by Zimbra.
the class LdapSSLUtil method createSSLContext.
static SSLContext createSSLContext(boolean allowUntrustedCerts) throws LdapException {
TrustManager tm = getTrustManager(allowUntrustedCerts);
SSLUtil sslUtil = new SSLUtil(tm);
try {
return sslUtil.createSSLContext();
} catch (GeneralSecurityException e) {
throw UBIDLdapException.mapToLdapException(e);
}
}
use of com.unboundid.util.ssl.SSLUtil in project admin-console-beta by connexta.
the class TestLdapServer method getServerSSLContext.
SSLContext getServerSSLContext() {
try {
char[] keyStorePassword = "changeit".toCharArray();
String keystore = getClass().getResource("/serverKeystore.jks").getFile();
KeyStoreKeyManager keyManager = new KeyStoreKeyManager(keystore, keyStorePassword, "JKS", getHostname());
String truststore = getClass().getResource("/serverTruststore.jks").getFile();
TrustStoreTrustManager trustManager = new TrustStoreTrustManager(truststore, keyStorePassword, null, false);
return new SSLUtil(keyManager, trustManager).createSSLContext();
} catch (GeneralSecurityException e) {
fail(e.getMessage());
}
return null;
}
use of com.unboundid.util.ssl.SSLUtil in project gitblit by gitblit.
the class LdapConnection method connect.
public boolean connect() {
try {
URI ldapUrl = new URI(settings.getRequiredString(Keys.realm.ldap.server));
String ldapHost = ldapUrl.getHost();
int ldapPort = ldapUrl.getPort();
if (ldapUrl.getScheme().equalsIgnoreCase("ldaps")) {
// SSL
SSLUtil sslUtil = new SSLUtil(new TrustAllTrustManager());
conn = new LDAPConnection(sslUtil.createSSLSocketFactory());
if (ldapPort == -1) {
ldapPort = 636;
}
} else if (ldapUrl.getScheme().equalsIgnoreCase("ldap") || ldapUrl.getScheme().equalsIgnoreCase("ldap+tls")) {
// no encryption or StartTLS
conn = new LDAPConnection();
if (ldapPort == -1) {
ldapPort = 389;
}
} else {
logger.error("Unsupported LDAP URL scheme: " + ldapUrl.getScheme());
return false;
}
conn.connect(ldapHost, ldapPort);
if (ldapUrl.getScheme().equalsIgnoreCase("ldap+tls")) {
SSLUtil sslUtil = new SSLUtil(new TrustAllTrustManager());
ExtendedResult extendedResult = conn.processExtendedOperation(new StartTLSExtendedRequest(sslUtil.createSSLContext()));
if (extendedResult.getResultCode() != ResultCode.SUCCESS) {
throw new LDAPException(extendedResult.getResultCode());
}
}
return true;
} catch (URISyntaxException e) {
logger.error("Bad LDAP URL, should be in the form: ldap(s|+tls)://<server>:<port>", e);
} catch (GeneralSecurityException e) {
logger.error("Unable to create SSL Connection", e);
} catch (LDAPException e) {
logger.error("Error Connecting to LDAP", e);
}
return false;
}
Aggregations