|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| SessionInformation.java | - | 100% | 87.5% | 95% |
|
||||||||||||||
| 1 | /* Copyright 2004, 2005 Acegi Technology Pty Limited | |
| 2 | * | |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 | * you may not use this file except in compliance with the License. | |
| 5 | * You may obtain a copy of the License at | |
| 6 | * | |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 | * | |
| 9 | * Unless required by applicable law or agreed to in writing, software | |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 | * See the License for the specific language governing permissions and | |
| 13 | * limitations under the License. | |
| 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 | //~ Instance fields ======================================================== | |
| 46 | ||
| 47 | private Date lastRequest; | |
| 48 | private Object principal; | |
| 49 | private String sessionId; | |
| 50 | private boolean expired = false; | |
| 51 | ||
| 52 | //~ Constructors =========================================================== | |
| 53 | ||
| 54 | 12 | public SessionInformation(Object principal, String sessionId, |
| 55 | Date lastRequest) { | |
| 56 | 12 | Assert.notNull(principal, "Principal required"); |
| 57 | 12 | Assert.hasText(sessionId, "SessionId required"); |
| 58 | 12 | Assert.notNull(lastRequest, "LastRequest required"); |
| 59 | 12 | this.principal = principal; |
| 60 | 12 | this.sessionId = sessionId; |
| 61 | 12 | this.lastRequest = lastRequest; |
| 62 | } | |
| 63 | ||
| 64 | 0 | private SessionInformation() {} |
| 65 | ||
| 66 | //~ Methods ================================================================ | |
| 67 | ||
| 68 | 8 | public boolean isExpired() { |
| 69 | 8 | return expired; |
| 70 | } | |
| 71 | ||
| 72 | 8 | public Date getLastRequest() { |
| 73 | 8 | return lastRequest; |
| 74 | } | |
| 75 | ||
| 76 | 11 | public Object getPrincipal() { |
| 77 | 11 | return principal; |
| 78 | } | |
| 79 | ||
| 80 | 10 | public String getSessionId() { |
| 81 | 10 | return sessionId; |
| 82 | } | |
| 83 | ||
| 84 | 3 | public void expireNow() { |
| 85 | 3 | this.expired = true; |
| 86 | } | |
| 87 | ||
| 88 | /** | |
| 89 | * Refreshes the internal lastRequest to the current date and time. | |
| 90 | */ | |
| 91 | 3 | public void refreshLastRequest() { |
| 92 | 3 | this.lastRequest = new Date(); |
| 93 | } | |
| 94 | } |
|
||||||||||