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