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