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