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.BooleanPropertyDefinition;
035    import org.opends.server.admin.ClassPropertyDefinition;
036    import org.opends.server.admin.client.AuthorizationException;
037    import org.opends.server.admin.client.CommunicationException;
038    import org.opends.server.admin.client.ConcurrentModificationException;
039    import org.opends.server.admin.client.ManagedObject;
040    import org.opends.server.admin.client.MissingMandatoryPropertiesException;
041    import org.opends.server.admin.client.OperationRejectedException;
042    import org.opends.server.admin.DefaultBehaviorProvider;
043    import org.opends.server.admin.DefinedDefaultBehaviorProvider;
044    import org.opends.server.admin.ManagedObjectAlreadyExistsException;
045    import org.opends.server.admin.ManagedObjectDefinition;
046    import org.opends.server.admin.PropertyOption;
047    import org.opends.server.admin.PropertyProvider;
048    import org.opends.server.admin.server.ConfigurationChangeListener;
049    import org.opends.server.admin.server.ServerManagedObject;
050    import org.opends.server.admin.std.client.CharacterSetPasswordValidatorCfgClient;
051    import org.opends.server.admin.std.server.CharacterSetPasswordValidatorCfg;
052    import org.opends.server.admin.std.server.PasswordValidatorCfg;
053    import org.opends.server.admin.StringPropertyDefinition;
054    import org.opends.server.admin.Tag;
055    import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
056    import org.opends.server.types.DN;
057    
058    
059    
060    /**
061     * An interface for querying the Character Set Password Validator
062     * managed object definition meta information.
063     * <p>
064     * The Character Set Password Validator determines whether a proposed
065     * password is acceptable by checking whether it contains a sufficient
066     * number of characters from one or more user-defined character sets.
067     */
068    public final class CharacterSetPasswordValidatorCfgDefn extends ManagedObjectDefinition<CharacterSetPasswordValidatorCfgClient, CharacterSetPasswordValidatorCfg> {
069    
070      // The singleton configuration definition instance.
071      private static final CharacterSetPasswordValidatorCfgDefn INSTANCE = new CharacterSetPasswordValidatorCfgDefn();
072    
073    
074    
075      // The "allow-unclassified-characters" property definition.
076      private static final BooleanPropertyDefinition PD_ALLOW_UNCLASSIFIED_CHARACTERS;
077    
078    
079    
080      // The "character-set" property definition.
081      private static final StringPropertyDefinition PD_CHARACTER_SET;
082    
083    
084    
085      // The "java-class" property definition.
086      private static final ClassPropertyDefinition PD_JAVA_CLASS;
087    
088    
089    
090      // Build the "allow-unclassified-characters" property definition.
091      static {
092          BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "allow-unclassified-characters");
093          builder.setOption(PropertyOption.MANDATORY);
094          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "allow-unclassified-characters"));
095          builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>());
096          PD_ALLOW_UNCLASSIFIED_CHARACTERS = builder.getInstance();
097          INSTANCE.registerPropertyDefinition(PD_ALLOW_UNCLASSIFIED_CHARACTERS);
098      }
099    
100    
101    
102      // Build the "character-set" property definition.
103      static {
104          StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "character-set");
105          builder.setOption(PropertyOption.MULTI_VALUED);
106          builder.setOption(PropertyOption.MANDATORY);
107          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "character-set"));
108          builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
109          builder.setCaseInsensitive(false);
110          PD_CHARACTER_SET = builder.getInstance();
111          INSTANCE.registerPropertyDefinition(PD_CHARACTER_SET);
112      }
113    
114    
115    
116      // Build the "java-class" property definition.
117      static {
118          ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
119          builder.setOption(PropertyOption.MANDATORY);
120          builder.setOption(PropertyOption.ADVANCED);
121          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
122          DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.CharacterSetPasswordValidator");
123          builder.setDefaultBehaviorProvider(provider);
124          builder.addInstanceOf("org.opends.server.api.PasswordValidator");
125          PD_JAVA_CLASS = builder.getInstance();
126          INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
127      }
128    
129    
130    
131      // Register the tags associated with this managed object definition.
132      static {
133        INSTANCE.registerTag(Tag.valueOf("user-management"));
134      }
135    
136    
137    
138      /**
139       * Get the Character Set Password Validator configuration definition
140       * singleton.
141       *
142       * @return Returns the Character Set Password Validator
143       *         configuration definition singleton.
144       */
145      public static CharacterSetPasswordValidatorCfgDefn getInstance() {
146        return INSTANCE;
147      }
148    
149    
150    
151      /**
152       * Private constructor.
153       */
154      private CharacterSetPasswordValidatorCfgDefn() {
155        super("character-set-password-validator", PasswordValidatorCfgDefn.getInstance());
156      }
157    
158    
159    
160      /**
161       * {@inheritDoc}
162       */
163      public CharacterSetPasswordValidatorCfgClient createClientConfiguration(
164          ManagedObject<? extends CharacterSetPasswordValidatorCfgClient> impl) {
165        return new CharacterSetPasswordValidatorCfgClientImpl(impl);
166      }
167    
168    
169    
170      /**
171       * {@inheritDoc}
172       */
173      public CharacterSetPasswordValidatorCfg createServerConfiguration(
174          ServerManagedObject<? extends CharacterSetPasswordValidatorCfg> impl) {
175        return new CharacterSetPasswordValidatorCfgServerImpl(impl);
176      }
177    
178    
179    
180      /**
181       * {@inheritDoc}
182       */
183      public Class<CharacterSetPasswordValidatorCfg> getServerConfigurationClass() {
184        return CharacterSetPasswordValidatorCfg.class;
185      }
186    
187    
188    
189      /**
190       * Get the "allow-unclassified-characters" property definition.
191       * <p>
192       * Indicates whether this password validator allows passwords to
193       * contain characters outside of any of the user-defined character
194       * sets.
195       * <p>
196       * If this is "false", then only those characters in the
197       * user-defined character sets may be used in passwords. Any password
198       * containing a character not included in any character set will be
199       * rejected.
200       *
201       * @return Returns the "allow-unclassified-characters" property definition.
202       */
203      public BooleanPropertyDefinition getAllowUnclassifiedCharactersPropertyDefinition() {
204        return PD_ALLOW_UNCLASSIFIED_CHARACTERS;
205      }
206    
207    
208    
209      /**
210       * Get the "character-set" property definition.
211       * <p>
212       * Specifies a character set containing characters that a password
213       * may contain and a value indicating the minimum number of
214       * characters required from that set.
215       * <p>
216       * Each value must be an integer (indicating the minimum required
217       * characters from the set) followed by a colon and the characters to
218       * include in that set (for example, "3:abcdefghijklmnopqrstuvwxyz"
219       * indicates that a user password must contain at least three
220       * characters from the set of lowercase ASCII letters). Multiple
221       * character sets can be defined in separate values, although no
222       * character can appear in more than one character set.
223       *
224       * @return Returns the "character-set" property definition.
225       */
226      public StringPropertyDefinition getCharacterSetPropertyDefinition() {
227        return PD_CHARACTER_SET;
228      }
229    
230    
231    
232      /**
233       * Get the "enabled" property definition.
234       * <p>
235       * Indicates whether the password validator is enabled for use.
236       *
237       * @return Returns the "enabled" property definition.
238       */
239      public BooleanPropertyDefinition getEnabledPropertyDefinition() {
240        return PasswordValidatorCfgDefn.getInstance().getEnabledPropertyDefinition();
241      }
242    
243    
244    
245      /**
246       * Get the "java-class" property definition.
247       * <p>
248       * Specifies the fully-qualified name of the Java class that
249       * provides the password validator implementation.
250       *
251       * @return Returns the "java-class" property definition.
252       */
253      public ClassPropertyDefinition getJavaClassPropertyDefinition() {
254        return PD_JAVA_CLASS;
255      }
256    
257    
258    
259      /**
260       * Managed object client implementation.
261       */
262      private static class CharacterSetPasswordValidatorCfgClientImpl implements
263        CharacterSetPasswordValidatorCfgClient {
264    
265        // Private implementation.
266        private ManagedObject<? extends CharacterSetPasswordValidatorCfgClient> impl;
267    
268    
269    
270        // Private constructor.
271        private CharacterSetPasswordValidatorCfgClientImpl(
272            ManagedObject<? extends CharacterSetPasswordValidatorCfgClient> impl) {
273          this.impl = impl;
274        }
275    
276    
277    
278        /**
279         * {@inheritDoc}
280         */
281        public Boolean isAllowUnclassifiedCharacters() {
282          return impl.getPropertyValue(INSTANCE.getAllowUnclassifiedCharactersPropertyDefinition());
283        }
284    
285    
286    
287        /**
288         * {@inheritDoc}
289         */
290        public void setAllowUnclassifiedCharacters(boolean value) {
291          impl.setPropertyValue(INSTANCE.getAllowUnclassifiedCharactersPropertyDefinition(), value);
292        }
293    
294    
295    
296        /**
297         * {@inheritDoc}
298         */
299        public SortedSet<String> getCharacterSet() {
300          return impl.getPropertyValues(INSTANCE.getCharacterSetPropertyDefinition());
301        }
302    
303    
304    
305        /**
306         * {@inheritDoc}
307         */
308        public void setCharacterSet(Collection<String> values) {
309          impl.setPropertyValues(INSTANCE.getCharacterSetPropertyDefinition(), values);
310        }
311    
312    
313    
314        /**
315         * {@inheritDoc}
316         */
317        public Boolean isEnabled() {
318          return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
319        }
320    
321    
322    
323        /**
324         * {@inheritDoc}
325         */
326        public void setEnabled(boolean value) {
327          impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
328        }
329    
330    
331    
332        /**
333         * {@inheritDoc}
334         */
335        public String getJavaClass() {
336          return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
337        }
338    
339    
340    
341        /**
342         * {@inheritDoc}
343         */
344        public void setJavaClass(String value) {
345          impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
346        }
347    
348    
349    
350        /**
351         * {@inheritDoc}
352         */
353        public ManagedObjectDefinition<? extends CharacterSetPasswordValidatorCfgClient, ? extends CharacterSetPasswordValidatorCfg> definition() {
354          return INSTANCE;
355        }
356    
357    
358    
359        /**
360         * {@inheritDoc}
361         */
362        public PropertyProvider properties() {
363          return impl;
364        }
365    
366    
367    
368        /**
369         * {@inheritDoc}
370         */
371        public void commit() throws ManagedObjectAlreadyExistsException,
372            MissingMandatoryPropertiesException, ConcurrentModificationException,
373            OperationRejectedException, AuthorizationException,
374            CommunicationException {
375          impl.commit();
376        }
377    
378      }
379    
380    
381    
382      /**
383       * Managed object server implementation.
384       */
385      private static class CharacterSetPasswordValidatorCfgServerImpl implements
386        CharacterSetPasswordValidatorCfg {
387    
388        // Private implementation.
389        private ServerManagedObject<? extends CharacterSetPasswordValidatorCfg> impl;
390    
391        // The value of the "allow-unclassified-characters" property.
392        private final boolean pAllowUnclassifiedCharacters;
393    
394        // The value of the "character-set" property.
395        private final SortedSet<String> pCharacterSet;
396    
397        // The value of the "enabled" property.
398        private final boolean pEnabled;
399    
400        // The value of the "java-class" property.
401        private final String pJavaClass;
402    
403    
404    
405        // Private constructor.
406        private CharacterSetPasswordValidatorCfgServerImpl(ServerManagedObject<? extends CharacterSetPasswordValidatorCfg> impl) {
407          this.impl = impl;
408          this.pAllowUnclassifiedCharacters = impl.getPropertyValue(INSTANCE.getAllowUnclassifiedCharactersPropertyDefinition());
409          this.pCharacterSet = impl.getPropertyValues(INSTANCE.getCharacterSetPropertyDefinition());
410          this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
411          this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
412        }
413    
414    
415    
416        /**
417         * {@inheritDoc}
418         */
419        public void addCharacterSetChangeListener(
420            ConfigurationChangeListener<CharacterSetPasswordValidatorCfg> listener) {
421          impl.registerChangeListener(listener);
422        }
423    
424    
425    
426        /**
427         * {@inheritDoc}
428         */
429        public void removeCharacterSetChangeListener(
430            ConfigurationChangeListener<CharacterSetPasswordValidatorCfg> listener) {
431          impl.deregisterChangeListener(listener);
432        }
433        /**
434         * {@inheritDoc}
435         */
436        public void addChangeListener(
437            ConfigurationChangeListener<PasswordValidatorCfg> listener) {
438          impl.registerChangeListener(listener);
439        }
440    
441    
442    
443        /**
444         * {@inheritDoc}
445         */
446        public void removeChangeListener(
447            ConfigurationChangeListener<PasswordValidatorCfg> listener) {
448          impl.deregisterChangeListener(listener);
449        }
450    
451    
452    
453        /**
454         * {@inheritDoc}
455         */
456        public boolean isAllowUnclassifiedCharacters() {
457          return pAllowUnclassifiedCharacters;
458        }
459    
460    
461    
462        /**
463         * {@inheritDoc}
464         */
465        public SortedSet<String> getCharacterSet() {
466          return pCharacterSet;
467        }
468    
469    
470    
471        /**
472         * {@inheritDoc}
473         */
474        public boolean isEnabled() {
475          return pEnabled;
476        }
477    
478    
479    
480        /**
481         * {@inheritDoc}
482         */
483        public String getJavaClass() {
484          return pJavaClass;
485        }
486    
487    
488    
489        /**
490         * {@inheritDoc}
491         */
492        public Class<? extends CharacterSetPasswordValidatorCfg> configurationClass() {
493          return CharacterSetPasswordValidatorCfg.class;
494        }
495    
496    
497    
498        /**
499         * {@inheritDoc}
500         */
501        public DN dn() {
502          return impl.getDN();
503        }
504    
505      }
506    }