Search in sources :

Example 1 with Entry

use of org.forgerock.opendj.ldap.Entry in project OpenAM by OpenRock.

the class OpenDJUpgrader method findBaseDNs.

private List<DN> findBaseDNs() throws IOException {
    final List<DN> baseDNs = new LinkedList<DN>();
    final SearchRequest request = LDAPRequests.newSearchRequest("cn=backends,cn=config", SearchScope.WHOLE_SUBTREE, "(objectclass=ds-cfg-backend)", "ds-cfg-base-dn");
    try (LDIFEntryReader reader = new LDIFEntryReader(new FileInputStream(installRoot + "/config/config.ldif"))) {
        final EntryReader filteredReader = LDIF.search(reader, request);
        while (filteredReader.hasNext()) {
            final Entry entry = filteredReader.readEntry();
            final Attribute values = entry.getAttribute("ds-cfg-base-dn");
            if (values != null) {
                for (final ByteString value : values) {
                    baseDNs.add(DN.valueOf(value.toString()));
                }
            }
        }
    }
    return baseDNs;
}
Also used : SearchRequest(org.forgerock.opendj.ldap.requests.SearchRequest) EntryReader(org.forgerock.opendj.ldif.EntryReader) LDIFEntryReader(org.forgerock.opendj.ldif.LDIFEntryReader) ZipEntry(java.util.zip.ZipEntry) Entry(org.forgerock.opendj.ldap.Entry) LDIFEntryReader(org.forgerock.opendj.ldif.LDIFEntryReader) Attribute(org.forgerock.opendj.ldap.Attribute) ByteString(org.forgerock.opendj.ldap.ByteString) DN(org.forgerock.opendj.ldap.DN) LinkedList(java.util.LinkedList) FileInputStream(java.io.FileInputStream)

Example 2 with Entry

use of org.forgerock.opendj.ldap.Entry in project OpenAM by OpenRock.

the class SMSLdapObject method create.

/**
     * Create an entry in the directory using the principal name
     */
private static void create(Principal p, String dn, Map attrs) throws SMSException, SSOException {
    int retry = 0;
    Entry entry = copyMapToEntry(attrs).setName(dn);
    while (retry <= connNumRetry) {
        debug.message("SMSLdapObject.create() retry: {}", retry);
        try (Connection conn = getConnection(p)) {
            conn.add(LDAPRequests.newAddRequest(entry));
            debug.message("SMSLdapObject.create Successfully created entry: {}", dn);
            break;
        } catch (LdapException e) {
            ResultCode errorCode = e.getResult().getResultCode();
            if (errorCode.equals(ResultCode.ENTRY_ALREADY_EXISTS) && retry > 0) {
                // During install time and other times,
                // this error gets throws due to unknown issue. Issue:
                // Hence mask it.
                debug.warning("SMSLdapObject.create() Entry Already Exists Error for DN {}", dn);
                break;
            }
            if (!retryErrorCodes.contains(errorCode) || retry >= connNumRetry) {
                debug.error("SMSLdapObject.create() Error in creating: {} By Principal: {}", dn, p.getName(), e);
                throw new SMSException(e, "sms-entry-cannot-create");
            }
            retry++;
            try {
                Thread.sleep(connRetryInterval);
            } catch (InterruptedException ex) {
            //ignored
            }
        }
    }
}
Also used : SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry) SMSDataEntry(com.sun.identity.sm.SMSDataEntry) SMSEntry(com.sun.identity.sm.SMSEntry) LinkedHashMapEntry(org.forgerock.opendj.ldap.LinkedHashMapEntry) Entry(org.forgerock.opendj.ldap.Entry) SMSException(com.sun.identity.sm.SMSException) Connection(org.forgerock.opendj.ldap.Connection) LdapException(org.forgerock.opendj.ldap.LdapException) ResultCode(org.forgerock.opendj.ldap.ResultCode)

Example 3 with Entry

use of org.forgerock.opendj.ldap.Entry in project OpenAM by OpenRock.

the class LdapAdapter method update.

/**
     * Update the Token based on whether there were any changes between the two.
     *
     * @param connection The non null connection to perform this call against.
     * @param previous The non null previous Token to check against.
     * @param updated The non null Token to update with.
     * @return True if the token was updated, or false if there were no changes detected.
     * @throws org.forgerock.openam.sm.datalayer.api.LdapOperationFailedException If the operation failed for a known reason.
     */
