use of org.forgerock.opendj.ldap.ResultCode in project OpenAM by OpenRock.
the class SMSEmbeddedLdapObject method internalCreate.
/**
* Create an entry in the directory using the principal name
*/
private void internalCreate(SSOToken token, String dn, Map attrs) throws SMSException, SSOException {
SMSAuditor auditor = newAuditor(token, dn, null);
List attrList = copyMapToAttrList(attrs);
AddOperation ao = icConn.processAdd(dn, attrList);
ResultCode resultCode = ao.getResultCode();
if (resultCode == ResultCode.SUCCESS) {
if (debug.messageEnabled()) {
debug.message("SMSEmbeddedLdapObject.create: Successfully created" + " entry: " + dn);
}
if (auditor != null) {
auditor.auditCreate(attrs);
}
} else if (resultCode == ResultCode.ENTRY_ALREADY_EXISTS) {
// During install time and other times,
// this error gets throws due to unknown issue. Issue:
// Hence mask it.
debug.warning("SMSEmbeddedLdapObject.create: Entry " + "Already Exists Error for DN" + dn);
} else {
debug.error("SMSEmbeddedLdapObject.create: Error creating entry: " + dn + ", error code = " + resultCode);
throw new SMSException("", "sms-entry-cannot-create");
}
}
use of org.forgerock.opendj.ldap.ResultCode in project OpenAM by OpenRock.
the class SearchResultIterator method hasNext.
public boolean hasNext() {
try {
if (results.hasNext()) {
if (current == null) {
if (results.isReference()) {
debug.warning("SearchResultIterator: ignoring reference: {}", results.readReference());
return hasNext();
}
SearchResultEntry entry = results.readEntry();
String dn = entry.getName().toString();
if (hasExcludeDNs && excludeDNs.contains(dn)) {
return hasNext();
}
current = new SMSDataEntry(dn, SMSUtils.convertEntryToAttributesMap(entry));
}
return true;
}
} catch (LdapException e) {
ResultCode errorCode = e.getResult().getResultCode();
if (errorCode.equals(ResultCode.SIZE_LIMIT_EXCEEDED)) {
debug.message("SearchResultIterator: size limit exceeded");
} else {
debug.error("SearchResultIterator.hasNext", e);
}
} catch (SearchResultReferenceIOException e) {
debug.error("SearchResultIterator.hasNext: reference should be already handled", e);
return hasNext();
}
conn.close();
return false;
}
use of org.forgerock.opendj.ldap.ResultCode in project OpenAM by OpenRock.
the class LDAPUsers method handleResultException.
private PolicyException handleResultException(LdapException e) {
ResultCode ldapErrorCode = e.getResult().getResultCode();
if (ldapErrorCode.equals(ResultCode.INVALID_CREDENTIALS)) {
return new PolicyException(ResBundleUtils.rbName, "ldap_invalid_password", null, null);
} else if (ldapErrorCode.equals(ResultCode.NO_SUCH_OBJECT)) {
String[] objs = { baseDN };
return new PolicyException(ResBundleUtils.rbName, "no_such_ldap_users_base_dn", objs, null);
}
String errorMsg = e.getResult().getDiagnosticMessage();
String additionalMsg = e.getMessage();
if (additionalMsg != null) {
return new PolicyException(errorMsg + ": " + additionalMsg);
} else {
return new PolicyException(errorMsg);
}
}
use of org.forgerock.opendj.ldap.ResultCode in project OpenAM by OpenRock.
the class LDAPUsers method getUserDN.
/**
* Gets the DN for a user identified
* by the token. If the Directory server is locally installed to speed
* up the search, no directoty search is performed and the DN obtained
* from the token is returned. If the directory is remote
* a LDAP search is performed to get the user DN.
*/
private DN getUserDN(SSOToken token) throws SSOException, PolicyException {
Set<String> qualifiedUserDNs = new HashSet<>();
String userLocalDN = token.getPrincipal().getName();
DN userDN = null;
if (localDS && !PolicyUtils.principalNameEqualsUuid(token)) {
userDN = DN.valueOf(userLocalDN);
} else {
// try to figure out the user name from the local user DN
int beginIndex = userLocalDN.indexOf("=");
int endIndex = userLocalDN.indexOf(",");
if ((beginIndex <= 0) || (endIndex <= 0) || (beginIndex >= endIndex)) {
throw (new PolicyException(ResBundleUtils.rbName, "ldapusers_subject_invalid_local_user_dn", null, null));
}
String userName = userLocalDN.substring(beginIndex + 1, endIndex);
String searchFilter = null;
if ((userSearchFilter != null) && !(userSearchFilter.length() == 0)) {
searchFilter = "(&" + userSearchFilter + PolicyUtils.constructUserFilter(token, userRDNAttrName, userName, aliasEnabled) + ")";
} else {
searchFilter = PolicyUtils.constructUserFilter(token, userRDNAttrName, userName, aliasEnabled);
}
if (debug.messageEnabled()) {
debug.message("LDAPUsers.getUserDN(): search filter is: " + searchFilter);
}
String[] attrs = { userRDNAttrName };
// search the remote ldap and find out the user DN
try (Connection ld = connPool.getConnection()) {
ConnectionEntryReader res = search(searchFilter, ld, attrs);
while (res.hasNext()) {
try {
SearchResultEntry entry = res.readEntry();
qualifiedUserDNs.add(entry.getName().toString());
} catch (SearchResultReferenceIOException e) {
// ignore referrals
continue;
} catch (LdapException e) {
String[] objs = { orgName };
ResultCode resultCode = e.getResult().getResultCode();
if (resultCode.equals(ResultCode.SIZE_LIMIT_EXCEEDED)) {
debug.warning("LDAPUsers.getUserDN(): exceeded the size limit");
throw new PolicyException(ResBundleUtils.rbName, "ldap_search_exceed_size_limit", objs, null);
} else if (resultCode.equals(ResultCode.TIME_LIMIT_EXCEEDED)) {
debug.warning("LDAPUsers.getUserDN(): exceeded the time limit");
throw new PolicyException(ResBundleUtils.rbName, "ldap_search_exceed_time_limit", objs, null);
} else {
throw new PolicyException(e);
}
}
}
} catch (LdapException e) {
throw handleResultException(e);
} catch (Exception e) {
throw new PolicyException(e);
}
// check if the user belongs to any of the selected users
if (qualifiedUserDNs.size() > 0) {
debug.message("LDAPUsers.getUserDN(): qualified users={}", qualifiedUserDNs);
Iterator<String> iter = qualifiedUserDNs.iterator();
// we only take the first qualified DN
userDN = DN.valueOf(iter.next());
}
}
return userDN;
}
use of org.forgerock.opendj.ldap.ResultCode in project OpenAM by OpenRock.
the class LDAPUsers method getValidEntries.
/**
* Returns a set of possible values that satisfy the <code>pattern</code>.
* The returned <code>ValidValues</code> object contains a set of
* map of user DN to a map of user's attribute name to a string array of
* attribute values.
*
* @param token Single Sign On token for fetching the possible values.
* @param pattern Search pattern of which possible values are matched to.
* @param attributeNames Array of attribute names to be to returned.
* @return a set of possible values that satify the <code>pattern</code>.
* @throws SSOException if <code>SSOToken</code> is invalid.
* @throws PolicyException if there are problems getting these values.
*/
public ValidValues getValidEntries(SSOToken token, String pattern, String[] attributeNames) throws SSOException, PolicyException {
if (!initialized) {
throw (new PolicyException(ResBundleUtils.rbName, "ldapusers_subject_not_yet_initialized", null, null));
}
Set<Map<String, Map<String, String[]>>> results = new HashSet<>();
String searchFilter = getSearchFilter(pattern);
int status = ValidValues.SUCCESS;
try (Connection ld = connPool.getConnection()) {
ConnectionEntryReader res = search(searchFilter, ld, attributeNames);
Map<String, Map<String, String[]>> map = new HashMap<>();
results.add(map);
while (res.hasNext()) {
try {
SearchResultEntry entry = res.readEntry();
if (entry != null) {
String userDN = entry.getName().toString();
map.put(userDN, getUserAttributeValues(entry, attributeNames));
}
} catch (SearchResultReferenceIOException lre) {
// ignore referrals
continue;
} catch (LdapException e) {
ResultCode resultCode = e.getResult().getResultCode();
if (resultCode.equals(ResultCode.SIZE_LIMIT_EXCEEDED)) {
debug.warning("LDAPUsers.getValidEntries(): exceeded the size limit");
status = ValidValues.SIZE_LIMIT_EXCEEDED;
} else if (resultCode.equals(ResultCode.TIME_LIMIT_EXCEEDED)) {
debug.warning("LDAPUsers.getValidEntries(): exceeded the time limit");
status = ValidValues.TIME_LIMIT_EXCEEDED;
} else {
throw new PolicyException(e);
}
}
}
} catch (LdapException e) {
throw handleResultException(e);
} catch (Exception e) {
throw new PolicyException(e);
}
return new ValidValues(status, results);
}
Aggregations