use of com.sun.identity.idm.common.IdCacheBlock in project OpenAM by OpenRock.
the class IdCachedServicesImpl 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;
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 IdCachedServicesImpl method removeAttributes.
public void removeAttributes(SSOToken token, IdType type, String name, Set attrNames, String orgName, String amsdkDN) throws IdRepoException, SSOException {
// Call parent to remove the attributes
super.removeAttributes(token, type, name, attrNames, orgName, amsdkDN);
// Update the cache
AMIdentity id = new AMIdentity(token, name, type, orgName, amsdkDN);
String dn = id.getUniversalId().toLowerCase();
IdCacheBlock cb = (IdCacheBlock) idRepoCache.get(dn);
if ((cb != null) && !cb.hasExpiredAndUpdated() && cb.isExists()) {
// Remove the attributes
cb.removeAttributes(attrNames);
}
}
use of com.sun.identity.idm.common.IdCacheBlock in project OpenAM by OpenRock.
the class IdCachedServicesImpl method toString.
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("\n<<<<<<< BEGIN 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 SDK CACHE CONTENTS >>>>>>>>");
return sb.toString();
}
use of com.sun.identity.idm.common.IdCacheBlock in project OpenAM by OpenRock.
the class IdCachedServicesImpl 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);
cacheStats.incrementSearchRequestCount(getSize());
if (MonitoringUtil.isRunning() && ((monIdRepo = Agent.getIdrepoSvcMBean()) != null)) {
long li = (long) getSize();
monIdRepo.incSearchRqts(li);
}
//
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 (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);
return answer;
} catch (IdRepoException ide) {
// Check if the exception is name not found
if (!ide.getErrorCode().equals(IdRepoErrorCode.UNABLE_FIND_ENTRY)) {
// Throw the exception
throw (ide);
}
}
}
}
}
// Not in Cache. Do a search on the server.
return super.search(token, type, ctrl, orgName, crestQuery);
}
use of com.sun.identity.idm.common.IdCacheBlock in project OpenAM by OpenRock.
the class IdCachedServicesImpl method removeCachedAttributes.
/*************************************************************************/
// Update/Dirty methods of this class.
// *************************************************************************
private void removeCachedAttributes(String affectDNs, Set attrNames) {
Enumeration cacheKeys = idRepoCache.keys();
while (cacheKeys.hasMoreElements()) {
String key = DNUtils.normalizeDN(cacheKeys.nextElement().toString());
int l1 = key.length();
int l2 = affectDNs.length();
if (key.regionMatches(true, (l1 - l2), affectDNs, 0, l2)) {
// key ends with 'affectDN' string
IdCacheBlock cb = (IdCacheBlock) idRepoCache.get(key);
if (cb != null) {
// key ends with 'affectDN' string
if ((attrNames != null) && !cb.hasExpiredAndUpdated() && cb.isExists()) {
cb.removeAttributes(attrNames);
} else {
cb.clear();
}
}
}
}
}
Aggregations