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