JMQSessionRepository.java revision c434d4a40343e3630a5e7a16993a4328bd6bb9d9
/**
* 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: JMQSessionRepository.java,v 1.6 2009/10/30 21:01:44 weisun2 Exp $
*
*/
/**
* Portions Copyrighted 2011-2012 ForgeRock AS
*/
/**
* This class implements JMQ-based session repository which
* state of InternalSession object
*/
class JMQSessionRepository extends GeneralTaskRunnable implements
/**
* Singleton Definition.
*/
private static JMQSessionRepository instance;
/* Operations */
/* JMQ Properties */
/* Config data */
private static boolean isDatabaseUp = true;
/**
* grace period before expired session records are removed from the
* repository
*/
private static final String BRIEF_DB_ERROR_MSG =
"Session failover service is not functional due to DB unavailability.";
private static final String DB_ERROR_MSG =
"Session database is not available at this moment."
+ "Please check with the system administrator " +
"for appropriate actions";
private static final String LOG_MSG_DB_BACK_ONLINE =
"SESSION_DATABASE_BACK_ONLINE";
private static final String LOG_MSG_DB_UNAVAILABLE =
"SESSION_DATABASE_UNAVAILABLE";
private static boolean lastLoggedDBStatusIsUp = true;
/**
* Time period between two successive runs of repository cleanup thread
* which checks and removes expired records
*/
private static long cleanUpValue = 0;
public static final String CLEANUP_RUN_PERIOD =
"com.sun.identity.session.repository.cleanupRunPeriod";
/**
* Time period between two successive runs of DBHealthChecker thread which
* checks for Database availability.
*/
public static final String HEALTH_CHECK_RUN_PERIOD =
"com.sun.identity.session.repository.healthCheckRunPeriod";
/**
* This period is actual one that is used by the thread. The value is set to
* the smallest value of cleanUPPeriod and healthCheckPeriod.
*/
private static boolean caseSensitiveUUID =
static {
try {
} catch (Exception e) {
+ ", using default");
}
try {
} catch (Exception e) {
+ ", using default");
}
try {
} catch (Exception e) {
+ ", using default");
}
}
// Message queues
/**
* Provide Service Instance Access to our Singleton
*
* @return JMQSessionRepository Singleton Instance.
*
*/
public JMQSessionRepository getInstance() {
return instance;
}
/**
* Constructs new JMQSessionRepository
*/
protected JMQSessionRepository() {
}
public String getInstanceClassName() {
return JMQSessionRepository.class.getName();
}
/**
*
* Initialize new persistant session
*/
private synchronized static void initPersistSession() {
try {
instance = new JMQSessionRepository();
isDatabaseUp = true;
} catch (Exception e) {
isDatabaseUp = false;
if (debug.messageEnabled()) {
}
}
}
/**
* Retrives new </code>InternalSession</code> for the session
* @param sid Session Id
* @return InternalSession
* @throws Exception when cannot create a retrieve internal session
*/
if (!isDatabaseUp) {
return null;
}
try {
//TODO: Add interface
}
/*
* ret.put(SESSIONID, message.getString(SESSIONID)); ret.put(DATA,
* message.getString(DATA));
*/
return is;
} catch (IllegalStateException e) {
isDatabaseUp = false;
logDBStatus();
if (debug.messageEnabled()) {
}
return null;
} catch (Exception e) {
+ "session", e);
return null;
}
}
/**
* Deletes the given <code>Session</code>from the repository
* @param sid SessionId
* @throws Exception when cannot delete a session
*/
if (!isDatabaseUp) {
return;
}
try {
} catch (IllegalStateException e) {
isDatabaseUp = false;
logDBStatus();
if (debug.messageEnabled()) {
}
} catch (Exception e) {
+ "session", e);
}
}
/**
* Deletes all expired Sessions from the repository
* @exception Exception thrown when Unable to delete the expired sessions
*/
public void deleteExpired() throws Exception {
if (!isDatabaseUp) {
return;
}
try {
//TODO: add interface revoke
} catch (IllegalStateException e) {
isDatabaseUp = false;
logDBStatus();
if (debug.messageEnabled()) {
}
} catch (Exception e) {
+ "deleting Expired Sessions", e);
}
}
/**
* Saves<code> InternalSession</code> into the <code>SessionRepository</code>
* @param is InternalSession
* @exception Exception thrown when cannot save the internal session
*/
if (!isDatabaseUp) {
return;
}
try {
if (debug.messageEnabled()) {
}
} catch (IllegalStateException e) {
isDatabaseUp = false;
logDBStatus();
if (debug.messageEnabled()) {
}
} catch (Exception e) {
+ "to save Session", e);
}
}
/**
* Returns the expiration information of all sessions belonging to a user.
* The returned value will be a Map (sid->expiration_time).
*
* @param uuid
* User's universal unique ID.
* @return Map of all Session for the user
* @throws Exception
* if there is any problem with accessing the session
* repository.
*/
if (!isDatabaseUp) {
throw new SessionException("Session repository is not "
+ "available.");
}
try {
}
} catch (IllegalStateException e) {
isDatabaseUp = false;
logDBStatus();
if (debug.messageEnabled()) {
}
throw new SessionException(e);
} catch (Exception e) {
throw new SessionException(e);
}
return sessions;
}
/**
* This method is invoked to log a message in the following two cases:
*
* (1) the DB is detected down by either the user requests
* (retrieve/save/delete/getSessionCount) or the background checker thread:
* Log message: SESSION_DATABASE_UNAVAILABLE (2) the DB is detected
* available again by the background health checker thread => Log message:
* SESSION_DATABASE_BACK_ONLINE
*
* The flag "lastLoggedDBStatusIsUp" is used to avoid logging the same DB
* status again and again if the status actually doesn't change over time.
*
* Please also note that if the DB is already down in the very beginning
* when starting the AM instance, there will be no message being logged
* since at this time the session service is not fully initialized yet
* therefore no sso token can be generated and used for the logging purpose.
* Nevertheless, the appropriate logging will be done later when the
* background thread kicks in.
*
*/
private void logDBStatus() {
if (!isDatabaseUp && lastLoggedDBStatusIsUp) {
lastLoggedDBStatusIsUp = false;
}
if (isDatabaseUp && !lastLoggedDBStatusIsUp) {
lastLoggedDBStatusIsUp = true;
}
}
public long getRunPeriod() {
return runPeriod;
}
return false;
}
return false;
}
public boolean isEmpty() {
return true;
}
/**
* Monitoring logic used by background thread This thread is used for both
* clenup expired sessions in the repository and for the Database health
* checking. The thread always runs with smallest value of cleanUpPeriod and
* healthCheckPeriod.
*/
public void run() {
try {
if (debug.messageEnabled()) {
}
/*
* Clean up is done based on the cleanUpPeriod even though the
* thread runs based on the runPeriod.
*/
if (cleanUpValue <= 0) {
}
/*
* HealthChecking is done based on the runPeriod but only when
* the Database is down.
*/
if (!isDatabaseUp) {
logDBStatus();
}
} catch (Exception e) {
e);
}
}
// *****************************************************************
//
// All methods below this comment are stubbed out for resolution
// of our implementations for consistency. This whole class will
// be removed for 10.1.0.
//
// *****************************************************************
public DBStatistics getDBStatistics() {
// TODO
return null;
}
// TODO
}
// TODO
}
// TODO
}
return null; // TODO
}
return null; // TODO
}
public void shutdown() {
// TODO
}
return null; // TODO
}
/**
* Retrives existing SAML2 object from persistent datastore
*
* @param samlKey primary key
* @return SAML2 object, if failed, return null.
*/
return null; // TODO
}
/**
* Retrives a list of existing SAML2 object from persistent datastore with
* secodaryKey
*
* @param secKey Secondary Key
* @return SAML2 object, if failed, return null.
*/
return null; // TODO
}
/**
* Deletes the SAML2 object by given primary key from the repository
*
* @param samlKey primary key
*/
// TODO
}
/**
* Deletes expired SAML2 object from the repository
*/
public void deleteExpiredSAML2Tokens() {
// TODO
}
/**
* Saves SAML2 data into the SAML2 Repository
*
* @param samlKey primary key
* @param samlObj saml object such as Response, IDPSession
* @param expirationTime expiration time
* @param secKey Secondary Key
*/
// TODO
}
}