use of com.unboundid.ldap.sdk.Entry in project oxCore by GluuFederation.
the class LdifDataUtility method checkIfSerrverHasEntryFromLDIFFile.
/**
* Check if DS has at least one DN simular to specified in ldif file.
*
* @param connection
* Connection to LDAP server
* @param ldifFileName
* LDIF file
* @return true if server contains at least one DN simular to specified in
* ldif file.
*/
public boolean checkIfSerrverHasEntryFromLDIFFile(LDAPConnection connection, String ldifFileName) {
// Set up the LDIF reader that will be used to read the changes to apply
LDIFReader ldifReader = createLdifReader(ldifFileName);
if (ldifReader == null) {
return true;
}
// Check all ldif entries
while (true) {
// Read the next change to process.
Entry entry = null;
try {
entry = ldifReader.readEntry();
} catch (LDIFException le) {
log.error("Malformed ldif record", le);
if (!le.mayContinueReading()) {
return true;
}
} catch (IOException ioe) {
log.error("I/O error encountered while reading a change record", ioe);
return true;
}
// changes to be processed.
if (entry == null) {
break;
}
// Search entry in the server.
try {
SearchResult sr = connection.search(entry.getDN(), SearchScope.BASE, "objectClass=*");
if ((sr != null) && (sr.getEntryCount() > 0)) {
return true;
}
} catch (LDAPException le) {
if (le.getResultCode() != ResultCode.NO_SUCH_OBJECT) {
log.error("Failed to search ldif record", le);
return true;
}
}
}
disposeLdifReader(ldifReader);
return false;
}
use of com.unboundid.ldap.sdk.Entry in project zm-mailbox by Zimbra.
the class UBIDUserCertificateAttributeTest method getMultiAttrStringShouldReturnCertificateForAttributeNameWithoutBinary.
@Test
public void getMultiAttrStringShouldReturnCertificateForAttributeNameWithoutBinary() {
Attribute attr = new Attribute(ContactConstants.A_userCertificate, certBase64);
Entry entry = PowerMockito.mock(Entry.class);
UBIDAttributes attributes = new UBIDAttributes(entry);
// entry does not contain "userCertificate;binary" attribute
Mockito.when(entry.getAttribute(lookupAttr)).thenReturn(null);
// entry contains "userCertificate" attribute
Mockito.when(entry.getAttribute(ContactConstants.A_userCertificate)).thenReturn(attr);
try {
assertEquals(attributes.getMultiAttrString(lookupAttr, false)[0], certBase64);
} catch (com.zimbra.cs.ldap.LdapException e) {
fail("Exception thrown");
}
}
use of com.unboundid.ldap.sdk.Entry in project CzechIdMng by bcvsolutions.
the class ComplexHrProcessIntegrationTest method startLdapTestServer.
/**
* Ldap server initialization and start
*/
private void startLdapTestServer() {
try (InputStream inputStream = new FileInputStream("src/test/resources/eu/bcvsolutions/idm/ldap/schema.ldif")) {
// Create the configuration to use for the server.
InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(ldapBaseOU);
// load schema
config.addAdditionalBindCredentials(ldapAdminLogin, ldapPassword);
// InputStream inputStream = new FileInputStream("src/test/resources/eu/bcvsolutions/idm/ldap/schema.ldif");
final LDIFReader ldifReader = new LDIFReader(inputStream);
final Entry schemaEntry = ldifReader.readEntry();
ldifReader.close();
Schema newSchema = new Schema(schemaEntry);
config.setSchema(newSchema);
// Create the directory server instance, populate it with data from the
// "crossLdapDemoData.ldif" file, and start listening for client connections.
directoryServer = new InMemoryDirectoryServer(config);
directoryServer.importFromLDIF(true, "src/test/resources/eu/bcvsolutions/idm/ldap/ldapDemoData.ldif");
directoryServer.startListening();
// Get a client connection to the server and use it to perform various
// operations.
ldapConnectionInfo = directoryServer.getConnection();
} catch (LDAPException | IOException | LDIFException e) {
e.printStackTrace();
Assert.fail();
}
LOG.error(String.format("Ldap server is running and available: %s", ldapConnectionInfo.getHostPort()));
}
use of com.unboundid.ldap.sdk.Entry in project oxCore by GluuFederation.
the class LdifDataUtility method checkIfSerrverHasEntryFromLDIFFile.
/**
* Check if DS has at least one DN simular to specified in ldif file.
*
* @param connection
* Connection to LDAP server
* @param ldifFileName
* LDIF file
* @return true if server contains at least one DN simular to specified in ldif
* file.
*/
public boolean checkIfSerrverHasEntryFromLDIFFile(LDAPConnection connection, String ldifFileName) {
// Set up the LDIF reader that will be used to read the changes to apply
LDIFReader ldifReader = createLdifReader(ldifFileName);
if (ldifReader == null) {
return true;
}
// Check all ldif entries
while (true) {
// Read the next change to process.
Entry entry = null;
try {
entry = ldifReader.readEntry();
} catch (LDIFException le) {
LOG.error("Malformed ldif record", le);
if (!le.mayContinueReading()) {
return true;
}
} catch (IOException ioe) {
LOG.error("I/O error encountered while reading a change record", ioe);
return true;
}
// changes to be processed.
if (entry == null) {
break;
}
// Search entry in the server.
try {
SearchResult sr = connection.search(entry.getDN(), SearchScope.BASE, "objectClass=*");
if ((sr != null) && (sr.getEntryCount() > 0)) {
return true;
}
} catch (LDAPException le) {
if (le.getResultCode() != ResultCode.NO_SUCH_OBJECT) {
LOG.error("Failed to search ldif record", le);
return true;
}
}
}
disposeLdifReader(ldifReader);
return false;
}
use of com.unboundid.ldap.sdk.Entry in project cdap by caskdata.
the class ExternalLDAPAuthenticationServerTestBase method startExternalAuthenticationServer.
protected void startExternalAuthenticationServer() throws Exception {
InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=example,dc=com");
config.setListenerConfigs(ldapListenerConfig);
Entry defaultEntry = new Entry("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example");
Entry userEntry = new Entry("dn: uid=user,dc=example,dc=com", "objectClass: inetorgperson", "cn: admin", "sn: User", "uid: user", "userPassword: realtime");
ldapServer = new InMemoryDirectoryServer(config);
ldapServer.addEntries(defaultEntry, userEntry);
ldapServer.startListening();
}
Aggregations