1   /*
2    *  SessionImpl.java
3    *
4    *  Copyright (c) 1998-2005, The University of Sheffield.
5    *
6    *  This file is part of GATE (see http://gate.ac.uk/), and is free
7    *  software, licenced under the GNU Library General Public License,
8    *  Version 2, June 1991 (in the distribution as file licence.html,
9    *  and also available at http://gate.ac.uk/gate/licence.html).
10   *
11   *  Marin Dimitrov, 19/Sep/2001
12   *
13   *  $Id: SessionImpl.java,v 1.11 2005/01/11 13:51:36 ian Exp $
14   */
15  
16  package gate.security;
17  
18  import junit.framework.Assert;
19  
20  public class SessionImpl implements Session {
21  
22    /** ID of the session */
23    private Long  id;
24  
25    /** User associated with the session */
26    private User  user;
27  
28    /** Group associated with the session
29     *  a user may be member of many groups, but at
30     *  login time only one could be specified */
31    private Group group;
32  
33    /** sesion timeout (in minutes)
34     *  @see  AccessControllerImpl#DEFAULT_SESSION_TIMEOUT_MIN
35     *  */
36    private int   timeout;
37  
38    /** TRUE if user associated with the session is in the
39     *  ADMINS user group, otherwise FALSE */
40    private boolean isPrivileged;
41  
42    /** --- */
43    public SessionImpl(Long id,User usr,Group grp, int timeout, boolean isPrivileged) {
44  
45      this.id = id;
46      this.user = usr;
47      this.group = grp;
48      this.timeout = timeout;
49      this.isPrivileged = isPrivileged;
50    }
51  
52    /* Session interface */
53  
54    /** returns the session ID */
55    public Long getID() {
56  
57      return this.id;
58    }
59  
60    /** returns the user associated with the session */
61    public User getUser() {
62  
63      return this.user;
64    }
65  
66    /**
67     *  returns the group associated with the session
68     *  a user may be member of many groups, but at
69     *  login time only one could be specified
70     *
71     */
72    public Group getGroup() {
73  
74      return this.group;
75    }
76  
77    /** TRUE if user associated with the session is in the
78     *  ADMINS user group, otherwise FALSE */
79    public boolean isPrivilegedSession() {
80  
81      return this.isPrivileged;
82    }
83  
84  
85  
86    /* misc methods */
87  
88  
89    /** returns the timeout (in minutes) of the session
90     *
91     *  @see  AccessControllerImpl#DEFAULT_SESSION_TIMEOUT_MIN
92     *
93     *  */
94    public int getTimeout() {
95  
96      return this.timeout;
97    }
98  
99  
100   /**
101    *
102    *  this one is necessary for the contains() operations in Lists
103    *  It is possible that two users have two different GroupImpl that refer
104    *  to the very same GATE group in the DB, because they got it from the security
105    *  factory at different times. So we assume that two instances refer the same
106    *  GATE group if NAME1==NAME2
107    *
108    *  */
109   public boolean equals(Object obj)
110   {
111     Assert.assertTrue(obj instanceof Session);
112 
113     Session s2 = (Session)obj;
114 
115     return (this.id.equals(s2.getID()));
116   }
117 
118 }
119