1 19 20 package com.sslexplorer.security; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 25 import com.sslexplorer.core.CoreServlet; 26 import com.sslexplorer.core.CoreUtil; 27 import com.sslexplorer.realms.Realm; 28 29 33 public abstract class DefaultUserDatabase implements UserDatabase { 34 static Log log = LogFactory.getLog(DefaultUserDatabase.class); 35 36 protected boolean open; 38 protected String description; 39 protected boolean supportsAccountCreation; 40 protected boolean supportsPasswordChange; 41 protected Realm realm; 42 43 49 public DefaultUserDatabase(String description, boolean supportsAccountCreation, boolean supportsPasswordChange) { 50 this.description = description; 51 this.supportsAccountCreation = supportsAccountCreation; 52 this.supportsPasswordChange = supportsPasswordChange; 53 } 54 55 59 public boolean supportsPasswordChange() { 60 return supportsPasswordChange; 61 } 62 63 67 public boolean supportsAccountCreation() { 68 return supportsAccountCreation; 69 } 70 71 75 public String getDatabaseDescription() { 76 return description; 77 } 78 79 public void open(CoreServlet controllingServlet, Realm realm) throws Exception { 80 if (realm == null) { 81 throw new IllegalArgumentException ("No realm supplied."); 82 } 83 this.open = true; 84 log.info("Opening user database " + getClass().getName() + " for realm " + realm.getResourceName()); 85 this.realm = realm; 86 } 87 88 public void open(CoreServlet controllingServlet) throws Exception { 89 throw new Exception ("User databases must be opened with the realm."); 90 } 91 92 96 public void changePassword(String username, String oldPassword, String password, boolean forcePasswordChangeAtLogon) 97 throws UserDatabaseException, InvalidLoginCredentialsException { 98 assertSupportsPasswordChange(); 99 throw new InvalidLoginCredentialsException( 100 "User database is not read-only, but the changePassword() method has not been implemented"); 101 } 102 103 107 public void setPassword(String username, String password, boolean forcePasswordChangeAtLogon, User adminUser, 108 String adminPassword) throws UserDatabaseException, InvalidLoginCredentialsException { 109 assertSupportsPasswordChange(); 110 throw new InvalidLoginCredentialsException(""); 111 112 } 113 114 118 public User createAccount(String username, String password, String email, String fullname, Role[] roles) throws Exception { 119 assertSupportsAccountCreation(); 120 throw new Exception ("User database is not read-only, but the createAccount() method has not been implemented"); 121 } 122 123 127 public User[] getUsersInRole(Role role) throws Exception { 128 return CoreUtil.getUsersInRole(role, this); 129 } 130 131 135 public void updateAccount(User user, String email, String fullname, Role[] roles) throws Exception { 136 assertSupportsAccountCreation(); 137 throw new Exception ("User database is not read-only, but the updateAccount() method has not been implemented"); 138 } 139 140 144 public void deleteAccount(User user) throws Exception , UserNotFoundException { 145 assertSupportsAccountCreation(); 146 throw new Exception ("User database is not read-only, but the deleteAccount() method has not been implemented"); 147 } 148 149 153 public Role createRole(String rolename) throws Exception { 154 assertSupportsAccountCreation(); 155 throw new Exception ("User database is not read-only, but the createRole() method has not been implemented"); 156 } 157 158 162 public void deleteRole(String rolename) throws Exception { 163 assertSupportsAccountCreation(); 164 throw new Exception ("User database is not read-only, but the deleteRole() method has not been implemented"); 165 } 166 167 protected void assertSupportsPasswordChange() throws InvalidLoginCredentialsException { 168 if (!supportsPasswordChange()) { 169 throw new InvalidLoginCredentialsException("Database doesn't support password change."); 170 } 171 } 172 173 protected void assertSupportsAccountCreation() throws Exception { 174 if (!supportsAccountCreation()) { 175 throw new Exception ("User database is read-only"); 176 } 177 } 178 179 183 public void cleanup() throws Exception { 184 } 185 186 190 public Realm getRealm() { 191 return realm; 192 } 193 194 198 public void close() throws Exception { 199 this.open = false; 200 log.info("Closing user database " + getClass().getName() + " for realm " + realm.getResourceName()); 201 } 202 203 207 public boolean isOpen() { 208 return open; 209 } 210 } | Popular Tags |