1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.shiro.session.mgt;
20
21 import org.apache.shiro.session.InvalidSessionException;
22 import org.apache.shiro.session.Session;
23
24 import java.io.Serializable;
25 import java.util.Collection;
26 import java.util.Date;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 public class DelegatingSession implements Session, Serializable {
44
45
46
47 private final SessionKey key;
48
49
50 private Date startTimestamp = null;
51 private String host = null;
52
53
54
55
56 private final transient NativeSessionManager sessionManager;
57
58
59 public DelegatingSession(NativeSessionManager sessionManager, SessionKey key) {
60 if (sessionManager == null) {
61 throw new IllegalArgumentException("sessionManager argument cannot be null.");
62 }
63 if (key == null) {
64 throw new IllegalArgumentException("sessionKey argument cannot be null.");
65 }
66 if (key.getSessionId() == null) {
67 String msg = "The " + DelegatingSession.class.getName() + " implementation requires that the " +
68 "SessionKey argument returns a non-null sessionId to support the " +
69 "Session.getId() invocations.";
70 throw new IllegalArgumentException(msg);
71 }
72 this.sessionManager = sessionManager;
73 this.key = key;
74 }
75
76
77
78
79 public Serializable getId() {
80 return key.getSessionId();
81 }
82
83
84
85
86 public Date getStartTimestamp() {
87 if (startTimestamp == null) {
88 startTimestamp = sessionManager.getStartTimestamp(key);
89 }
90 return startTimestamp;
91 }
92
93
94
95
96 public Date getLastAccessTime() {
97
98 return sessionManager.getLastAccessTime(key);
99 }
100
101 public long getTimeout() throws InvalidSessionException {
102 return sessionManager.getTimeout(key);
103 }
104
105 public void setTimeout(long maxIdleTimeInMillis) throws InvalidSessionException {
106 sessionManager.setTimeout(key, maxIdleTimeInMillis);
107 }
108
109 public String getHost() {
110 if (host == null) {
111 host = sessionManager.getHost(key);
112 }
113 return host;
114 }
115
116
117
118
119 public void touch() throws InvalidSessionException {
120 sessionManager.touch(key);
121 }
122
123
124
125
126 public void stop() throws InvalidSessionException {
127 sessionManager.stop(key);
128 }
129
130
131
132
133 public Collection<Object> getAttributeKeys() throws InvalidSessionException {
134 return sessionManager.getAttributeKeys(key);
135 }
136
137
138
139
140 public Object getAttribute(Object attributeKey) throws InvalidSessionException {
141 return sessionManager.getAttribute(this.key, attributeKey);
142 }
143
144
145
146
147 public void setAttribute(Object attributeKey, Object value) throws InvalidSessionException {
148 if (value == null) {
149 removeAttribute(attributeKey);
150 } else {
151 sessionManager.setAttribute(this.key, attributeKey, value);
152 }
153 }
154
155
156
157
158 public Object removeAttribute(Object attributeKey) throws InvalidSessionException {
159 return sessionManager.removeAttribute(this.key, attributeKey);
160 }
161 }