Search in sources :

Example 46 with LdapException

use of org.forgerock.opendj.ldap.LdapException in project admin-console-beta by connexta.

the class LdapUserAttributes method performFunction.

@Override
public ListField<StringField> performFunction() {
    LdapConnectionAttempt ldapConnectionAttempt = utils.bindUserToLdapConnection(config.connectionField(), config.bindUserInfoField());
    addArgumentMessages(ldapConnectionAttempt.messages());
    if (!ldapConnectionAttempt.connection().isPresent()) {
        // TODO: tbatie - 4/3/17 - Make a toString for LDAPConfig
        LOGGER.warn("Error binding to LDAP server with config: {}", config.toString());
        return null;
    }
    Set<String> ldapEntryAttributes = null;
    try {
        ServerGuesser serverGuesser = ServerGuesser.buildGuesser(ldapType.getValue(), ldapConnectionAttempt.connection().get());
        ldapEntryAttributes = serverGuesser.getClaimAttributeOptions(config.settingsField().baseUserDn());
    } catch (SearchResultReferenceIOException | LdapException e) {
        // TODO: tbatie - 4/3/17 - Make a toString for LDAPConfig
        LOGGER.warn("Error retrieving attributes from LDAP server; this may indicate a " + "configuration issue with config: ", config.toString());
    }
    // TODO: tbatie - 4/3/17 - Make a set field instead
    ListFieldImpl entries = new ListFieldImpl<>(StringField.class);
    entries.setValue(Arrays.asList(ldapEntryAttributes.toArray()));
    return entries;
}
Also used : ListFieldImpl(org.codice.ddf.admin.common.fields.base.ListFieldImpl) SearchResultReferenceIOException(org.forgerock.opendj.ldap.SearchResultReferenceIOException) LdapException(org.forgerock.opendj.ldap.LdapException) LdapConnectionAttempt(org.codice.ddf.admin.ldap.commons.LdapConnectionAttempt) ServerGuesser(org.codice.ddf.admin.ldap.commons.ServerGuesser)

Example 47 with LdapException

