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  /** {@inheritDoc} */
164  public MemberVirtualAttributeCfgClient createClientConfiguration(
165      ManagedObject<? extends MemberVirtualAttributeCfgClient> impl) {
166    return new MemberVirtualAttributeCfgClientImpl(impl);
167  }
168
169
170
171  /** {@inheritDoc} */
172  public MemberVirtualAttributeCfg createServerConfiguration(
173      ServerManagedObject<? extends MemberVirtualAttributeCfg> impl) {
174    return new MemberVirtualAttributeCfgServerImpl(impl);
175  }
176
177
178
179  /** {@inheritDoc} */
180  public Class<MemberVirtualAttributeCfg> getServerConfigurationClass() {
181    return MemberVirtualAttributeCfg.class;
182  }
183
184
185
186  /**
187   * Get the "allow-retrieving-membership" property definition.
188   * <p>
189   * Indicates whether to handle requests that request all values for
190   * the virtual attribute.
191   * <p>
192   * This operation can be very expensive in some cases and is not
193   * consistent with the primary function of virtual static groups,
194   * which is to make it possible to use static group idioms to
195   * determine whether a given user is a member. If this attribute is
196   * set to false, attempts to retrieve the entire set of values
197   * receive an empty set, and only attempts to determine whether the
198   * attribute has a specific value or set of values (which is the
199   * primary anticipated use for virtual static groups) are handled
200   * properly.
201   *
202   * @return Returns the "allow-retrieving-membership" property definition.
203   */
204  public BooleanPropertyDefinition getAllowRetrievingMembershipPropertyDefinition() {
205    return PD_ALLOW_RETRIEVING_MEMBERSHIP;
206  }
207
208
209
210  /**
211   * Get the "attribute-type" property definition.
212   * <p>
213   * Specifies the attribute type for the attribute whose values are
214   * to be dynamically assigned by the virtual attribute.
215   *
216   * @return Returns the "attribute-type" property definition.
217   */
218  public AttributeTypePropertyDefinition getAttributeTypePropertyDefinition() {
219    return VirtualAttributeCfgDefn.getInstance().getAttributeTypePropertyDefinition();
220  }
221
222
223
224  /**
225   * Get the "base-dn" property definition.
226   * <p>
227   * Specifies the base DNs for the branches containing entries that
228   * are eligible to use this virtual attribute.
229   * <p>
230   * If no values are given, then the server generates virtual
231   * attributes anywhere in the server.
232   *
233   * @return Returns the "base-dn" property definition.
234   */
235  public DNPropertyDefinition getBaseDNPropertyDefinition() {
236    return VirtualAttributeCfgDefn.getInstance().getBaseDNPropertyDefinition();
237  }
238
239
240
241  /**
242   * Get the "conflict-behavior" property definition.
243   * <p>
244   * Specifies the behavior that the server is to exhibit for entries
245   * that already contain one or more real values for the associated
246   * attribute.
247   *
248   * @return Returns the "conflict-behavior" property definition.
249   */
250  public EnumPropertyDefinition<ConflictBehavior> getConflictBehaviorPropertyDefinition() {
251    return PD_CONFLICT_BEHAVIOR;
252  }
253
254
255
256  /**
257   * Get the "enabled" property definition.
258   * <p>
259   * Indicates whether the Member Virtual Attribute is enabled for
260   * use.
261   *
262   * @return Returns the "enabled" property definition.
263   */
264  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
265    return VirtualAttributeCfgDefn.getInstance().getEnabledPropertyDefinition();
266  }
267
268
269
270  /**
271   * Get the "filter" property definition.
272   * <p>
273   * Specifies the search filters to be applied against entries to
274   * determine if the virtual attribute is to be generated for those
275   * entries.
276   * <p>
277   * If no values are given, then any entry is eligible to have the
278   * value generated. If one or more filters are specified, then only
279   * entries that match at least one of those filters are allowed to
280   * have the virtual attribute.
281   *
282   * @return Returns the "filter" property definition.
283   */
284  public StringPropertyDefinition getFilterPropertyDefinition() {
285    return VirtualAttributeCfgDefn.getInstance().getFilterPropertyDefinition();
286  }
287
288
289
290  /**
291   * Get the "group-dn" property definition.
292   * <p>
293   * Specifies the DNs of the groups whose members can be eligible to
294   * use this virtual attribute.
295   * <p>
296   * If no values are given, then group membership is not taken into
297   * account when generating the virtual attribute. If one or more
298   * group DNs are specified, then only members of those groups are
299   * allowed to have the virtual attribute.
300   *
301   * @return Returns the "group-dn" property definition.
302   */
303  public DNPropertyDefinition getGroupDNPropertyDefinition() {
304    return VirtualAttributeCfgDefn.getInstance().getGroupDNPropertyDefinition();
305  }
306
307
308
309  /**
310   * Get the "java-class" property definition.
311   * <p>
312   * Specifies the fully-qualified name of the virtual attribute
313   * provider class that generates the attribute values.
314   *
315   * @return Returns the "java-class" property definition.
316   */
317  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
318    return PD_JAVA_CLASS;
319  }
320
321
322
323  /**
324   * Get the "scope" property definition.
325   * <p>
326   * Specifies the LDAP scope associated with base DNs for entries
327   * that are eligible to use this virtual attribute.
328   *
329   * @return Returns the "scope" property definition.
330   */
331  public EnumPropertyDefinition<Scope> getScopePropertyDefinition() {
332    return VirtualAttributeCfgDefn.getInstance().getScopePropertyDefinition();
333  }
334
335
336
337  /**
338   * Managed object client implementation.
339   */
340  private static class MemberVirtualAttributeCfgClientImpl implements
341    MemberVirtualAttributeCfgClient {
342
343    /** Private implementation. */
344    private ManagedObject<? extends MemberVirtualAttributeCfgClient> impl;
345
346
347
348    /** Private constructor. */
349    private MemberVirtualAttributeCfgClientImpl(
350        ManagedObject<? extends MemberVirtualAttributeCfgClient> impl) {
351      this.impl = impl;
352    }
353
354
355
356    /** {@inheritDoc} */
357    public boolean isAllowRetrievingMembership() {
358      return impl.getPropertyValue(INSTANCE.getAllowRetrievingMembershipPropertyDefinition());
359    }
360
361
362
363    /** {@inheritDoc} */
364    public void setAllowRetrievingMembership(boolean value) {
365      impl.setPropertyValue(INSTANCE.getAllowRetrievingMembershipPropertyDefinition(), value);
366    }
367
368
369
370    /** {@inheritDoc} */
371    public AttributeType getAttributeType() {
372      return impl.getPropertyValue(INSTANCE.getAttributeTypePropertyDefinition());
373    }
374
375
376
377    /** {@inheritDoc} */
378    public void setAttributeType(AttributeType value) {
379      impl.setPropertyValue(INSTANCE.getAttributeTypePropertyDefinition(), value);
380    }
381
382
383
384    /** {@inheritDoc} */
385    public SortedSet<DN> getBaseDN() {
386      return impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition());
387    }
388
389
390
391    /** {@inheritDoc} */
392    public void setBaseDN(Collection<DN> values) {
393      impl.setPropertyValues(INSTANCE.getBaseDNPropertyDefinition(), values);
394    }
395
396
397
398    /** {@inheritDoc} */
399    public ConflictBehavior getConflictBehavior() {
400      return impl.getPropertyValue(INSTANCE.getConflictBehaviorPropertyDefinition());
401    }
402
403
404
405    /** {@inheritDoc} */
406    public void setConflictBehavior(ConflictBehavior value) {
407      impl.setPropertyValue(INSTANCE.getConflictBehaviorPropertyDefinition(), value);
408    }
409
410
411
412    /** {@inheritDoc} */
413    public Boolean isEnabled() {
414      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
415    }
416
417
418
419    /** {@inheritDoc} */
420    public void setEnabled(boolean value) {
421      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
422    }
423
424
425
426    /** {@inheritDoc} */
427    public SortedSet<String> getFilter() {
428      return impl.getPropertyValues(INSTANCE.getFilterPropertyDefinition());
429    }
430
431
432
433    /** {@inheritDoc} */
434    public void setFilter(Collection<String> values) {
435      impl.setPropertyValues(INSTANCE.getFilterPropertyDefinition(), values);
436    }
437
438
439
440    /** {@inheritDoc} */
441    public SortedSet<DN> getGroupDN() {
442      return impl.getPropertyValues(INSTANCE.getGroupDNPropertyDefinition());
443    }
444
445
446
447    /** {@inheritDoc} */
448    public void setGroupDN(Collection<DN> values) {
449      impl.setPropertyValues(INSTANCE.getGroupDNPropertyDefinition(), values);
450    }
451
452
453
454    /** {@inheritDoc} */
455    public String getJavaClass() {
456      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
457    }
458
459
460
461    /** {@inheritDoc} */
462    public void setJavaClass(String value) {
463      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
464    }
465
466
467
468    /** {@inheritDoc} */
469    public Scope getScope() {
470      return impl.getPropertyValue(INSTANCE.getScopePropertyDefinition());
471    }
472
473
474
475    /** {@inheritDoc} */
476    public void setScope(Scope value) {
477      impl.setPropertyValue(INSTANCE.getScopePropertyDefinition(), value);
478    }
479
480
481
482    /** {@inheritDoc} */
483    public ManagedObjectDefinition<? extends MemberVirtualAttributeCfgClient, ? extends MemberVirtualAttributeCfg> definition() {
484      return INSTANCE;
485    }
486
487
488
489    /** {@inheritDoc} */
490    public PropertyProvider properties() {
491      return impl;
492    }
493
494
495
496    /** {@inheritDoc} */
497    public void commit() throws ManagedObjectAlreadyExistsException,
498        MissingMandatoryPropertiesException, ConcurrentModificationException,
499        OperationRejectedException, LdapException {
500      impl.commit();
501    }
502
503
504
505    /** {@inheritDoc} */
506    public String toString() {
507      return impl.toString();
508    }
509  }
510
511
512
513  /**
514   * Managed object server implementation.
515   */
516  private static class MemberVirtualAttributeCfgServerImpl implements
517    MemberVirtualAttributeCfg {
518
519    /** Private implementation. */
520    private ServerManagedObject<? extends MemberVirtualAttributeCfg> impl;
521
522    /** The value of the "allow-retrieving-membership" property. */
523    private final boolean pAllowRetrievingMembership;
524
525    /** The value of the "attribute-type" property. */
526    private final AttributeType pAttributeType;
527
528    /** The value of the "base-dn" property. */
529    private final SortedSet<DN> pBaseDN;
530
531    /** The value of the "conflict-behavior" property. */
532    private final ConflictBehavior pConflictBehavior;
533
534    /** The value of the "enabled" property. */
535    private final boolean pEnabled;
536
537    /** The value of the "filter" property. */
538    private final SortedSet<String> pFilter;
539
540    /** The value of the "group-dn" property. */
541    private final SortedSet<DN> pGroupDN;
542
543    /** The value of the "java-class" property. */
544    private final String pJavaClass;
545
546    /** The value of the "scope" property. */
547    private final Scope pScope;
548
549
550
551    /** Private constructor. */
552    private MemberVirtualAttributeCfgServerImpl(ServerManagedObject<? extends MemberVirtualAttributeCfg> impl) {
553      this.impl = impl;
554      this.pAllowRetrievingMembership = impl.getPropertyValue(INSTANCE.getAllowRetrievingMembershipPropertyDefinition());
555      this.pAttributeType = impl.getPropertyValue(INSTANCE.getAttributeTypePropertyDefinition());
556      this.pBaseDN = impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition());
557      this.pConflictBehavior = impl.getPropertyValue(INSTANCE.getConflictBehaviorPropertyDefinition());
558      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
559      this.pFilter = impl.getPropertyValues(INSTANCE.getFilterPropertyDefinition());
560      this.pGroupDN = impl.getPropertyValues(INSTANCE.getGroupDNPropertyDefinition());
561      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
562      this.pScope = impl.getPropertyValue(INSTANCE.getScopePropertyDefinition());
563    }
564
565
566
567    /** {@inheritDoc} */
568    public void addMemberChangeListener(
569        ConfigurationChangeListener<MemberVirtualAttributeCfg> listener) {
570      impl.registerChangeListener(listener);
571    }
572
573
574
575    /** {@inheritDoc} */
576    public void removeMemberChangeListener(
577        ConfigurationChangeListener<MemberVirtualAttributeCfg> listener) {
578      impl.deregisterChangeListener(listener);
579    }
580    /** {@inheritDoc} */
581    public void addChangeListener(
582        ConfigurationChangeListener<VirtualAttributeCfg> listener) {
583      impl.registerChangeListener(listener);
584    }
585
586
587
588    /** {@inheritDoc} */
589    public void removeChangeListener(
590        ConfigurationChangeListener<VirtualAttributeCfg> listener) {
591      impl.deregisterChangeListener(listener);
592    }
593
594
595
596    /** {@inheritDoc} */
597    public boolean isAllowRetrievingMembership() {
598      return pAllowRetrievingMembership;
599    }
600
601
602
603    /** {@inheritDoc} */
604    public AttributeType getAttributeType() {
605      return pAttributeType;
606    }
607
608
609
610    /** {@inheritDoc} */
611    public SortedSet<DN> getBaseDN() {
612      return pBaseDN;
613    }
614
615
616
617    /** {@inheritDoc} */
618    public ConflictBehavior getConflictBehavior() {
619      return pConflictBehavior;
620    }
621
622
623
624    /** {@inheritDoc} */
625    public boolean isEnabled() {
626      return pEnabled;
627    }
628
629
630
631    /** {@inheritDoc} */
632    public SortedSet<String> getFilter() {
633      return pFilter;
634    }
635
636
637
638    /** {@inheritDoc} */
639    public SortedSet<DN> getGroupDN() {
640      return pGroupDN;
641    }
642
643
644
645    /** {@inheritDoc} */
646    public String getJavaClass() {
647      return pJavaClass;
648    }
649
650
651
652    /** {@inheritDoc} */
653    public Scope getScope() {
654      return pScope;
655    }
656
657
658
659    /** {@inheritDoc} */
660    public Class<? extends MemberVirtualAttributeCfg> configurationClass() {
661      return MemberVirtualAttributeCfg.class;
662    }
663
664
665
666    /** {@inheritDoc} */
667    public DN dn() {
668      return impl.getDN();
669    }
670
671
672
673    /** {@inheritDoc} */
674    public String toString() {
675      return impl.toString();
676    }
677  }
678}