use of com.iplanet.am.sdk.AMHashMap in project OpenAM by OpenRock.
the class CachedDirectoryServicesImpl method getAttributes.
/**
* Gets the specific attributes corresponding to the entryDN. This method
* obtains the DC Tree node attributes and also performs compliance related
* verification checks in compliance mode. Note: In compliance mode you can
* skip the compliance checks by setting ignoreCompliance to "false".
*
* @param token
* a valid SSOToken
* @param entryDN
* the DN of the entry whose attributes need to retrieved
* @param attrNames
* a Set of names of the attributes that need to be retrieved.
* The attrNames should not be null
* @param ignoreCompliance
* a boolean value specificying if compliance related entries
* need to ignored or not. Ignored if true.
* @return a Map containing attribute names as keys and Set of values
* corresponding to each key.
* @throws AMException
* if an error is encountered in fetching the attributes
*/
public Map getAttributes(SSOToken token, String entryDN, Set attrNames, boolean ignoreCompliance, boolean byteValues, int profileType) throws AMException, SSOException {
if (attrNames == null || attrNames.isEmpty()) {
return getAttributes(token, entryDN, ignoreCompliance, byteValues, profileType);
}
// Attributes are being requested; increment cache stats request counter
cacheStats.incrementRequestCount(getSize());
// Not good for performance, but fix later TODO (Deepa)
if (dcTreeImpl.isRequired()) {
// TODO: This needs to be fixed!
getAttributes(token, entryDN, ignoreCompliance, byteValues, profileType);
}
String principalDN = CommonUtils.getPrincipalDN(token);
if (debug.messageEnabled()) {
debug.message("In CachedDirectoryServicesImpl.getAttributes(" + "SSOToken entryDN, attrNames, ignoreCompliance, " + "byteValues) " + "(" + principalDN + ", " + entryDN + ", " + attrNames + ", " + ignoreCompliance + ", " + byteValues + " method.");
}
String dn = LDAPUtils.formatToRFC(entryDN);
CacheBlock cb = (CacheBlock) sdkCache.get(dn);
if (cb == null) {
// Entry not present in cache
if (debug.messageEnabled()) {
debug.message("CachedDirectoryServicesImpl.getAttributes(): " + "NO entry found in Cache. Getting all these " + "attributes from DS: " + attrNames);
}
// If the attributes returned here have an empty set as value, then
// such attributes do not have a value or invalid attributes.
// Internally keep track of these attributes.
AMHashMap attributes = (AMHashMap) super.getAttributes(token, entryDN, attrNames, ignoreCompliance, byteValues, profileType);
// These attributes are either not present or not found in DS.
// Try to check if they need to be fetched by external
// plugins
cb = new CacheBlock(dn, true);
Set missAttrNames = attributes.getMissingAndEmptyKeys(attrNames);
cb.putAttributes(principalDN, attributes, missAttrNames, false, byteValues);
sdkCache.put(dn, cb);
if (!missAttrNames.isEmpty()) {
attributes = getPluginAttrsAndUpdateCache(token, principalDN, entryDN, cb, attributes, missAttrNames, byteValues, profileType);
}
return attributes;
} else {
// Entry present in cache
// Entry may be an invalid entry
validateEntry(token, cb);
AMHashMap attributes = (AMHashMap) cb.getAttributes(principalDN, attrNames, byteValues);
// Find the missing attributes that need to be obtained from DS
// Only find the missing keys as the ones with empty sets are not
// found in DS
Set missAttrNames = attributes.getMissingKeys(attrNames);
if (!missAttrNames.isEmpty()) {
boolean isComplete = cb.hasCompleteSet(principalDN);
AMHashMap dsAttributes = null;
if (!isComplete || // Check for "nsRole" and "nsRoleDN" attributes
missAttrNames.contains(NSROLEDN_ATTR) || missAttrNames.contains(NSROLE_ATTR)) {
if (debug.messageEnabled()) {
debug.message("CachedDirectoryServicesImpl." + "getAttributes(): Trying to get these missing" + " attributes from DS: " + missAttrNames);
}
dsAttributes = (AMHashMap) super.getAttributes(token, entryDN, missAttrNames, ignoreCompliance, byteValues, profileType);
if (dsAttributes != null) {
attributes.putAll(dsAttributes);
// Add these attributes, may be found in DS or just mark
// as invalid (Attribute level Negative caching)
Set newMissAttrNames = dsAttributes.getMissingAndEmptyKeys(missAttrNames);
// Update dsAttributes with rest of the attributes
// in cache
dsAttributes.putAll(cb.getAttributes(principalDN, byteValues));
// Update the cache
cb.putAttributes(principalDN, dsAttributes, newMissAttrNames, isComplete, byteValues);
missAttrNames = newMissAttrNames;
}
} else {
// Update cache with invalid attributes
cb.putAttributes(principalDN, cb.getAttributes(principalDN, byteValues), missAttrNames, isComplete, byteValues);
}
if (!missAttrNames.isEmpty()) {
attributes = getPluginAttrsAndUpdateCache(token, principalDN, entryDN, cb, attributes, missAttrNames, byteValues, profileType);
}
} else {
// All attributes found in cache
if (debug.messageEnabled()) {
debug.message("CachedDirectoryServicesImpl." + "getAttributes(): found all attributes in " + "Cache.");
}
cacheStats.updateHitCount(getSize());
}
// Remove all the empty values from the return attributes
return attributes;
}
}
use of com.iplanet.am.sdk.AMHashMap in project OpenAM by OpenRock.
the class CommonUtils method attrSetToMap.
/**
* Method to convert a AttrSet object to Map.
*
* @param attrSet
* the AttrSet to be converted to a Map
* @param fetchByteValues
* if false stringValues are added, if true byteValues are added.
* @return a Map containing attribute names as key's and a Set of attribute
* values or byte Values
*/
protected static Map attrSetToMap(AttrSet attrSet, boolean fetchByteValues) {
Map attributesMap = new AMHashMap(fetchByteValues);
if (attrSet == null) {
return attributesMap;
}
int attrSetSize = attrSet.size();
if (!fetchByteValues) {
for (int i = 0; i < attrSetSize; i++) {
Attr attr = attrSet.elementAt(i);
String[] values = attr.getStringValues();
attributesMap.put(attr.getName(), stringArrayToSet(values));
}
} else {
for (int i = 0; i < attrSetSize; i++) {
Attr attr = attrSet.elementAt(i);
attributesMap.put(attr.getName(), attr.getByteValues());
}
}
return attributesMap;
}
use of com.iplanet.am.sdk.AMHashMap in project OpenAM by OpenRock.
the class RemoteServicesImpl method getAttributes.
public Map getAttributes(SSOToken token, String entryDN, Set attrNames, int profileType) throws AMException, SSOException {
try {
String tokenID = token.getTokenID().toString();
Object[] objs = { tokenID, entryDN, attrNames, new Integer(profileType) };
Map map = (Map) client.send(client.encodeMessage("getAttributes2", objs), sessionCookies.getLBCookie(tokenID), null);
AMHashMap res = new AMHashMap();
res.copy(map);
return res;
} catch (AMRemoteException amrex) {
if (getDebug().messageEnabled()) {
getDebug().message("RemoteServicesImpl.getAttributes 2: entryDN=" + entryDN + "; AMRemoteException caught exception=", amrex);
}
throw convertException(amrex);
} catch (RemoteException rex) {
getDebug().error("RemoteServicesImpl.getAttributes: caught exception=", rex);
throw new AMException(AMSDKBundle.getString("1000"), "1000");
} catch (SSOException ssoe) {
getDebug().error("RemoteServicesImpl.getAttributes: caught SSOException=", ssoe);
throw ssoe;
} catch (Exception ex) {
if (getDebug().messageEnabled()) {
getDebug().message("RemoteServicesImpl.getAttributes2: entryDN=" + entryDN + "; caught exception=", ex);
}
throw new AMException(AMSDKBundle.getString("1000"), "1000");
}
}
use of com.iplanet.am.sdk.AMHashMap in project OpenAM by OpenRock.
the class IdCachedServicesImpl method getAttributes.
public Map getAttributes(SSOToken token, IdType type, String name, Set attrNames, String amOrgName, String amsdkDN, boolean isStringValues) throws IdRepoException, SSOException {
if ((attrNames == null) || attrNames.isEmpty()) {
return getAttributes(token, type, name, amOrgName, amsdkDN);
}
cacheStats.incrementGetRequestCount(getSize());
if (MonitoringUtil.isRunning() && ((monIdRepo = Agent.getIdrepoSvcMBean()) != null)) {
long li = (long) getSize();
monIdRepo.incGetRqts(li);
}
// Get the entry DN
AMIdentity id = new AMIdentity(token, name, type, amOrgName, amsdkDN);
String dn = id.getUniversalId().toLowerCase();
// Get the principal DN
AMIdentity tokenId = IdUtils.getIdentity(token);
String principalDN = IdUtils.getUniversalId(tokenId);
// Debug messages
if (DEBUG.messageEnabled()) {
DEBUG.message("In IdCachedServicesImpl." + "getAttributes(SSOToken, type, name, attrNames, " + "amOrgName, amsdkDN) (" + principalDN + ", " + dn + ", " + attrNames + " ," + amOrgName + " , " + amsdkDN + " method.");
}
// Attributes to be returned
AMHashMap attributes;
// Check in the cache
IdCacheBlock cb = (IdCacheBlock) idRepoCache.get(dn);
if (cb == null) {
// Entry not present in cache
if (DEBUG.messageEnabled()) {
DEBUG.message("IdCachedServicesImpl.getAttributes(): " + "NO entry found in Cachefor key = " + dn + ". Getting all these attributes from DS: " + attrNames);
}
// If the attributes returned here have an empty set as value, then
// such attributes do not have a value or invalid attributes.
// Internally keep track of these attributes.
attributes = (AMHashMap) super.getAttributes(token, type, name, attrNames, amOrgName, amsdkDN, isStringValues);
// Find the missing attributes and add to cache
Set missAttrNames = attributes.getMissingAndEmptyKeys(attrNames);
cb = new IdCacheBlock(dn, true);
cb.putAttributes(principalDN, attributes, missAttrNames, false, !isStringValues);
idRepoCache.put(dn, cb);
} else {
// Entry present in cache
attributes = (AMHashMap) cb.getAttributes(principalDN, attrNames, !isStringValues);
// Find the missing attributes that need to be obtained from DS
// Only find the missing keys as the ones with empty sets are not
// found in DS
Set missAttrNames = attributes.getMissingKeys(attrNames);
if (!missAttrNames.isEmpty()) {
if (DEBUG.messageEnabled()) {
DEBUG.message("IdCachedServicesImpl." + "getAttributes(): Trying to gett these missing " + "attributes from DS: " + missAttrNames);
}
AMHashMap dsAttributes = (AMHashMap) super.getAttributes(token, type, name, attrNames, amOrgName, amsdkDN, isStringValues);
attributes.putAll(dsAttributes);
// Add these attributes, may be found in DS or just mark them
// as invalid (Attribute level Negative caching)
Set newMissAttrNames = dsAttributes.getMissingAndEmptyKeys(missAttrNames);
cb.putAttributes(principalDN, dsAttributes, newMissAttrNames, false, !isStringValues);
} else {
// All attributes found in cache
cacheStats.updateGetHitCount(getSize());
if (MonitoringUtil.isRunning() && ((monIdRepo = Agent.getIdrepoSvcMBean()) != null)) {
long li = (long) getSize();
monIdRepo.incCacheHits(li);
}
if (DEBUG.messageEnabled()) {
DEBUG.message("IdCachedServicesImpl" + ".getAttributes(): " + amsdkDN + " found all attributes in Cache.");
}
}
}
return attributes;
}
use of com.iplanet.am.sdk.AMHashMap in project OpenAM by OpenRock.
the class IdCachedServicesImpl method getAttributes.
public Map getAttributes(SSOToken token, IdType type, String name, String amOrgName, String amsdkDN) throws IdRepoException, SSOException {
cacheStats.incrementGetRequestCount(getSize());
if (MonitoringUtil.isRunning() && ((monIdRepo = Agent.getIdrepoSvcMBean()) != null)) {
long li = (long) getSize();
monIdRepo.incGetRqts(li);
}
// Get the identity dn
AMIdentity id = new AMIdentity(token, name, type, amOrgName, amsdkDN);
String dn = id.getUniversalId().toLowerCase();
// Get the principal dn
AMIdentity tokenId = IdUtils.getIdentity(token);
String principalDN = IdUtils.getUniversalId(tokenId);
// Get the cache entry
IdCacheBlock cb = (IdCacheBlock) idRepoCache.get(dn);
AMHashMap attributes;
if ((cb != null) && cb.hasCompleteSet(principalDN)) {
cacheStats.updateGetHitCount(getSize());
if (MonitoringUtil.isRunning() && ((monIdRepo = Agent.getIdrepoSvcMBean()) != null)) {
long li = (long) getSize();
monIdRepo.incCacheHits(li);
}
if (DEBUG.messageEnabled()) {
DEBUG.message("IdCachedServicesImpl." + "getAttributes(): DN: " + dn + " found all attributes in Cache.");
}
attributes = (AMHashMap) cb.getAttributes(principalDN, false);
} else {
// Get all the attributes from data store
if (DEBUG.messageEnabled()) {
DEBUG.message("IdCachedServicesImpl." + "getAttributes(): " + dn + " complete attribute" + " set NOT found in cache. Getting from DS.");
}
attributes = (AMHashMap) super.getAttributes(token, type, name, amOrgName, amsdkDN);
if (cb == null) {
cb = new IdCacheBlock(dn, true);
idRepoCache.put(dn, cb);
}
cb.putAttributes(principalDN, attributes, null, true, false);
if (DEBUG.messageEnabled()) {
DEBUG.message("IdCachedServicesImpl.getAttributes(): " + "attributes NOT found in cache. Fetched from DS.");
}
}
return attributes;
}
Aggregations