/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: IdCachedServicesImpl.java,v 1.21 2009/08/25 06:50:53 hengming Exp $
*
* Portions Copyrighted 2011-2015 ForgeRock AS.
*/
/*
* Class which provides caching on top of available IdRepoLDAPServices.
*/
public class IdCachedServicesImpl extends IdServicesImpl implements IdCachedServices, ConfigurationListener {
private static int maxSize;
// Class Private
static {
}
}
if (DEBUG.messageEnabled()) {
}
}
private IdCachedServicesImpl() {
super();
if (MonitoringUtil.isRunning()) {
}
}
private void initializeCache() {
}
clearCache();
}
/**
* Method to get the current cache size
*
* @return the size of the SDK LRU cache
*/
public int getSize() {
return idRepoCache.size();
}
+ "Creating new Instance of IdCachedServicesImpl()");
//the instance should be created before acquiring the lock to
//prevent possible deadlocks by using Stats
instance = new IdCachedServicesImpl();
new ShutdownListener() {
public void shutdown() {
synchronized (instance) {
shutdownCalled = true;
}
}
});
}
return instance;
}
/**
* Method to get the maximum size of the Cache. To be called by all other
* LRU Caches that are created in AM SDK
*
* @return the maximum cache size for a LRU cache
*/
protected static int getMaxSize() {
return maxSize;
}
while (cacheKeys.hasMoreElements()) {
}
} else {
}
}
/*************************************************************************/
// *************************************************************************
while (cacheKeys.hasMoreElements()) {
// key ends with 'affectDN' string
// key ends with 'affectDN' string
} else {
}
}
}
}
}
}
/**
* This method is used to clear the entire SDK cache in the event that
* EventService notifies that all entries have been modified (or should be
* marked dirty).
*/
public synchronized void clearCache() {
idRepoCache.clear();
}
/**
* This method will be called by <code>AMIdRepoListener</code>. This
* method will update the cache by removing all the entires which are
* affected as a result of an event notification caused because of
*
* <p>
* NOTE: The event could have been caused either by changes to an aci entry
* or a costemplate or a cosdefinition or changes to a normal entry
*
* @param dn
* name of entity being modified
* @param eventType
* type of modification
* @param cosType
* true if it is cos related. false otherwise
* @param aciChange
* true if it is aci related. false otherwise
* @param attrNames
* Set of attribute Names which should be removed from the
* CacheEntry in the case of COS change
*/
switch (eventType) {
case AMEvent.OBJECT_ADDED:
}
if (cosType) { // A cos type event remove all affected attributes
}
break;
case AMEvent.OBJECT_REMOVED:
}
if (cosType) {
}
break;
case AMEvent.OBJECT_RENAMED:
// Better to remove the renamed entry, or else it will be just
// hanging in the cache, until LRU kicks in.
}
if (cosType) {
}
break;
case AMEvent.OBJECT_CHANGED:
}
if (cosType) {
} else if (aciChange) { // Clear all affected entries
}
break;
}
if (DEBUG.messageEnabled()) {
+ "dirtied because of Event Notification. Parameters - "
}
}
/**
* Method that updates the cache entries locally. This method does a write
* through cache
*/
}
}
}
}
// If required attributes is null or empty, call the
// other interface to get all the attributes
// TODO: Need to provide means to get all the binary attributes too!
// Currently not needed as AMIdentity does not have getAllBinaryAttr..
}
if (MonitoringUtil.isRunning() &&
}
// Get the entry DN
// Get the principal DN
// Debug messages
if (DEBUG.messageEnabled()) {
"getAttributes(SSOToken, type, name, attrNames, " +
}
// Attributes to be returned
// Check in the cache
if (DEBUG.messageEnabled()) {
+ "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.
// Find the missing attributes and add to cache
} else { // Entry present in cache
// 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
if (!missAttrNames.isEmpty()) {
if (DEBUG.messageEnabled()) {
+ "getAttributes(): Trying to gett these missing "
+ "attributes from DS: "
+ missAttrNames);
}
// Add these attributes, may be found in DS or just mark them
// as invalid (Attribute level Negative caching)
false, !isStringValues);
} else { // All attributes found in cache
if (MonitoringUtil.isRunning() &&
}
if (DEBUG.messageEnabled()) {
+ ".getAttributes(): " + amsdkDN
+ " found all attributes in Cache.");
}
}
}
return attributes;
}
throws IdRepoException, SSOException {
if (MonitoringUtil.isRunning() &&
}
// Get the identity dn
// Get the principal dn
// Get the cache entry
if (MonitoringUtil.isRunning() &&
}
if (DEBUG.messageEnabled()) {
+ "getAttributes(): DN: " + dn
+ " found all attributes in Cache.");
}
} else {
// Get all the attributes from data store
if (DEBUG.messageEnabled()) {
+ "getAttributes(): " + dn
+ " complete attribute"
+ " set NOT found in cache. Getting from DS.");
}
}
if (DEBUG.messageEnabled()) {
+ "attributes NOT found in cache. Fetched from DS.");
}
}
return attributes;
}
dirtyCache(dn);
}
// Update attributes in data store
// Get identity DN
// Update the cache
// Update cache locally for modified delted user attributes
if (isString) {
} else {
}
} else {
dirtyCache(dn);
}
}
// Call parent to delete the entry
// Clear the cache, get identity DN
}
throws IdRepoException, SSOException {
// Call parent to remove the attributes
// Update the cache
// Remove the attributes
}
}
throws IdRepoException, SSOException {
if (MonitoringUtil.isRunning() &&
}
// If searching for a string (presumably from a _queryID), it is possible to see if the value is cached. If
// so we can bypass the real search.
//
// If, on the other hand, we are searching with a query filter, we must always perform the search.
//
if (crestQuery.hasQueryId()) {
// 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.
//
// First check if the specific identity is in cache.
// If yes, get Attributes from cache.
// If not search in server.
// Check if search is for a specific identity
// Search is for a specific user, look in the cache
try {
}
if (ctrl.isGetAllReturnAttributesEnabled()) {
} else {
}
// Construct IdSearchResults
return answer;
} catch (IdRepoException ide) {
// Check if the exception is name not found
// Throw the exception
throw (ide);
}
}
}
}
}
// Not in Cache. Do a search on the server.
}
// Returns fully qualified names for the identity
throws IdRepoException, SSOException {
// Get the identity DN
// Get the cache entry
// Get the fully qualified names
}
// Obtain from the data stores
answer = super.getFullyQualifiedNames(
}
}
return (answer);
}
// Return cache block for the universal identifier
if (ind > -1) {
// TODO: Should return entries which might have amsdkDN but
// notifications have not told us about it (like
// notifications from plugins other than AMSDKRepo
}
}
return cb;
}
// strip away amsdkdn from dn.
if (ind > -1) {
}
return cachedId;
}
public synchronized void notifyChanges() {
}
}
}