1 package de.webman.acl; 2 3 import java.util.Enumeration ; 4 import java.util.Hashtable ; 5 import java.util.Properties ; 6 import com.teamkonzept.lib.ErrorCodes; 7 import com.teamkonzept.lib.TKException; 8 import com.teamkonzept.lib.TKVector; 9 import de.webman.acl.db.LoginDBData; 10 import de.webman.acl.resolver.ResolverFactory; 11 import com.teamkonzept.webman.mainint.events.TKUserException; 12 import com.teamkonzept.webman.mainint.events.UserCodes; 13 14 22 public abstract class Login 23 extends WMObject 24 { 25 26 28 30 33 private boolean parentsModified = false; 34 35 38 private String name = null; 39 40 43 private String login = null; 44 45 48 private TKVector parents = null; 49 50 51 53 58 protected Login (LoginDBData data) 59 { 60 super(data); 61 62 this.name = data.getName(); 63 this.login = data.getLogin(); 64 } 65 66 67 69 75 public abstract boolean isUser (); 76 77 83 public abstract boolean isProfile (); 84 85 93 public abstract boolean isParent (Login login) 94 throws TKException; 95 96 97 99 104 public final String getName () 105 { 106 return name; 107 } 108 109 114 public final void setName (String name) 115 { 116 super.modifyAttribute(this.name, name); 117 this.name = name; 118 } 119 120 125 public final String getLogin () 126 { 127 return login; 128 } 129 130 137 public final void setLogin (String login) 138 throws TKException 139 { 140 LoginFactory.getInstance().checkLogin(login); 142 143 super.modifyAttribute(this.login, login); 145 this.login = login; 146 } 147 148 154 public final TKVector getParents () 155 throws TKException 156 { 157 return LoginFactory.getInstance().getLogins(this); 158 } 159 160 161 163 170 public final boolean isModifiedParents () 171 { 172 return this.parentsModified; 173 } 174 175 179 protected final void updatedParents () 180 { 181 this.parentsModified = false; 182 this.parents = null; 183 } 184 185 193 public final TKVector getParentOrder () 194 throws TKException 195 { 196 if (this.parents == null) 197 { 198 this.parents = LoginFactory.getInstance().getLoginIDs(this); 199 } 200 201 return this.parents; 202 } 203 204 211 public final void setParentOrder (TKVector order) 212 throws TKException 213 { 214 if (order != null) 215 { 216 TKVector current = getParentOrder(); 217 218 if (current != null) 219 { 220 if (current.size() != order.size()) 222 { 223 throw new TKUserException("The number of groups given (" 224 + order.size() 225 + ") does not match the number of the parent groups (" 226 + current.size() 227 + ").", 228 UserCodes.INVALID_PARENT_COUNT, 229 ErrorCodes.USER_SEVERITY, 230 true, 231 new Object []{String.valueOf(order.size()), 232 String.valueOf(current.size())}, 233 null); 234 } 235 236 int index = 0; 238 int size = current.size(); 239 240 this.parents = new TKVector(size); 241 242 while (index < size) 243 { 244 Integer parent = (Integer ) order.elementAt(index++); 245 246 if (! current.contains(parent)) 247 { 248 updatedParents(); 250 251 String name = ProfileFactory.getInstance() 253 .getProfile(parent) 254 .getName(); 255 256 throw new TKUserException("The group '" + 257 name + 258 "' does not belong to the parent groups.", 259 UserCodes.INVALID_PARENT_GROUP, 260 ErrorCodes.USER_SEVERITY, 261 true, 262 new Object []{name}, 263 null); 264 } 265 266 this.parents.addElement(parent); 267 } 268 269 this.parentsModified = true; 271 } 272 } 273 } 274 275 276 278 285 public final boolean isAllowed (Integer event, 286 Integer context) 287 throws TKException 288 { 289 return isAllowed(event, context, null, null); 291 } 292 293 302 public final boolean isAllowed (Integer event, 303 Integer context, 304 Integer type, 305 Integer reference) 306 throws TKException 307 { 308 boolean allowed = false; 309 Hashtable checks = new Hashtable (); 310 311 ResolverFactory.getInstance() 313 .getResolver(this) 314 .resolve(checks, context, type, reference); 315 316 allowed = checks.containsKey(event); 318 319 return allowed; 320 } 321 322 329 public final TKVector getAllowedEvents (Integer context) 330 throws TKException 331 { 332 return getAllowedEvents(context, null, null); 334 } 335 336 345 public final TKVector getAllowedEvents (Integer context, 346 Integer type, 347 Integer reference) 348 throws TKException 349 { 350 Hashtable resolutions = new Hashtable (); 351 352 ResolverFactory.getInstance() 354 .getResolver(this) 355 .resolve(resolutions, context, type, reference); 356 357 TKVector events = new TKVector(resolutions.size()); 359 events.fill(resolutions.keys()); 360 361 return EventFactory.getInstance().getObjects(events); 363 } 364 365 371 public final TKVector getPolicies () 372 throws TKException 373 { 374 return PolicyFactory.getInstance() 375 .getObjects(PolicyFactory.getInstance() 376 .getPolicyProxies(this.getID(), 377 null, 378 null, 379 null)); 380 } 381 382 389 public final TKVector getPolicies (Context context) 390 throws TKException 391 { 392 return PolicyFactory.getInstance() 393 .getObjects(PolicyFactory.getInstance() 394 .getPolicyProxies(this.getID(), 395 context.getID(), 396 null, 397 null)); 398 } 399 400 408 public final TKVector getPolicies (Context context, 409 Integer type) 410 throws TKException 411 { 412 return PolicyFactory.getInstance() 413 .getObjects(PolicyFactory.getInstance() 414 .getPolicyProxies(this.getID(), 415 context.getID(), 416 type, 417 null)); 418 } 419 420 429 public final TKVector getPolicies (Context context, 430 Integer type, 431 Integer reference) 432 throws TKException 433 { 434 return PolicyFactory.getInstance() 435 .getObjects(PolicyFactory.getInstance() 436 .getPolicyProxies(this.getID(), 437 context.getID(), 438 type, 439 reference)); 440 } 441 442 443 445 452 public final Properties getProperties () 453 throws TKException 454 { 455 Properties properties = new Properties (); 457 458 applyOwnProperties(properties); 460 461 return properties; 463 } 464 465 472 public final void setProperties (Properties properties) 473 throws TKException 474 { 475 TKVector own = PropertyFactory.getInstance() 477 .getProperties(this); 478 479 480 for (int i = 0; i < own.size(); i++) 481 { 482 PropertyFactory.getInstance() 483 .deleteProperty((Property) own.elementAt(i)); 484 } 485 486 if (properties != null) 488 { 489 Enumeration keys = properties.keys(); 490 String key = null; 491 492 while (keys.hasMoreElements()) 493 { 494 key = (String ) keys.nextElement(); 495 496 PropertyFactory.getInstance() 497 .createProperty(this, key, properties.getProperty(key)); 498 } 499 } 500 } 501 502 509 public final Properties getInheritedProperties () 510 throws TKException 511 { 512 Properties properties = new Properties (); 514 515 applyInheritedProperties(properties); 517 518 return properties; 520 } 521 522 529 private final void resolveInheritedProperties (Properties properties) 530 throws TKException 531 { 532 applyInheritedProperties(properties); 534 535 applyOwnProperties(properties); 537 } 538 539 540 547 private final void applyInheritedProperties (Properties properties) 548 throws TKException 549 { 550 TKVector inherited = getParentOrder(); 551 552 if (inherited != null) 553 { 554 Login actLogin = null; 557 for (int i = 0; i < inherited.size(); i++) 558 { 559 actLogin = LoginFactory.getInstance() 560 .getLogin((Integer ) inherited.elementAt(i)); 561 actLogin.resolveInheritedProperties(properties); 562 } 563 } 564 } 565 566 573 private final void applyOwnProperties (Properties properties) 574 throws TKException 575 { 576 TKVector own = PropertyFactory.getInstance() 577 .getProperties(this); 578 579 Property property = null; 580 581 for (int i = 0; i < own.size(); i++) 582 { 583 property = (Property) own.elementAt(i); 584 properties.setProperty(property.getName(), property.getValue()); 585 } 586 } 587 588 } 589 | Popular Tags |