use of com.sun.identity.idm.common.IdCacheBlock in project OpenAM by OpenRock.
the class IdRemoteCachedServicesImpl method getFullyQualifiedNames.
// Returns fully qualified names for the identity
// @Override
public Set getFullyQualifiedNames(SSOToken token, IdType type, String name, String orgName) throws IdRepoException, SSOException {
// Get the identity DN
AMIdentity id = new AMIdentity(token, name, type, orgName, null);
String dn = id.getUniversalId().toLowerCase();
// Get the cache entry
Set answer = null;
IdCacheBlock cb = (IdCacheBlock) idRepoCache.get(dn);
if (cb != null) {
// Get the fully qualified names
answer = cb.getFullyQualifiedNames();
}
if (answer == null) {
// Obtain from the data stores
answer = super.getFullyQualifiedNames(token, type, name, orgName);
if (cb != null) {
cb.setFullyQualifiedNames(answer);
}
}
return (answer);
}
use of com.sun.identity.idm.common.IdCacheBlock in project OpenAM by OpenRock.
the class IdRemoteCachedServicesImpl method updateCache.
/**
* Method that updates the cache entries locally. This method does a write
* through cache
*/
private void updateCache(SSOToken token, String dn, Map stringAttributes, Map byteAttributes) throws IdRepoException, SSOException {
// This is already normalized
String key = dn.toLowerCase();
IdCacheBlock cb = (IdCacheBlock) idRepoCache.get(key);
if (cb != null && !cb.hasExpiredAndUpdated() && cb.isExists()) {
AMIdentity tokenId = IdUtils.getIdentity(token);
String pDN = tokenId.getUniversalId();
cb.replaceAttributes(pDN, stringAttributes, byteAttributes);
}
}
use of com.sun.identity.idm.common.IdCacheBlock in project OpenAM by OpenRock.
the class IdRemoteCachedServicesImpl method toString.
// @Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("\n<<<<<<< BEGIN IDREPO SDK CACHE CONTENTS >>>>>>>>");
if (!idRepoCache.isEmpty()) {
// Should never be null
Enumeration cacheKeys = idRepoCache.keys();
while (cacheKeys.hasMoreElements()) {
String key = (String) cacheKeys.nextElement();
IdCacheBlock cb = (IdCacheBlock) idRepoCache.get(key);
sb.append("\nSDK Cache Block: ").append(key);
sb.append(cb.toString());
}
} else {
sb.append("<empty>");
}
sb.append("\n<<<<<<< END IDREPO SDK CACHE CONTENTS >>>>>>>>");
return sb.toString();
}
use of com.sun.identity.idm.common.IdCacheBlock in project OpenAM by OpenRock.
the class IdRemoteCachedServicesImpl method getAttributes.
// @Override
public Map getAttributes(SSOToken token, IdType type, String name, Set attrNames, String amOrgName, String amsdkDN, boolean isStringValues) throws IdRepoException, SSOException {
// Currently not needed as AMIdentity does not have getAllBinaryAttr..
if ((attrNames == null) || attrNames.isEmpty()) {
return (getAttributes(token, type, name, amOrgName, amsdkDN));
}
cacheStats.incrementGetRequestCount(getSize());
if (SystemProperties.isServerMode() && 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 = tokenId.getUniversalId();
if (DEBUG.messageEnabled()) {
DEBUG.message("In IdRemoteCachedServicesImpl." + "getAttributes(SSOToken type, name, attrNames, " + "amOrgName, amsdkDN) (" + principalDN + ", " + dn + ", " + attrNames + " ," + amOrgName + " , " + amsdkDN + " method.");
}
// Attributes to be returned
AMHashMap attributes;
IdCacheBlock cb = (IdCacheBlock) idRepoCache.get(dn);
if (cb == null) {
// Entry not present in cache
if (DEBUG.messageEnabled()) {
DEBUG.message("IdRemoteCachedServicesImpl." + "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);
// These attributes are either not present or not found in DS.
// Try to check if they need to be fetched by external
// plugins
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("IdRemoteCachedServicesImpl." + "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, just mark to hem 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 (SystemProperties.isServerMode() && MonitoringUtil.isRunning() && ((monIdRepo = Agent.getIdrepoSvcMBean()) != null)) {
long li = (long) getSize();
monIdRepo.incCacheHits(li);
}
if (DEBUG.messageEnabled()) {
DEBUG.message("IdRemoteCachedServicesImpl." + "getAttributes(): found all attributes in Cache.");
}
}
}
return attributes;
}
use of com.sun.identity.idm.common.IdCacheBlock in project OpenAM by OpenRock.
the class IdCachedServicesImpl method getFullyQualifiedNames.
// Returns fully qualified names for the identity
public Set getFullyQualifiedNames(SSOToken token, IdType type, String name, String orgName) throws IdRepoException, SSOException {
// Get the identity DN
AMIdentity id = new AMIdentity(token, name, type, orgName, null);
String dn = id.getUniversalId().toLowerCase();
// Get the cache entry
Set answer = null;
IdCacheBlock cb = (IdCacheBlock) idRepoCache.get(dn);
if (cb != null) {
// Get the fully qualified names
answer = cb.getFullyQualifiedNames();
}
if (answer == null) {
// Obtain from the data stores
answer = super.getFullyQualifiedNames(token, type, name, orgName);
if (cb != null) {
cb.setFullyQualifiedNames(answer);
}
}
return (answer);
}
Aggregations