DefaultJMQSAML2Repository.java revision e70418658b6daa84fc8a1f13677d2cb616a66725
067b7cf571968fe8e91212059da1590c2dfa741aJonathan von Schroeder * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
067b7cf571968fe8e91212059da1590c2dfa741aJonathan von Schroeder * Copyright (c) 2008 Sun Microsystems Inc. All Rights Reserved
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder * The contents of this file are subject to the terms
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder * of the Common Development and Distribution License
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder * (the License). You may not use this file except in
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder * compliance with the License.
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder * You can obtain a copy of the License at
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder * https://opensso.dev.java.net/public/CDDLv1.0.html or
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder * See the License for the specific language governing
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder * permission and limitations under the License.
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder * When distributing Covered Code, include this CDDL
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder * Header Notice in each file and include the License file
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder * If applicable, add the following below the CDDL Header,
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder * with the fields enclosed by brackets [] replaced by
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder * your own identifying information:
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder * "Portions Copyrighted [year] [name of copyright owner]"
067b7cf571968fe8e91212059da1590c2dfa741aJonathan von Schroeder * $Id: DefaultJMQSAML2Repository.java,v 1.5 2008/08/01 22:23:47 hengming Exp $
067b7cf571968fe8e91212059da1590c2dfa741aJonathan von Schroederpackage com.sun.identity.saml2.plugins;
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroederimport com.sun.identity.common.SystemTimer;
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroederimport com.sun.identity.common.GeneralTaskRunnable;
7bbfb15142ab4286dfc6fcde2fc94a5512297e41Jonathan von Schroederimport com.iplanet.dpro.session.SessionException;
067b7cf571968fe8e91212059da1590c2dfa741aJonathan von Schroederimport com.sun.identity.shared.configuration.SystemPropertiesManager;
067b7cf571968fe8e91212059da1590c2dfa741aJonathan von Schroederimport com.iplanet.dpro.session.service.SessionService;
067b7cf571968fe8e91212059da1590c2dfa741aJonathan von Schroederimport com.iplanet.dpro.session.share.SessionBundle;
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroederimport com.iplanet.services.naming.WebtopNaming;
067b7cf571968fe8e91212059da1590c2dfa741aJonathan von Schroederimport com.sun.identity.session.util.SessionUtils;
067b7cf571968fe8e91212059da1590c2dfa741aJonathan von Schroederimport com.sun.identity.shared.Constants;
067b7cf571968fe8e91212059da1590c2dfa741aJonathan von Schroederimport com.sun.identity.shared.debug.Debug;
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroederimport javax.jms.IllegalStateException;
067b7cf571968fe8e91212059da1590c2dfa741aJonathan von Schroederimport org.forgerock.openam.session.model.FAMRecord;
067b7cf571968fe8e91212059da1590c2dfa741aJonathan von Schroederimport com.sun.identity.ha.FAMRecordPersister;
067b7cf571968fe8e91212059da1590c2dfa741aJonathan von Schroederimport com.sun.identity.ha.FAMPersisterManager;
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroederimport com.sun.identity.saml2.common.SAML2Utils;
22b772f8753f0cdb4508ba460356c238de2ee375Jonathan von Schroeder * This class is used in SAML2 failover mode to store/recover serialized
22b772f8753f0cdb4508ba460356c238de2ee375Jonathan von Schroeder * state of Assertion/Response object
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroederpublic class DefaultJMQSAML2Repository extends GeneralTaskRunnable
067b7cf571968fe8e91212059da1590c2dfa741aJonathan von Schroeder /* Operations */
067b7cf571968fe8e91212059da1590c2dfa741aJonathan von Schroeder static public final String READ = "READ";
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder static public final String WRITE = "WRITE";
067b7cf571968fe8e91212059da1590c2dfa741aJonathan von Schroeder static public final String DELETE = "DELETE";
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder static public final String DELETEBYDATE = "DELETEBYDATE";
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder // Private data members
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder /* Config data */
6516023b9db74939c0a0f79fd6cc5bc7d9bab382Jonathan von Schroeder private static boolean isDatabaseUp = true;
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder * grace period before expired session records are removed from the
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder private static long gracePeriod = 5 * 60; /* 5 mins in secs */
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder private static final String CLEANUP_GRACE_PERIOD =
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder "com.sun.identity.session.repository.cleanupGracePeriod";
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder private static final String BRIEF_DB_ERROR_MSG =
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder "SAML2 failover service is not functional due to DB unavailability.";
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder private static final String DB_ERROR_MSG =
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder "SAML2 database is not available at this moment."
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder + "Please check with the system administrator " +
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder "for appropriate actions";
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder private static final String LOG_MSG_DB_BACK_ONLINE =
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder "SESSION_DATABASE_BACK_ONLINE";
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder private static final String LOG_MSG_DB_UNAVAILABLE =
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder "SESSION_DATABASE_UNAVAILABLE";
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder private static boolean lastLoggedDBStatusIsUp = true;
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder * Time period between two successive runs of repository cleanup thread
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder * which checks and removes expired records
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder private static long cleanUpPeriod = 5 * 60 * 1000; // 5 min in milliseconds
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder private static long cleanUpValue = 0;
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder public static final String CLEANUP_RUN_PERIOD =
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder "com.sun.identity.saml2.repository.cleanupRunPeriod";
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder * Time period between two successive runs of DBHealthChecker thread which
97dc615bc3ce381eaa3e75cc23dfc3c4b566d9a0Jonathan von Schroeder * checks for Database availability.
} catch (Exception e) {
} catch (Exception e) {
} catch (Exception e) {
private void initPersistSession() {
isDatabaseUp = true;
} catch (Exception e) {
isDatabaseUp = false;
if (!isDatabaseUp) {
return null;
return retObj;
} catch (IllegalStateException e) {
isDatabaseUp = false;
logDBStatus();
return null;
} catch (Exception e) {
return null;
if (!isDatabaseUp) {
return null;
return list;
return null;
} catch (IllegalStateException e) {
isDatabaseUp = false;
logDBStatus();
return null;
} catch (Exception e) {
return null;
if (!isDatabaseUp) {
} catch (IllegalStateException e) {
isDatabaseUp = false;
logDBStatus();
} catch (Exception e) {
public void deleteExpired() {
if (!isDatabaseUp) {
} catch (IllegalStateException e) {
isDatabaseUp = false;
logDBStatus();
} catch (Exception e) {
if (!isDatabaseUp) {
} catch (IllegalStateException e) {
isDatabaseUp = false;
logDBStatus();
} catch (Exception e) {
private void logDBStatus() {
lastLoggedDBStatusIsUp = false;
lastLoggedDBStatusIsUp = true;
public long getRunPeriod() {
return runPeriod;
public boolean isEmpty() {
public void run() {
logDBStatus();
} catch (Exception e) {