Project

General

Profile

« Previous | Next » 

Revision 5374

Added by berkley almost 14 years ago

refactored the sessionService to use a correct singleton initialization scheme. Added true authentication to ResourceHandler.

View differences:

SessionService.java
82 82
	 * 
83 83
	 * @return the single instance of SessionService
84 84
	 */
85
	public static SessionService getInstance() throws ServiceException {
86
		if (sessionService == null) {
87
			sessionService = new SessionService();
88
		}
89
		return sessionService;
85
	public static SessionService getInstance() {
86
	    try
87
	    {
88
	        if (sessionService == null) {
89
	            sessionService = new SessionService();
90
	        }
91
	        return sessionService;
92
	    }
93
	    catch(ServiceException se)
94
	    {
95
	        logMetacat.error("SessionService.getInstance - could not get " +
96
	                "an instance of SessionService: " + se.getMessage());
97
	    }
98
		return null;
90 99
	}
91 100
	
92 101
	public boolean refreshable() {
......
114 123
	 * @param password
115 124
	 *            the password for the session
116 125
	 */
117
	public static void registerSession(String sessionId, String userName,
126
	public void registerSession(String sessionId, String userName,
118 127
			String[] groupNames, String password, String name) throws ServiceException {
119 128
		synchronized(lockObj) {
120 129
			if (sessionId == null) {
......
134 143
	 * @param sessionData
135 144
	 *            the session data object to add to the session hash
136 145
	 */
137
	public static void registerSession(SessionData sessionData) throws ServiceException {
146
	public void registerSession(SessionData sessionData) throws ServiceException {
138 147
		synchronized(lockObj) {
139 148
			if (sessionData == null) {
140 149
				throw new ServiceException("SessionService.registerSession - " + 
......
152 161
	 * @param sessionId
153 162
	 *            the id of the session to remove.
154 163
	 */
155
	public static void unRegisterSession(String sessionId) {
164
	public void unRegisterSession(String sessionId) {
156 165
		synchronized(lockObj) {
157 166
			if (sessionId == null) {
158 167
				logMetacat.error("SessionService.unRegisterSession - trying to " + 
......
170 179
	 * @param sessionId
171 180
	 *            the id of the session to remove.
172 181
	 */
173
	public static void unRegisterAllSessions() {
182
	public void unRegisterAllSessions() {
174 183
		synchronized(lockObj) {
175 184
			Enumeration<String> keyEnum = sessionHash.keys();
176 185
			while (keyEnum.hasMoreElements()) {
......
189 198
	 * @param sessionId
190 199
	 *            the id of the session to look for.
191 200
	 */
192
	public static boolean isSessionRegistered(String sessionId) {		
201
	public boolean isSessionRegistered(String sessionId) {		
193 202
		if (sessionId == null) {
194 203
			logMetacat.error("SessionService.isSessionRegistered - trying to check if a " + 
195 204
					"session with null id is registered");
......
210 219
	 * @param sessionId
211 220
	 *            the id of the session to look for.
212 221
	 */
213
	public static void validateSession(PrintWriter out, HttpServletResponse response, 
222
	public void validateSession(PrintWriter out, HttpServletResponse response, 
214 223
			String sessionId) {		
215 224
		
216 225
		response.setContentType("text/xml");
......
232 241
	 * @param sessionId
233 242
	 *            the id of the session to look for.
234 243
	 */
235
	public static boolean validateSession(String sessionId) {				
244
	public boolean validateSession(String sessionId) {				
236 245
		if (sessionId != null && !sessionId.equals(PUBLIC_SESSION_ID) && isSessionRegistered(sessionId)) {
237 246
			return true;
238 247
		} else {
......
247 256
	 * @param sessionId
248 257
	 *            the id of the session to retrieve.
249 258
	 */
250
	public static SessionData getRegisteredSession(String sessionId) {
259
	public SessionData getRegisteredSession(String sessionId) {
251 260
		if (sessionId == null) {
252 261
			logMetacat.error("SessionService.getRegisteredSession - trying to get a session with null id");
253 262
			return null;
......
260 269
	/**
261 270
	 * Get the public session from the session hash table. 
262 271
	 */
263
	public static SessionData getPublicSession() {
272
	public SessionData getPublicSession() {
264 273
		return sessionHash.get(PUBLIC_SESSION_ID);
265 274
	}
266 275
	
......
270 279
	 * @param sessionId
271 280
	 *            the id of the session to update.
272 281
	 */
273
	public static synchronized void touchSession(String sessionId) {
282
	public synchronized void touchSession(String sessionId) {
274 283
		if (sessionId == null) {
275 284
			logMetacat.error("SessionService.touchSession - trying to touch a session with null id");
276 285
		} else if (isSessionRegistered(sessionId)) {
......
281 290
		}
282 291
	}
283 292
	
284
	private static void checkTimeout (String sessionId) {
293
	private void checkTimeout (String sessionId) {
285 294
		SessionData sessionData = null;
286 295
		if ((sessionData = sessionHash.get(sessionId)) != null) {
287 296
			Calendar expireTime = Calendar.getInstance();

Also available in: Unified diff