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