use of com.iplanet.am.sdk.common.CacheBlock in project OpenAM by OpenRock.
the class CachedDirectoryServicesImpl method setOrganizationDNs.
private void setOrganizationDNs(String organizationDN, Set childDNSet) {
Iterator itr = childDNSet.iterator();
while (itr.hasNext()) {
String cDN = (String) itr.next();
CacheBlock cb = (CacheBlock) sdkCache.get(cDN);
if (cb == null) {
cb = new CacheBlock(cDN, organizationDN, true);
sdkCache.put(cDN, cb);
} else {
cb.setOrganizationDN(organizationDN);
}
}
if (debug.messageEnabled() && !childDNSet.isEmpty()) {
debug.message("CachedDirectoryServicesImpl.setOrganizationDNs(): " + "Set org DNs as: " + organizationDN + " for children: " + childDNSet);
}
}
use of com.iplanet.am.sdk.common.CacheBlock in project OpenAM by OpenRock.
the class CachedDirectoryServicesImpl method getOrganizationDN.
/**
* Gets the Organization DN for the specified entryDN. If the entry itself
* is an org, then same DN is returned.
* <p>
* <b>NOTE:</b> This method will involve serveral directory searches, hence
* be cautious of Performance hit.
*
* <p>
* This method does not call its base classes method unlike the rest of the
* overriden methods to obtain the organization DN, as it requires special
* processing requirements.
*
* @param token
* a valid SSOToken
* @param entryDN
* the 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 getOrganizationDN(SSOToken token, String entryDN) throws AMException {
if (!LDAPUtils.isDN(entryDN)) {
debug.error("CachedDirectoryServicesImpl.getOrganizationDN() " + "Invalid DN: " + entryDN);
throw new AMException(token, "157");
}
String organizationDN = "";
Set childDNSet = new HashSet();
boolean errorCondition = false;
boolean found = false;
while (!errorCondition && !found) {
DN dnObject = DN.valueOf(entryDN);
boolean lookupDirectory = true;
String childDN = dnObject.toString().toLowerCase();
if (debug.messageEnabled()) {
debug.message("CachedDirectoryServicesImpl." + "getOrganizationDN() - looping Organization DN for" + " entry: " + childDN);
}
CacheBlock cb = (CacheBlock) sdkCache.get(childDN);
if (cb != null) {
organizationDN = cb.getOrganizationDN();
if (organizationDN != null) {
if (debug.messageEnabled()) {
debug.message("CachedDirectoryServicesImpl." + "getOrganizationDN(): found OrganizationDN: " + organizationDN + " for: " + childDN);
}
found = true;
setOrganizationDNs(organizationDN, childDNSet);
continue;
} else if (cb.getObjectType() == AMObject.ORGANIZATION || cb.getObjectType() == AMObject.ORGANIZATIONAL_UNIT) {
// Object type is organization
organizationDN = childDN;
found = true;
childDNSet.add(childDN);
setOrganizationDNs(organizationDN, childDNSet);
continue;
} else if (cb.getObjectType() != AMObject.UNDETERMINED_OBJECT_TYPE) {
// Don't lookup directory if the object type is unknown
lookupDirectory = false;
}
}
childDNSet.add(childDN);
if (lookupDirectory) {
organizationDN = super.verifyAndGetOrgDN(token, entryDN, childDN);
}
if (organizationDN != null && organizationDN.length() > 0) {
found = true;
setOrganizationDNs(organizationDN, childDNSet);
} else if (dnObject.size() == 1) {
// Reached topmost level
errorCondition = true;
debug.error("CachedDirectoryServicesImpl.getOrgnizationDN(): " + "Reached root suffix. Unable to get parent Org");
} else {
// Climb tree on level up
dnObject = dnObject.parent();
}
}
return organizationDN;
}
use of com.iplanet.am.sdk.common.CacheBlock in project OpenAM by OpenRock.
the class CachedDirectoryServicesImpl method createAMTemplate.
/**
* Create an AMTemplate (COSTemplate)
*
* @param token
* token
* @param entryDN
* DN of the profile whose template is to be set
* @param objectType
* Template type, AMTemplate.DYNAMIC_TEMPLATE
* @param serviceName
* Service Name
* @param attributes
* attributes to be set
* @param priority
* template priority
* @return String DN of the newly created template
*/
public String createAMTemplate(SSOToken token, String entryDN, int objectType, String serviceName, Map attributes, int priority) throws AMException {
String templateDN = super.createAMTemplate(token, entryDN, objectType, serviceName, attributes, priority);
// Mark the entry as exists in cache
String dn = LDAPUtils.formatToRFC(templateDN);
CacheBlock cb = (CacheBlock) sdkCache.get(dn);
if (cb != null) {
cb.setExists(true);
}
return templateDN;
}
use of com.iplanet.am.sdk.common.CacheBlock in project OpenAM by OpenRock.
the class CachedDirectoryServicesImpl method renameEntry.
/**
* Renames an entry. Currently used for only user renaming.
*
* @param token
* the sso token
* @param objectType
* the type of entry
* @param entryDN
* the entry DN
* @param newName
* the new name (i.e., if RDN is cn=John, the value passed should
* be "John"
* @param deleteOldName
* if true the old name is deleted otherwise it is retained.
* @return new <code>DN</code> of the renamed entry
* @throws AMException
* if the operation was not successful
*/
public String renameEntry(SSOToken token, int objectType, String entryDN, String newName, boolean deleteOldName) throws AMException {
String newDN = super.renameEntry(token, objectType, entryDN, newName, deleteOldName);
// Just rename the dn in the cache. Don't remove the entry. So when the
// event notification happens, it won't find the entry as it is already
// renamed. Chances are this cache rename operation may happen before
// the notification thread trys clean up.
// NOTE: We should have the code to remove the entry for rename
// operation as the operation could have been performed by some other
// process such as amadmin.
String oldDN = LDAPUtils.formatToRFC(entryDN);
CacheBlock cb = (CacheBlock) sdkCache.remove(oldDN);
newDN = LDAPUtils.formatToRFC(newDN);
sdkCache.put(newDN, cb);
return newDN;
}
use of com.iplanet.am.sdk.common.CacheBlock in project OpenAM by OpenRock.
the class CachedDirectoryServicesImpl method toString.
/**
* Prints the contents of the cache. For debug purpose only
*/
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("\n<<<<<<< BEGIN SDK CACHE CONTENTS >>>>>>>>");
if (!sdkCache.isEmpty()) {
// Should never be null
Enumeration cacheKeys = sdkCache.keys();
while (cacheKeys.hasMoreElements()) {
String key = (String) cacheKeys.nextElement();
CacheBlock cb = (CacheBlock) sdkCache.get(key);
sb.append("\nSDK Cache Block: ").append(key);
sb.append(cb.toString());
}
} else {
sb.append("<empty>");
}
sb.append("\n<<<<<<< END SDK CACHE CONTENTS >>>>>>>>");
return sb.toString();
}
Aggregations