use of org.forgerock.opendj.ldap.LdapException 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));
}
Also used : Connection(org.forgerock.opendj.ldap.Connection) BindResult(org.forgerock.opendj.ldap.responses.BindResult) LDAPConnectionFactory(org.forgerock.opendj.ldap.LDAPConnectionFactory) Matchers.anyString(org.mockito.Matchers.anyString) LdapException(org.forgerock.opendj.ldap.LdapException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 48 with LdapException

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

the class AMSetupDSConfig method isDITLoaded.

/**
     * Check if DS is loaded with OpenAM entries
     *
     * @param ssl <code>true</code> of directory server is running on LDAPS.
     * @return <code>true</code> if Service Schema is loaded into
     *         Directory Server.
     */
String isDITLoaded(boolean ssl) {
    String baseDN = "ou=services," + suffix;
    String filter = "(|(ou=DAI)(ou=sunIdentityRepositoryService))";
    try (Connection conn = getLDAPConnection(ssl)) {
        ConnectionEntryReader results = conn.search(LDAPRequests.newSearchRequest(baseDN, SearchScope.WHOLE_SUBTREE, filter, "dn"));
        return Boolean.toString(results.hasNext());
    } catch (LdapException e) {
        if (Debug.getInstance(SetupConstants.DEBUG_NAME).messageEnabled()) {
            Debug.getInstance(SetupConstants.DEBUG_NAME).message("AMSetupDSConfig.isDITLoaded: LDAP Operation return code: " + e.getResult().getResultCode());
        }
        return "false";
    }
}
Also used : ConnectionEntryReader(org.forgerock.opendj.ldif.ConnectionEntryReader) Connection(org.forgerock.opendj.ldap.Connection) LdapException(org.forgerock.opendj.ldap.LdapException)

Example 49 with LdapException

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

the class SMSLdapObject method modify.

/**
     * Save the entry using the token provided. The principal provided will be
     * used to get the proxy connection.
     */
public void modify(SSOToken token, String dn, ModificationItem[] mods) throws SMSException, SSOException {
    int retry = 0;
    ModifyRequest request = copyModItemsToModifyRequest(DN.valueOf(dn), mods);
    while (retry <= connNumRetry) {
        debug.message("SMSLdapObject.modify() retry: {}", retry);
        try (Connection conn = getConnection(token.getPrincipal())) {
            conn.modify(request);
            debug.message("SMSLdapObject.modify(): Successfully modified entry: {}", dn);
            break;
        } catch (LdapException e) {
            ResultCode errorCode = e.getResult().getResultCode();
            if (!retryErrorCodes.contains(errorCode) || retry == connNumRetry) {
                debug.error("SMSLdapObject.modify(): Error modifying: {} By Principal {}", dn, token.getPrincipal().getName(), e);
                throw new SMSException(e, "sms-entry-cannot-modify");
            }
            retry++;
            try {
                Thread.sleep(connRetryInterval);
            } catch (InterruptedException ex) {
            // ignored
            }
        }
    }
}
Also used : SMSException(com.sun.identity.sm.SMSException) Connection(org.forgerock.opendj.ldap.Connection) ModifyRequest(org.forgerock.opendj.ldap.requests.ModifyRequest) LdapException(org.forgerock.opendj.ldap.LdapException) ResultCode(org.forgerock.opendj.ldap.ResultCode)

Example 50 with LdapException

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

the class SMSLdapObject method getSubEntries.

private Set<String> getSubEntries(SSOToken token, String dn, String filter, int numOfEntries, boolean sortResults, boolean ascendingOrder) throws SMSException, SSOException {
    SearchRequest request = getSearchRequest(dn, filter, SearchScope.SINGLE_LEVEL, numOfEntries, 0, sortResults, ascendingOrder, getNamingAttribute(), O_ATTR);
    int retry = 0;
    Set<String> answer = new LinkedHashSet<>();
    ConnectionEntryReader results;
    while (retry <= connNumRetry) {
        debug.message("SMSLdapObject.subEntries() retry: {}", retry);
        try (Connection conn = getConnection(token.getPrincipal())) {
            // Get the sub entries
            ConnectionEntryReader iterResults = conn.search(request);
            iterResults.hasNext();
            results = iterResults;
            // Construct the results and return
            try {
                while (results != null && results.hasNext()) {
                    try {
                        if (results.isReference()) {
                            debug.warning("Skipping reference result: {}", results.readReference());
                            continue;
                        }
                        SearchResultEntry entry = results.readEntry();
                        // Workaround for 3823, where (objectClass=*) is used
                        if (entry.getName().toString().toLowerCase().startsWith("ou=")) {
                            answer.add(entry.getName().rdn().getFirstAVA().getAttributeValue().toString());
                        }
                    } catch (SearchResultReferenceIOException e) {
                        debug.error("SMSLdapObject.subEntries: Reference should be handled already for dn {}", dn, e);
                    }
                }
            } catch (LdapException e) {
                debug.warning("SMSLdapObject.subEntries: Error in obtaining sub-entries: {}", dn, e);
                throw new SMSException(e, "sms-entry-cannot-obtain");
            }
            break;
        } catch (LdapException e) {
            ResultCode errorCode = e.getResult().getResultCode();
            if (errorCode.equals(ResultCode.NO_SUCH_OBJECT)) {
                debug.message("SMSLdapObject.subEntries(): entry not present: {}", dn);
                break;
            }
            if (!retryErrorCodes.contains(errorCode) || retry >= connNumRetry) {
                debug.warning("SMSLdapObject.subEntries: Unable to search for sub-entries: {}", dn, e);
                throw new SMSException(e, "sms-entry-cannot-search");
            }
            retry++;
            try {
                Thread.sleep(connRetryInterval);
            } catch (InterruptedException ex) {
            // ignored
            }
        }
    }
    debug.message("SMSLdapObject.subEntries: Successfully obtained sub-entries for {}", dn);
    return answer;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SearchRequest(org.forgerock.opendj.ldap.requests.SearchRequest) SMSException(com.sun.identity.sm.SMSException) Connection(org.forgerock.opendj.ldap.Connection) SearchResultReferenceIOException(org.forgerock.opendj.ldap.SearchResultReferenceIOException) ConnectionEntryReader(org.forgerock.opendj.ldif.ConnectionEntryReader) LdapException(org.forgerock.opendj.ldap.LdapException) ResultCode(org.forgerock.opendj.ldap.ResultCode) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry)

Aggregations

LdapException (org.forgerock.opendj.ldap.LdapException)88 Connection (org.forgerock.opendj.ldap.Connection)62 ByteString (org.forgerock.opendj.ldap.ByteString)41 ResultCode (org.forgerock.opendj.ldap.ResultCode)37 SearchResultEntry (org.forgerock.opendj.ldap.responses.SearchResultEntry)35 ConnectionEntryReader (org.forgerock.opendj.ldif.ConnectionEntryReader)34 SearchRequest (org.forgerock.opendj.ldap.requests.SearchRequest)23 HashSet (java.util.HashSet)22 SearchResultReferenceIOException (org.forgerock.opendj.ldap.SearchResultReferenceIOException)22 Attribute (org.forgerock.opendj.ldap.Attribute)17 PolicyException (com.sun.identity.policy.PolicyException)13 SMSException (com.sun.identity.sm.SMSException)12 ModifyRequest (org.forgerock.opendj.ldap.requests.ModifyRequest)12 SSOException (com.iplanet.sso.SSOException)11 LinkedHashSet (java.util.LinkedHashSet)11 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)10 IOException (java.io.IOException)10 DN (org.forgerock.opendj.ldap.DN)10 InvalidNameException (com.sun.identity.policy.InvalidNameException)9 NameNotFoundException (com.sun.identity.policy.NameNotFoundException)9