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