Search in sources :

Example 1 with Entry

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;
}
Also used : Entry(com.unboundid.ldap.sdk.Entry) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry) LDAPException(com.unboundid.ldap.sdk.LDAPException) LDIFReader(com.unboundid.ldif.LDIFReader) LDIFException(com.unboundid.ldif.LDIFException) SearchResult(com.unboundid.ldap.sdk.SearchResult) IOException(java.io.IOException)

Example 2 with Entry

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");
    }
}
Also used : Entry(com.unboundid.ldap.sdk.Entry) Attribute(com.unboundid.ldap.sdk.Attribute) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with Entry

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()));
}
Also used : Entry(com.unboundid.ldap.sdk.Entry) LDAPException(com.unboundid.ldap.sdk.LDAPException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) LDIFReader(com.unboundid.ldif.LDIFReader) Schema(com.unboundid.ldap.sdk.schema.Schema) InMemoryDirectoryServerConfig(com.unboundid.ldap.listener.InMemoryDirectoryServerConfig) LDIFException(com.unboundid.ldif.LDIFException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 4 with Entry

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;
}
Also used : Entry(com.unboundid.ldap.sdk.Entry) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry) LDAPException(com.unboundid.ldap.sdk.LDAPException) LDIFReader(com.unboundid.ldif.LDIFReader) LDIFException(com.unboundid.ldif.LDIFException) SearchResult(com.unboundid.ldap.sdk.SearchResult) IOException(java.io.IOException)

Example 5 with Entry

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();
}
Also used : Entry(com.unboundid.ldap.sdk.Entry) InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) InMemoryDirectoryServerConfig(com.unboundid.ldap.listener.InMemoryDirectoryServerConfig)

Aggregations

Entry (com.unboundid.ldap.sdk.Entry)9 LDAPException (com.unboundid.ldap.sdk.LDAPException)6 Attribute (com.unboundid.ldap.sdk.Attribute)4 LDIFReader (com.unboundid.ldif.LDIFReader)4 IOException (java.io.IOException)4 InMemoryDirectoryServer (com.unboundid.ldap.listener.InMemoryDirectoryServer)3 InMemoryDirectoryServerConfig (com.unboundid.ldap.listener.InMemoryDirectoryServerConfig)3 SearchResult (com.unboundid.ldap.sdk.SearchResult)3 LDIFException (com.unboundid.ldif.LDIFException)3 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Ints (com.google.common.primitives.Ints)1 BindRequest (com.unboundid.ldap.sdk.BindRequest)1 BindResult (com.unboundid.ldap.sdk.BindResult)1 DN (com.unboundid.ldap.sdk.DN)1 ExtendedResult (com.unboundid.ldap.sdk.ExtendedResult)1 FailoverServerSet (com.unboundid.ldap.sdk.FailoverServerSet)1