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