use of org.apache.directory.ldap.client.api.LdapNetworkConnection in project midpoint by Evolveum.
the class AbstractLdapTest method ldapConnect.
protected LdapNetworkConnection ldapConnect(UserLdapConnectionConfig config) throws LdapException, IOException {
if (config == null) {
config = new UserLdapConnectionConfig();
config.setLdapHost(getLdapServerHost());
config.setLdapPort(getLdapServerPort());
config.setBindDn(getLdapBindDn());
config.setBindPassword(getLdapBindPassword());
}
LOGGER.trace("LDAP connect to {}:{} as {}", config.getLdapHost(), config.getLdapPort(), config.getBindDn());
if (useSsl()) {
config.setUseSsl(true);
TrustManager trustManager = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
};
config.setTrustManagers(trustManager);
}
config.setBinaryAttributeDetector(binaryAttributeDetector);
LdapNetworkConnection connection = new LdapNetworkConnection(config);
boolean connected = connection.connect();
if (!connected) {
AssertJUnit.fail("Cannot connect to LDAP server " + config.getLdapHost() + ":" + config.getLdapPort());
}
LOGGER.trace("LDAP connected to {}:{}, executing bind as {}", config.getLdapHost(), config.getLdapPort(), config.getBindDn());
BindRequest bindRequest = new BindRequestImpl();
bindRequest.setDn(new Dn(config.getBindDn()));
bindRequest.setCredentials(config.getBindPassword());
bindRequest.setSimple(true);
BindResponse bindResponse = connection.bind(bindRequest);
if (bindResponse.getLdapResult().getResultCode() != ResultCodeEnum.SUCCESS) {
ldapDisconnect(connection);
throw new SecurityException("Bind as " + config.getBindDn() + " failed: " + bindResponse.getLdapResult().getDiagnosticMessage() + " (" + bindResponse.getLdapResult().getResultCode() + ")");
}
LOGGER.trace("LDAP connected to {}:{}, bound as {}", config.getLdapHost(), config.getLdapPort(), config.getBindDn());
return connection;
}
use of org.apache.directory.ldap.client.api.LdapNetworkConnection in project midpoint by Evolveum.
the class AbstractLdapTest method getLdapEntry.
protected Entry getLdapEntry(String dn) throws LdapException, IOException, CursorException {
LdapNetworkConnection connection = ldapConnect();
Entry entry = getLdapEntry(connection, dn);
ldapDisconnect(connection);
return entry;
}
use of org.apache.directory.ldap.client.api.LdapNetworkConnection in project midpoint by Evolveum.
the class AbstractLdapTest method searchLdapAccount.
protected Entry searchLdapAccount(UserLdapConnectionConfig config, String filter) throws LdapException, IOException, CursorException {
LdapNetworkConnection connection = ldapConnect(config);
List<Entry> entries = ldapSearch(config, connection, filter);
ldapDisconnect(connection);
assertEquals("Unexpected number of entries for " + filter + ": " + entries, 1, entries.size());
Entry entry = entries.get(0);
return entry;
}
use of org.apache.directory.ldap.client.api.LdapNetworkConnection in project midpoint by Evolveum.
the class AbstractLdapTest method getLdapGroupByName.
protected Entry getLdapGroupByName(String name) throws LdapException, IOException, CursorException {
LdapNetworkConnection connection = ldapConnect();
List<Entry> entries = ldapSearch(connection, "(&(cn=" + name + ")(objectClass=" + getLdapGroupObjectClass() + "))");
ldapDisconnect(connection);
assertEquals("Unexpected number of entries for group cn=" + name + ": " + entries, 1, entries.size());
Entry entry = entries.get(0);
return entry;
}
use of org.apache.directory.ldap.client.api.LdapNetworkConnection in project midpoint by Evolveum.
the class AbstractLdapSynchronizationTest method test822ModifyAccountHt.
@Test
public void test822ModifyAccountHt() throws Exception {
final String TEST_NAME = "test822ModifyAccountHt";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
long tsStart = System.currentTimeMillis();
// WHEN
TestUtil.displayWhen(TEST_NAME);
LdapNetworkConnection connection = ldapConnect();
Modification modCn = new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, "sn", ACCOUNT_HT_SN_MODIFIED);
connection.modify(toAccountDn(ACCOUNT_HT_UID, ACCOUNT_HT_CN), modCn);
ldapDisconnect(connection);
waitForTaskNextRunAssertSuccess(getSyncTaskOid(), true);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
long tsEnd = System.currentTimeMillis();
PrismObject<UserType> user = findUserByUsername(ACCOUNT_HT_UID);
assertNotNull("No user " + ACCOUNT_HT_UID + " created", user);
assertUser(user, user.getOid(), ACCOUNT_HT_UID, ACCOUNT_HT_CN, ACCOUNT_HT_GIVENNAME, ACCOUNT_HT_SN_MODIFIED);
assertStepSyncToken(getSyncTaskOid(), 7, tsStart, tsEnd);
}
Aggregations