public boolean update(Connection connection, Token previous, Token updated) throws LdapOperationFailedException {
    Entry currentEntry = conversion.getEntry(updated);
    LdapTokenAttributeConversion.stripObjectClass(currentEntry);
    Entry previousEntry = conversion.getEntry(previous);
    LdapTokenAttributeConversion.stripObjectClass(previousEntry);
    ModifyRequest request = Entries.diffEntries(previousEntry, currentEntry);
    request.addControl(TransactionIdControl.newControl(AuditRequestContext.createSubTransactionIdValue()));
    // Test to see if there are any modifications
    if (request.getModifications().isEmpty()) {
        return false;
    }
    try {
        processResult(connection.modify(request));
    } catch (LdapException e) {
        throw new LdapOperationFailedException(e.getResult());
    }
    return true;
}
Also used : Entry(org.forgerock.opendj.ldap.Entry) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry) LdapOperationFailedException(org.forgerock.openam.sm.datalayer.api.LdapOperationFailedException) ModifyRequest(org.forgerock.opendj.ldap.requests.ModifyRequest) LdapException(org.forgerock.opendj.ldap.LdapException)

Example 4 with Entry

use of org.forgerock.opendj.ldap.Entry in project OpenAM by OpenRock.

the class LdapTokenAttributeConversionTest method shouldStripObjectClass.

@Test
public void shouldStripObjectClass() {
    // Given
    Entry entry = mock(Entry.class);
    Attribute attribute = mock(Attribute.class);
    given(entry.getAttribute(anyString())).willReturn(attribute);
    AttributeDescription description = AttributeDescription.valueOf("badger");
    given(attribute.getAttributeDescription()).willReturn(description);
    // When
    LdapTokenAttributeConversion.stripObjectClass(entry);
    // Then
    verify(entry).removeAttribute(description);
}
Also used : LinkedHashMapEntry(org.forgerock.opendj.ldap.LinkedHashMapEntry) Entry(org.forgerock.opendj.ldap.Entry) Attribute(org.forgerock.opendj.ldap.Attribute) AttributeDescription(org.forgerock.opendj.ldap.AttributeDescription) Test(org.testng.annotations.Test)

Example 5 with Entry

use of org.forgerock.opendj.ldap.Entry in project OpenAM by OpenRock.

the class LdapTokenAttributeConversionTest method shouldAddObjectClass.

@Test
public void shouldAddObjectClass() {
    // Given
    Entry entry = mock(Entry.class);
    given(entry.getAttribute(anyString())).willReturn(null);
    // When
    LdapTokenAttributeConversion.addObjectClass(entry);
    // Then
    verify(entry).addAttribute(anyString(), any());
}
Also used : LinkedHashMapEntry(org.forgerock.opendj.ldap.LinkedHashMapEntry) Entry(org.forgerock.opendj.ldap.Entry) Test(org.testng.annotations.Test)

Aggregations

Entry (org.forgerock.opendj.ldap.Entry)15 LinkedHashMapEntry (org.forgerock.opendj.ldap.LinkedHashMapEntry)12 Test (org.testng.annotations.Test)8 Token (org.forgerock.openam.cts.api.tokens.Token)4 Attribute (org.forgerock.opendj.ldap.Attribute)4 Connection (org.forgerock.opendj.ldap.Connection)4 LdapException (org.forgerock.opendj.ldap.LdapException)4 SearchResultEntry (org.forgerock.opendj.ldap.responses.SearchResultEntry)4 SearchRequest (org.forgerock.opendj.ldap.requests.SearchRequest)3 SMSDataEntry (com.sun.identity.sm.SMSDataEntry)2 SMSEntry (com.sun.identity.sm.SMSEntry)2 SMSException (com.sun.identity.sm.SMSException)2 Calendar (java.util.Calendar)2 LinkedList (java.util.LinkedList)2 ByteString (org.forgerock.opendj.ldap.ByteString)2 ResultCode (org.forgerock.opendj.ldap.ResultCode)2 ModifyRequest (org.forgerock.opendj.ldap.requests.ModifyRequest)2 CaseInsensitiveHashMap (com.sun.identity.common.CaseInsensitiveHashMap)1 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)1 FileInputStream (java.io.FileInputStream)1