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.ManagedObjectAlreadyExistsException;
048    import org.opends.server.admin.ManagedObjectDefinition;
049    import org.opends.server.admin.PropertyOption;
050    import org.opends.server.admin.PropertyProvider;
051    import org.opends.server.admin.server.ConfigurationChangeListener;
052    import org.opends.server.admin.server.ServerManagedObject;
053    import org.opends.server.admin.std.client.RegularExpressionIdentityMapperCfgClient;
054    import org.opends.server.admin.std.server.IdentityMapperCfg;
055    import org.opends.server.admin.std.server.RegularExpressionIdentityMapperCfg;
056    import org.opends.server.admin.StringPropertyDefinition;
057    import org.opends.server.admin.Tag;
058    import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
059    import org.opends.server.types.AttributeType;
060    import org.opends.server.types.DN;
061    
062    
063    
064    /**
065     * An interface for querying the Regular Expression Identity Mapper
066     * managed object definition meta information.
067     * <p>
068     * The Regular Expression Identity Mapper provides a way to use a
069     * regular expression to translate the provided identifier when
070     * searching for the appropriate user entry.
071     */
072    public final class RegularExpressionIdentityMapperCfgDefn extends ManagedObjectDefinition<RegularExpressionIdentityMapperCfgClient, RegularExpressionIdentityMapperCfg> {
073    
074      // The singleton configuration definition instance.
075      private static final RegularExpressionIdentityMapperCfgDefn INSTANCE = new RegularExpressionIdentityMapperCfgDefn();
076    
077    
078    
079      // The "java-class" property definition.
080      private static final ClassPropertyDefinition PD_JAVA_CLASS;
081    
082    
083    
084      // The "match-attribute" property definition.
085      private static final AttributeTypePropertyDefinition PD_MATCH_ATTRIBUTE;
086    
087    
088    
089      // The "match-base-dn" property definition.
090      private static final DNPropertyDefinition PD_MATCH_BASE_DN;
091    
092    
093    
094      // The "match-pattern" property definition.
095      private static final StringPropertyDefinition PD_MATCH_PATTERN;
096    
097    
098    
099      // The "replace-pattern" property definition.
100      private static final StringPropertyDefinition PD_REPLACE_PATTERN;
101    
102    
103    
104      // Build the "java-class" property definition.
105      static {
106          ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
107          builder.setOption(PropertyOption.MANDATORY);
108          builder.setOption(PropertyOption.ADVANCED);
109          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
110          DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.RegularExpressionIdentityMapper");
111          builder.setDefaultBehaviorProvider(provider);
112          builder.addInstanceOf("org.opends.server.api.IdentityMapper");
113          PD_JAVA_CLASS = builder.getInstance();
114          INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
115      }
116    
117    
118    
119      // Build the "match-attribute" property definition.
120      static {
121          AttributeTypePropertyDefinition.Builder builder = AttributeTypePropertyDefinition.createBuilder(INSTANCE, "match-attribute");
122          builder.setOption(PropertyOption.MULTI_VALUED);
123          builder.setOption(PropertyOption.MANDATORY);
124          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "match-attribute"));
125          DefaultBehaviorProvider<AttributeType> provider = new DefinedDefaultBehaviorProvider<AttributeType>("uid");
126          builder.setDefaultBehaviorProvider(provider);
127          PD_MATCH_ATTRIBUTE = builder.getInstance();
128          INSTANCE.registerPropertyDefinition(PD_MATCH_ATTRIBUTE);
129      }
130    
131    
132    
133      // Build the "match-base-dn" property definition.
134      static {
135          DNPropertyDefinition.Builder builder = DNPropertyDefinition.createBuilder(INSTANCE, "match-base-dn");
136          builder.setOption(PropertyOption.MULTI_VALUED);
137          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "match-base-dn"));
138          builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<DN>(INSTANCE, "match-base-dn"));
139          PD_MATCH_BASE_DN = builder.getInstance();
140          INSTANCE.registerPropertyDefinition(PD_MATCH_BASE_DN);
141      }
142    
143    
144    
145      // Build the "match-pattern" property definition.
146      static {
147          StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "match-pattern");
148          builder.setOption(PropertyOption.MANDATORY);
149          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "match-pattern"));
150          builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
151          builder.setPattern(".*", "REGEXP");
152          PD_MATCH_PATTERN = builder.getInstance();
153          INSTANCE.registerPropertyDefinition(PD_MATCH_PATTERN);
154      }
155    
156    
157    
158      // Build the "replace-pattern" property definition.
159      static {
160          StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "replace-pattern");
161          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "replace-pattern"));
162          builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<String>(INSTANCE, "replace-pattern"));
163          builder.setPattern(".*", "REGEXP");
164          PD_REPLACE_PATTERN = builder.getInstance();
165          INSTANCE.registerPropertyDefinition(PD_REPLACE_PATTERN);
166      }
167    
168    
169    
170      // Register the tags associated with this managed object definition.
171      static {
172        INSTANCE.registerTag(Tag.valueOf("security"));
173        INSTANCE.registerTag(Tag.valueOf("user-management"));
174      }
175    
176    
177    
178      /**
179       * Get the Regular Expression Identity Mapper configuration
180       * definition singleton.
181       *
182       * @return Returns the Regular Expression Identity Mapper
183       *         configuration definition singleton.
184       */
185      public static RegularExpressionIdentityMapperCfgDefn getInstance() {
186        return INSTANCE;
187      }
188    
189    
190    
191      /**
192       * Private constructor.
193       */
194      private RegularExpressionIdentityMapperCfgDefn() {
195        super("regular-expression-identity-mapper", IdentityMapperCfgDefn.getInstance());
196      }
197    
198    
199    
200      /**
201       * {@inheritDoc}
202       */
203      public RegularExpressionIdentityMapperCfgClient createClientConfiguration(
204          ManagedObject<? extends RegularExpressionIdentityMapperCfgClient> impl) {
205        return new RegularExpressionIdentityMapperCfgClientImpl(impl);
206      }
207    
208    
209    
210      /**
211       * {@inheritDoc}
212       */
213      public RegularExpressionIdentityMapperCfg createServerConfiguration(
214          ServerManagedObject<? extends RegularExpressionIdentityMapperCfg> impl) {
215        return new RegularExpressionIdentityMapperCfgServerImpl(impl);
216      }
217    
218    
219    
220      /**
221       * {@inheritDoc}
222       */
223      public Class<RegularExpressionIdentityMapperCfg> getServerConfigurationClass() {
224        return RegularExpressionIdentityMapperCfg.class;
225      }
226    
227    
228    
229      /**
230       * Get the "enabled" property definition.
231       * <p>
232       * Indicates whether the Regular Expression Identity Mapper is
233       * enabled for use.
234       *
235       * @return Returns the "enabled" property definition.
236       */
237      public BooleanPropertyDefinition getEnabledPropertyDefinition() {
238        return IdentityMapperCfgDefn.getInstance().getEnabledPropertyDefinition();
239      }
240    
241    
242    
243      /**
244       * Get the "java-class" property definition.
245       * <p>
246       * Specifies the fully-qualified name of the Java class that
247       * provides the Regular Expression Identity Mapper implementation.
248       *
249       * @return Returns the "java-class" property definition.
250       */
251      public ClassPropertyDefinition getJavaClassPropertyDefinition() {
252        return PD_JAVA_CLASS;
253      }
254    
255    
256    
257      /**
258       * Get the "match-attribute" property definition.
259       * <p>
260       * Specifies the name or OID of the attribute whose value should
261       * match the provided identifier string after it has been processed
262       * by the associated regular expression.
263       * <p>
264       * All values must refer to the name or OID of an attribute type
265       * defined in the Directory Server schema. If multiple attributes or
266       * OIDs are provided, at least one of those attributes must contain
267       * the provided ID string value in exactly one entry.
268       *
269       * @return Returns the "match-attribute" property definition.
270       */
271      public AttributeTypePropertyDefinition getMatchAttributePropertyDefinition() {
272        return PD_MATCH_ATTRIBUTE;
273      }
274    
275    
276    
277      /**
278       * Get the "match-base-dn" property definition.
279       * <p>
280       * Specifies the base DN(s) that should be used when performing
281       * searches to map the provided ID string to a user entry. If
282       * multiple values are given, searches are performed below all the
283       * specified base DNs.
284       *
285       * @return Returns the "match-base-dn" property definition.
286       */
287      public DNPropertyDefinition getMatchBaseDNPropertyDefinition() {
288        return PD_MATCH_BASE_DN;
289      }
290    
291    
292    
293      /**
294       * Get the "match-pattern" property definition.
295       * <p>
296       * Specifies the regular expression pattern that is used to identify
297       * portions of the ID string that will be replaced.
298       * <p>
299       * Any portion of the ID string that matches this pattern is
300       * replaced in accordance with the provided replace pattern (or is
301       * removed if no replace pattern is specified). If multiple
302       * substrings within the given ID string match this pattern, all
303       * occurrences are replaced. If no part of the given ID string
304       * matches this pattern, the ID string is not altered. Exactly one
305       * match pattern value must be provided, and it must be a valid
306       * regular expression as described in the API documentation for the
307       * java.util.regex.Pattern class, including support for capturing
308       * groups.
309       *
310       * @return Returns the "match-pattern" property definition.
311       */
312      public StringPropertyDefinition getMatchPatternPropertyDefinition() {
313        return PD_MATCH_PATTERN;
314      }
315    
316    
317    
318      /**
319       * Get the "replace-pattern" property definition.
320       * <p>
321       * Specifies the replacement pattern that should be used for
322       * substrings in the ID string that match the provided regular
323       * expression pattern.
324       * <p>
325       * If no replacement pattern is provided, then any matching portions
326       * of the ID string will be removed (i.e., replaced with an empty
327       * string). The replacement pattern may include a string from a
328       * capturing group by using a dollar sign ($) followed by an integer
329       * value that indicates which capturing group should be used.
330       *
331       * @return Returns the "replace-pattern" property definition.
332       */
333      public StringPropertyDefinition getReplacePatternPropertyDefinition() {
334        return PD_REPLACE_PATTERN;
335      }
336    
337    
338    
339      /**
340       * Managed object client implementation.
341       */
342      private static class RegularExpressionIdentityMapperCfgClientImpl implements
343        RegularExpressionIdentityMapperCfgClient {
344    
345        // Private implementation.
346        private ManagedObject<? extends RegularExpressionIdentityMapperCfgClient> impl;
347    
348    
349    
350        // Private constructor.
351        private RegularExpressionIdentityMapperCfgClientImpl(
352            ManagedObject<? extends RegularExpressionIdentityMapperCfgClient> impl) {
353          this.impl = impl;
354        }
355    
356    
357    
358        /**
359         * {@inheritDoc}
360         */
361        public Boolean isEnabled() {
362          return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
363        }
364    
365    
366    
367        /**
368         * {@inheritDoc}
369         */
370        public void setEnabled(boolean value) {
371          impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
372        }
373    
374    
375    
376        /**
377         * {@inheritDoc}
378         */
379        public String getJavaClass() {
380          return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
381        }
382    
383    
384    
385        /**
386         * {@inheritDoc}
387         */
388        public void setJavaClass(String value) {
389          impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
390        }
391    
392    
393    
394        /**
395         * {@inheritDoc}
396         */
397        public SortedSet<AttributeType> getMatchAttribute() {
398          return impl.getPropertyValues(INSTANCE.getMatchAttributePropertyDefinition());
399        }
400    
401    
402    
403        /**
404         * {@inheritDoc}
405         */
406        public void setMatchAttribute(Collection<AttributeType> values) {
407          impl.setPropertyValues(INSTANCE.getMatchAttributePropertyDefinition(), values);
408        }
409    
410    
411    
412        /**
413         * {@inheritDoc}
414         */
415        public SortedSet<DN> getMatchBaseDN() {
416          return impl.getPropertyValues(INSTANCE.getMatchBaseDNPropertyDefinition());
417        }
418    
419    
420    
421        /**
422         * {@inheritDoc}
423         */
424        public void setMatchBaseDN(Collection<DN> values) {
425          impl.setPropertyValues(INSTANCE.getMatchBaseDNPropertyDefinition(), values);
426        }
427    
428    
429    
430        /**
431         * {@inheritDoc}
432         */
433        public String getMatchPattern() {
434          return impl.getPropertyValue(INSTANCE.getMatchPatternPropertyDefinition());
435        }
436    
437    
438    
439        /**
440         * {@inheritDoc}
441         */
442        public void setMatchPattern(String value) {
443          impl.setPropertyValue(INSTANCE.getMatchPatternPropertyDefinition(), value);
444        }
445    
446    
447    
448        /**
449         * {@inheritDoc}
450         */
451        public String getReplacePattern() {
452          return impl.getPropertyValue(INSTANCE.getReplacePatternPropertyDefinition());
453        }
454    
455    
456    
457        /**
458         * {@inheritDoc}
459         */
460        public void setReplacePattern(String value) {
461          impl.setPropertyValue(INSTANCE.getReplacePatternPropertyDefinition(), value);
462        }
463    
464    
465    
466        /**
467         * {@inheritDoc}
468         */
469        public ManagedObjectDefinition<? extends RegularExpressionIdentityMapperCfgClient, ? extends RegularExpressionIdentityMapperCfg> definition() {
470          return INSTANCE;
471        }
472    
473    
474    
475        /**
476         * {@inheritDoc}
477         */
478        public PropertyProvider properties() {
479          return impl;
480        }
481    
482    
483    
484        /**
485         * {@inheritDoc}
486         */
487        public void commit() throws ManagedObjectAlreadyExistsException,
488            MissingMandatoryPropertiesException, ConcurrentModificationException,
489            OperationRejectedException, AuthorizationException,
490            CommunicationException {
491          impl.commit();
492        }
493    
494      }
495    
496    
497    
498      /**
499       * Managed object server implementation.
500       */
501      private static class RegularExpressionIdentityMapperCfgServerImpl implements
502        RegularExpressionIdentityMapperCfg {
503    
504        // Private implementation.
505        private ServerManagedObject<? extends RegularExpressionIdentityMapperCfg> impl;
506    
507        // The value of the "enabled" property.
508        private final boolean pEnabled;
509    
510        // The value of the "java-class" property.
511        private final String pJavaClass;
512    
513        // The value of the "match-attribute" property.
514        private final SortedSet<AttributeType> pMatchAttribute;
515    
516        // The value of the "match-base-dn" property.
517        private final SortedSet<DN> pMatchBaseDN;
518    
519        // The value of the "match-pattern" property.
520        private final String pMatchPattern;
521    
522        // The value of the "replace-pattern" property.
523        private final String pReplacePattern;
524    
525    
526    
527        // Private constructor.
528        private RegularExpressionIdentityMapperCfgServerImpl(ServerManagedObject<? extends RegularExpressionIdentityMapperCfg> impl) {
529          this.impl = impl;
530          this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
531          this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
532          this.pMatchAttribute = impl.getPropertyValues(INSTANCE.getMatchAttributePropertyDefinition());
533          this.pMatchBaseDN = impl.getPropertyValues(INSTANCE.getMatchBaseDNPropertyDefinition());
534          this.pMatchPattern = impl.getPropertyValue(INSTANCE.getMatchPatternPropertyDefinition());
535          this.pReplacePattern = impl.getPropertyValue(INSTANCE.getReplacePatternPropertyDefinition());
536        }
537    
538    
539    
540        /**
541         * {@inheritDoc}
542         */
543        public void addRegularExpressionChangeListener(
544            ConfigurationChangeListener<RegularExpressionIdentityMapperCfg> listener) {
545          impl.registerChangeListener(listener);
546        }
547    
548    
549    
550        /**
551         * {@inheritDoc}
552         */
553        public void removeRegularExpressionChangeListener(
554            ConfigurationChangeListener<RegularExpressionIdentityMapperCfg> listener) {
555          impl.deregisterChangeListener(listener);
556        }
557        /**
558         * {@inheritDoc}
559         */
560        public void addChangeListener(
561            ConfigurationChangeListener<IdentityMapperCfg> listener) {
562          impl.registerChangeListener(listener);
563        }
564    
565    
566    
567        /**
568         * {@inheritDoc}
569         */
570        public void removeChangeListener(
571            ConfigurationChangeListener<IdentityMapperCfg> listener) {
572          impl.deregisterChangeListener(listener);
573        }
574    
575    
576    
577        /**
578         * {@inheritDoc}
579         */
580        public boolean isEnabled() {
581          return pEnabled;
582        }
583    
584    
585    
586        /**
587         * {@inheritDoc}
588         */
589        public String getJavaClass() {
590          return pJavaClass;
591        }
592    
593    
594    
595        /**
596         * {@inheritDoc}
597         */
598        public SortedSet<AttributeType> getMatchAttribute() {
599          return pMatchAttribute;
600        }
601    
602    
603    
604        /**
605         * {@inheritDoc}
606         */
607        public SortedSet<DN> getMatchBaseDN() {
608          return pMatchBaseDN;
609        }
610    
611    
612    
613        /**
614         * {@inheritDoc}
615         */
616        public String getMatchPattern() {
617          return pMatchPattern;
618        }
619    
620    
621    
622        /**
623         * {@inheritDoc}
624         */
625        public String getReplacePattern() {
626          return pReplacePattern;
627        }
628    
629    
630    
631        /**
632         * {@inheritDoc}
633         */
634        public Class<? extends RegularExpressionIdentityMapperCfg> configurationClass() {
635          return RegularExpressionIdentityMapperCfg.class;
636        }
637    
638    
639    
640        /**
641         * {@inheritDoc}
642         */
643        public DN dn() {
644          return impl.getDN();
645        }
646    
647      }
648    }