Hold Authentication and Attribute statements for a remote user.
[java-idp.git] / src / edu / internet2 / middleware / shibboleth / serviceprovider / Session.java
1 /*
2  * Session.java
3  * 
4  * Session object holds Principal ID [handle] and Attributes.
5  * A generated UUID is used as the object key in the Cache and
6  * is returned to the Browser as a Cookie value. 
7  *
8  * External Dependencies: jug.jar to generate UUID
9  * Recovery Context: No exceptions expected or generated.
10  * 
11  * --------------------
12  * Copyright 2002, 2004 
13  * University Corporation for Advanced Internet Development, Inc. 
14  * All rights reserved
15  * [Thats all we have to say to protect ourselves]
16  * Your permission to use this code is governed by "The Shibboleth License".
17  * A copy may be found at http://shibboleth.internet2.edu/license.html
18  * [Nothing in copyright law requires license text in every file.]
19  */
20 package edu.internet2.middleware.shibboleth.serviceprovider;
21
22 import java.io.Serializable;
23
24 import org.doomdark.uuid.UUIDGenerator;
25 import org.opensaml.SAMLAssertion;
26 import org.opensaml.SAMLAuthenticationStatement;
27 import org.opensaml.SAMLResponse;
28
29 /**
30  * Session object holds Authentication and Attribute Assertions for one
31  * remote Browser/User.<br>
32  * Each session generates its own UUID key.<br>
33  * The collection of Session objects may be checkpointed to disk using
34  * any attractive persistence framework, Object Relational mapping, 
35  * or, hell, just serialize the objects to a flat file if you like.
36  *
37  *  @author Howard Gilbert
38  */
39 public class Session implements Serializable {
40         
41         Session() {
42                 // Should only be created by SessionManager.newSession()
43         }
44         
45         // Properties
46         private String key = generateKey();
47         private String applicationId = null;
48         private String ipaddr = null;
49         private String entityId = null; // a.k.a providerId
50         public String getEntityId() {
51                 return entityId;
52         }
53         public void setEntityId(String entityId) {
54                 this.entityId = entityId;
55         }
56         private long lifetime;
57         private long timeout;
58         
59         public long getLifetime() {
60                 return lifetime;
61         }
62         public void setLifetime(long lifetime) {
63                 this.lifetime = lifetime;
64         }
65         public long getTimeout() {
66                 return timeout;
67         }
68         public void setTimeout(long timeout) {
69                 this.timeout = timeout;
70         }
71     // private persisted variable
72         private long timestamp = System.currentTimeMillis();
73         
74         
75         // Stuff saved from the POST
76         private SAMLAssertion authenticationAssertion = null;
77         private SAMLAuthenticationStatement authenticationStatement=null;
78         
79         // Stuff saved from the Attribute Query
80         private SAMLResponse attributeResponse = null;
81         /*
82          * Internal key generation logic. Designed not to fail.
83          * This is not the place to signal configuration problems.
84          * Sanity check the CLASSPATH long before you call down to here.
85          */
86         private static long terriblefallback = new java.util.Random().nextLong();
87         private static String generateKey() {
88                 try {
89                         // Note: performance can be improved by creating a synchonized
90                         // static UUIDGenerator preinitialized. 
91                         return UUIDGenerator.getInstance().generateTimeBasedUUID().toString();
92                 } catch (Throwable t) {
93                         // Probably the jug.jar file is missing in WEB-INF/lib
94                         // Generate a unique but easy to guess integer.
95                         return Long.toString(terriblefallback++);
96                 }
97         }
98
99         /**
100          * @return Returns the ipaddr.
101          */
102         public String getIpaddr() {
103                 return ipaddr;
104         }
105         /**
106          * @param ipaddr The ipaddr to set.
107          */
108         public void setIpaddr(String ipaddr) {
109                 this.ipaddr = ipaddr;
110         }
111         /**
112          * @return Returns the applicationId.
113          */
114         public String getApplicationId() {
115                 return applicationId;
116         }
117         /**
118          * @param applicationId The applicationId to set.
119          */
120         public void setApplicationId(String applicationId) {
121                 this.applicationId = applicationId;
122         }
123         /**
124          * @return Returns the key.
125          */
126         public String getKey() {
127                 return key;
128         }
129         public void renew(){
130                 timestamp = System.currentTimeMillis();
131         }
132         
133
134         public SAMLAssertion getAuthenticationAssertion() {
135                 return authenticationAssertion;
136         }
137         public void setAuthenticationAssertion(SAMLAssertion authentication) {
138                 this.authenticationAssertion = authentication;
139         }
140         public SAMLAuthenticationStatement getAuthenticationStatement() {
141                 return authenticationStatement;
142         }
143         public void setAuthenticationStatement(
144                         SAMLAuthenticationStatement authenticationStatement) {
145                 this.authenticationStatement = authenticationStatement;
146         }
147         public SAMLResponse getAttributeResponse() {
148                 return attributeResponse;
149         }
150         public void setAttributeResponse(SAMLResponse attributeResponse) {
151                 this.attributeResponse = attributeResponse;
152         }
153 }