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;
}
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));
}
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";
}
}
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
}
}
}
}
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;
}
Aggregations