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 legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2008 Sun Microsystems, Inc.
025 */
026package org.opends.server.admin.std.meta;
027
028
029
030import org.opends.server.admin.AdministratorAction;
031import org.opends.server.admin.BooleanPropertyDefinition;
032import org.opends.server.admin.ClassPropertyDefinition;
033import org.opends.server.admin.client.AuthorizationException;
034import org.opends.server.admin.client.CommunicationException;
035import org.opends.server.admin.client.ConcurrentModificationException;
036import org.opends.server.admin.client.ManagedObject;
037import org.opends.server.admin.client.MissingMandatoryPropertiesException;
038import org.opends.server.admin.client.OperationRejectedException;
039import org.opends.server.admin.DefaultBehaviorProvider;
040import org.opends.server.admin.DefinedDefaultBehaviorProvider;
041import org.opends.server.admin.IntegerPropertyDefinition;
042import org.opends.server.admin.ManagedObjectAlreadyExistsException;
043import org.opends.server.admin.ManagedObjectDefinition;
044import org.opends.server.admin.PropertyOption;
045import org.opends.server.admin.PropertyProvider;
046import org.opends.server.admin.server.ConfigurationChangeListener;
047import org.opends.server.admin.server.ServerManagedObject;
048import org.opends.server.admin.std.client.PBKDF2PasswordStorageSchemeCfgClient;
049import org.opends.server.admin.std.server.PasswordStorageSchemeCfg;
050import org.opends.server.admin.std.server.PBKDF2PasswordStorageSchemeCfg;
051import org.opends.server.admin.Tag;
052import org.opends.server.types.DN;
053
054
055
056/**
057 * An interface for querying the PBKDF2 Password Storage Scheme
058 * managed object definition meta information.
059 * <p>
060 * The PBKDF2 Password Storage Scheme provides a mechanism for
061 * encoding user passwords using the PBKDF2 message digest algorithm.
062 */
063public final class PBKDF2PasswordStorageSchemeCfgDefn extends ManagedObjectDefinition<PBKDF2PasswordStorageSchemeCfgClient, PBKDF2PasswordStorageSchemeCfg> {
064
065  // The singleton configuration definition instance.
066  private static final PBKDF2PasswordStorageSchemeCfgDefn INSTANCE = new PBKDF2PasswordStorageSchemeCfgDefn();
067
068
069
070  // The "java-class" property definition.
071  private static final ClassPropertyDefinition PD_JAVA_CLASS;
072
073
074
075  // The "pbkdf2-iterations" property definition.
076  private static final IntegerPropertyDefinition PD_PBKDF2_ITERATIONS;
077
078
079
080  // Build the "java-class" property definition.
081  static {
082      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
083      builder.setOption(PropertyOption.MANDATORY);
084      builder.setOption(PropertyOption.ADVANCED);
085      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
086      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.PBKDF2PasswordStorageScheme");
087      builder.setDefaultBehaviorProvider(provider);
088      builder.addInstanceOf("org.opends.server.api.PasswordStorageScheme");
089      PD_JAVA_CLASS = builder.getInstance();
090      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
091  }
092
093
094
095  // Build the "pbkdf2-iterations" property definition.
096  static {
097      IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "pbkdf2-iterations");
098      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "pbkdf2-iterations"));
099      DefaultBehaviorProvider<Integer> provider = new DefinedDefaultBehaviorProvider<Integer>("10000");
100      builder.setDefaultBehaviorProvider(provider);
101      builder.setLowerLimit(1);
102      PD_PBKDF2_ITERATIONS = builder.getInstance();
103      INSTANCE.registerPropertyDefinition(PD_PBKDF2_ITERATIONS);
104  }
105
106
107
108  // Register the tags associated with this managed object definition.
109  static {
110    INSTANCE.registerTag(Tag.valueOf("user-management"));
111  }
112
113
114
115  /**
116   * Get the PBKDF2 Password Storage Scheme configuration definition
117   * singleton.
118   *
119   * @return Returns the PBKDF2 Password Storage Scheme configuration
120   *         definition singleton.
121   */
122  public static PBKDF2PasswordStorageSchemeCfgDefn getInstance() {
123    return INSTANCE;
124  }
125
126
127
128  /**
129   * Private constructor.
130   */
131  private PBKDF2PasswordStorageSchemeCfgDefn() {
132    super("pbkdf2-password-storage-scheme", PasswordStorageSchemeCfgDefn.getInstance());
133  }
134
135
136
137  /**
138   * {@inheritDoc}
139   */
140  public PBKDF2PasswordStorageSchemeCfgClient createClientConfiguration(
141      ManagedObject<? extends PBKDF2PasswordStorageSchemeCfgClient> impl) {
142    return new PBKDF2PasswordStorageSchemeCfgClientImpl(impl);
143  }
144
145
146
147  /**
148   * {@inheritDoc}
149   */
150  public PBKDF2PasswordStorageSchemeCfg createServerConfiguration(
151      ServerManagedObject<? extends PBKDF2PasswordStorageSchemeCfg> impl) {
152    return new PBKDF2PasswordStorageSchemeCfgServerImpl(impl);
153  }
154
155
156
157  /**
158   * {@inheritDoc}
159   */
160  public Class<PBKDF2PasswordStorageSchemeCfg> getServerConfigurationClass() {
161    return PBKDF2PasswordStorageSchemeCfg.class;
162  }
163
164
165
166  /**
167   * Get the "enabled" property definition.
168   * <p>
169   * Indicates whether the PBKDF2 Password Storage Scheme is enabled
170   * for use.
171   *
172   * @return Returns the "enabled" property definition.
173   */
174  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
175    return PasswordStorageSchemeCfgDefn.getInstance().getEnabledPropertyDefinition();
176  }
177
178
179
180  /**
181   * Get the "java-class" property definition.
182   * <p>
183   * Specifies the fully-qualified name of the Java class that
184   * provides the PBKDF2 Password Storage Scheme implementation.
185   *
186   * @return Returns the "java-class" property definition.
187   */
188  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
189    return PD_JAVA_CLASS;
190  }
191
192
193
194  /**
195   * Get the "pbkdf2-iterations" property definition.
196   * <p>
197   * The number of algorithm iterations to make. NIST recommends at
198   * least 1000.
199   *
200   * @return Returns the "pbkdf2-iterations" property definition.
201   */
202  public IntegerPropertyDefinition getPBKDF2IterationsPropertyDefinition() {
203    return PD_PBKDF2_ITERATIONS;
204  }
205
206
207
208  /**
209   * Managed object client implementation.
210   */
211  private static class PBKDF2PasswordStorageSchemeCfgClientImpl implements
212    PBKDF2PasswordStorageSchemeCfgClient {
213
214    // Private implementation.
215    private ManagedObject<? extends PBKDF2PasswordStorageSchemeCfgClient> impl;
216
217
218
219    // Private constructor.
220    private PBKDF2PasswordStorageSchemeCfgClientImpl(
221        ManagedObject<? extends PBKDF2PasswordStorageSchemeCfgClient> impl) {
222      this.impl = impl;
223    }
224
225
226
227    /**
228     * {@inheritDoc}
229     */
230    public Boolean isEnabled() {
231      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
232    }
233
234
235
236    /**
237     * {@inheritDoc}
238     */
239    public void setEnabled(boolean value) {
240      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
241    }
242
243
244
245    /**
246     * {@inheritDoc}
247     */
248    public String getJavaClass() {
249      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
250    }
251
252
253
254    /**
255     * {@inheritDoc}
256     */
257    public void setJavaClass(String value) {
258      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
259    }
260
261
262
263    /**
264     * {@inheritDoc}
265     */
266    public int getPBKDF2Iterations() {
267      return impl.getPropertyValue(INSTANCE.getPBKDF2IterationsPropertyDefinition());
268    }
269
270
271
272    /**
273     * {@inheritDoc}
274     */
275    public void setPBKDF2Iterations(Integer value) {
276      impl.setPropertyValue(INSTANCE.getPBKDF2IterationsPropertyDefinition(), value);
277    }
278
279
280
281    /**
282     * {@inheritDoc}
283     */
284    public ManagedObjectDefinition<? extends PBKDF2PasswordStorageSchemeCfgClient, ? extends PBKDF2PasswordStorageSchemeCfg> definition() {
285      return INSTANCE;
286    }
287
288
289
290    /**
291     * {@inheritDoc}
292     */
293    public PropertyProvider properties() {
294      return impl;
295    }
296
297
298
299    /**
300     * {@inheritDoc}
301     */
302    public void commit() throws ManagedObjectAlreadyExistsException,
303        MissingMandatoryPropertiesException, ConcurrentModificationException,
304        OperationRejectedException, AuthorizationException,
305        CommunicationException {
306      impl.commit();
307    }
308
309  }
310
311
312
313  /**
314   * Managed object server implementation.
315   */
316  private static class PBKDF2PasswordStorageSchemeCfgServerImpl implements
317    PBKDF2PasswordStorageSchemeCfg {
318
319    // Private implementation.
320    private ServerManagedObject<? extends PBKDF2PasswordStorageSchemeCfg> impl;
321
322    // The value of the "enabled" property.
323    private final boolean pEnabled;
324
325    // The value of the "java-class" property.
326    private final String pJavaClass;
327
328    // The value of the "pbkdf2-iterations" property.
329    private final int pPBKDF2Iterations;
330
331
332
333    // Private constructor.
334    private PBKDF2PasswordStorageSchemeCfgServerImpl(ServerManagedObject<? extends PBKDF2PasswordStorageSchemeCfg> impl) {
335      this.impl = impl;
336      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
337      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
338      this.pPBKDF2Iterations = impl.getPropertyValue(INSTANCE.getPBKDF2IterationsPropertyDefinition());
339    }
340
341
342
343    /**
344     * {@inheritDoc}
345     */
346    public void addPBKDF2ChangeListener(
347        ConfigurationChangeListener<PBKDF2PasswordStorageSchemeCfg> listener) {
348      impl.registerChangeListener(listener);
349    }
350
351
352
353    /**
354     * {@inheritDoc}
355     */
356    public void removePBKDF2ChangeListener(
357        ConfigurationChangeListener<PBKDF2PasswordStorageSchemeCfg> listener) {
358      impl.deregisterChangeListener(listener);
359    }
360    /**
361     * {@inheritDoc}
362     */
363    public void addChangeListener(
364        ConfigurationChangeListener<PasswordStorageSchemeCfg> listener) {
365      impl.registerChangeListener(listener);
366    }
367
368
369
370    /**
371     * {@inheritDoc}
372     */
373    public void removeChangeListener(
374        ConfigurationChangeListener<PasswordStorageSchemeCfg> listener) {
375      impl.deregisterChangeListener(listener);
376    }
377
378
379
380    /**
381     * {@inheritDoc}
382     */
383    public boolean isEnabled() {
384      return pEnabled;
385    }
386
387
388
389    /**
390     * {@inheritDoc}
391     */
392    public String getJavaClass() {
393      return pJavaClass;
394    }
395
396
397
398    /**
399     * {@inheritDoc}
400     */
401    public int getPBKDF2Iterations() {
402      return pPBKDF2Iterations;
403    }
404
405
406
407    /**
408     * {@inheritDoc}
409     */
410    public Class<? extends PBKDF2PasswordStorageSchemeCfg> configurationClass() {
411      return PBKDF2PasswordStorageSchemeCfg.class;
412    }
413
414
415
416    /**
417     * {@inheritDoc}
418     */
419    public DN dn() {
420      return impl.getDN();
421    }
422
423  }
424}