01: /*
02: * Copyright Javelin Software, All rights reserved.
03: */
04:
05: package com.javelin.security;
06:
07: import java.util.*;
08:
09: public class Security {
10: protected static User defaultUser = new DefaultUser();
11:
12: protected static Hashtable users = new Hashtable();
13:
14: public static String getLoginName() throws RuntimeException {
15: User user = getUser();
16: return user.getLoginName();
17: }
18:
19: /**
20: * Gets the current logged in user,
21: * or if not logged in yet then the singleton default user
22: */
23: public static User getUser() throws RuntimeException {
24: User us = (User) users.get(Thread.currentThread());
25:
26: if (us == null) {
27: return defaultUser;
28: } else {
29: return us;
30: }
31: }
32:
33: public static void setUser(User us) {
34: users.put(Thread.currentThread(), us);
35: }
36:
37: public static void logout() {
38: setUser(null);
39: }
40:
41: public static void setDefaultUser(User user) {
42: defaultUser = user;
43: }
44:
45: }
|