use of com.sun.identity.idm.common.IdCacheBlock in project OpenAM by OpenRock.
the class IdRemoteCachedServicesImpl method search.
@Override
public IdSearchResults search(SSOToken token, IdType type, IdSearchControl ctrl, String orgName, CrestQuery crestQuery) throws IdRepoException, SSOException {
IdSearchResults answer = new IdSearchResults(type, orgName);
// in legacy mode we must do search in order
// to get the AMSDKDN component added to AMIdentity's uvid.
// otherwise unix and anonymous login will fail.
cacheStats.incrementSearchRequestCount(getSize());
if (SystemProperties.isServerMode() && MonitoringUtil.isRunning() && ((monIdRepo = Agent.getIdrepoSvcMBean()) != null)) {
long li = (long) getSize();
monIdRepo.incSearchRqts(li);
}
boolean isCached = false;
if (crestQuery.hasQueryId()) {
String pattern = crestQuery.getQueryId();
if ((pattern.indexOf('*') == -1) && ServiceManager.isRealmEnabled()) {
// First check if the specific identity is in cache.
// If yes, get Attributes from cache.
// If not search in server.
AMIdentity uvid = new AMIdentity(token, pattern, type, orgName, null);
String universalID = uvid.getUniversalId().toLowerCase();
IdCacheBlock cb = (IdCacheBlock) idRepoCache.get(universalID);
if ((cb != null) && !cb.hasExpiredAndUpdated() && cb.isExists() && (ctrl.getSearchModifierMap() == null)) {
// Check if search is for a specific identity
// Search is for a specific user, look in the cache
Map attributes;
try {
cacheStats.updateSearchHitCount(getSize());
if (SystemProperties.isServerMode() && MonitoringUtil.isRunning() && ((monIdRepo = Agent.getIdrepoSvcMBean()) != null)) {
long li = (long) getSize();
monIdRepo.incSearchCacheHits(li);
}
if (ctrl.isGetAllReturnAttributesEnabled()) {
attributes = getAttributes(token, type, pattern, orgName, null);
} else {
Set attrNames = ctrl.getReturnAttributes();
attributes = getAttributes(token, type, pattern, attrNames, orgName, null, true);
}
// Construct IdSearchResults
AMIdentity id = new AMIdentity(token, pattern, type, orgName, null);
answer.addResult(id, attributes);
isCached = true;
} catch (IdRepoException ide) {
// Check if the exception is name not found
if (!ide.getErrorCode().equals(IdRepoErrorCode.UNABLE_FIND_ENTRY)) {
// Throw the exception
throw (ide);
}
}
}
}
}
if (!isCached) {
// Not in Cache. Do a search in server.
answer = super.search(token, type, ctrl, orgName, crestQuery);
}
return (answer);
}
use of com.sun.identity.idm.common.IdCacheBlock in project OpenAM by OpenRock.
the class IdRemoteCachedServicesImpl method getFromCache.
private IdCacheBlock getFromCache(String dn) {
IdCacheBlock cb = (IdCacheBlock) idRepoCache.get(dn);
if ((cb == null)) {
int ind = dn.toLowerCase().indexOf(",amsdkdn=");
if (ind > -1) {
String tmp = dn.substring(0, ind);
// TODO: Should return entries which might have amsdkDN but
// notifications have not told us about it (like
// notifications from plugins other than AMSDKRepo
cb = (IdCacheBlock) idRepoCache.get(tmp);
}
}
return cb;
}
use of com.sun.identity.idm.common.IdCacheBlock in project OpenAM by OpenRock.
the class IdCachedServicesImpl method getFromCache.
// Return cache block for the universal identifier
private IdCacheBlock getFromCache(String dn) {
IdCacheBlock cb = (IdCacheBlock) idRepoCache.get(dn);
if (cb == null) {
int ind = dn.toLowerCase().indexOf(",amsdkdn=");
if (ind > -1) {
String tmp = dn.substring(0, ind);
// TODO: Should return entries which might have amsdkDN but
// notifications have not told us about it (like
// notifications from plugins other than AMSDKRepo
cb = (IdCacheBlock) idRepoCache.get(tmp);
}
}
return cb;
}
use of com.sun.identity.idm.common.IdCacheBlock in project OpenAM by OpenRock.
the class IdCachedServicesImpl method dirtyCache.
private void dirtyCache(String dn) {
String key = DNUtils.normalizeDN(dn);
IdCacheBlock cb = getFromCache(key);
if (cb != null) {
cb.clear();
}
}
use of com.sun.identity.idm.common.IdCacheBlock 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;
}
Aggregations