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