2 * Copyright [2005] [University Corporation for Advanced Internet Development, Inc.]
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 * Session object holds Principal ID [handle] and Attributes.
21 * A random ID is used as the object key in the Cache and
22 * is returned to the Browser as a Cookie value.
24 * Recovery Context: No exceptions expected or generated.
26 package edu.internet2.middleware.shibboleth.serviceprovider;
28 import java.io.Serializable;
29 import org.opensaml.SAMLAssertion;
30 import org.opensaml.SAMLAuthenticationStatement;
31 import org.opensaml.SAMLResponse;
34 * Session object holds Authentication and Attribute Assertions for one
35 * remote Browser/User.<br>
36 * Each session generates its own random key.<br>
37 * The collection of Session objects may be checkpointed to disk using
38 * any attractive persistence framework, Object Relational mapping,
39 * or, hell, just serialize the objects to a flat file if you like.
41 * @author Howard Gilbert
43 public class Session implements Serializable {
44 private long maxSessionLife;
45 private long unusedSessionTimeout;
46 private long defaultAttributeLifetime;
49 * Create a Session object. Only used by the Session Manager, so it has package scope.
51 * @param key Random generated sessionId string
52 * @param maxSessionLife Maximum time this Session can remain valid
53 * @param unusedSessionTimeout Discard an unused Session
54 * @param defaultAttributeLifetime Default attribute validity time
58 long unusedSessionTimeout,
59 long defaultAttributeLifetime) {
61 throw new IllegalArgumentException();
63 this.lastused = System.currentTimeMillis();
64 this.created = this.lastused;
65 this.maxSessionLife=maxSessionLife;
66 this.unusedSessionTimeout=unusedSessionTimeout;
67 this.defaultAttributeLifetime=defaultAttributeLifetime;
73 public String getKey() {
77 private String applicationId = null;
78 public String getApplicationId() {
81 public void setApplicationId(String applicationId) {
82 this.applicationId = applicationId;
85 private String ipaddr = null;
86 public String getIpaddr() {
89 public void setIpaddr(String ipaddr) {
93 private String entityId = null; // a.k.a providerId
94 public String getEntityId() {
97 public void setEntityId(String entityId) {
98 this.entityId = entityId;
101 private long lastused = 0;
102 private long created = 0;
104 public boolean isExpired() {
105 long now = System.currentTimeMillis();
106 if (maxSessionLife>0 &&
107 created+maxSessionLife<now)
109 if (unusedSessionTimeout>0 &&
110 lastused+unusedSessionTimeout<now)
116 // Stuff saved from the POST
117 private SAMLAssertion authenticationAssertion = null;
118 public SAMLAssertion getAuthenticationAssertion() {
119 return authenticationAssertion;
121 public void setAuthenticationAssertion(SAMLAssertion authentication) {
122 this.authenticationAssertion = authentication;
125 private SAMLAuthenticationStatement authenticationStatement=null;
126 public SAMLAuthenticationStatement getAuthenticationStatement() {
127 return authenticationStatement;
129 public void setAuthenticationStatement(
130 SAMLAuthenticationStatement authenticationStatement) {
131 this.authenticationStatement = authenticationStatement;
134 // Stuff saved from the Attribute Query
135 private SAMLResponse attributeResponse = null;
136 public SAMLResponse getAttributeResponse() {
137 return attributeResponse;
139 public void setAttributeResponse(SAMLResponse attributeResponse) {
140 this.attributeResponse = attributeResponse;
144 * Called by Session Manager when the Session is used. Reset the
148 lastused = System.currentTimeMillis();
151 public long getDefaultAttributeLifetime() {
152 return defaultAttributeLifetime;
155 public void setDefaultAttributeLifetime(long defaultAttributeLifetime) {
156 this.defaultAttributeLifetime = defaultAttributeLifetime;
159 public long getMaxSessionLife() {
160 return maxSessionLife;
163 public void setMaxSessionLife(long maxSessionLife) {
164 this.maxSessionLife = maxSessionLife;
167 public long getUnusedSessionTimeout() {
168 return unusedSessionTimeout;
171 public void setUnusedSessionTimeout(long unusedSessionTimeout) {
172 this.unusedSessionTimeout = unusedSessionTimeout;