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.ManagedObjectAlreadyExistsException;
041    import org.opends.server.admin.ManagedObjectDefinition;
042    import org.opends.server.admin.PropertyOption;
043    import org.opends.server.admin.PropertyProvider;
044    import org.opends.server.admin.server.ConfigurationChangeListener;
045    import org.opends.server.admin.server.ServerManagedObject;
046    import org.opends.server.admin.std.client.PasswordValidatorCfgClient;
047    import org.opends.server.admin.std.server.PasswordValidatorCfg;
048    import org.opends.server.admin.Tag;
049    import org.opends.server.admin.TopCfgDefn;
050    import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
051    import org.opends.server.types.DN;
052    
053    
054    
055    /**
056     * An interface for querying the Password Validator managed object
057     * definition meta information.
058     * <p>
059     * Password Validators are responsible for determining whether a
060     * proposed password is acceptable for use and could include checks
061     * like ensuring it meets minimum length requirements, that it has an
062     * appropriate range of characters, or that it is not in the history.
063     */
064    public final class PasswordValidatorCfgDefn extends ManagedObjectDefinition<PasswordValidatorCfgClient, PasswordValidatorCfg> {
065    
066      // The singleton configuration definition instance.
067      private static final PasswordValidatorCfgDefn INSTANCE = new PasswordValidatorCfgDefn();
068    
069    
070    
071      // The "enabled" property definition.
072      private static final BooleanPropertyDefinition PD_ENABLED;
073    
074    
075    
076      // The "java-class" property definition.
077      private static final ClassPropertyDefinition PD_JAVA_CLASS;
078    
079    
080    
081      // Build the "enabled" property definition.
082      static {
083          BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled");
084          builder.setOption(PropertyOption.MANDATORY);
085          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled"));
086          builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>());
087          PD_ENABLED = builder.getInstance();
088          INSTANCE.registerPropertyDefinition(PD_ENABLED);
089      }
090    
091    
092    
093      // Build the "java-class" property definition.
094      static {
095          ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
096          builder.setOption(PropertyOption.MANDATORY);
097          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
098          builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
099          builder.addInstanceOf("org.opends.server.api.PasswordValidator");
100          PD_JAVA_CLASS = builder.getInstance();
101          INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
102      }
103    
104    
105    
106      // Register the tags associated with this managed object definition.
107      static {
108        INSTANCE.registerTag(Tag.valueOf("user-management"));
109      }
110    
111    
112    
113      /**
114       * Get the Password Validator configuration definition singleton.
115       *
116       * @return Returns the Password Validator configuration definition
117       *         singleton.
118       */
119      public static PasswordValidatorCfgDefn getInstance() {
120        return INSTANCE;
121      }
122    
123    
124    
125      /**
126       * Private constructor.
127       */
128      private PasswordValidatorCfgDefn() {
129        super("password-validator", TopCfgDefn.getInstance());
130      }
131    
132    
133    
134      /**
135       * {@inheritDoc}
136       */
137      public PasswordValidatorCfgClient createClientConfiguration(
138          ManagedObject<? extends PasswordValidatorCfgClient> impl) {
139        return new PasswordValidatorCfgClientImpl(impl);
140      }
141    
142    
143    
144      /**
145       * {@inheritDoc}
146       */
147      public PasswordValidatorCfg createServerConfiguration(
148          ServerManagedObject<? extends PasswordValidatorCfg> impl) {
149        return new PasswordValidatorCfgServerImpl(impl);
150      }
151    
152    
153    
154      /**
155       * {@inheritDoc}
156       */
157      public Class<PasswordValidatorCfg> getServerConfigurationClass() {
158        return PasswordValidatorCfg.class;
159      }
160    
161    
162    
163      /**
164       * Get the "enabled" property definition.
165       * <p>
166       * Indicates whether the password validator is enabled for use.
167       *
168       * @return Returns the "enabled" property definition.
169       */
170      public BooleanPropertyDefinition getEnabledPropertyDefinition() {
171        return PD_ENABLED;
172      }
173    
174    
175    
176      /**
177       * Get the "java-class" property definition.
178       * <p>
179       * Specifies the fully-qualified name of the Java class that
180       * provides the password validator implementation.
181       *
182       * @return Returns the "java-class" property definition.
183       */
184      public ClassPropertyDefinition getJavaClassPropertyDefinition() {
185        return PD_JAVA_CLASS;
186      }
187    
188    
189    
190      /**
191       * Managed object client implementation.
192       */
193      private static class PasswordValidatorCfgClientImpl implements
194        PasswordValidatorCfgClient {
195    
196        // Private implementation.
197        private ManagedObject<? extends PasswordValidatorCfgClient> impl;
198    
199    
200    
201        // Private constructor.
202        private PasswordValidatorCfgClientImpl(
203            ManagedObject<? extends PasswordValidatorCfgClient> impl) {
204          this.impl = impl;
205        }
206    
207    
208    
209        /**
210         * {@inheritDoc}
211         */
212        public Boolean isEnabled() {
213          return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
214        }
215    
216    
217    
218        /**
219         * {@inheritDoc}
220         */
221        public void setEnabled(boolean value) {
222          impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
223        }
224    
225    
226    
227        /**
228         * {@inheritDoc}
229         */
230        public String getJavaClass() {
231          return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
232        }
233    
234    
235    
236        /**
237         * {@inheritDoc}
238         */
239        public void setJavaClass(String value) {
240          impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
241        }
242    
243    
244    
245        /**
246         * {@inheritDoc}
247         */
248        public ManagedObjectDefinition<? extends PasswordValidatorCfgClient, ? extends PasswordValidatorCfg> definition() {
249          return INSTANCE;
250        }
251    
252    
253    
254        /**
255         * {@inheritDoc}
256         */
257        public PropertyProvider properties() {
258          return impl;
259        }
260    
261    
262    
263        /**
264         * {@inheritDoc}
265         */
266        public void commit() throws ManagedObjectAlreadyExistsException,
267            MissingMandatoryPropertiesException, ConcurrentModificationException,
268            OperationRejectedException, AuthorizationException,
269            CommunicationException {
270          impl.commit();
271        }
272    
273      }
274    
275    
276    
277      /**
278       * Managed object server implementation.
279       */
280      private static class PasswordValidatorCfgServerImpl implements
281        PasswordValidatorCfg {
282    
283        // Private implementation.
284        private ServerManagedObject<? extends PasswordValidatorCfg> impl;
285    
286        // The value of the "enabled" property.
287        private final boolean pEnabled;
288    
289        // The value of the "java-class" property.
290        private final String pJavaClass;
291    
292    
293    
294        // Private constructor.
295        private PasswordValidatorCfgServerImpl(ServerManagedObject<? extends PasswordValidatorCfg> impl) {
296          this.impl = impl;
297          this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
298          this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
299        }
300    
301    
302    
303        /**
304         * {@inheritDoc}
305         */
306        public void addChangeListener(
307            ConfigurationChangeListener<PasswordValidatorCfg> listener) {
308          impl.registerChangeListener(listener);
309        }
310    
311    
312    
313        /**
314         * {@inheritDoc}
315         */
316        public void removeChangeListener(
317            ConfigurationChangeListener<PasswordValidatorCfg> listener) {
318          impl.deregisterChangeListener(listener);
319        }
320    
321    
322    
323        /**
324         * {@inheritDoc}
325         */
326        public boolean isEnabled() {
327          return pEnabled;
328        }
329    
330    
331    
332        /**
333         * {@inheritDoc}
334         */
335        public String getJavaClass() {
336          return pJavaClass;
337        }
338    
339    
340    
341        /**
342         * {@inheritDoc}
343         */
344        public Class<? extends PasswordValidatorCfg> configurationClass() {
345          return PasswordValidatorCfg.class;
346        }
347    
348    
349    
350        /**
351         * {@inheritDoc}
352         */
353        public DN dn() {
354          return impl.getDN();
355        }
356    
357      }
358    }