1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity.concurrent;
17
18 import org.springframework.util.Assert;
19
20 import java.util.Date;
21
22
23 /***
24 * Represents a record of a session within the Acegi Security framework.
25 *
26 * <p>
27 * This is primarily used for concurrent session support.
28 * </p>
29 *
30 * <p>
31 * Sessions have three states: active, expired, and destroyed. A session can
32 * that is invalidated by <code>session.invalidate()</code> or via Servlet
33 * Container management is considered "destroyed". An "expired" session, on
34 * the other hand, is a session that Acegi Security wants to end because it
35 * was selected for removal for some reason (generally as it was the least
36 * recently used session and the maximum sessions for the user were reached).
37 * An "expired" session is removed as soon as possible by a
38 * <code>Filter</code>.
39 * </p>
40 *
41 * @author Ben Alex
42 * @version $Id: SessionInformation.java,v 1.2 2005/11/17 00:55:56 benalex Exp $
43 */
44 public class SessionInformation {
45
46
47 private Date lastRequest;
48 private Object principal;
49 private String sessionId;
50 private boolean expired = false;
51
52
53
54 public SessionInformation(Object principal, String sessionId,
55 Date lastRequest) {
56 Assert.notNull(principal, "Principal required");
57 Assert.hasText(sessionId, "SessionId required");
58 Assert.notNull(lastRequest, "LastRequest required");
59 this.principal = principal;
60 this.sessionId = sessionId;
61 this.lastRequest = lastRequest;
62 }
63
64 private SessionInformation() {}
65
66
67
68 public boolean isExpired() {
69 return expired;
70 }
71
72 public Date getLastRequest() {
73 return lastRequest;
74 }
75
76 public Object getPrincipal() {
77 return principal;
78 }
79
80 public String getSessionId() {
81 return sessionId;
82 }
83
84 public void expireNow() {
85 this.expired = true;
86 }
87
88 /***
89 * Refreshes the internal lastRequest to the current date and time.
90 */
91 public void refreshLastRequest() {
92 this.lastRequest = new Date();
93 }
94 }