8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: SessionInfo.java,v 1.3 2008/06/25 05:41:31 qcheng Exp $
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott * Portions Copyrighted 2011-2015 ForgeRock AS.
0fb4093da08d574d3d1b661d4425dfbac8e02aabJames Phillpottsimport com.fasterxml.jackson.annotation.JsonIgnore;
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott * <code>SessionInfo</code> class holds all the information about the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <code>Session</code>
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott private Hashtable<String, String> properties = new Hashtable<String, String>();
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott * Constructs <code> SessionInfo </code>
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott * translates the <code>Session</code> Information to an XML document
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott * String based
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott * @return An XML String representing the information
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append("<Session sid=").append(QUOTE).append(sid).append(QUOTE)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster .append(" stype=").append(QUOTE).append(stype).append(QUOTE)
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott XMLUtils.escapeSpecialCharacters(cid)).append(QUOTE)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster .append(QUOTE).append(" maxtime=").append(QUOTE)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster .append(maxtime).append(QUOTE).append(" maxidle=")
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster .append(QUOTE).append(maxidle).append(QUOTE).append(
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott " maxcaching=").append(QUOTE).append(maxcaching)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster .append(QUOTE).append(" timeidle=").append(QUOTE).append(
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott getTimeIdle()).append(QUOTE).append(" timeleft=").append(
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott QUOTE).append(getTimeLeft()).append(QUOTE).append(" state=")
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster .append(QUOTE).append(state).append(QUOTE).append(">").append(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String name = (String) enumerator.nextElement();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append("<Property name=").append(QUOTE).append(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster XMLUtils.escapeSpecialCharacters(name)).append(QUOTE)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster .append(QUOTE).append(">").append("</Property>")
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott * <code>Session</code> id
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott public void setSessionID(final String sid) {
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott public void setSecret(final String secret) {
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott * <code>Session</code> type
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott public void setSessionType(final String stype) {
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott * <code>Cookie</code> id
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott * <code> Cookie</code> domain
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott public void setClientDomain(final String cdomain) {
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott * Max <code>Session</code> Time in minutes.
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott public void setMaxTime(final long maxtime) {
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott * Max <code>Session</code> Idle time in minutes.
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott public void setMaxIdle(final long maxidle) {
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott * Max <code>Session</code> Cache time in minutes.
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott public void setMaxCaching(final long maxcaching) {
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott * Time at which this session will expire in milliseconds from the UTC epoch.
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott public void setExpiryTime(final long expiryTime) {
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott * Indicates that the session should never expire.
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott * @param neverExpiring {@code true} if the session should never expire. If {@code false} this method does nothing.
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott public void setNeverExpiring(final boolean neverExpiring) {
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott * Whether the session will ever expire or not.
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott * Time at which there was last activity on this session as milliseconds from the UTC epoch.
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott public void setLastActivityTime(final long lastActivityTime) {
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott * <code>Session</code> idle time in seconds.
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott return TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - lastActivityTime);
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott public void setTimeIdle(final long timeidle) {
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott this.lastActivityTime = System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(timeidle);
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott * Time left for <code>Session</code> to become inactive, in seconds.
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott return TimeUnit.MILLISECONDS.toSeconds(expiryTime - System.currentTimeMillis());
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott public void setTimeLeft(final long timeleft) {
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott expiryTime = TimeUnit.SECONDS.toMillis(timeleft) + System.currentTimeMillis();
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott // Check for overflow - expiryTime should always be positive
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott * <code>Session</code> state
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott public Hashtable<String, String> getProperties() {
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott public void setProperties(final Hashtable<String, String> properties) {
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott if (this == o) {
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott if (o == null || getClass() != o.getClass()) {
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott return false;
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott return maxcaching == that.maxcaching && maxidle == that.maxidle && maxtime == that.maxtime
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott && lastActivityTime == that.lastActivityTime && expiryTime == that.expiryTime
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott && !(cdomain != null ? !cdomain.equals(that.cdomain) : that.cdomain != null)
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott && !(cid != null ? !cid.equals(that.cid) : that.cid != null)
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott && !(properties != null ? !properties.equals(that.properties) : that.properties != null)
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott && !(secret != null ? !secret.equals(that.secret) : that.secret != null)
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott && !(sid != null ? !sid.equals(that.sid) : that.sid != null)
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott && !(state != null ? !state.equals(that.state) : that.state != null)
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott && !(stype != null ? !stype.equals(that.stype) : that.stype != null);
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott int result = sid != null ? sid.hashCode() : 0;
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott result = 31 * result + (secret != null ? secret.hashCode() : 0);
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott result = 31 * result + (stype != null ? stype.hashCode() : 0);
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott result = 31 * result + (cid != null ? cid.hashCode() : 0);
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott result = 31 * result + (cdomain != null ? cdomain.hashCode() : 0);
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott result = 31 * result + (int) (maxtime ^ (maxtime >>> 32));
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott result = 31 * result + (int) (maxidle ^ (maxidle >>> 32));
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott result = 31 * result + (int) (maxcaching ^ (maxcaching >>> 32));
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott result = 31 * result + (int) (lastActivityTime ^ (lastActivityTime >>> 32));
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott result = 31 * result + (int) (expiryTime ^ (expiryTime >>> 32));
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott result = 31 * result + (state != null ? state.hashCode() : 0);
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott result = 31 * result + (properties != null ? properties.hashCode() : 0);
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshott return "SessionInfo{" +