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.BooleanPropertyDefinition;
035import org.opends.server.admin.ClassPropertyDefinition;
036import org.opends.server.admin.client.AuthorizationException;
037import org.opends.server.admin.client.CommunicationException;
038import org.opends.server.admin.client.ConcurrentModificationException;
039import org.opends.server.admin.client.ManagedObject;
040import org.opends.server.admin.client.MissingMandatoryPropertiesException;
041import org.opends.server.admin.client.OperationRejectedException;
042import org.opends.server.admin.condition.Conditions;
043import org.opends.server.admin.DefaultBehaviorProvider;
044import org.opends.server.admin.DefinedDefaultBehaviorProvider;
045import org.opends.server.admin.GenericConstraint;
046import org.opends.server.admin.IntegerPropertyDefinition;
047import org.opends.server.admin.ManagedObjectAlreadyExistsException;
048import org.opends.server.admin.ManagedObjectDefinition;
049import org.opends.server.admin.PropertyOption;
050import org.opends.server.admin.PropertyProvider;
051import org.opends.server.admin.server.ConfigurationChangeListener;
052import org.opends.server.admin.server.ServerManagedObject;
053import org.opends.server.admin.std.client.CharacterSetPasswordValidatorCfgClient;
054import org.opends.server.admin.std.server.CharacterSetPasswordValidatorCfg;
055import org.opends.server.admin.std.server.PasswordValidatorCfg;
056import org.opends.server.admin.StringPropertyDefinition;
057import org.opends.server.admin.Tag;
058import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
059import org.opends.server.types.DN;
060
061
062
063/**
064 * An interface for querying the Character Set Password Validator
065 * managed object definition meta information.
066 * <p>
067 * The Character Set Password Validator determines whether a proposed
068 * password is acceptable by checking whether it contains a sufficient
069 * number of characters from one or more user-defined character sets
070 * and ranges.
071 */
072public final class CharacterSetPasswordValidatorCfgDefn extends ManagedObjectDefinition<CharacterSetPasswordValidatorCfgClient, CharacterSetPasswordValidatorCfg> {
073
074  // The singleton configuration definition instance.
075  private static final CharacterSetPasswordValidatorCfgDefn INSTANCE = new CharacterSetPasswordValidatorCfgDefn();
076
077
078
079  // The "allow-unclassified-characters" property definition.
080  private static final BooleanPropertyDefinition PD_ALLOW_UNCLASSIFIED_CHARACTERS;
081
082
083
084  // The "character-set" property definition.
085  private static final StringPropertyDefinition PD_CHARACTER_SET;
086
087
088
089  // The "character-set-ranges" property definition.
090  private static final StringPropertyDefinition PD_CHARACTER_SET_RANGES;
091
092
093
094  // The "java-class" property definition.
095  private static final ClassPropertyDefinition PD_JAVA_CLASS;
096
097
098
099  // The "min-character-sets" property definition.
100  private static final IntegerPropertyDefinition PD_MIN_CHARACTER_SETS;
101
102
103
104  // Build the "allow-unclassified-characters" property definition.
105  static {
106      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "allow-unclassified-characters");
107      builder.setOption(PropertyOption.MANDATORY);
108      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "allow-unclassified-characters"));
109      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>());
110      PD_ALLOW_UNCLASSIFIED_CHARACTERS = builder.getInstance();
111      INSTANCE.registerPropertyDefinition(PD_ALLOW_UNCLASSIFIED_CHARACTERS);
112  }
113
114
115
116  // Build the "character-set" property definition.
117  static {
118      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "character-set");
119      builder.setOption(PropertyOption.MULTI_VALUED);
120      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "character-set"));
121      builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<String>(INSTANCE, "character-set"));
122      builder.setCaseInsensitive(false);
123      PD_CHARACTER_SET = builder.getInstance();
124      INSTANCE.registerPropertyDefinition(PD_CHARACTER_SET);
125  }
126
127
128
129  // Build the "character-set-ranges" property definition.
130  static {
131      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "character-set-ranges");
132      builder.setOption(PropertyOption.MULTI_VALUED);
133      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "character-set-ranges"));
134      builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<String>(INSTANCE, "character-set-ranges"));
135      builder.setCaseInsensitive(false);
136      PD_CHARACTER_SET_RANGES = builder.getInstance();
137      INSTANCE.registerPropertyDefinition(PD_CHARACTER_SET_RANGES);
138  }
139
140
141
142  // Build the "java-class" property definition.
143  static {
144      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
145      builder.setOption(PropertyOption.MANDATORY);
146      builder.setOption(PropertyOption.ADVANCED);
147      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
148      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.CharacterSetPasswordValidator");
149      builder.setDefaultBehaviorProvider(provider);
150      builder.addInstanceOf("org.opends.server.api.PasswordValidator");
151      PD_JAVA_CLASS = builder.getInstance();
152      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
153  }
154
155
156
157  // Build the "min-character-sets" property definition.
158  static {
159      IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "min-character-sets");
160      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "min-character-sets"));
161      builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<Integer>(INSTANCE, "min-character-sets"));
162      PD_MIN_CHARACTER_SETS = builder.getInstance();
163      INSTANCE.registerPropertyDefinition(PD_MIN_CHARACTER_SETS);
164  }
165
166
167
168  // Register the tags associated with this managed object definition.
169  static {
170    INSTANCE.registerTag(Tag.valueOf("user-management"));
171  }
172
173
174
175  // Register the constraints associated with this managed object definition.
176  static {
177    INSTANCE.registerConstraint(new GenericConstraint(INSTANCE, 1, Conditions.or(Conditions.isPresent("character-set"), Conditions.isPresent("character-set-ranges"))));
178  }
179
180
181
182  /**
183   * Get the Character Set Password Validator configuration definition
184   * singleton.
185   *
186   * @return Returns the Character Set Password Validator
187   *         configuration definition singleton.
188   */
189  public static CharacterSetPasswordValidatorCfgDefn getInstance() {
190    return INSTANCE;
191  }
192
193
194
195  /**
196   * Private constructor.
197   */
198  private CharacterSetPasswordValidatorCfgDefn() {
199    super("character-set-password-validator", PasswordValidatorCfgDefn.getInstance());
200  }
201
202
203
204  /**
205   * {@inheritDoc}
206   */
207  public CharacterSetPasswordValidatorCfgClient createClientConfiguration(
208      ManagedObject<? extends CharacterSetPasswordValidatorCfgClient> impl) {
209    return new CharacterSetPasswordValidatorCfgClientImpl(impl);
210  }
211
212
213
214  /**
215   * {@inheritDoc}
216   */
217  public CharacterSetPasswordValidatorCfg createServerConfiguration(
218      ServerManagedObject<? extends CharacterSetPasswordValidatorCfg> impl) {
219    return new CharacterSetPasswordValidatorCfgServerImpl(impl);
220  }
221
222
223
224  /**
225   * {@inheritDoc}
226   */
227  public Class<CharacterSetPasswordValidatorCfg> getServerConfigurationClass() {
228    return CharacterSetPasswordValidatorCfg.class;
229  }
230
231
232
233  /**
234   * Get the "allow-unclassified-characters" property definition.
235   * <p>
236   * Indicates whether this password validator allows passwords to
237   * contain characters outside of any of the user-defined character
238   * sets and ranges.
239   * <p>
240   * If this is "false", then only those characters in the
241   * user-defined character sets and ranges may be used in passwords.
242   * Any password containing a character not included in any character
243   * set or range will be rejected.
244   *
245   * @return Returns the "allow-unclassified-characters" property definition.
246   */
247  public BooleanPropertyDefinition getAllowUnclassifiedCharactersPropertyDefinition() {
248    return PD_ALLOW_UNCLASSIFIED_CHARACTERS;
249  }
250
251
252
253  /**
254   * Get the "character-set" property definition.
255   * <p>
256   * Specifies a character set containing characters that a password
257   * may contain and a value indicating the minimum number of
258   * characters required from that set.
259   * <p>
260   * Each value must be an integer (indicating the minimum required
261   * characters from the set which may be zero, indicating that the
262   * character set is optional) followed by a colon and the characters
263   * to include in that set (for example,
264   * "3:abcdefghijklmnopqrstuvwxyz" indicates that a user password must
265   * contain at least three characters from the set of lowercase ASCII
266   * letters). Multiple character sets can be defined in separate
267   * values, although no character can appear in more than one
268   * character set.
269   *
270   * @return Returns the "character-set" property definition.
271   */
272  public StringPropertyDefinition getCharacterSetPropertyDefinition() {
273    return PD_CHARACTER_SET;
274  }
275
276
277
278  /**
279   * Get the "character-set-ranges" property definition.
280   * <p>
281   * Specifies a character range containing characters that a password
282   * may contain and a value indicating the minimum number of
283   * characters required from that range.
284   * <p>
285   * Each value must be an integer (indicating the minimum required
286   * characters from the range which may be zero, indicating that the
287   * character range is optional) followed by a colon and one or more
288   * range specifications. A range specification is 3 characters: the
289   * first character allowed, a minus, and the last character allowed.
290   * For example, "3:A-Za-z0-9". The ranges in each value should not
291   * overlap, and the characters in each range specification should be
292   * ordered.
293   *
294   * @return Returns the "character-set-ranges" property definition.
295   */
296  public StringPropertyDefinition getCharacterSetRangesPropertyDefinition() {
297    return PD_CHARACTER_SET_RANGES;
298  }
299
300
301
302  /**
303   * Get the "enabled" property definition.
304   * <p>
305   * Indicates whether the password validator is enabled for use.
306   *
307   * @return Returns the "enabled" property definition.
308   */
309  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
310    return PasswordValidatorCfgDefn.getInstance().getEnabledPropertyDefinition();
311  }
312
313
314
315  /**
316   * Get the "java-class" property definition.
317   * <p>
318   * Specifies the fully-qualified name of the Java class that
319   * provides the password validator implementation.
320   *
321   * @return Returns the "java-class" property definition.
322   */
323  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
324    return PD_JAVA_CLASS;
325  }
326
327
328
329  /**
330   * Get the "min-character-sets" property definition.
331   * <p>
332   * Specifies the minimum number of character sets and ranges that a
333   * password must contain.
334   * <p>
335   * This property should only be used in conjunction with optional
336   * character sets and ranges (those requiring zero characters). Its
337   * value must include any mandatory character sets and ranges (those
338   * requiring greater than zero characters). This is useful in
339   * situations where a password must contain characters from mandatory
340   * character sets and ranges, and characters from at least N optional
341   * character sets and ranges. For example, it is quite common to
342   * require that a password contains at least one non-alphanumeric
343   * character as well as characters from two alphanumeric character
344   * sets (lower-case, upper-case, digits). In this case, this property
345   * should be set to 3.
346   *
347   * @return Returns the "min-character-sets" property definition.
348   */
349  public IntegerPropertyDefinition getMinCharacterSetsPropertyDefinition() {
350    return PD_MIN_CHARACTER_SETS;
351  }
352
353
354
355  /**
356   * Managed object client implementation.
357   */
358  private static class CharacterSetPasswordValidatorCfgClientImpl implements
359    CharacterSetPasswordValidatorCfgClient {
360
361    // Private implementation.
362    private ManagedObject<? extends CharacterSetPasswordValidatorCfgClient> impl;
363
364
365
366    // Private constructor.
367    private CharacterSetPasswordValidatorCfgClientImpl(
368        ManagedObject<? extends CharacterSetPasswordValidatorCfgClient> impl) {
369      this.impl = impl;
370    }
371
372
373
374    /**
375     * {@inheritDoc}
376     */
377    public Boolean isAllowUnclassifiedCharacters() {
378      return impl.getPropertyValue(INSTANCE.getAllowUnclassifiedCharactersPropertyDefinition());
379    }
380
381
382
383    /**
384     * {@inheritDoc}
385     */
386    public void setAllowUnclassifiedCharacters(boolean value) {
387      impl.setPropertyValue(INSTANCE.getAllowUnclassifiedCharactersPropertyDefinition(), value);
388    }
389
390
391
392    /**
393     * {@inheritDoc}
394     */
395    public SortedSet<String> getCharacterSet() {
396      return impl.getPropertyValues(INSTANCE.getCharacterSetPropertyDefinition());
397    }
398
399
400
401    /**
402     * {@inheritDoc}
403     */
404    public void setCharacterSet(Collection<String> values) {
405      impl.setPropertyValues(INSTANCE.getCharacterSetPropertyDefinition(), values);
406    }
407
408
409
410    /**
411     * {@inheritDoc}
412     */
413    public SortedSet<String> getCharacterSetRanges() {
414      return impl.getPropertyValues(INSTANCE.getCharacterSetRangesPropertyDefinition());
415    }
416
417
418
419    /**
420     * {@inheritDoc}
421     */
422    public void setCharacterSetRanges(Collection<String> values) {
423      impl.setPropertyValues(INSTANCE.getCharacterSetRangesPropertyDefinition(), values);
424    }
425
426
427
428    /**
429     * {@inheritDoc}
430     */
431    public Boolean isEnabled() {
432      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
433    }
434
435
436
437    /**
438     * {@inheritDoc}
439     */
440    public void setEnabled(boolean value) {
441      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
442    }
443
444
445
446    /**
447     * {@inheritDoc}
448     */
449    public String getJavaClass() {
450      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
451    }
452
453
454
455    /**
456     * {@inheritDoc}
457     */
458    public void setJavaClass(String value) {
459      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
460    }
461
462
463
464    /**
465     * {@inheritDoc}
466     */
467    public Integer getMinCharacterSets() {
468      return impl.getPropertyValue(INSTANCE.getMinCharacterSetsPropertyDefinition());
469    }
470
471
472
473    /**
474     * {@inheritDoc}
475     */
476    public void setMinCharacterSets(Integer value) {
477      impl.setPropertyValue(INSTANCE.getMinCharacterSetsPropertyDefinition(), value);
478    }
479
480
481
482    /**
483     * {@inheritDoc}
484     */
485    public ManagedObjectDefinition<? extends CharacterSetPasswordValidatorCfgClient, ? extends CharacterSetPasswordValidatorCfg> definition() {
486      return INSTANCE;
487    }
488
489
490
491    /**
492     * {@inheritDoc}
493     */
494    public PropertyProvider properties() {
495      return impl;
496    }
497
498
499
500    /**
501     * {@inheritDoc}
502     */
503    public void commit() throws ManagedObjectAlreadyExistsException,
504        MissingMandatoryPropertiesException, ConcurrentModificationException,
505        OperationRejectedException, AuthorizationException,
506        CommunicationException {
507      impl.commit();
508    }
509
510
511
512    /** {@inheritDoc} */
513    public String toString() {
514      return impl.toString();
515    }
516  }
517
518
519
520  /**
521   * Managed object server implementation.
522   */
523  private static class CharacterSetPasswordValidatorCfgServerImpl implements
524    CharacterSetPasswordValidatorCfg {
525
526    // Private implementation.
527    private ServerManagedObject<? extends CharacterSetPasswordValidatorCfg> impl;
528
529    // The value of the "allow-unclassified-characters" property.
530    private final boolean pAllowUnclassifiedCharacters;
531
532    // The value of the "character-set" property.
533    private final SortedSet<String> pCharacterSet;
534
535    // The value of the "character-set-ranges" property.
536    private final SortedSet<String> pCharacterSetRanges;
537
538    // The value of the "enabled" property.
539    private final boolean pEnabled;
540
541    // The value of the "java-class" property.
542    private final String pJavaClass;
543
544    // The value of the "min-character-sets" property.
545    private final Integer pMinCharacterSets;
546
547
548
549    // Private constructor.
550    private CharacterSetPasswordValidatorCfgServerImpl(ServerManagedObject<? extends CharacterSetPasswordValidatorCfg> impl) {
551      this.impl = impl;
552      this.pAllowUnclassifiedCharacters = impl.getPropertyValue(INSTANCE.getAllowUnclassifiedCharactersPropertyDefinition());
553      this.pCharacterSet = impl.getPropertyValues(INSTANCE.getCharacterSetPropertyDefinition());
554      this.pCharacterSetRanges = impl.getPropertyValues(INSTANCE.getCharacterSetRangesPropertyDefinition());
555      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
556      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
557      this.pMinCharacterSets = impl.getPropertyValue(INSTANCE.getMinCharacterSetsPropertyDefinition());
558    }
559
560
561
562    /**
563     * {@inheritDoc}
564     */
565    public void addCharacterSetChangeListener(
566        ConfigurationChangeListener<CharacterSetPasswordValidatorCfg> listener) {
567      impl.registerChangeListener(listener);
568    }
569
570
571
572    /**
573     * {@inheritDoc}
574     */
575    public void removeCharacterSetChangeListener(
576        ConfigurationChangeListener<CharacterSetPasswordValidatorCfg> listener) {
577      impl.deregisterChangeListener(listener);
578    }
579    /**
580     * {@inheritDoc}
581     */
582    public void addChangeListener(
583        ConfigurationChangeListener<PasswordValidatorCfg> listener) {
584      impl.registerChangeListener(listener);
585    }
586
587
588
589    /**
590     * {@inheritDoc}
591     */
592    public void removeChangeListener(
593        ConfigurationChangeListener<PasswordValidatorCfg> listener) {
594      impl.deregisterChangeListener(listener);
595    }
596
597
598
599    /**
600     * {@inheritDoc}
601     */
602    public boolean isAllowUnclassifiedCharacters() {
603      return pAllowUnclassifiedCharacters;
604    }
605
606
607
608    /**
609     * {@inheritDoc}
610     */
611    public SortedSet<String> getCharacterSet() {
612      return pCharacterSet;
613    }
614
615
616
617    /**
618     * {@inheritDoc}
619     */
620    public SortedSet<String> getCharacterSetRanges() {
621      return pCharacterSetRanges;
622    }
623
624
625
626    /**
627     * {@inheritDoc}
628     */
629    public boolean isEnabled() {
630      return pEnabled;
631    }
632
633
634
635    /**
636     * {@inheritDoc}
637     */
638    public String getJavaClass() {
639      return pJavaClass;
640    }
641
642
643
644    /**
645     * {@inheritDoc}
646     */
647    public Integer getMinCharacterSets() {
648      return pMinCharacterSets;
649    }
650
651
652
653    /**
654     * {@inheritDoc}
655     */
656    public Class<? extends CharacterSetPasswordValidatorCfg> configurationClass() {
657      return CharacterSetPasswordValidatorCfg.class;
658    }
659
660
661
662    /**
663     * {@inheritDoc}
664     */
665    public DN dn() {
666      return impl.getDN();
667    }
668
669
670
671    /** {@inheritDoc} */
672    public String toString() {
673      return impl.toString();
674    }
675  }
676}