use of org.forgerock.opendj.ldap.LdapException in project OpenAM by OpenRock.
the class ServiceBase method connectDSwithDN.
/**
* Check if Directory Server has the suffix.
*
* @return <code>true</code> if specified suffix exists.
*/
protected static boolean connectDSwithDN(Connection ld, String suffix) {
String filter = "cn=" + suffix;
String[] attrs = { "" };
try (ConnectionEntryReader reader = ld.search(LDAPRequests.newSearchRequest(suffix, SearchScope.BASE_OBJECT, filter, attrs))) {
return reader.hasNext();
} catch (LdapException e) {
return false;
}
}
use of org.forgerock.opendj.ldap.LdapException in project OpenAM by OpenRock.
the class UpgradeUtils method delete.
/**
* Delete an entry, recursing if the entry has children
*
* @param dn DN of the entry to delete
* @param ld active connection to server
* @param doDelete true if the entries really
* are to be deleted
*/
public static void delete(String dn, Connection ld, boolean doDelete) {
String theDN = "";
try {
// Find all immediate child nodes; return no
// attributes
ConnectionEntryReader res = ld.search(LDAPRequests.newSearchRequest(dn, SearchScope.SINGLE_LEVEL, "objectclass=*"));
while (res.hasNext()) {
if (res.isReference()) {
//ignore
res.readReference();
} else {
// Next directory entry
SearchResultEntry entry = res.readEntry();
theDN = entry.getName().toString();
// Recurse down
delete(theDN, ld, doDelete);
}
}
// so stop recursing and delete the node
try {
if (doDelete) {
ld.delete(LDAPRequests.newDeleteRequest(dn));
if (debug.messageEnabled()) {
debug.message(dn + " deleted");
}
}
} catch (LdapException e) {
if (debug.messageEnabled()) {
debug.message(e.toString());
}
} catch (Exception e) {
if (debug.messageEnabled()) {
debug.message(e.toString());
}
}
} catch (Exception me) {
// do nothing
}
}
use of org.forgerock.opendj.ldap.LdapException 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.LdapException 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.LdapException 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;
}
Aggregations