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