001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2008 Sun Microsystems, Inc. 025 */ 026package org.forgerock.opendj.server.config.meta; 027 028 029 030import java.util.Collection; 031import java.util.SortedSet; 032import org.forgerock.opendj.config.AdministratorAction; 033import org.forgerock.opendj.config.AttributeTypePropertyDefinition; 034import org.forgerock.opendj.config.BooleanPropertyDefinition; 035import org.forgerock.opendj.config.ClassPropertyDefinition; 036import org.forgerock.opendj.config.client.ConcurrentModificationException; 037import org.forgerock.opendj.config.client.ManagedObject; 038import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 039import org.forgerock.opendj.config.client.OperationRejectedException; 040import org.forgerock.opendj.config.DefaultBehaviorProvider; 041import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; 042import org.forgerock.opendj.config.DNPropertyDefinition; 043import org.forgerock.opendj.config.EnumPropertyDefinition; 044import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 045import org.forgerock.opendj.config.ManagedObjectDefinition; 046import org.forgerock.opendj.config.PropertyOption; 047import org.forgerock.opendj.config.PropertyProvider; 048import org.forgerock.opendj.config.server.ConfigurationChangeListener; 049import org.forgerock.opendj.config.server.ServerManagedObject; 050import org.forgerock.opendj.config.StringPropertyDefinition; 051import org.forgerock.opendj.config.Tag; 052import org.forgerock.opendj.ldap.DN; 053import org.forgerock.opendj.ldap.LdapException; 054import org.forgerock.opendj.ldap.schema.AttributeType; 055import org.forgerock.opendj.server.config.client.MemberVirtualAttributeCfgClient; 056import org.forgerock.opendj.server.config.meta.VirtualAttributeCfgDefn.ConflictBehavior; 057import org.forgerock.opendj.server.config.meta.VirtualAttributeCfgDefn.Scope; 058import org.forgerock.opendj.server.config.server.MemberVirtualAttributeCfg; 059import org.forgerock.opendj.server.config.server.VirtualAttributeCfg; 060 061 062 063/** 064 * An interface for querying the Member Virtual Attribute managed 065 * object definition meta information. 066 * <p> 067 * The Member Virtual Attribute generates a member or uniqueMember 068 * attribute whose values are the DNs of the members of a specified 069 * virtual static group. 070 */ 071public final class MemberVirtualAttributeCfgDefn extends ManagedObjectDefinition<MemberVirtualAttributeCfgClient, MemberVirtualAttributeCfg> { 072 073 // The singleton configuration definition instance. 074 private static final MemberVirtualAttributeCfgDefn INSTANCE = new MemberVirtualAttributeCfgDefn(); 075 076 077 078 // The "allow-retrieving-membership" property definition. 079 private static final BooleanPropertyDefinition PD_ALLOW_RETRIEVING_MEMBERSHIP; 080 081 082 083 // The "conflict-behavior" property definition. 084 private static final EnumPropertyDefinition<ConflictBehavior> PD_CONFLICT_BEHAVIOR; 085 086 087 088 // The "java-class" property definition. 089 private static final ClassPropertyDefinition PD_JAVA_CLASS; 090 091 092 093 // Build the "allow-retrieving-membership" property definition. 094 static { 095 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "allow-retrieving-membership"); 096 builder.setOption(PropertyOption.MANDATORY); 097 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "allow-retrieving-membership")); 098 DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("false"); 099 builder.setDefaultBehaviorProvider(provider); 100 PD_ALLOW_RETRIEVING_MEMBERSHIP = builder.getInstance(); 101 INSTANCE.registerPropertyDefinition(PD_ALLOW_RETRIEVING_MEMBERSHIP); 102 } 103 104 105 106 // Build the "conflict-behavior" property definition. 107 static { 108 EnumPropertyDefinition.Builder<ConflictBehavior> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "conflict-behavior"); 109 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "conflict-behavior")); 110 DefaultBehaviorProvider<ConflictBehavior> provider = new DefinedDefaultBehaviorProvider<ConflictBehavior>("virtual-overrides-real"); 111 builder.setDefaultBehaviorProvider(provider); 112 builder.setEnumClass(ConflictBehavior.class); 113 PD_CONFLICT_BEHAVIOR = builder.getInstance(); 114 INSTANCE.registerPropertyDefinition(PD_CONFLICT_BEHAVIOR); 115 } 116 117 118 119 // Build the "java-class" property definition. 120 static { 121 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 122 builder.setOption(PropertyOption.MANDATORY); 123 builder.setOption(PropertyOption.ADVANCED); 124 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class")); 125 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.MemberVirtualAttributeProvider"); 126 builder.setDefaultBehaviorProvider(provider); 127 builder.addInstanceOf("org.opends.server.api.VirtualAttributeProvider"); 128 PD_JAVA_CLASS = builder.getInstance(); 129 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 130 } 131 132 133 134 // Register the tags associated with this managed object definition. 135 static { 136 INSTANCE.registerTag(Tag.valueOf("core-server")); 137 } 138 139 140 141 /** 142 * Get the Member Virtual Attribute configuration definition 143 * singleton. 144 * 145 * @return Returns the Member Virtual Attribute configuration 146 * definition singleton. 147 */ 148 public static MemberVirtualAttributeCfgDefn getInstance() { 149 return INSTANCE; 150 } 151 152 153 154 /** 155 * Private constructor. 156 */ 157 private MemberVirtualAttributeCfgDefn() { 158 super("member-virtual-attribute", VirtualAttributeCfgDefn.getInstance()); 159 } 160 161 162 163 /** 164 * {@inheritDoc} 165 */ 166 public MemberVirtualAttributeCfgClient createClientConfiguration( 167 ManagedObject<? extends MemberVirtualAttributeCfgClient> impl) { 168 return new MemberVirtualAttributeCfgClientImpl(impl); 169 } 170 171 172 173 /** 174 * {@inheritDoc} 175 */ 176 public MemberVirtualAttributeCfg createServerConfiguration( 177 ServerManagedObject<? extends MemberVirtualAttributeCfg> impl) { 178 return new MemberVirtualAttributeCfgServerImpl(impl); 179 } 180 181 182 183 /** 184 * {@inheritDoc} 185 */ 186 public Class<MemberVirtualAttributeCfg> getServerConfigurationClass() { 187 return MemberVirtualAttributeCfg.class; 188 } 189 190 191 192 /** 193 * Get the "allow-retrieving-membership" property definition. 194 * <p> 195 * Indicates whether to handle requests that request all values for 196 * the virtual attribute. 197 * <p> 198 * This operation can be very expensive in some cases and is not 199 * consistent with the primary function of virtual static groups, 200 * which is to make it possible to use static group idioms to 201 * determine whether a given user is a member. If this attribute is 202 * set to false, attempts to retrieve the entire set of values 203 * receive an empty set, and only attempts to determine whether the 204 * attribute has a specific value or set of values (which is the 205 * primary anticipated use for virtual static groups) are handled 206 * properly. 207 * 208 * @return Returns the "allow-retrieving-membership" property definition. 209 */ 210 public BooleanPropertyDefinition getAllowRetrievingMembershipPropertyDefinition() { 211 return PD_ALLOW_RETRIEVING_MEMBERSHIP; 212 } 213 214 215 216 /** 217 * Get the "attribute-type" property definition. 218 * <p> 219 * Specifies the attribute type for the attribute whose values are 220 * to be dynamically assigned by the virtual attribute. 221 * 222 * @return Returns the "attribute-type" property definition. 223 */ 224 public AttributeTypePropertyDefinition getAttributeTypePropertyDefinition() { 225 return VirtualAttributeCfgDefn.getInstance().getAttributeTypePropertyDefinition(); 226 } 227 228 229 230 /** 231 * Get the "base-dn" property definition. 232 * <p> 233 * Specifies the base DNs for the branches containing entries that 234 * are eligible to use this virtual attribute. 235 * <p> 236 * If no values are given, then the server generates virtual 237 * attributes anywhere in the server. 238 * 239 * @return Returns the "base-dn" property definition. 240 */ 241 public DNPropertyDefinition getBaseDNPropertyDefinition() { 242 return VirtualAttributeCfgDefn.getInstance().getBaseDNPropertyDefinition(); 243 } 244 245 246 247 /** 248 * Get the "conflict-behavior" property definition. 249 * <p> 250 * Specifies the behavior that the server is to exhibit for entries 251 * that already contain one or more real values for the associated 252 * attribute. 253 * 254 * @return Returns the "conflict-behavior" property definition. 255 */ 256 public EnumPropertyDefinition<ConflictBehavior> getConflictBehaviorPropertyDefinition() { 257 return PD_CONFLICT_BEHAVIOR; 258 } 259 260 261 262 /** 263 * Get the "enabled" property definition. 264 * <p> 265 * Indicates whether the Member Virtual Attribute is enabled for 266 * use. 267 * 268 * @return Returns the "enabled" property definition. 269 */ 270 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 271 return VirtualAttributeCfgDefn.getInstance().getEnabledPropertyDefinition(); 272 } 273 274 275 276 /** 277 * Get the "filter" property definition. 278 * <p> 279 * Specifies the search filters to be applied against entries to 280 * determine if the virtual attribute is to be generated for those 281 * entries. 282 * <p> 283 * If no values are given, then any entry is eligible to have the 284 * value generated. If one or more filters are specified, then only 285 * entries that match at least one of those filters are allowed to 286 * have the virtual attribute. 287 * 288 * @return Returns the "filter" property definition. 289 */ 290 public StringPropertyDefinition getFilterPropertyDefinition() { 291 return VirtualAttributeCfgDefn.getInstance().getFilterPropertyDefinition(); 292 } 293 294 295 296 /** 297 * Get the "group-dn" property definition. 298 * <p> 299 * Specifies the DNs of the groups whose members can be eligible to 300 * use this virtual attribute. 301 * <p> 302 * If no values are given, then group membership is not taken into 303 * account when generating the virtual attribute. If one or more 304 * group DNs are specified, then only members of those groups are 305 * allowed to have the virtual attribute. 306 * 307 * @return Returns the "group-dn" property definition. 308 */ 309 public DNPropertyDefinition getGroupDNPropertyDefinition() { 310 return VirtualAttributeCfgDefn.getInstance().getGroupDNPropertyDefinition(); 311 } 312 313 314 315 /** 316 * Get the "java-class" property definition. 317 * <p> 318 * Specifies the fully-qualified name of the virtual attribute 319 * provider class that generates the attribute values. 320 * 321 * @return Returns the "java-class" property definition. 322 */ 323 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 324 return PD_JAVA_CLASS; 325 } 326 327 328 329 /** 330 * Get the "scope" property definition. 331 * <p> 332 * Specifies the LDAP scope associated with base DNs for entries 333 * that are eligible to use this virtual attribute. 334 * 335 * @return Returns the "scope" property definition. 336 */ 337 public EnumPropertyDefinition<Scope> getScopePropertyDefinition() { 338 return VirtualAttributeCfgDefn.getInstance().getScopePropertyDefinition(); 339 } 340 341 342 343 /** 344 * Managed object client implementation. 345 */ 346 private static class MemberVirtualAttributeCfgClientImpl implements 347 MemberVirtualAttributeCfgClient { 348 349 // Private implementation. 350 private ManagedObject<? extends MemberVirtualAttributeCfgClient> impl; 351 352 353 354 // Private constructor. 355 private MemberVirtualAttributeCfgClientImpl( 356 ManagedObject<? extends MemberVirtualAttributeCfgClient> impl) { 357 this.impl = impl; 358 } 359 360 361 362 /** 363 * {@inheritDoc} 364 */ 365 public boolean isAllowRetrievingMembership() { 366 return impl.getPropertyValue(INSTANCE.getAllowRetrievingMembershipPropertyDefinition()); 367 } 368 369 370 371 /** 372 * {@inheritDoc} 373 */ 374 public void setAllowRetrievingMembership(boolean value) { 375 impl.setPropertyValue(INSTANCE.getAllowRetrievingMembershipPropertyDefinition(), value); 376 } 377 378 379 380 /** 381 * {@inheritDoc} 382 */ 383 public AttributeType getAttributeType() { 384 return impl.getPropertyValue(INSTANCE.getAttributeTypePropertyDefinition()); 385 } 386 387 388 389 /** 390 * {@inheritDoc} 391 */ 392 public void setAttributeType(AttributeType value) { 393 impl.setPropertyValue(INSTANCE.getAttributeTypePropertyDefinition(), value); 394 } 395 396 397 398 /** 399 * {@inheritDoc} 400 */ 401 public SortedSet<DN> getBaseDN() { 402 return impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition()); 403 } 404 405 406 407 /** 408 * {@inheritDoc} 409 */ 410 public void setBaseDN(Collection<DN> values) { 411 impl.setPropertyValues(INSTANCE.getBaseDNPropertyDefinition(), values); 412 } 413 414 415 416 /** 417 * {@inheritDoc} 418 */ 419 public ConflictBehavior getConflictBehavior() { 420 return impl.getPropertyValue(INSTANCE.getConflictBehaviorPropertyDefinition()); 421 } 422 423 424 425 /** 426 * {@inheritDoc} 427 */ 428 public void setConflictBehavior(ConflictBehavior value) { 429 impl.setPropertyValue(INSTANCE.getConflictBehaviorPropertyDefinition(), value); 430 } 431 432 433 434 /** 435 * {@inheritDoc} 436 */ 437 public Boolean isEnabled() { 438 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 439 } 440 441 442 443 /** 444 * {@inheritDoc} 445 */ 446 public void setEnabled(boolean value) { 447 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 448 } 449 450 451 452 /** 453 * {@inheritDoc} 454 */ 455 public SortedSet<String> getFilter() { 456 return impl.getPropertyValues(INSTANCE.getFilterPropertyDefinition()); 457 } 458 459 460 461 /** 462 * {@inheritDoc} 463 */ 464 public void setFilter(Collection<String> values) { 465 impl.setPropertyValues(INSTANCE.getFilterPropertyDefinition(), values); 466 } 467 468 469 470 /** 471 * {@inheritDoc} 472 */ 473 public SortedSet<DN> getGroupDN() { 474 return impl.getPropertyValues(INSTANCE.getGroupDNPropertyDefinition()); 475 } 476 477 478 479 /** 480 * {@inheritDoc} 481 */ 482 public void setGroupDN(Collection<DN> values) { 483 impl.setPropertyValues(INSTANCE.getGroupDNPropertyDefinition(), values); 484 } 485 486 487 488 /** 489 * {@inheritDoc} 490 */ 491 public String getJavaClass() { 492 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 493 } 494 495 496 497 /** 498 * {@inheritDoc} 499 */ 500 public void setJavaClass(String value) { 501 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 502 } 503 504 505 506 /** 507 * {@inheritDoc} 508 */ 509 public Scope getScope() { 510 return impl.getPropertyValue(INSTANCE.getScopePropertyDefinition()); 511 } 512 513 514 515 /** 516 * {@inheritDoc} 517 */ 518 public void setScope(Scope value) { 519 impl.setPropertyValue(INSTANCE.getScopePropertyDefinition(), value); 520 } 521 522 523 524 /** 525 * {@inheritDoc} 526 */ 527 public ManagedObjectDefinition<? extends MemberVirtualAttributeCfgClient, ? extends MemberVirtualAttributeCfg> definition() { 528 return INSTANCE; 529 } 530 531 532 533 /** 534 * {@inheritDoc} 535 */ 536 public PropertyProvider properties() { 537 return impl; 538 } 539 540 541 542 /** 543 * {@inheritDoc} 544 */ 545 public void commit() throws ManagedObjectAlreadyExistsException, 546 MissingMandatoryPropertiesException, ConcurrentModificationException, 547 OperationRejectedException, LdapException { 548 impl.commit(); 549 } 550 551 } 552 553 554 555 /** 556 * Managed object server implementation. 557 */ 558 private static class MemberVirtualAttributeCfgServerImpl implements 559 MemberVirtualAttributeCfg { 560 561 // Private implementation. 562 private ServerManagedObject<? extends MemberVirtualAttributeCfg> impl; 563 564 // The value of the "allow-retrieving-membership" property. 565 private final boolean pAllowRetrievingMembership; 566 567 // The value of the "attribute-type" property. 568 private final AttributeType pAttributeType; 569 570 // The value of the "base-dn" property. 571 private final SortedSet<DN> pBaseDN; 572 573 // The value of the "conflict-behavior" property. 574 private final ConflictBehavior pConflictBehavior; 575 576 // The value of the "enabled" property. 577 private final boolean pEnabled; 578 579 // The value of the "filter" property. 580 private final SortedSet<String> pFilter; 581 582 // The value of the "group-dn" property. 583 private final SortedSet<DN> pGroupDN; 584 585 // The value of the "java-class" property. 586 private final String pJavaClass; 587 588 // The value of the "scope" property. 589 private final Scope pScope; 590 591 592 593 // Private constructor. 594 private MemberVirtualAttributeCfgServerImpl(ServerManagedObject<? extends MemberVirtualAttributeCfg> impl) { 595 this.impl = impl; 596 this.pAllowRetrievingMembership = impl.getPropertyValue(INSTANCE.getAllowRetrievingMembershipPropertyDefinition()); 597 this.pAttributeType = impl.getPropertyValue(INSTANCE.getAttributeTypePropertyDefinition()); 598 this.pBaseDN = impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition()); 599 this.pConflictBehavior = impl.getPropertyValue(INSTANCE.getConflictBehaviorPropertyDefinition()); 600 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 601 this.pFilter = impl.getPropertyValues(INSTANCE.getFilterPropertyDefinition()); 602 this.pGroupDN = impl.getPropertyValues(INSTANCE.getGroupDNPropertyDefinition()); 603 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 604 this.pScope = impl.getPropertyValue(INSTANCE.getScopePropertyDefinition()); 605 } 606 607 608 609 /** 610 * {@inheritDoc} 611 */ 612 public void addMemberChangeListener( 613 ConfigurationChangeListener<MemberVirtualAttributeCfg> listener) { 614 impl.registerChangeListener(listener); 615 } 616 617 618 619 /** 620 * {@inheritDoc} 621 */ 622 public void removeMemberChangeListener( 623 ConfigurationChangeListener<MemberVirtualAttributeCfg> listener) { 624 impl.deregisterChangeListener(listener); 625 } 626 /** 627 * {@inheritDoc} 628 */ 629 public void addChangeListener( 630 ConfigurationChangeListener<VirtualAttributeCfg> listener) { 631 impl.registerChangeListener(listener); 632 } 633 634 635 636 /** 637 * {@inheritDoc} 638 */ 639 public void removeChangeListener( 640 ConfigurationChangeListener<VirtualAttributeCfg> listener) { 641 impl.deregisterChangeListener(listener); 642 } 643 644 645 646 /** 647 * {@inheritDoc} 648 */ 649 public boolean isAllowRetrievingMembership() { 650 return pAllowRetrievingMembership; 651 } 652 653 654 655 /** 656 * {@inheritDoc} 657 */ 658 public AttributeType getAttributeType() { 659 return pAttributeType; 660 } 661 662 663 664 /** 665 * {@inheritDoc} 666 */ 667 public SortedSet<DN> getBaseDN() { 668 return pBaseDN; 669 } 670 671 672 673 /** 674 * {@inheritDoc} 675 */ 676 public ConflictBehavior getConflictBehavior() { 677 return pConflictBehavior; 678 } 679 680 681 682 /** 683 * {@inheritDoc} 684 */ 685 public boolean isEnabled() { 686 return pEnabled; 687 } 688 689 690 691 /** 692 * {@inheritDoc} 693 */ 694 public SortedSet<String> getFilter() { 695 return pFilter; 696 } 697 698 699 700 /** 701 * {@inheritDoc} 702 */ 703 public SortedSet<DN> getGroupDN() { 704 return pGroupDN; 705 } 706 707 708 709 /** 710 * {@inheritDoc} 711 */ 712 public String getJavaClass() { 713 return pJavaClass; 714 } 715 716 717 718 /** 719 * {@inheritDoc} 720 */ 721 public Scope getScope() { 722 return pScope; 723 } 724 725 726 727 /** 728 * {@inheritDoc} 729 */ 730 public Class<? extends MemberVirtualAttributeCfg> configurationClass() { 731 return MemberVirtualAttributeCfg.class; 732 } 733 734 735 736 /** 737 * {@inheritDoc} 738 */ 739 public DN dn() { 740 return impl.getDN(); 741 } 742 743 } 744}