SessionCount.java revision 80f9073cc214ae22fb611d28610bc7f304dc4bec
/**
* 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: SessionCount.java,v 1.5 2008/06/25 05:41:31 qcheng Exp $
*
*/
/**
* Portions Copyrighted 2011-2012 ForgeRock Inc
*/
/**
* <code>SessionCount</code> represents the session count for a given user
* in 3 different mutually exclusive deployment modes from which the user
* sessions can be obtained.
*
* <ul>
* <li> SINGLE_SERVER_MODE :
*I Simply return the local sessions for the given user.
* <li> MULTI_SERVER_MODE :
* Query other AM servers for the sessions for the given user Add the numbers
* up (including the local one) and return the value. If any of the AM servers
* is down, simply ignores it since all the sessions maintained by that instance
* are not available.
* <li> SFO_MODE : Fetch the sessions for the given user directly from the
* session repository.
* </ul>
*/
public class SessionCount {
// SessionInfoMap: uuid -> Set (list of sids)
.synchronizedMap(new HashMap());
/* Single server mode*/
static final int SINGLE_SERVER_MODE = 1;
/* Multiserver mode */
static final int MULTI_SERVER_MODE = 2;
/* Directly from Session repository*/
static final int SFO_MODE = 3;
private static int deploymentMode = 0;
private static boolean useLocalSessionsInMultiServerMode = false;
private static boolean caseSensitiveUUID =
static {
try {
+ "SSOTokenManager instance.");
}
if (getSS().isSessionFailoverEnabled()) {
} else {
try {
&& (getSS().isSiteEnabled()
} else {
}
//If an error occurs fallback to multi server mode
}
}
// Without this property defined the default will be false which is
// backwards compatable.
if (debug.messageEnabled()) {
debug.message("SessionCount: useLocalSessionsInMultiServerMode set to " + useLocalSessionsInMultiServerMode);
}
}
static int getDeploymentMode() {
return deploymentMode;
}
static SessionService getSS() {
+ " Failed to get the session service instance");
}
return ss;
}
/**
* Returns the expiration information of all sessions belonging to a user
* (uuid). The returned value will be a Map (sid->expiration_time).
*
* @param uuid
* User's universal unique ID.
* @return user Sessions
* @exception Exception
* if there is any problem with accessing the session
* repository.
*/
if (!caseSensitiveUUID) {
}
switch (deploymentMode) {
case SINGLE_SERVER_MODE:
break;
case MULTI_SERVER_MODE:
if (useLocalSessionsInMultiServerMode()) {
} else {
}
break;
case SFO_MODE:
break;
default:
break;
}
" returning empty map");
}
return sessions;
}
/*
* Return true if the Constants.USE_LOCAL_SESSIONS_IN_MULTI_SERVER_MODE property
* has been defined and set to true.
*/
static boolean useLocalSessionsInMultiServerMode() {
}
/*
* Get user sessions from local server
*/
synchronized (sessions) {
}
}
}
}
return retSessions;
}
/*
* Get user sessions from session repository
*/
try {
} catch (Exception e) {
e);
return sessions;
}
continue;
}
try {
.getTokenID().toString(), false);
} catch (SessionException se) {
if (debug.messageEnabled()) {
+ "peer AM server is down...");
}
}
}
return sessions;
}
.getRepository();
try {
} catch (Exception e) {
"Session repository is not available", e);
throw e;
}
return sessions;
}
/**
* Increments the session count
* @param is for the user
*
*/
if ((deploymentMode == SINGLE_SERVER_MODE) ||
Set sessions = (Set) uuidSessionMap.get((caseSensitiveUUID) ? is.getUUID() : is.getUUID().toLowerCase());
} else {
}
}
}
/**
* Decrements the session count
* @param is the <code>InternalSession</code> for the user
*
*/
}
if ((deploymentMode == SINGLE_SERVER_MODE) ||
}
}
}
}
try {
}
}
return sres;
} catch (SessionException se) {
throw se;
} catch (Exception e) {
throw new SessionException(e);
}
}
/*
* Gets the admin token for checking the session constraints for the users
* @return admin <code>SSOTken</code>
*/
static SSOToken getAdminToken() {
if (adminToken == null) {
try {
} catch (Exception e) {
+ "Session constraint checking.", e);
}
}
return adminToken;
}
}