01: /**
02: * Copyright (C) 2006, 2007 David Bulmore, Software Sensation Inc.
03: * All Rights Reserved.
04: *
05: * This file is part of jCommonTk.
06: *
07: * jCommonTk is free software; you can redistribute it and/or modify it under
08: * the terms of the GNU General Public License (Version 2) as published by
09: * the Free Software Foundation.
10: *
11: * jCommonTk is distributed in the hope that it will be useful, but WITHOUT
12: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14: * for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with jCommonTk; if not, write to the Free Software Foundation,
18: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19: */package jcommontk.utils;
20:
21: public class ServerSecurity {
22: ExpiringHashtable security_objs;
23: NullObject null_object = new NullObject();
24:
25: public ServerSecurity(long expiration_time) {
26: security_objs = new ExpiringHashtable(expiration_time);
27: }
28:
29: static class NullObject {
30: }
31:
32: public String getNewSecurityId(String suffix, Object security_obj) {
33: if (security_obj == null)
34: security_obj = null_object;
35:
36: String id = suffix + PseudoRandomID.getPseudoRandomID();
37:
38: security_objs.put(id, security_obj);
39:
40: return id;
41: }
42:
43: public Object remove(String session_id) {
44: return security_objs.remove(session_id);
45: }
46:
47: public Object getSecurityObject(String session_id) {
48: return security_objs.get(session_id);
49: }
50:
51: public boolean isValidSecurityId(String session_id) {
52: return security_objs.containsKey(session_id);
53: }
54: }
|