1 package de.webman.acl; 2 3 import com.teamkonzept.lib.ConfigurationManager; 4 import com.teamkonzept.lib.ErrorCodes; 5 import com.teamkonzept.lib.PropertyManager; 6 import com.teamkonzept.lib.TKConfigurationException; 7 import com.teamkonzept.lib.TKException; 8 import com.teamkonzept.lib.TKReg; 9 import com.teamkonzept.lib.TKVector; 10 import de.webman.acl.db.*; 11 import de.webman.acl.resolver.ResolverFactory; 12 import com.teamkonzept.webman.mainint.events.TKUserException; 13 import com.teamkonzept.webman.mainint.events.UserCodes; 14 import com.teamkonzept.webman.mainint.WebmanExceptionHandler; 15 16 23 public class LoginFactory 24 extends ObjectFactoryBase 25 implements ObjectFactory 26 { 27 28 30 32 35 private static LoginFactory SINGLETON = null; 36 37 38 40 43 private String validLogins = null; 44 45 46 48 51 private LoginFactory () 52 { 53 super(); 54 } 55 56 57 59 65 public static synchronized final LoginFactory getInstance () 66 throws TKException 67 { 68 if (SINGLETON == null) 69 { 70 SINGLETON = new LoginFactory(); 71 SINGLETON.configurationChanged(); 72 ConfigurationManager.getInstance() 73 .registerConfigurationListener(SINGLETON, 74 PROPERTY_GROUP_NAME); 75 } 76 77 return SINGLETON; 78 } 79 80 81 83 88 public final ObjectDBInterface getDBInterface () 89 { 90 return LoginDBInterface.getInstance(); 91 } 92 93 99 public final ObjectDBData getDBData (Integer id) 100 { 101 return new LoginDBData(id, null, null, null); 102 } 103 104 110 public final ObjectDBData getDBData (WMObject object) 111 { 112 return new LoginDBData((Login) object); 113 } 114 115 121 public final WMObject buildObject (ObjectDBData data) 122 { 123 return ((LoginDBData) data).isUser() 124 ? (Login) new User((LoginDBData) data) 125 : (Login) new Profile((LoginDBData) data); 126 } 127 128 129 131 136 public synchronized final void configurationChanged () 137 throws TKException 138 { 139 super.configurationChanged(); 141 142 try 144 { 145 PropertyManager manager = PropertyManager.getPropertyManager(PROPERTY_GROUP_NAME); 147 148 this.validLogins = manager.getValue(PROPERTY_VALID_LOGINS, DEFAULT_VALID_LOGINS); 150 } 151 catch (TKConfigurationException tkce) 152 { 153 this.validLogins = DEFAULT_VALID_LOGINS; 155 } 156 } 157 158 164 public final void modifyObject (WMObject object) 165 throws TKException 166 { 167 try 168 { 169 Login login = (Login) object; 171 172 if (login.isModifiedParents()) 174 { 175 ObjectDBData data = getDBData(login); 177 data.setQuery(LoginDBInterface.WM_PROFILE_UPDATE); 178 data.setPrototype(new ProfileCollectionDBData(login.getID())); 179 data.setCollection(login.getParentOrder()); 180 181 getDBInterface().updateDependent(data); 183 184 login.updatedParents(); 186 } 187 188 super.modifyObject(object); 190 } 191 catch (Exception x) 192 { 193 throw WebmanExceptionHandler.getException(x); 194 } 195 } 196 197 203 public void deleteObject (WMObject object) 204 throws TKException 205 { 206 ResolverFactory.getInstance().removeResolver((Login) object); 207 208 super.deleteObject(object); 209 } 210 211 212 214 220 public final TKVector getLogins () 221 throws TKException 222 { 223 return getObjects(); 224 } 225 226 227 234 public final TKVector getLogins (Login login) 235 throws TKException 236 { 237 TKVector objects = null; 238 239 try 240 { 241 objects = getObjects(getLoginIDs(login)); 243 } 244 catch (Exception x) 245 { 246 throw WebmanExceptionHandler.getException(x); 247 } 248 249 return objects; 250 } 251 252 259 public final Login getLogin (Integer id) 260 throws TKException 261 { 262 return (Login) getObject(id); 263 } 264 265 272 public final Login getLogin (String login) 273 throws TKException 274 { 275 Login object = null; 276 277 try 278 { 279 LoginDBData data = new LoginDBData(null, login, null, null); 281 data.setQuery(LoginDBInterface.WM_USER_SELECT_BY_LOGIN); 282 data.setPrototype(new ObjectCollectionDBData(null, 283 null, 284 LoginDBInterface.PRIMARY_KEY_NAME, 285 null)); 286 287 TKVector id = getObjectIDs(data); 289 290 if (id != null && id.size() == 1) 291 { 292 object = (Login) getObject((Integer ) id.firstElement()); 293 } 294 else 295 { 296 throw new TKUserException("The user or group '" + login + "' is unknown.", 297 UserCodes.LOGIN_UNKNOWN, 298 ErrorCodes.USER_SEVERITY, 299 true, 300 new Object []{login}, 301 null); 302 } 303 } 304 catch (Exception x) 305 { 306 throw WebmanExceptionHandler.getException(x); 307 } 308 309 return object; 310 } 311 312 319 public final TKVector getLoginIDs (Login login) 320 throws TKException 321 { 322 TKVector proxies = null; 323 324 try 325 { 326 LoginDBData data = new LoginDBData(null, null, null, null); 328 data.setQuery(LoginDBInterface.WM_PROFILE_SELECT_BY_PROFILE); 329 data.setPrototype(new ObjectCollectionDBData(LoginDBInterface.DEPENDENT_KEY_NAME, 330 login.getID(), 331 LoginDBInterface.PRIMARY_KEY_NAME, 332 null)); 333 334 proxies = getObjectIDs(data); 336 } 337 catch (Exception x) 338 { 339 throw WebmanExceptionHandler.getException(x); 340 } 341 342 return proxies; 343 } 344 345 351 public final void modifyLogin (Login login) 352 throws TKException 353 { 354 modifyObject(login); 355 } 356 357 363 public final void deleteLogin (Login login) 364 throws TKException 365 { 366 deleteObject(login); 367 } 368 369 375 public final void checkLogin (String login) 376 throws TKException 377 { 378 try 379 { 380 if (login == null || 381 ! TKReg.getMatcher().matches(login, TKReg.getCompiler().compile(this.validLogins))) 382 { 383 throw new TKUserException("The login '" + login + "' is not valid.", 384 UserCodes.INVALID_LOGIN_TOKEN, 385 ErrorCodes.USER_SEVERITY, 386 true, 387 new Object []{login}, 388 null); 389 } 390 } 391 catch (Exception x) 392 { 393 throw WebmanExceptionHandler.getException(x); 394 } 395 } 396 397 } 398 | Popular Tags |