/
StandardSession.java
2036 lines (1760 loc) · 69.5 KB
/
StandardSession.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 1997-2018 Oracle and/or its affiliates. All rights reserved.
* Copyright 2004 The Apache Software Foundation
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.catalina.session;
import static com.sun.logging.LogCleanerUtil.neutralizeForLog;
import com.sun.enterprise.spi.io.BaseIndirectlySerializable;
import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpSession;
import jakarta.servlet.http.HttpSessionActivationListener;
import jakarta.servlet.http.HttpSessionAttributeListener;
import jakarta.servlet.http.HttpSessionBindingEvent;
import jakarta.servlet.http.HttpSessionBindingListener;
import jakarta.servlet.http.HttpSessionEvent;
import jakarta.servlet.http.HttpSessionIdListener;
import jakarta.servlet.http.HttpSessionListener;
import java.io.IOException;
import java.io.NotSerializableException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.security.Principal;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.EventListener;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.catalina.ContainerEvent;
import org.apache.catalina.Context;
import org.apache.catalina.Globals;
import org.apache.catalina.LogFacade;
import org.apache.catalina.Manager;
import org.apache.catalina.Session;
import org.apache.catalina.SessionEvent;
import org.apache.catalina.SessionListener;
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.util.Enumerator;
/**
* Standard implementation of the <b>Session</b> interface. This object is serializable, so that it can be stored in
* persistent storage or transferred to a different JVM for distributable session support.
* <p>
* <b>IMPLEMENTATION NOTE</b>: An instance of this class represents both the internal (Session) and application level
* (HttpSession) view of the session. However, because the class itself is not declared public, Java logic outside of
* the <code>org.apache.catalina.session</code> package cannot cast an HttpSession view of this instance back to a
* Session view.
* <p>
* <b>IMPLEMENTATION NOTE</b>: If you add fields to this class, you must make sure that you carry them over in the
* read/writeObject methods so that this class is properly serialized.
*
* @author Craig R. McClanahan
* @author Sean Legassick
* @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
* @version $Revision: 1.33 $ $Date: 2007/03/12 21:41:52 $
*/
public class StandardSession implements HttpSession, Session, Serializable {
private static final Logger log = LogFacade.getLogger();
private static final ResourceBundle rb = log.getResourceBundle();
// ----------------------------------------------------------- Constructors
/**
* Construct a new Session associated with the specified Manager.
*
* @param manager The manager with which this Session is associated
*/
public StandardSession(Manager manager) {
super();
setManager(manager);
if (manager instanceof ManagerBase) {
this.debug = ((ManagerBase) manager).getDebug();
}
}
// ----------------------------------------------------- Class Variables
/**
* Type array.
*/
protected static final String EMPTY_ARRAY[] = new String[0];
/**
* The dummy attribute value serialized when a NotSerializableException is encountered in <code>writeObject()</code>.
*/
protected static final String NOT_SERIALIZED = "___NOT_SERIALIZABLE_EXCEPTION___";
// HERCULES:add
/**
* The string used in the name for setAttribute and removeAttribute to signify on-demand sync
*/
protected static final String SYNC_STRING = "com.sun.sync";
// end HERCULES:add
/**
* The method signature for the <code>fireContainerEvent</code> method.
*/
static final Class<?> containerEventTypes[] = { String.class, Object.class };
/**
* Descriptive information describing this Session implementation.
*/
protected static final String info = "StandardSession/1.0";
/**
* Set of attribute names which are not allowed to be persisted.
*/
private static final String[] excludedAttributes = { Globals.SUBJECT_ATTR };
/**
* Used for serialized format versioning. 1 = first version where this is being tracked.
*
* NOTE: You must increment this version whenever any changes are made to the serialized representation of this class
* between releases
*/
private static final Short SERIALIZED_FORM_VERSION = Short.valueOf("1");
// ----------------------------------------------------- Instance Variables
/**
* The session identifier of the parent SipApplicationSession, if any
*/
private String sipAppSessionId = null;
/**
* The BEKEY of this session, or <tt>null</tt>.
*
* <p>
* The BEKEY is used by the Converged Loadbalancer (CLB) in DCR mode for loadbalancing purposes, and supplied to the web
* container in the form of a request header.
*
* <p>
* See https://sailfin.dev.java.net/issues/show_bug.cgi?id=1647 for additional details
*/
private String beKey;
/**
* The collection of user data attributes associated with this Session.
*/
protected Map<String, Object> attributes = new ConcurrentHashMap<String, Object>();
/**
* The authentication type used to authenticate our cached Principal, if any. NOTE: This value is not included in the
* serialized version of this object.
*/
protected transient String authType = null;
/**
* The <code>java.lang.Method</code> for the <code>fireContainerEvent()</code> method of the
* <code>org.apache.catalina.core.StandardContext</code> method, if our Context implementation is of this class. This
* value is computed dynamically the first time it is needed, or after a session reload (since it is declared
* transient).
*/
protected transient Method containerEventMethod = null;
/**
* The time this session was created, in milliseconds since midnight, January 1, 1970 GMT.
*/
protected long creationTime = 0L;
/**
* The debugging detail level for this component. NOTE: This value is not included in the serialized version of this
* object.
*/
protected transient int debug = 0;
/**
* We are currently processing a session expiration, so bypass certain IllegalStateException tests. NOTE: This value is
* not included in the serialized version of this object.
*/
protected transient boolean expiring = false;
/**
* The facade associated with this session. NOTE: This value is not included in the serialized version of this object.
*/
protected transient StandardSessionFacade facade = null;
/**
* The session identifier of this Session.
*/
protected String id = null;
/**
* The last accessed time for this Session.
*/
protected long lastAccessedTime = creationTime;
/**
* The session event listeners for this Session.
*/
protected transient ArrayList<SessionListener> listeners = new ArrayList<SessionListener>();
/**
* The Manager with which this Session is associated.
*/
protected transient Manager manager = null;
/**
* The context with which this Session is associated.
*/
protected transient StandardContext context = null;
/**
* The maximum time interval, in seconds, between client requests before the servlet container may invalidate this
* session. A negative time indicates that the session should never time out.
*/
protected int maxInactiveInterval = -1;
/**
* Flag indicating whether this session is new or not.
*/
protected boolean isNew = false;
/**
* Flag indicating whether this session is valid or not.
*/
protected boolean isValid = false;
/**
* Internal notes associated with this session by Catalina components and event listeners. <b>IMPLEMENTATION NOTE:</b>
* This object is <em>not</em> saved and restored across session serializations!
*/
protected transient Map<String, Object> notes = new Hashtable<String, Object>();
/**
* The authenticated Principal associated with this session, if any. // START SJSWS 6371339 // * <b>IMPLEMENTATION
* NOTE:</b> This object is <i>not</i> saved and // * restored across session serializations! // END SJSWS 6371339
*/
protected transient Principal principal = null;
/**
* The current accessed time for this session.
*/
protected long thisAccessedTime = creationTime;
/**
* The session version, incremented and used by in-memory-replicating session managers
*/
protected AtomicLong version = new AtomicLong(-1);
/**
* single sign on id. It is null if there is no SSO.
*/
protected String ssoId = null;
/**
* single sign on version.
*/
protected volatile long ssoVersion = 0L;
// ----------------------------------------------------- Session Properties
/**
* Return the authentication type used to authenticate our cached Principal, if any.
*/
@Override
public String getAuthType() {
return (this.authType);
}
/**
* Set the authentication type used to authenticate our cached Principal, if any.
*
* @param authType The new cached authentication type
*/
@Override
public void setAuthType(String authType) {
this.authType = authType;
}
/**
* Set the creation time for this session. This method is called by the Manager when an existing Session instance is
* reused.
*
* @param time The new creation time
*/
@Override
public void setCreationTime(long time) {
this.creationTime = time;
this.lastAccessedTime = time;
this.thisAccessedTime = time;
}
/**
* Return the session identifier for this session.
*/
@Override
public String getId() {
return getIdInternal();
}
/**
* Return the session identifier for this session.
*/
@Override
public String getIdInternal() {
return (this.id);
}
/**
* Set the session identifier for this session.
*
* @param id The new session identifier
*/
@Override
public void setId(String id) {
if ((this.id != null) && (manager != null))
manager.remove(this);
String oldId = this.id;
this.id = id;
if (manager != null)
manager.add(this);
// Notify interested session event listeners
if (oldId == null) { // the session is just created
tellNew();
} else { // change session id
HttpSessionEvent event = null;
List<EventListener> listeners = context.getApplicationEventListeners();
if (listeners.isEmpty()) {
return;
}
Iterator<EventListener> iter = listeners.iterator();
while (iter.hasNext()) {
EventListener eventListener = iter.next();
if (!(eventListener instanceof HttpSessionIdListener)) {
continue;
}
HttpSessionIdListener listener = (HttpSessionIdListener) eventListener;
try {
fireContainerEvent(context, "beforeSessionIdChanged", listener);
if (event == null) {
event = new HttpSessionEvent(getSession());
}
listener.sessionIdChanged(event, oldId);
fireContainerEvent(context, "afterSessionIdChanged", listener);
} catch (Throwable t) {
try {
fireContainerEvent(context, "afterSessionIdChanged", listener);
} catch (Exception e) {
// Ignore
}
log(rb.getString(LogFacade.SESSION_ID_CHANGE_EVENT_LISTENER_EXCEPTION), t);
}
}
}
}
/**
* Sets the BEKEY for this session
*
* <p>
* The BEKEY is used by the Converged Loadbalancer (CLB) in DCR mode for loadbalancing purposes, and supplied to the web
* container in the form of a request header.
*
* @param beKey the BEKEY for this session, or <tt>null</tt> if not present
*/
public void setBeKey(String beKey) {
this.beKey = beKey;
}
/**
* Gets the BEKEY of this session
*
* @return the BEKEY of this session, or <tt>null</tt> if not present
*/
public String getBeKey() {
return beKey;
}
/**
* Sets the id of the SipApplicationSession that is the parent of this StandardSession.
*
* @param id SipApplicationSession id
*/
public void setSipApplicationSessionId(String id) {
sipAppSessionId = id;
}
/**
* Gets the id of the SipApplicationSession that is the parent of this StandardSession.
*
* @return The SipApplicationSession id, or null if this StandardSession does not have any SipApplicationSession parent
*/
public String getSipApplicationSessionId() {
return sipAppSessionId;
}
/**
* Inform the listeners about the new session.
*
*/
public void tellNew() {
// Notify interested session event listeners
fireSessionEvent(Session.SESSION_CREATED_EVENT, null);
HttpSessionEvent event = new HttpSessionEvent(getSession());
// Notify interested application event listeners
for (HttpSessionListener listener : context.getSessionListeners()) {
try {
fireContainerEvent(context, "beforeSessionCreated", listener);
listener.sessionCreated(event);
fireContainerEvent(context, "afterSessionCreated", listener);
} catch (Throwable t) {
try {
fireContainerEvent(context, "afterSessionCreated", listener);
} catch (Exception e) {
// Ignore
}
log(rb.getString(LogFacade.SESSION_EVENT_LISTENER_EXCEPTION), t);
}
}
}
/**
* Return descriptive information about this Session implementation and the corresponding version number, in the format
* <code><description>/<version></code>.
*/
@Override
public String getInfo() {
return (this.info);
}
/**
* Return the last time the client sent a request associated with this session, as the number of milliseconds since
* midnight, January 1, 1970 GMT. Actions that your application takes, such as getting or setting a value associated
* with the session, do not affect the access time.
*/
@Override
public long getLastAccessedTime() {
if (!isValid()) {
throw new IllegalStateException("getLastAccessedTime: " + rb.getString(LogFacade.SESSION_INVALIDATED_EXCEPTION));
}
return (this.lastAccessedTime);
}
// START SJSAS 6470831
/**
* Same as getLastAccessedTime(), except that there is no call to isValid(), which may expire the session and cause any
* subsequent session access to throw an IllegalStateException.
*/
public long getLastAccessedTimeInternal() {
return this.lastAccessedTime;
}
// END SJSAS 6470831
/**
* Set the last time the client sent a request associated with this session, as the number of milliseconds since
* midnight, January 1, 1970 GMT. Actions that your application takes, such as getting or setting a value associated
* with the session, do not affect the access time. HERCULES: added method
*/
public void setLastAccessedTime(long lastAcessedTime) {
this.lastAccessedTime = lastAcessedTime;
}
/**
* Return the Manager within which this Session is valid.
*/
@Override
public Manager getManager() {
return (this.manager);
}
/**
* Set the Manager within which this Session is valid.
*
* @param manager The new Manager
*/
@Override
public void setManager(Manager manager) {
this.manager = manager;
context = (StandardContext) manager.getContainer();
}
/**
* Return the maximum time interval, in seconds, between client requests before the servlet container will invalidate
* the session. A negative time indicates that the session should never time out.
*/
@Override
public int getMaxInactiveInterval() {
return (this.maxInactiveInterval);
}
/**
* Set the maximum time interval, in seconds, between client requests before the servlet container will invalidate the
* session. A negative time indicates that the session should never time out.
*
* @param interval The new maximum interval
*/
@Override
public void setMaxInactiveInterval(int interval) {
this.maxInactiveInterval = interval;
if (isValid && interval == 0) {
expire();
}
}
/**
* Set the <code>isNew</code> flag for this session.
*
* @param isNew The new value for the <code>isNew</code> flag
*/
@Override
public void setNew(boolean isNew) {
this.isNew = isNew;
}
/**
* Return the authenticated Principal that is associated with this Session. This provides an <code>Authenticator</code>
* with a means to cache a previously authenticated Principal, and avoid potentially expensive
* <code>Realm.authenticate()</code> calls on every request. If there is no current associated Principal, return
* <code>null</code>.
*/
@Override
public Principal getPrincipal() {
return (this.principal);
}
/**
* Set the authenticated Principal that is associated with this Session. This provides an <code>Authenticator</code>
* with a means to cache a previously authenticated Principal, and avoid potentially expensive
* <code>Realm.authenticate()</code> calls on every request.
*
* @param principal The new Principal, or <code>null</code> if none
*/
@Override
public void setPrincipal(Principal principal) {
this.principal = principal;
}
/**
* Return the <code>HttpSession</code> for which this object is the facade.
*/
@Override
public HttpSession getSession() {
if (facade == null) {
facade = new StandardSessionFacade(this);
}
return facade;
}
/**
* Return the <code>isValid</code> flag for this session.
*/
@Override
public boolean isValid() {
if (expiring) {
return true;
}
if (!isValid) {
return false;
}
if (isForegroundLocked()) {
return true;
}
if (hasExpired()) {
expire(true);
}
return isValid;
}
@Override
public boolean getIsValid() {
return isValid;
}
/**
* Set the <code>isValid</code> flag for this session.
*
* @param isValid The new value for the <code>isValid</code> flag
*/
@Override
public void setValid(boolean isValid) {
this.isValid = isValid;
if (!isValid && (getManager() instanceof PersistentManagerBase)) {
((PersistentManagerBase) getManager()).addToInvalidatedSessions(this.id);
}
}
// ------------------------------------------------- Session Public Methods
/**
* Update the accessed time information for this session. This method should be called by the context when a request
* comes in for a particular session, even if the application does not reference it.
*/
@Override
public void access() {
this.lastAccessedTime = this.thisAccessedTime;
this.thisAccessedTime = System.currentTimeMillis();
evaluateIfValid();
}
/**
* End the access.
*/
@Override
public void endAccess() {
isNew = false;
}
/**
* Add a session event listener to this component.
*/
@Override
public void addSessionListener(SessionListener listener) {
synchronized (listeners) {
listeners.add(listener);
}
}
/**
* Perform the internal processing required to invalidate this session, without triggering an exception if the session
* has already expired.
*/
@Override
public void expire() {
expire(true);
}
/**
* Perform the internal processing required to invalidate this session, without triggering an exception if the session
* has already expired.
*
* @param notify Should we notify listeners about the demise of this session?
*/
public void expire(boolean notify) {
expire(notify, true);
}
/**
* Perform the internal processing required to invalidate this session, without triggering an exception if the session
* has already expired.
*
* @param notify Should we notify listeners about the demise of this session?
* @param persistentRemove should we call store to remove the session if available
*/
public void expire(boolean notify, boolean persistentRemove) {
// Mark this session as "being expired" if needed
if (expiring)
return;
synchronized (this) {
if (manager == null)
return;
expiring = true;
// Notify interested application event listeners
// FIXME - Assumes we call listeners in reverse order
// The call to expire() may not have been triggered by the webapp.
// Make sure the webapp's class loader is set when calling the
// listeners
ClassLoader oldTccl = null;
if (context.getLoader() != null && context.getLoader().getClassLoader() != null) {
oldTccl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(context.getLoader().getClassLoader());
}
try {
List<HttpSessionListener> listeners = context.getSessionListeners();
if (notify && !listeners.isEmpty()) {
HttpSessionEvent event = new HttpSessionEvent(getSession());
int len = listeners.size();
for (int i = 0; i < len; i++) {
// Invoke in reverse order of declaration
HttpSessionListener listener = listeners.get((len - 1) - i);
try {
fireContainerEvent(context, "beforeSessionDestroyed", listener);
listener.sessionDestroyed(event);
fireContainerEvent(context, "afterSessionDestroyed", listener);
} catch (Throwable t) {
try {
fireContainerEvent(context, "afterSessionDestroyed", listener);
} catch (Exception e) {
// Ignore
}
// FIXME - should we do anything besides log these?
log(rb.getString(LogFacade.SESSION_EVENT_LISTENER_EXCEPTION), t);
}
}
}
} finally {
if (oldTccl != null) {
Thread.currentThread().setContextClassLoader(oldTccl);
}
}
setValid(false);
/*
* Compute how long this session has been alive, and update session manager's related properties accordingly
*/
long timeNow = System.currentTimeMillis();
int timeAlive = (int) ((timeNow - creationTime) / 1000);
synchronized (manager) {
if (timeAlive > manager.getSessionMaxAliveTimeSeconds()) {
manager.setSessionMaxAliveTimeSeconds(timeAlive);
}
int numExpired = manager.getExpiredSessions();
numExpired++;
manager.setExpiredSessions(numExpired);
int average = manager.getSessionAverageAliveTimeSeconds();
average = ((average * (numExpired - 1)) + timeAlive) / numExpired;
manager.setSessionAverageAliveTimeSeconds(average);
}
// Remove this session from our manager's active sessions
if (persistentRemove) {
manager.remove(this);
} else {
if (manager instanceof PersistentManagerBase) {
((PersistentManagerBase) manager).remove(this, false);
}
}
/*
* Mark session as expired *before* removing its attributes, so that its HttpSessionBindingListener objects will get an
* IllegalStateException when accessing the session attributes from within their valueUnbound() method
*/
expiring = false;
// Unbind any objects associated with this session
String keys[] = keys();
for (int i = 0; i < keys.length; i++)
removeAttribute(keys[i], notify, false);
// Notify interested session event listeners
if (notify) {
context.sessionExpiredEvent(this);
fireSessionEvent(Session.SESSION_DESTROYED_EVENT, null);
}
}
}
/**
* Perform the internal processing required to passivate this session.
*/
public void passivate() {
context.sessionPassivatedStartEvent(this);
try {
// Notify ActivationListeners
HttpSessionEvent event = null;
String keys[] = keys();
for (int i = 0; i < keys.length; i++) {
Object attribute = getAttributeInternal(keys[i]);
if (attribute instanceof HttpSessionActivationListener) {
if (event == null)
event = new HttpSessionEvent(getSession());
// FIXME: Should we catch throwables?
((HttpSessionActivationListener) attribute).sessionWillPassivate(event);
}
}
} finally {
context.sessionPassivatedEndEvent(this);
}
}
/**
* Perform internal processing required to activate this session.
*/
public void activate() {
context.sessionActivatedStartEvent(this);
try {
// Notify ActivationListeners
HttpSessionEvent event = null;
String keys[] = keys();
for (int i = 0; i < keys.length; i++) {
Object attribute = getAttributeInternal(keys[i]);
if (attribute instanceof HttpSessionActivationListener) {
if (event == null)
event = new HttpSessionEvent(getSession());
// FIXME: Should we catch throwables?
((HttpSessionActivationListener) attribute).sessionDidActivate(event);
}
}
} finally {
context.sessionActivatedEndEvent(this);
}
}
/**
* Return the object bound with the specified name to the internal notes for this session, or <code>null</code> if no
* such binding exists.
*
* @param name Name of the note to be returned
*/
@Override
public Object getNote(String name) {
return (notes.get(name));
}
/**
* Return an Iterator containing the String names of all notes bindings that exist for this session.
*/
@Override
public Iterator<String> getNoteNames() {
return (notes.keySet().iterator());
}
/**
* Release all object references, and initialize instance variables, in preparation for reuse of this object.
*/
@Override
public void recycle() {
// Reset the instance variables associated with this Session
attributes.clear();
setAuthType(null);
creationTime = 0L;
expiring = false;
id = null;
lastAccessedTime = 0L;
maxInactiveInterval = -1;
notes.clear();
setPrincipal(null);
isNew = false;
isValid = false;
listeners.clear();
manager = null;
}
/**
* Remove any object bound to the specified name in the internal notes for this session.
*
* @param name Name of the note to be removed
*/
@Override
public void removeNote(String name) {
notes.remove(name);
}
/**
* Remove a session event listener from this component.
*/
@Override
public void removeSessionListener(SessionListener listener) {
synchronized (listeners) {
listeners.remove(listener);
}
}
/**
* Bind an object to a specified name in the internal notes associated with this session, replacing any existing binding
* for this name.
*
* @param name Name to which the object should be bound
* @param value Object to be bound to the specified name
*/
@Override
public void setNote(String name, Object value) {
notes.put(name, value);
}
// START SJSAS 6329289
/**
* Checks whether this Session has expired.
*
* @return true if this Session has expired, false otherwise
*/
@Override
public boolean hasExpired() {
if (maxInactiveInterval >= 0 && (System.currentTimeMillis() - thisAccessedTime >= maxInactiveInterval * 1000L)) {
return true;
} else {
return false;
}
}
// END SJSAS 6329289
/**
* Increments the version number
*/
public long incrementVersion() {
return version.incrementAndGet();
}
/**
* Gets the version number
*/
@Override
public long getVersion() {
return version.get();
}
/**
* Sets the version number
*/
public void setVersion(long value) {
version.set(value);
}
/**
* Return the single sign on id. It is null if there is no SSO.
*/
@Override
public String getSsoId() {
return ssoId;
}
/**
* Set the single sign on id.
*/
@Override
public void setSsoId(String ssoId) {
this.ssoId = ssoId;
}
/**
* Return the single sign on version.
*/
@Override
public long getSsoVersion() {
return ssoVersion;
}
/**
* Set the single sign on version.
*/
@Override
public void setSsoVersion(long value) {
ssoVersion = value;
}
/**