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