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