CachedSMSEntry.java revision 8af80418ba1ec431c8027fa9668e5678658d3611
/**
* 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: CachedSMSEntry.java,v 1.16 2009/10/08 20:33:54 hengming Exp $
*
*/
/**
* The class <code>CachedSchemaManagerImpl</code> provides interfaces to
* manage the SMSEntry. It caches SMSEntries which is used by ServiceSchema and
* ServiceConfig classes.
*/
public class CachedSMSEntry {
// Notification method that will be called for ServiceSchemaManagerImpls
// Cache of CachedSMSEntries (static)
new HashMap(1000));
// Instance variables
// Set of ServiceSchemaManagerImpls and ServiceConfigImpls
// that must be updated where entry changes
new HashSet());
protected String notificationID;
// Flag that determines if this object can be used
private boolean valid;
// Flag to determine if the cached entry is dirty and
// must be refreshed along with the last update time & TTL
private boolean dirty;
static boolean ttlEnabled;
static long lastUpdate;
// Private constructor, can be instantiated only via getInstance
private CachedSMSEntry(SMSEntry e) {
smsEntry = e;
token = e.getSSOToken();
valid = true;
// Set the SMSEntry as read only
// Register for notifications
// Write debug messages
}
}
// ----------------------------------------------
// Protected instance methods
// ----------------------------------------------
boolean isValid() {
return valid;
}
// Used by JAXRPCObjectImpl
public boolean isDirty() {
if (ttlEnabled && !dirty &&
synchronized (dirtyLock) {
dirty = true;
}
}
return dirty;
}
/**
* Invoked by SMSEventListenerManager when entry has been changed.
* Mark the entry as dirty and return. The method refresh() must be
* called to read the attributes.
*/
void update() {
+ "method called: " + dn2Str );
}
synchronized (dirtyLock) {
dirty = true;
}
}
/**
* Reads the attributes from the datastore and send notifications to
* objects caching this entry. Used by JAXRPCObjectImpl
*/
public void refresh() {
synchronized (dirtyLock) {
+ "method called: " + dn2Str );
}
// Read the LDAP attributes and update listeners
boolean updated = false;
dirty = true;
try {
SSOToken t = getValidSSOToken();
if (t != null) {
updated = true;
"SSOToken found for dn: " + dn2Str);
}
} catch (SMSException e) {
// Error in reading the attribtues, entry could be deleted
// or does not have permissions to read the object
dn2Str, e);
} catch (SSOException ssoe) {
// Error in reading the attribtues, SSOToken problem
// Might have timed-out
}
if (!updated) {
// No valid SSOToken were foung
// this entry is no long valid, remove from cache
clear();
}
// Update service listeners either success or failure
// updateServiceListeners(UPDATE_METHOD);
dirty = false;
}
}
/**
* Updates the attributes from the provided <class>SMSEntry</class>
* and marks the entry as non-dirty.
* @param e object that contains the updated values for the attributes
* @throws com.sun.identity.sm.SMSException
*/
synchronized (dirtyLock) {
dirty = false;
}
}
/**
* Clears the local variables and marks the entry as invalid
* Called by the SMS objects that have an instance of CachedSMSEntry
*/
void clear() {
clear(true);
}
/**
* Marks the object to be invalid and deregisters for notifications.
* Called by the static method clearCache()
* @param removeFromCache remove itself from cache if set to true
*/
private void clear(boolean removeFromCache) {
// this entry is no long valid, remove from cache
valid = false;
synchronized(dirtyLock) {
dirty = true;
}
// Remove from cache
if (removeFromCache) {
}
}
// Returns a valid SSOToken that can be used for reading
private SSOToken getValidSSOToken() {
// Check if the cached SSOToken is valid
// Get a valid ssoToken from cached TokenIDs
synchronized (principals) {
try {
break;
}
} catch (SSOException ssoe) {
// SSOToken has expired, remove from list
}
}
}
}
// If there are no valid SSO Tokens return null
if (principals.isEmpty()) {
return (null);
}
return (token);
}
/**
* Sends notifications to ServiceSchemaManagerImpl and ServiceConfigImpl
* The method determines the object's method that would be invoked.
* It could be either update() -- in which only the local instances are
* updated, or updateAndNotify() -- in which case the listeners are also
* notified.
* @param method either "update" or "updateAndNotify"
*/
+ "method called: " + dn2Str);
}
// Inform the ServiceSchemaManager's of changes to attributes
synchronized (serviceObjects) {
}
}
try {
} catch (Throwable e) {
}
}
}
/**
* Method to add objects that needs notifications
*/
protected void addServiceListener(Object o) {
serviceObjects.add(o);
}
/**
* Method to remove objects that needs notifications
*/
protected void removeServiceListener(Object o) {
serviceObjects.remove(o);
if (serviceObjects.isEmpty()) {
}
}
synchronized void addPrincipal(SSOToken t) {
// Making a local copy to avoid synchronization problems
}
boolean checkPrincipal(SSOToken t) {
}
public SMSEntry getSMSEntry() {
return (smsEntry);
}
public SMSEntry getClonedSMSEntry() {
if (isDirty()) {
refresh();
}
try {
} catch (CloneNotSupportedException c) {
}
return (null);
}
boolean isNewEntry() {
if (isDirty()) {
refresh();
}
return (smsEntry.isNewEntry());
}
return (dn2Str);
}
// ----------------------------------------------
// protected static methods
// ----------------------------------------------
// Used by ServiceSchemaManager
try {
} catch (SSOException ssoe) {
}
return (entry);
}
throws SMSException, SSOException {
}
// Construct the SMS entry. Should be outside the synchronized
// block since SMSEntry call delegation which in turn calls
// policy, idrepo, special repo and SMS again
synchronized (smsEntries) {
// Add it to cache
}
}
}
// Check if user has permissions
if (!answer.checkPrincipal(t)) {
// Read the SMS entry as that user, and ignore the results
answer.addPrincipal(t);
}
}
if (answer.isNewEntry()) {
}
return (answer);
}
static void initializeProperties() {
// Initialize the TTL
if (ttlEnabled) {
try {
// Convert minutes to milliseconds
} catch (NumberFormatException nfe) {
"for SMS Cache TTL: " + cacheTime);
}
}
}
}
// Clears the cache
static void clearCache() {
synchronized (smsEntries) {
// this entry is no long valid
}
// Remove all entries from cache
smsEntries.clear();
}
}
// ----------------------------------------------
// protected instance methods for ServiceSchemaManager
// ----------------------------------------------
String getXMLSchema() {
// The entry could be deleted, hence return null
return (null);
}
// Since schema is a single valued attribute
return (schema[0]);
}
byte[] byteArray = new byte[lengthOfStream];
}
// Validate SSOtoken
// Replace the attribute in the directory
SMSEntry e = getClonedSMSEntry();
refresh(e);
+ "successfully wrote the XML schema for dn: " + e.getDN());
}
}
// Protected static variables
private static Class CACHED_SMSENTRY;
private static Method UPDATE_FUNC;
static {
try {
"com.sun.identity.sm.CachedSMSEntry");
} catch (Exception e) {
// Should not happen, ignore
}
}
}