001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.runtime.util;
038:
039: import com.sun.xml.ws.rm.Sequence;
040: import com.sun.xml.ws.security.SecurityContextTokenInfo;
041:
042: /**
043: * The <code> Session </Session> object is used to manage state between multiple requests
044: * from the same client. It contains a session key field to uniquely identify the Session,
045: * a <code>SecurityInfo</code> field that contains the security parameters used to
046: * protect the session and userdata field that can store the state for multiple
047: * requests from the client.
048: *
049: * @author Bhakti Mehta
050: * @author Mike Grogan
051: */
052: public class Session {
053:
054: /**
055: * Well-known invocationProperty names
056: */
057: public static final String SESSION_ID_KEY = "com.sun.xml.ws.sessionid";
058: public static final String SESSION_KEY = "com.sun.xml.ws.session";
059:
060: /**
061: * Session manager that can handle Sessions of this exact type.
062: * (Different SessionManagers might use different subclasses of this Class)
063: */
064: private final SessionManager manager;
065:
066: /*
067: * These fields might be persisted
068: */
069: /**
070: * Unique key based either on the SCT or RM sequence id for the session
071: */
072: private final String key;
073:
074: /**
075: * A container for user-defined data that will be exposed in WebServiceContext.
076: */
077: private final Object userData;
078:
079: private SecurityContextTokenInfo securityInfo;
080: private Sequence sequence;
081:
082: /*
083: * These fields are for internal use
084: */
085: private final long creationTime;
086: private long lastAccessedTime;
087:
088: /**
089: * Public constructor
090: *
091: * @param manager - A <code>SessionManager</code> that can handle <code>Sessions</code>
092: * of this type.
093: * @param key - The unique session id
094: * @param data - Holder for user-defined data.
095: */
096: public Session(SessionManager manager, String key, Object userData) {
097: this .manager = manager;
098: this .userData = userData;
099: this .key = key;
100: creationTime = lastAccessedTime = System.currentTimeMillis();
101: }
102:
103: /**
104: * Accessor for Session Key.
105: *
106: * @returns The session key
107: */
108: public String getSessionKey() {
109: return key;
110: }
111:
112: /**
113: * Accessor for the <code>userData</code> field.
114: *
115: * @return The value of the field.
116: */
117: public Object getUserData() {
118: return userData;
119: }
120:
121: /**
122: * Accessor for the <code>securityInfo</code> field.
123: *
124: * @returns The value of the field.
125: */
126: public SecurityContextTokenInfo getSecurityInfo() {
127: return securityInfo;
128: }
129:
130: /**
131: * Mutator for the <code>securityInfo</code> field.
132: *
133: * @returns The value of the field.
134: */
135: public void setSecurityInfo(SecurityContextTokenInfo securityInfo) {
136: this .securityInfo = securityInfo;
137: }
138:
139: /**
140: * Accessor for the <code>sequence</code> field.
141: *
142: * @return The value of the field.
143: */
144: public Sequence getSequence() {
145: return sequence;
146: }
147:
148: /**
149: * Mutator for the <code>securityInfo</code> field.
150: *
151: * @returns The value of the field.
152: */
153: public void setSequence(Sequence sequence) {
154: this .sequence = sequence;
155: }
156:
157: /**
158: * Accessor for creation time.
159: *
160: * @returns The creation time.
161: */
162: public long getCreationTime() {
163: return creationTime;
164: }
165:
166: /**
167: * Accessor for lastAccessed time, which can be used to invalidate Sessions
168: * have not been active since a certain time.
169: *
170: * @returns The lastAccessedTime
171: */
172: public long getLastAccessedTime() {
173: return lastAccessedTime;
174: }
175:
176: /**
177: * Resets the lastAccessedTime to the current time.
178: */
179: public void resetLastAccessedTime() {
180: lastAccessedTime = System.currentTimeMillis();
181: }
182:
183: /**
184: * Saves the state of the session using whatever persistence mechanism the
185: * <code>SessionManager</code> offers.
186: */
187: public void save() {
188: manager.saveSession(getSessionKey());
189: }
190:
191: }
|