001 /*
002 * SessionImpl.java
003 *
004 * Copyright (c) 1995-2010, The University of Sheffield. See the file
005 * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
006 *
007 * This file is part of GATE (see http://gate.ac.uk/), and is free
008 * software, licenced under the GNU Library General Public License,
009 * Version 2, June 1991 (in the distribution as file licence.html,
010 * and also available at http://gate.ac.uk/gate/licence.html).
011 *
012 * Marin Dimitrov, 19/Sep/2001
013 *
014 * $Id: SessionImpl.java 12006 2009-12-01 17:24:28Z thomas_heitz $
015 */
016
017 package gate.security;
018
019 import junit.framework.Assert;
020
021 public class SessionImpl implements Session {
022
023 /** ID of the session */
024 private Long id;
025
026 /** User associated with the session */
027 private User user;
028
029 /** Group associated with the session
030 * a user may be member of many groups, but at
031 * login time only one could be specified */
032 private Group group;
033
034 /** sesion timeout (in minutes)
035 * @see AccessControllerImpl#DEFAULT_SESSION_TIMEOUT_MIN
036 * */
037 private int timeout;
038
039 /** TRUE if user associated with the session is in the
040 * ADMINS user group, otherwise FALSE */
041 private boolean isPrivileged;
042
043 /** --- */
044 public SessionImpl(Long id,User usr,Group grp, int timeout, boolean isPrivileged) {
045
046 this.id = id;
047 this.user = usr;
048 this.group = grp;
049 this.timeout = timeout;
050 this.isPrivileged = isPrivileged;
051 }
052
053 /* Session interface */
054
055 /** returns the session ID */
056 public Long getID() {
057
058 return this.id;
059 }
060
061 /** returns the user associated with the session */
062 public User getUser() {
063
064 return this.user;
065 }
066
067 /**
068 * returns the group associated with the session
069 * a user may be member of many groups, but at
070 * login time only one could be specified
071 *
072 */
073 public Group getGroup() {
074
075 return this.group;
076 }
077
078 /** TRUE if user associated with the session is in the
079 * ADMINS user group, otherwise FALSE */
080 public boolean isPrivilegedSession() {
081
082 return this.isPrivileged;
083 }
084
085
086
087 /* misc methods */
088
089
090 /** returns the timeout (in minutes) of the session
091 *
092 * @see AccessControllerImpl#DEFAULT_SESSION_TIMEOUT_MIN
093 *
094 * */
095 public int getTimeout() {
096
097 return this.timeout;
098 }
099
100
101 /**
102 *
103 * this one is necessary for the contains() operations in Lists
104 * It is possible that two users have two different GroupImpl that refer
105 * to the very same GATE group in the DB, because they got it from the security
106 * factory at different times. So we assume that two instances refer the same
107 * GATE group if NAME1==NAME2
108 *
109 * */
110 public boolean equals(Object obj)
111 {
112 Assert.assertTrue(obj instanceof Session);
113
114 Session s2 = (Session)obj;
115
116 return (this.id.equals(s2.getID()));
117 }
118
119 }
|