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.EnumPropertyDefinition;
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.CryptPasswordStorageSchemeCfgClient;
040import org.opends.server.admin.std.server.CryptPasswordStorageSchemeCfg;
041import org.opends.server.admin.std.server.PasswordStorageSchemeCfg;
042import org.opends.server.admin.Tag;
043
044
045
046/**
047 * An interface for querying the Crypt Password Storage Scheme managed
048 * object definition meta information.
049 * <p>
050 * The Crypt Password Storage Scheme provides a mechanism for encoding
051 * user passwords like Unix crypt does. Like on most Unix systems, the
052 * password may be encrypted using different algorithms, either Unix
053 * crypt, md5, sha256 or sha512.
054 */
055public final class CryptPasswordStorageSchemeCfgDefn extends ManagedObjectDefinition<CryptPasswordStorageSchemeCfgClient, CryptPasswordStorageSchemeCfg> {
056
057  // The singleton configuration definition instance.
058  private static final CryptPasswordStorageSchemeCfgDefn INSTANCE = new CryptPasswordStorageSchemeCfgDefn();
059
060
061
062  /**
063   * Defines the set of permissable values for the "crypt-password-storage-encryption-algorithm" property.
064   * <p>
065   * Specifies the algorithm to use to encrypt new passwords.
066   * <p>
067   * Select the crypt algorithm to use to encrypt new passwords. The
068   * value can either be "unix", which means the password is encrypted
069   * with the weak Unix crypt algorithm, or "md5" which means the
070   * password is encrypted with the BSD MD5 algorithm and has a $1$
071   * prefix, or "sha256" which means the password is encrypted with the
072   * SHA256 algorithm and has a $5$ prefix, or "sha512" which means the
073   * password is encrypted with the SHA512 algorithm and has a $6$
074   * prefix.
075   */
076  public static enum CryptPasswordStorageEncryptionAlgorithm {
077
078    /**
079     * New passwords are encrypted with the BSD MD5 algorithm.
080     */
081    MD5("md5"),
082
083
084
085    /**
086     * New passwords are encrypted with the Unix crypt SHA256
087     * algorithm.
088     */
089    SHA256("sha256"),
090
091
092
093    /**
094     * New passwords are encrypted with the Unix crypt SHA512
095     * algorithm.
096     */
097    SHA512("sha512"),
098
099
100
101    /**
102     * New passwords are encrypted with the Unix crypt algorithm.
103     * Passwords are truncated at 8 characters and the top bit of each
104     * character is ignored.
105     */
106    UNIX("unix");
107
108
109
110    // String representation of the value.
111    private final String name;
112
113
114
115    // Private constructor.
116    private CryptPasswordStorageEncryptionAlgorithm(String name) { this.name = name; }
117
118
119
120    /**
121     * {@inheritDoc}
122     */
123    public String toString() { return name; }
124
125  }
126
127
128
129  // The "crypt-password-storage-encryption-algorithm" property definition.
130  private static final EnumPropertyDefinition<CryptPasswordStorageEncryptionAlgorithm> PD_CRYPT_PASSWORD_STORAGE_ENCRYPTION_ALGORITHM;
131
132
133
134  // The "java-class" property definition.
135  private static final ClassPropertyDefinition PD_JAVA_CLASS;
136
137
138
139  // Build the "crypt-password-storage-encryption-algorithm" property definition.
140  static {
141      EnumPropertyDefinition.Builder<CryptPasswordStorageEncryptionAlgorithm> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "crypt-password-storage-encryption-algorithm");
142      builder.setOption(PropertyOption.MANDATORY);
143      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "crypt-password-storage-encryption-algorithm"));
144      DefaultBehaviorProvider<CryptPasswordStorageEncryptionAlgorithm> provider = new DefinedDefaultBehaviorProvider<CryptPasswordStorageEncryptionAlgorithm>("unix");
145      builder.setDefaultBehaviorProvider(provider);
146      builder.setEnumClass(CryptPasswordStorageEncryptionAlgorithm.class);
147      PD_CRYPT_PASSWORD_STORAGE_ENCRYPTION_ALGORITHM = builder.getInstance();
148      INSTANCE.registerPropertyDefinition(PD_CRYPT_PASSWORD_STORAGE_ENCRYPTION_ALGORITHM);
149  }
150
151
152
153  // Build the "java-class" property definition.
154  static {
155      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
156      builder.setOption(PropertyOption.MANDATORY);
157      builder.setOption(PropertyOption.ADVANCED);
158      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
159      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.CryptPasswordStorageScheme");
160      builder.setDefaultBehaviorProvider(provider);
161      builder.addInstanceOf("org.opends.server.api.PasswordStorageScheme");
162      PD_JAVA_CLASS = builder.getInstance();
163      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
164  }
165
166
167
168  // Register the tags associated with this managed object definition.
169  static {
170    INSTANCE.registerTag(Tag.valueOf("user-management"));
171  }
172
173
174
175  /**
176   * Get the Crypt Password Storage Scheme configuration definition
177   * singleton.
178   *
179   * @return Returns the Crypt Password Storage Scheme configuration
180   *         definition singleton.
181   */
182  public static CryptPasswordStorageSchemeCfgDefn getInstance() {
183    return INSTANCE;
184  }
185
186
187
188  /**
189   * Private constructor.
190   */
191  private CryptPasswordStorageSchemeCfgDefn() {
192    super("crypt-password-storage-scheme", PasswordStorageSchemeCfgDefn.getInstance());
193  }
194
195
196
197  /**
198   * {@inheritDoc}
199   */
200  public CryptPasswordStorageSchemeCfgClient createClientConfiguration(
201      ManagedObject<? extends CryptPasswordStorageSchemeCfgClient> impl) {
202    return new CryptPasswordStorageSchemeCfgClientImpl(impl);
203  }
204
205
206
207  /**
208   * {@inheritDoc}
209   */
210  public CryptPasswordStorageSchemeCfg createServerConfiguration(
211      ServerManagedObject<? extends CryptPasswordStorageSchemeCfg> impl) {
212    return new CryptPasswordStorageSchemeCfgServerImpl(impl);
213  }
214
215
216
217  /**
218   * {@inheritDoc}
219   */
220  public Class<CryptPasswordStorageSchemeCfg> getServerConfigurationClass() {
221    return CryptPasswordStorageSchemeCfg.class;
222  }
223
224
225
226  /**
227   * Get the "crypt-password-storage-encryption-algorithm" property definition.
228   * <p>
229   * Specifies the algorithm to use to encrypt new passwords.
230   * <p>
231   * Select the crypt algorithm to use to encrypt new passwords. The
232   * value can either be "unix", which means the password is encrypted
233   * with the weak Unix crypt algorithm, or "md5" which means the
234   * password is encrypted with the BSD MD5 algorithm and has a $1$
235   * prefix, or "sha256" which means the password is encrypted with the
236   * SHA256 algorithm and has a $5$ prefix, or "sha512" which means the
237   * password is encrypted with the SHA512 algorithm and has a $6$
238   * prefix.
239   *
240   * @return Returns the "crypt-password-storage-encryption-algorithm" property definition.
241   */
242  public EnumPropertyDefinition<CryptPasswordStorageEncryptionAlgorithm> getCryptPasswordStorageEncryptionAlgorithmPropertyDefinition() {
243    return PD_CRYPT_PASSWORD_STORAGE_ENCRYPTION_ALGORITHM;
244  }
245
246
247
248  /**
249   * Get the "enabled" property definition.
250   * <p>
251   * Indicates whether the Crypt Password Storage Scheme is enabled
252   * for use.
253   *
254   * @return Returns the "enabled" property definition.
255   */
256  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
257    return PasswordStorageSchemeCfgDefn.getInstance().getEnabledPropertyDefinition();
258  }
259
260
261
262  /**
263   * Get the "java-class" property definition.
264   * <p>
265   * Specifies the fully-qualified name of the Java class that
266   * provides the Crypt Password Storage Scheme implementation.
267   *
268   * @return Returns the "java-class" property definition.
269   */
270  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
271    return PD_JAVA_CLASS;
272  }
273
274
275
276  /**
277   * Managed object client implementation.
278   */
279  private static class CryptPasswordStorageSchemeCfgClientImpl implements
280    CryptPasswordStorageSchemeCfgClient {
281
282    // Private implementation.
283    private ManagedObject<? extends CryptPasswordStorageSchemeCfgClient> impl;
284
285
286
287    // Private constructor.
288    private CryptPasswordStorageSchemeCfgClientImpl(
289        ManagedObject<? extends CryptPasswordStorageSchemeCfgClient> impl) {
290      this.impl = impl;
291    }
292
293
294
295    /**
296     * {@inheritDoc}
297     */
298    public CryptPasswordStorageEncryptionAlgorithm getCryptPasswordStorageEncryptionAlgorithm() {
299      return impl.getPropertyValue(INSTANCE.getCryptPasswordStorageEncryptionAlgorithmPropertyDefinition());
300    }
301
302
303
304    /**
305     * {@inheritDoc}
306     */
307    public void setCryptPasswordStorageEncryptionAlgorithm(CryptPasswordStorageEncryptionAlgorithm value) {
308      impl.setPropertyValue(INSTANCE.getCryptPasswordStorageEncryptionAlgorithmPropertyDefinition(), value);
309    }
310
311
312
313    /**
314     * {@inheritDoc}
315     */
316    public Boolean isEnabled() {
317      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
318    }
319
320
321
322    /**
323     * {@inheritDoc}
324     */
325    public void setEnabled(boolean value) {
326      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
327    }
328
329
330
331    /**
332     * {@inheritDoc}
333     */
334    public String getJavaClass() {
335      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
336    }
337
338
339
340    /**
341     * {@inheritDoc}
342     */
343    public void setJavaClass(String value) {
344      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
345    }
346
347
348
349    /**
350     * {@inheritDoc}
351     */
352    public ManagedObjectDefinition<? extends CryptPasswordStorageSchemeCfgClient, ? extends CryptPasswordStorageSchemeCfg> definition() {
353      return INSTANCE;
354    }
355
356
357
358    /**
359     * {@inheritDoc}
360     */
361    public PropertyProvider properties() {
362      return impl;
363    }
364
365
366
367    /**
368     * {@inheritDoc}
369     */
370    public void commit() throws ManagedObjectAlreadyExistsException,
371        MissingMandatoryPropertiesException, ConcurrentModificationException,
372        OperationRejectedException, AuthorizationException,
373        CommunicationException {
374      impl.commit();
375    }
376
377
378
379    /** {@inheritDoc} */
380    public String toString() {
381      return impl.toString();
382    }
383  }
384
385
386
387  /**
388   * Managed object server implementation.
389   */
390  private static class CryptPasswordStorageSchemeCfgServerImpl implements
391    CryptPasswordStorageSchemeCfg {
392
393    // Private implementation.
394    private ServerManagedObject<? extends CryptPasswordStorageSchemeCfg> impl;
395
396    // The value of the "crypt-password-storage-encryption-algorithm" property.
397    private final CryptPasswordStorageEncryptionAlgorithm pCryptPasswordStorageEncryptionAlgorithm;
398
399    // The value of the "enabled" property.
400    private final boolean pEnabled;
401
402    // The value of the "java-class" property.
403    private final String pJavaClass;
404
405
406
407    // Private constructor.
408    private CryptPasswordStorageSchemeCfgServerImpl(ServerManagedObject<? extends CryptPasswordStorageSchemeCfg> impl) {
409      this.impl = impl;
410      this.pCryptPasswordStorageEncryptionAlgorithm = impl.getPropertyValue(INSTANCE.getCryptPasswordStorageEncryptionAlgorithmPropertyDefinition());
411      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
412      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
413    }
414
415
416
417    /**
418     * {@inheritDoc}
419     */
420    public void addCryptChangeListener(
421        ConfigurationChangeListener<CryptPasswordStorageSchemeCfg> listener) {
422      impl.registerChangeListener(listener);
423    }
424
425
426
427    /**
428     * {@inheritDoc}
429     */
430    public void removeCryptChangeListener(
431        ConfigurationChangeListener<CryptPasswordStorageSchemeCfg> listener) {
432      impl.deregisterChangeListener(listener);
433    }
434    /**
435     * {@inheritDoc}
436     */
437    public void addChangeListener(
438        ConfigurationChangeListener<PasswordStorageSchemeCfg> listener) {
439      impl.registerChangeListener(listener);
440    }
441
442
443
444    /**
445     * {@inheritDoc}
446     */
447    public void removeChangeListener(
448        ConfigurationChangeListener<PasswordStorageSchemeCfg> listener) {
449      impl.deregisterChangeListener(listener);
450    }
451
452
453
454    /**
455     * {@inheritDoc}
456     */
457    public CryptPasswordStorageEncryptionAlgorithm getCryptPasswordStorageEncryptionAlgorithm() {
458      return pCryptPasswordStorageEncryptionAlgorithm;
459    }
460
461
462
463    /**
464     * {@inheritDoc}
465     */
466    public boolean isEnabled() {
467      return pEnabled;
468    }
469
470
471
472    /**
473     * {@inheritDoc}
474     */
475    public String getJavaClass() {
476      return pJavaClass;
477    }
478
479
480
481    /**
482     * {@inheritDoc}
483     */
484    public Class<? extends CryptPasswordStorageSchemeCfg> configurationClass() {
485      return CryptPasswordStorageSchemeCfg.class;
486    }
487
488
489
490    /**
491     * {@inheritDoc}
492     */
493    public DN dn() {
494      return impl.getDN();
495    }
496
497
498
499    /** {@inheritDoc} */
500    public String toString() {
501      return impl.toString();
502    }
503  }
504}