1 package org.myoodb.core; 25 26 import java.io.*; 27 import java.util.*; 28 29 import org.myoodb.util.*; 30 import org.myoodb.exception.*; 31 32 public final class UserManager extends AbstractManager 33 { 34 private static boolean m_authenticationPassThroughFlag = false; 35 public final static String USERS = "myoodb.users"; 36 37 private HashMap m_users; 38 39 public static void setAuthenticationPassThroughFlag(boolean flag) 40 { 41 m_authenticationPassThroughFlag = flag; 42 } 43 44 public static boolean getAuthenticationPassThroughFlag() 45 { 46 return m_authenticationPassThroughFlag; 47 } 48 49 public UserManager() 50 { 51 m_users = new HashMap(); 52 } 53 54 public void startup() throws Exception 55 { 56 if (getAuthenticationPassThroughFlag() == false) 57 { 58 m_users = (HashMap) MyOodbManager.getTheManager().getUserProperties().getProperty(USERS, (Object ) null); 59 } 60 61 if (m_users == null) 62 { 63 m_users = new HashMap(); 64 } 65 } 66 67 public void shutdown() throws Exception 68 { 69 } 70 71 public User newUser(String username, String password) throws PermissionException 72 { 73 if ((username == null) || (username.equals("") == true)) 74 { 75 throw new PermissionException("Invalid parameter (username is null)"); 76 } 77 78 if ((password == null) ) 79 { 80 throw new PermissionException("Invalid parameter (password is null)"); 81 } 82 83 if (getUser(username) != null) 84 { 85 throw new PermissionException("Invalid user (username '" + username + "' already exists)"); 86 } 87 88 User user = new User(username, password); 89 m_users.put(user.getName(), user); 90 91 if (getAuthenticationPassThroughFlag() == false) 92 { 93 MyOodbManager.getTheManager().getUserProperties().setProperty(USERS, m_users); 94 MyOodbManager.getTheManager().storeUserProperties(); 95 } 96 97 return user; 98 } 99 100 public void renameUser(String oldName, String newName) throws PermissionException 101 { 102 if (oldName == null) 103 { 104 throw new PermissionException("Invalid rename (old username is null)"); 105 } 106 107 if ((newName == null) || (newName.equals("") == true)) 108 { 109 throw new PermissionException("Invalid rename (new username is null)"); 110 } 111 112 User user = (User) m_users.remove(oldName); 113 114 if (user == null) 115 { 116 throw new PermissionException("Invalid rename (old user '" + oldName + "' does not exist)"); 117 } 118 119 user = new User(newName, user.getPassword()); 120 m_users.put(user.getName(), user); 121 122 if (getAuthenticationPassThroughFlag() == false) 123 { 124 MyOodbManager.getTheManager().getUserProperties().setProperty(USERS, m_users); 125 MyOodbManager.getTheManager().storeUserProperties(); 126 } 127 } 128 129 public void updateUserPassword(String username, String password) throws PermissionException 130 { 131 if (username == null) 132 { 133 throw new PermissionException("Invalid password change (username is null)"); 134 } 135 136 if (password == null ) 137 { 138 throw new PermissionException("Invalid password change (password is null)"); 139 } 140 141 User user = (User) m_users.get(username); 142 143 if (user == null) 144 { 145 throw new PermissionException("Invalid password change (username '" + username + "' does not exist)"); 146 } 147 148 user.setPassword(password); 149 150 if (getAuthenticationPassThroughFlag() == false) 151 { 152 MyOodbManager.getTheManager().getUserProperties().setProperty(USERS, m_users); 153 MyOodbManager.getTheManager().storeUserProperties(); 154 } 155 } 156 157 public void removeUser(String username) throws PermissionException 158 { 159 if (username == null) 160 { 161 throw new PermissionException("Invalid remove (username is null)"); 162 } 163 164 User user = (User) m_users.remove(username); 165 166 if (user == null) 167 { 168 throw new PermissionException("Invalid remove (username '" + username + "' does not exist)"); 169 } 170 171 if (getAuthenticationPassThroughFlag() == false) 172 { 173 MyOodbManager.getTheManager().getUserProperties().setProperty(USERS, m_users); 174 MyOodbManager.getTheManager().storeUserProperties(); 175 } 176 } 177 178 public User getUser(String name) throws PermissionException 179 { 180 if (name == null) 181 { 182 throw new PermissionException("Invalid get (username is null)"); 183 } 184 185 return (User) m_users.get(name); 186 } 187 188 public HashMap getUsers() 189 { 190 return m_users; 191 } 192 } 193 | Popular Tags |