use of org.forgerock.opendj.ldap.LDAPConnectionFactory in project ddf by codice.
the class SslLdapLoginModuleTest method testUnsuccessfulConnectionBind1.
@Test
public void testUnsuccessfulConnectionBind1() throws LoginException {
LDAPConnectionFactory mockedConnectionFactory = PowerMockito.mock(LDAPConnectionFactory.class);
BindResult mockedBindResult = mock(BindResult.class);
when(mockedBindResult.isSuccess()).thenReturn(false);
Connection mockedConnection = mock(Connection.class);
SslLdapLoginModule testLoginModule = mock(SslLdapLoginModule.class);
try {
when(mockedConnectionFactory.getConnection()).thenReturn(mockedConnection);
when(mockedConnection.bind(anyString(), any(char[].class))).thenReturn(mockedBindResult);
when(testLoginModule.createLdapConnectionFactory(any(String.class), any(Boolean.class))).thenReturn(mockedConnectionFactory);
} catch (LdapException e) {
LOGGER.debug("LDAP exception", e);
}
Boolean loginBool = testLoginModule.doLogin();
assertThat(loginBool, is(false));
}
use of org.forgerock.opendj.ldap.LDAPConnectionFactory in project ddf by codice.
the class ClaimsHandlerManager method createLdapConnectionFactory.
protected LDAPConnectionFactory createLdapConnectionFactory(String url, Boolean startTls) throws LdapException {
boolean useSsl = url.startsWith("ldaps");
boolean useTls = !url.startsWith("ldaps") && startTls;
Options lo = Options.defaultOptions();
try {
if (useSsl || useTls) {
lo.set(LDAPConnectionFactory.SSL_CONTEXT, SSLContext.getDefault());
}
} catch (GeneralSecurityException e) {
LOGGER.info("Error encountered while configuring SSL. Secure connection will fail.", e);
}
lo.set(LDAPConnectionFactory.SSL_USE_STARTTLS, useTls);
lo.set(LDAPConnectionFactory.SSL_ENABLED_CIPHER_SUITES, Arrays.asList(System.getProperty("https.cipherSuites").split(",")));
lo.set(LDAPConnectionFactory.SSL_ENABLED_PROTOCOLS, Arrays.asList(System.getProperty("https.protocols").split(",")));
lo.set(LDAPConnectionFactory.TRANSPORT_PROVIDER_CLASS_LOADER, ClaimsHandlerManager.class.getClassLoader());
String host = url.substring(url.indexOf("://") + 3, url.lastIndexOf(":"));
Integer port = useSsl ? 636 : 389;
try {
port = Integer.valueOf(url.substring(url.lastIndexOf(":") + 1));
} catch (NumberFormatException ignore) {
}
auditRemoteConnection(host);
return new LDAPConnectionFactory(host, port, lo);
}
use of org.forgerock.opendj.ldap.LDAPConnectionFactory in project ddf by codice.
the class ClaimsHandlerManager method update.
/**
* Callback method that is called when configuration is updated. Also called by the
* blueprint init-method when all properties have been set.
*
* @param props Map of properties.
*/
public void update(Map<String, Object> props) {
if (props == null) {
return;
}
LOGGER.debug("Received an updated set of configurations for the LDAP/Role Claims Handlers.");
String url = new PropertyResolver((String) props.get(ClaimsHandlerManager.URL)).toString();
Boolean startTls;
if (props.get(ClaimsHandlerManager.START_TLS) instanceof String) {
startTls = Boolean.valueOf((String) props.get(ClaimsHandlerManager.START_TLS));
} else {
startTls = (Boolean) props.get(ClaimsHandlerManager.START_TLS);
}
String userDn = (String) props.get(ClaimsHandlerManager.LDAP_BIND_USER_DN);
String password = (String) props.get(ClaimsHandlerManager.PASSWORD);
String userBaseDn = (String) props.get(ClaimsHandlerManager.USER_BASE_DN);
String objectClass = (String) props.get(ClaimsHandlerManager.OBJECT_CLASS);
String memberNameAttribute = (String) props.get(ClaimsHandlerManager.MEMBER_NAME_ATTRIBUTE);
String groupBaseDn = (String) props.get(ClaimsHandlerManager.GROUP_BASE_DN);
String loginUserAttribute = (String) props.get(ClaimsHandlerManager.LOGIN_USER_ATTRIBUTE);
String membershipUserAttribute = (String) props.get(ClaimsHandlerManager.MEMBER_USER_ATTRIBUTE);
String propertyFileLocation = (String) props.get(ClaimsHandlerManager.PROPERTY_FILE_LOCATION);
String bindMethod = (String) props.get(ClaimsHandlerManager.BIND_METHOD);
String realm = (props.get(ClaimsHandlerManager.REALM) != null) ? (String) props.get(ClaimsHandlerManager.REALM) : "";
String kdcAddress = (props.get(ClaimsHandlerManager.KDC_ADDRESS) != null) ? (String) props.get(ClaimsHandlerManager.KDC_ADDRESS) : "";
if ("GSSAPI SASL".equals(bindMethod) && (StringUtils.isEmpty(realm) || StringUtils.isEmpty(kdcAddress))) {
LOGGER.warn("LDAP connection will fail. GSSAPI SASL connection requires Kerberos Realm and KDC Address.");
}
Boolean overrideCertDn;
if (props.get(ClaimsHandlerManager.OVERRIDE_CERT_DN) instanceof String) {
overrideCertDn = Boolean.valueOf((String) props.get(ClaimsHandlerManager.OVERRIDE_CERT_DN));
} else {
overrideCertDn = (Boolean) props.get(ClaimsHandlerManager.OVERRIDE_CERT_DN);
}
if (startTls == null) {
startTls = false;
}
if (overrideCertDn == null) {
overrideCertDn = false;
}
try {
if (encryptService != null) {
password = encryptService.decryptValue(password);
}
LDAPConnectionFactory connection1 = createLdapConnectionFactory(url, startTls);
LDAPConnectionFactory connection2 = createLdapConnectionFactory(url, startTls);
registerRoleClaimsHandler(connection1, propertyFileLocation, userBaseDn, loginUserAttribute, membershipUserAttribute, objectClass, memberNameAttribute, groupBaseDn, userDn, password, overrideCertDn, bindMethod, realm, kdcAddress);
registerLdapClaimsHandler(connection2, propertyFileLocation, userBaseDn, loginUserAttribute, userDn, password, overrideCertDn, bindMethod, realm, kdcAddress);
} catch (Exception e) {
LOGGER.warn("Experienced error while configuring claims handlers. Handlers are NOT configured and claim retrieval will not work. Check LDAP configuration.", e);
}
}
use of org.forgerock.opendj.ldap.LDAPConnectionFactory in project admin-console-beta by connexta.
the class LdapTestingUtils method getLdapConnection.
/**
* Attempts to connect to the given ldap address given the hostname, port, and encryptionMethod
*
* Possible message types: CANNOT_CONFIGURE, CANNOT_CONNECT
* @return
*/
public LdapConnectionAttempt getLdapConnection(LdapConnectionField connection) {
LDAPOptions ldapOptions = new LDAPOptions();
try {
if (connection.encryptionMethod().equals(LDAPS)) {
ldapOptions.setSSLContext(SSLContext.getDefault());
} else if (connection.encryptionMethod().equals(START_TLS)) {
ldapOptions.setUseStartTLS(true);
}
ldapOptions.addEnabledCipherSuite(System.getProperty("https.cipherSuites").split(","));
ldapOptions.addEnabledProtocol(System.getProperty("https.protocols").split(","));
//sets the classloader so it can find the grizzly protocol handler class
ldapOptions.setProviderClassLoader(LdapTestingUtils.class.getClassLoader());
} catch (Exception e) {
LOGGER.debug("Error prepping LDAP connection", e);
return new LdapConnectionAttempt(CANNOT_CONFIGURE);
}
Connection ldapConnection;
try {
ldapConnection = new LDAPConnectionFactory(connection.hostname(), connection.port(), ldapOptions).getConnection();
} catch (Exception e) {
LOGGER.debug("Error opening LDAP connection to [{}:{}]", connection.hostname(), connection.port());
return new LdapConnectionAttempt(CANNOT_CONNECT);
}
return new LdapConnectionAttempt(ldapConnection);
}
use of org.forgerock.opendj.ldap.LDAPConnectionFactory in project OpenAM by OpenRock.
the class AMCertStore method getConnection.
/**
* Return ldap connection for ldap certificate store, or null if an error occured when connecting.
*/
synchronized Connection getConnection() {
if (ldapconn == null) {
/*
* Setup the LDAP certificate directory service context for
* use in verification of the users certificates.
*/
String serverName = storeParam.getServerName();
int port = storeParam.getPort();
LDAPConnectionFactory factory;
// Regardless of SSL on connection, we will use authentication
SimpleBindRequest authenticatedRequest = LDAPRequests.newSimpleBindRequest(storeParam.getUser(), storeParam.getPassword().toCharArray());
Options options = Options.defaultOptions().set(AUTHN_BIND_REQUEST, authenticatedRequest);
if (storeParam.isSecure()) {
debug.message("AMCertStore.getConnection: initial connection factory using ssl.");
try {
options = options.set(SSL_CONTEXT, new SSLContextBuilder().getSSLContext());
ldapconn = new LDAPConnectionFactory(serverName, port, options);
debug.message("AMCertStore.getConnection: SSLSocketFactory called");
} catch (GeneralSecurityException e) {
debug.error("AMCertStore.getConnection: Error getting SSL Context", e);
return null;
}
} else {
// non-ssl
ldapconn = new LDAPConnectionFactory(serverName, port, options);
}
}
try {
return ldapconn.getConnection();
} catch (LdapException e) {
debug.error("AMCertStore.getConnection: Exception in connection to LDAP server", e);
return null;
}
}
Aggregations