Project

General

Profile

« Previous | Next » 

Revision 5070

Added by daigle over 14 years ago

Add user name to SessionData object

View differences:

src/edu/ucsb/nceas/metacat/service/SessionService.java
64 64
		
65 65
			logMetacat.debug("SessionService() - Registering public session id: " + 
66 66
					PUBLIC_SESSION_ID);
67
			registerSession(PUBLIC_SESSION_ID, "public", null, null);
67
			registerSession(PUBLIC_SESSION_ID, "public", null, null, "Public User");
68 68
		} catch (PropertyNotFoundException pnfe) {
69 69
			throw new ServiceException("SessionService() - Error getting property: " + 
70 70
					pnfe.getMessage());
......
112 112
	 *            the password for the session
113 113
	 */
114 114
	public static void registerSession(String sessionId, String userName,
115
			String[] groupNames, String password) throws ServiceException {
115
			String[] groupNames, String password, String name) throws ServiceException {
116 116
		if (sessionId == null) {
117 117
			throw new ServiceException("SessionService.registerSession - " + 
118 118
					"Cannot register a null session id");
119 119
		}
120 120
		logMetacat.debug("SessionService.registerSession - Registering session id: " + sessionId);
121 121
		SessionData sessionData = new SessionData(sessionId, userName, groupNames,
122
				password);
122
				password, name);
123 123
		sessionHash.put(sessionId, sessionData);
124 124
	}
125 125
	
......
146 146
	 *            the id of the session to remove.
147 147
	 */
148 148
	public static void unRegisterSession(String sessionId) {
149
		if (sessionId != null) {
149
		if (sessionId == null) {
150 150
			logMetacat.error("SessionService.unRegisterSession - trying to " + 
151 151
					"unregister a session with null id");
152
			sessionHash.remove(sessionId);
153 152
		}
153
		
154
		logMetacat.error("SessionService.unRegisterSession - unRegistering session: " + sessionId);
155
		sessionHash.remove(sessionId);
154 156
	}
155 157
	
156 158
	/**
......
186 188
		response.setContentType("text/xml");
187 189
		out.println("<?xml version=\"1.0\"?>");
188 190
		out.write("<validateSession><status>");
189
		if (sessionId != null && !sessionId.equals(PUBLIC_SESSION_ID) && isSessionRegistered(sessionId)) {
191
		if (validateSession(sessionId)) {
190 192
			out.write("valid");
191 193
		} else {
192 194
			out.write("invalid");
......
196 198
	}
197 199
	
198 200
	/**
201
	 * Check if a session is registered in the session hash table. Return
202
	 * true if the session is valid and false otherwise.
203
	 * 
204
	 * @param sessionId
205
	 *            the id of the session to look for.
206
	 */
207
	public static boolean validateSession(String sessionId) {				
208
		if (sessionId != null && !sessionId.equals(PUBLIC_SESSION_ID) && isSessionRegistered(sessionId)) {
209
			return true;
210
		} else {
211
			return false;
212
		}			
213
	}
214
	
215
	/**
199 216
	 * Get a registered session from the session hash table. 
200 217
	 * TODO MCD need to time sessions out
201 218
	 * 
src/edu/ucsb/nceas/metacat/util/AuthUtil.java
201 201
		SessionService.registerSession(sessionId, 
202 202
				(String) session.getAttribute("username"), 
203 203
				(String[]) session.getAttribute("groupnames"),
204
				(String) session.getAttribute("password"));
204
				(String) session.getAttribute("password"),
205
				(String) session.getAttribute("name"));
205 206
		} catch (ServiceException se) {
206 207
			throw new MetacatUtilException("Problem registering session: " + se.getMessage());
207 208
		}
src/edu/ucsb/nceas/metacat/util/SessionData.java
39 39
	private String userName = null;
40 40
	private String[] groupNames = null;
41 41
	private String password = null;
42
	private String name = null;
42 43
	private final Calendar creationTime = Calendar.getInstance();
43 44
	private Calendar lastAccessedTime = Calendar.getInstance();
44 45
	private DocumentCart documentCart = null;
......
51 52
	 * @param groupNames
52 53
	 * @param password
53 54
	 */
54
	public SessionData(String id, String userName, String[] groupNames, String password) {
55
	public SessionData(String id, String userName, String[] groupNames, String password, String name) {
55 56
		this.id = id;
56 57
		this.userName = userName;
57 58
		this.groupNames = groupNames;
58 59
		this.password = password;
60
		this.name = name;
59 61
	}
60 62
	
61 63
	public String getId() {
......
86 88
		this.password = password;
87 89
	}
88 90
	
91
	public String getName() {
92
		return name;
93
	}
94
	
95
	public void setName(String name) {
96
		this.name = name;
97
	}
98
	
89 99
	public Calendar getLastAccessedTime() {
90 100
		return lastAccessedTime;
91 101
	}
src/edu/ucsb/nceas/metacat/replication/ReplicationServlet.java
132 132
					}
133 133
				}
134 134
				if (sessionData == null) {
135
					sessionData = new SessionData(sess.getId(), (String) sess
136
							.getAttribute("username"), (String[]) sess
137
							.getAttribute("groups"), (String) sess
138
							.getAttribute("password"));
135
					sessionData = new SessionData(sess.getId(), 
136
							(String) sess.getAttribute("username"), 
137
							(String[]) sess.getAttribute("groups"),
138
							(String) sess.getAttribute("password"), 
139
							(String) sess.getAttribute("name"));
139 140
				}
140 141

  
141 142
				username = sessionData.getUserName();

Also available in: Unified diff