1 16 25 26 package org.apache.cocoon.samples.flow.prefs; 27 28 import java.util.HashMap ; 29 import java.util.Map ; 30 31 40 public class UserRegistry 41 { 42 static UserRegistry userRegistry = new UserRegistry(); 43 44 Map registeredUsers = new HashMap (); 45 46 public static UserRegistry getUserRegistry() 47 { 48 return userRegistry; 49 } 50 51 protected UserRegistry() 52 { 53 } 54 55 public synchronized boolean addUser(User user) 56 { 57 if (registeredUsers.containsKey(user.getLogin())) 58 return false; 59 60 registeredUsers.put(user.getLogin(), user); 61 return true; 62 } 63 64 public boolean removeUser(User user) 65 { 66 return registeredUsers.remove(user) != null; 67 } 68 69 75 public boolean isLoginNameTaken(String loginName) 76 { 77 return registeredUsers.get(loginName) != null; 78 } 79 80 89 public User getUserWithLogin(String loginName, String password) 90 { 91 User user = (User)registeredUsers.get(loginName); 92 93 if (user == null) 94 return null; 95 96 return password.equals(user.getPassword()) ? user : null; 97 } 98 } 99 | Popular Tags |