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