use of org.forgerock.opendj.ldap.ResultCode in project OpenAM by OpenRock.
the class DirectoryServicesImpl method verifyAndGetOrgDN.
/**
* Gets the Organization DN for the specified entryDN. If the entry itself
* is an org, then same DN is returned.
*
* @param token
* a valid SSOToken
* @param entryDN
* the entry whose parent Organization is to be obtained
* @param childDN
* the immediate entry whose parent Organization is to be
* obtained
* @return the DN String of the parent Organization
* @throws AMException
* if an error occured while obtaining the parent Organization
*/
public String verifyAndGetOrgDN(SSOToken token, String entryDN, String childDN) throws AMException {
if (entryDN.isEmpty() || DN.valueOf(entryDN).size() <= 0) {
debug.error("DirectoryServicesImpl.verifyAndGetOrgDN() Invalid " + "DN: " + entryDN);
throw new AMException(token, "157");
}
String organizationDN = null;
boolean errorCondition = false;
try {
PersistentObject po = UMSObject.getObjectHandle(internalToken, new Guid(childDN));
String searchFilter = getOrgSearchFilter(entryDN);
SearchResults result = po.search(searchFilter, aName, scontrol);
if (result.hasMoreElements()) {
// ABANDON logged in directory server access logs.
while (result.hasMoreElements()) {
result.next();
}
organizationDN = po.getGuid().toString().toLowerCase();
}
} catch (InvalidSearchFilterException e) {
errorCondition = true;
debug.error("DirectoryServicesImpl.verifyAndGetOrgDN(): Invalid " + "search filter, unable to get Parent Organization: ", e);
} catch (UMSException ue) {
errorCondition = true;
if (debug.warningEnabled()) {
debug.warning("DirectoryServicesImpl.verifyAndGetOrgDN(): " + "Unable to Obtain Parent Organization", ue);
}
LdapException lex = (LdapException) ue.getRootCause();
ResultCode errorCode = lex.getResult().getResultCode();
if (retryErrorCodes.contains("" + errorCode)) {
throw new AMException(token, Integer.toString(errorCode.intValue()), ue);
}
}
if (errorCondition) {
String locale = CommonUtils.getUserLocale(token);
throw new AMException(AMSDKBundle.getString("124", locale), "124");
}
return organizationDN;
}
use of org.forgerock.opendj.ldap.ResultCode in project OpenAM by OpenRock.
the class DirectoryServicesImpl method search.
/**
* Searches the Directory
*
* @param token
* SSOToken
* @param entryDN
* DN of the entry to start the search with
* @param searchFilter
* search filter
* @param searchScope
* search scope, BASE, ONELEVEL or SUBTREE
* @return Set set of matching DNs
*/
public Set search(SSOToken token, String entryDN, String searchFilter, int searchScope) throws AMException {
Set resultSet = Collections.EMPTY_SET;
try {
PersistentObject po = UMSObject.getObjectHandle(token, new Guid(entryDN));
SearchControl control = new SearchControl();
control.setSearchScope(searchScope);
SearchResults results = po.search(searchFilter, control);
resultSet = searchResultsToSet(results);
} catch (UMSException ue) {
LdapException lex = (LdapException) ue.getRootCause();
ResultCode errorCode = lex.getResult().getResultCode();
if (retryErrorCodes.contains("" + errorCode)) {
throw new AMException(token, Integer.toString(errorCode.intValue()), ue);
}
if (debug.warningEnabled()) {
debug.warning("DirectoryServicesImpl.search(token:, entryDN: " + entryDN + ", searchFilter: " + searchFilter + "searchScope: " + searchScope + " error occurred: ", ue);
}
processInternalException(token, ue, "341");
}
return resultSet;
}
use of org.forgerock.opendj.ldap.ResultCode in project OpenAM by OpenRock.
the class Step4 method validateUMDomainName.
public boolean validateUMDomainName() {
setPath(null);
Context ctx = getContext();
String strSSL = (String) ctx.getSessionAttribute(SessionAttributeNames.USER_STORE_SSL);
boolean ssl = (strSSL != null) && (strSSL.equals("SSL"));
String domainName = (String) ctx.getSessionAttribute(SessionAttributeNames.USER_STORE_DOMAINNAME);
String rootSuffixAD = dnsDomainToDN(domainName);
getContext().setSessionAttribute(SessionAttributeNames.USER_STORE_ROOT_SUFFIX, rootSuffixAD);
String[] hostAndPort = { "" };
try {
hostAndPort = getLdapHostAndPort(domainName);
} catch (NamingException nex) {
writeToResponse(getLocalizedString("cannot.connect.to.UM.datastore"));
return false;
} catch (IOException ioex) {
writeToResponse(getLocalizedString("cannot.connect.to.UM.datastore"));
return false;
}
String host = hostAndPort[0];
int port = Integer.parseInt(hostAndPort[1]);
String bindDN = (String) ctx.getSessionAttribute(SessionAttributeNames.USER_STORE_LOGIN_ID);
String rootSuffix = (String) ctx.getSessionAttribute(SessionAttributeNames.USER_STORE_ROOT_SUFFIX);
String bindPwd = (String) ctx.getSessionAttribute(SessionAttributeNames.USER_STORE_LOGIN_PWD);
try (Connection conn = getConnection(host, port, bindDN, bindPwd.toCharArray(), 3, ssl)) {
//String filter = "cn=" + "\"" + rootSuffix + "\"";
String[] attrs = { "" };
conn.search(LDAPRequests.newSearchRequest(rootSuffix, SearchScope.BASE_OBJECT, ObjectClassFilter, attrs));
writeToResponse("ok");
} catch (LdapException lex) {
ResultCode resultCode = lex.getResult().getResultCode();
if (!writeErrorToResponse(resultCode)) {
writeToResponse(getLocalizedString("cannot.connect.to.UM.datastore"));
}
} catch (Exception e) {
writeToResponse(getLocalizedString("cannot.connect.to.UM.datastore"));
}
return false;
}
use of org.forgerock.opendj.ldap.ResultCode in project OpenAM by OpenRock.
the class Step4 method validateUMHost.
public boolean validateUMHost() {
Context ctx = getContext();
String strSSL = (String) ctx.getSessionAttribute(SessionAttributeNames.USER_STORE_SSL);
boolean ssl = (strSSL != null) && (strSSL.equals("SSL"));
String host = (String) ctx.getSessionAttribute(SessionAttributeNames.USER_STORE_HOST);
String strPort = (String) ctx.getSessionAttribute(SessionAttributeNames.USER_STORE_PORT);
int port = Integer.parseInt(strPort);
String bindDN = (String) ctx.getSessionAttribute(SessionAttributeNames.USER_STORE_LOGIN_ID);
String rootSuffix = (String) ctx.getSessionAttribute(SessionAttributeNames.USER_STORE_ROOT_SUFFIX);
String bindPwd = (String) ctx.getSessionAttribute(SessionAttributeNames.USER_STORE_LOGIN_PWD);
try (Connection conn = getConnection(host, port, bindDN, bindPwd.toCharArray(), 5, ssl)) {
//String filter = "cn=" + "\"" + rootSuffix + "\""; // NOT SURE Why "cn" is specified. would never work.
String[] attrs = { "" };
conn.search(LDAPRequests.newSearchRequest(rootSuffix, SearchScope.BASE_OBJECT, ObjectClassFilter, attrs));
writeToResponse("ok");
} catch (LdapException lex) {
ResultCode resultCode = lex.getResult().getResultCode();
if (!writeErrorToResponse(resultCode)) {
writeToResponse(getLocalizedString("cannot.connect.to.SM.datastore"));
}
} catch (Exception e) {
writeToResponse(getLocalizedString("cannot.connect.to.SM.datastore"));
}
setPath(null);
return false;
}
use of org.forgerock.opendj.ldap.ResultCode in project OpenAM by OpenRock.
the class LDAPRoles method getValidValues.
/**
* Returns a list of possible values for the <code>LDAPRoles
* </code> that satisfy the given <code>pattern</code>.
*
* @param token the <code>SSOToken</code> that will be used
* to determine the possible values
* @param pattern search pattern that will be used to narrow
* the list of valid names.
*
* @return <code>ValidValues</code> object
*
* @exception SSOException if <code>SSOToken></code> is not valid
* @exception PolicyException if unable to get the list of valid
* names.
*/
public ValidValues getValidValues(SSOToken token, String pattern) throws SSOException, PolicyException {
if (!initialized) {
throw (new PolicyException(ResBundleUtils.rbName, "ldaproles_subject_not_yet_initialized", null, null));
}
String searchFilter = null;
if ((pattern != null) && !(pattern.trim().length() == 0)) {
searchFilter = "(&" + roleSearchFilter + "(" + roleRDNAttrName + "=" + pattern + "))";
} else {
searchFilter = roleSearchFilter;
}
if (debug.messageEnabled()) {
debug.message("LDAPRoles.getValidValues(): role search filter is: " + searchFilter);
}
String[] attrs = { roleRDNAttrName };
Set<String> validRoleDNs = new HashSet<>();
int status = ValidValues.SUCCESS;
try (Connection conn = connPool.getConnection()) {
SearchRequest searchRequest = LDAPRequests.newSearchRequest(baseDN, roleSearchScope, searchFilter, attrs);
ConnectionEntryReader reader = conn.search(searchRequest);
while (reader.hasNext()) {
if (reader.isReference()) {
//Ignore
reader.readReference();
} else {
SearchResultEntry entry = reader.readEntry();
if (entry != null) {
validRoleDNs.add(entry.getName().toString());
debug.message("LDAPRoles.getValidValues(): found role name={}", entry.getName().toString());
}
}
}
} catch (LdapException le) {
ResultCode resultCode = le.getResult().getResultCode();
if (ResultCode.SIZE_LIMIT_EXCEEDED.equals(resultCode)) {
debug.warning("LDAPRoles.getValidValues(): exceeded the size limit");
return new ValidValues(ValidValues.SIZE_LIMIT_EXCEEDED, validRoleDNs);
} else if (ResultCode.TIME_LIMIT_EXCEEDED.equals(resultCode)) {
debug.warning("LDAPRoles.getValidValues(): exceeded the time limit");
return new ValidValues(ValidValues.TIME_LIMIT_EXCEEDED, validRoleDNs);
} else if (ResultCode.INVALID_CREDENTIALS.equals(resultCode)) {
throw new PolicyException(ResBundleUtils.rbName, "ldap_invalid_password", null, null);
} else if (ResultCode.NO_SUCH_OBJECT.equals(resultCode)) {
String[] objs = { baseDN };
throw new PolicyException(ResBundleUtils.rbName, "no_such_ldap_base_dn", objs, null);
}
String errorMsg = le.getMessage();
String additionalMsg = le.getResult().getDiagnosticMessage();
if (additionalMsg != null) {
throw new PolicyException(errorMsg + ": " + additionalMsg);
} else {
throw new PolicyException(errorMsg);
}
} catch (Exception e) {
throw new PolicyException(e);
}
return new ValidValues(status, validRoleDNs);
}
Aggregations