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