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.forgerock.opendj.server.config.meta;
017
018
019
020import org.forgerock.opendj.config.AdministratorAction;
021import org.forgerock.opendj.config.BooleanPropertyDefinition;
022import org.forgerock.opendj.config.ClassPropertyDefinition;
023import org.forgerock.opendj.config.client.ConcurrentModificationException;
024import org.forgerock.opendj.config.client.ManagedObject;
025import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
026import org.forgerock.opendj.config.client.OperationRejectedException;
027import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
028import org.forgerock.opendj.config.ManagedObjectDefinition;
029import org.forgerock.opendj.config.PropertyOption;
030import org.forgerock.opendj.config.PropertyProvider;
031import org.forgerock.opendj.config.server.ConfigurationChangeListener;
032import org.forgerock.opendj.config.server.ServerManagedObject;
033import org.forgerock.opendj.config.Tag;
034import org.forgerock.opendj.config.TopCfgDefn;
035import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
036import org.forgerock.opendj.ldap.DN;
037import org.forgerock.opendj.ldap.LdapException;
038import org.forgerock.opendj.server.config.client.PasswordStorageSchemeCfgClient;
039import org.forgerock.opendj.server.config.server.PasswordStorageSchemeCfg;
040
041
042
043/**
044 * An interface for querying the Password Storage Scheme managed
045 * object definition meta information.
046 * <p>
047 * Password Storage Schemes encode new passwords provided by users so
048 * that they are stored in an encoded manner. This makes it difficult
049 * or impossible for someone to determine the clear-text passwords from
050 * the encoded values.
051 */
052public final class PasswordStorageSchemeCfgDefn extends ManagedObjectDefinition<PasswordStorageSchemeCfgClient, PasswordStorageSchemeCfg> {
053
054  /** The singleton configuration definition instance. */
055  private static final PasswordStorageSchemeCfgDefn INSTANCE = new PasswordStorageSchemeCfgDefn();
056
057
058
059  /** The "enabled" property definition. */
060  private static final BooleanPropertyDefinition PD_ENABLED;
061
062
063
064  /** The "java-class" property definition. */
065  private static final ClassPropertyDefinition PD_JAVA_CLASS;
066
067
068
069  /** Build the "enabled" property definition. */
070  static {
071      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled");
072      builder.setOption(PropertyOption.MANDATORY);
073      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled"));
074      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>());
075      PD_ENABLED = builder.getInstance();
076      INSTANCE.registerPropertyDefinition(PD_ENABLED);
077  }
078
079
080
081  /** Build the "java-class" property definition. */
082  static {
083      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
084      builder.setOption(PropertyOption.MANDATORY);
085      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
086      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
087      builder.addInstanceOf("org.opends.server.api.PasswordStorageScheme");
088      PD_JAVA_CLASS = builder.getInstance();
089      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
090  }
091
092
093
094  // Register the tags associated with this managed object definition.
095  static {
096    INSTANCE.registerTag(Tag.valueOf("user-management"));
097  }
098
099
100
101  /**
102   * Get the Password Storage Scheme configuration definition
103   * singleton.
104   *
105   * @return Returns the Password Storage Scheme configuration
106   *         definition singleton.
107   */
108  public static PasswordStorageSchemeCfgDefn getInstance() {
109    return INSTANCE;
110  }
111
112
113
114  /**
115   * Private constructor.
116   */
117  private PasswordStorageSchemeCfgDefn() {
118    super("password-storage-scheme", TopCfgDefn.getInstance());
119  }
120
121
122
123  /** {@inheritDoc} */
124  public PasswordStorageSchemeCfgClient createClientConfiguration(
125      ManagedObject<? extends PasswordStorageSchemeCfgClient> impl) {
126    return new PasswordStorageSchemeCfgClientImpl(impl);
127  }
128
129
130
131  /** {@inheritDoc} */
132  public PasswordStorageSchemeCfg createServerConfiguration(
133      ServerManagedObject<? extends PasswordStorageSchemeCfg> impl) {
134    return new PasswordStorageSchemeCfgServerImpl(impl);
135  }
136
137
138
139  /** {@inheritDoc} */
140  public Class<PasswordStorageSchemeCfg> getServerConfigurationClass() {
141    return PasswordStorageSchemeCfg.class;
142  }
143
144
145
146  /**
147   * Get the "enabled" property definition.
148   * <p>
149   * Indicates whether the Password Storage Scheme is enabled for use.
150   *
151   * @return Returns the "enabled" property definition.
152   */
153  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
154    return PD_ENABLED;
155  }
156
157
158
159  /**
160   * Get the "java-class" property definition.
161   * <p>
162   * Specifies the fully-qualified name of the Java class that
163   * provides the Password Storage Scheme implementation.
164   *
165   * @return Returns the "java-class" property definition.
166   */
167  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
168    return PD_JAVA_CLASS;
169  }
170
171
172
173  /**
174   * Managed object client implementation.
175   */
176  private static class PasswordStorageSchemeCfgClientImpl implements
177    PasswordStorageSchemeCfgClient {
178
179    /** Private implementation. */
180    private ManagedObject<? extends PasswordStorageSchemeCfgClient> impl;
181
182
183
184    /** Private constructor. */
185    private PasswordStorageSchemeCfgClientImpl(
186        ManagedObject<? extends PasswordStorageSchemeCfgClient> impl) {
187      this.impl = impl;
188    }
189
190
191
192    /** {@inheritDoc} */
193    public Boolean isEnabled() {
194      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
195    }
196
197
198
199    /** {@inheritDoc} */
200    public void setEnabled(boolean value) {
201      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
202    }
203
204
205
206    /** {@inheritDoc} */
207    public String getJavaClass() {
208      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
209    }
210
211
212
213    /** {@inheritDoc} */
214    public void setJavaClass(String value) {
215      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
216    }
217
218
219
220    /** {@inheritDoc} */
221    public ManagedObjectDefinition<? extends PasswordStorageSchemeCfgClient, ? extends PasswordStorageSchemeCfg> definition() {
222      return INSTANCE;
223    }
224
225
226
227    /** {@inheritDoc} */
228    public PropertyProvider properties() {
229      return impl;
230    }
231
232
233
234    /** {@inheritDoc} */
235    public void commit() throws ManagedObjectAlreadyExistsException,
236        MissingMandatoryPropertiesException, ConcurrentModificationException,
237        OperationRejectedException, LdapException {
238      impl.commit();
239    }
240
241
242
243    /** {@inheritDoc} */
244    public String toString() {
245      return impl.toString();
246    }
247  }
248
249
250
251  /**
252   * Managed object server implementation.
253   */
254  private static class PasswordStorageSchemeCfgServerImpl implements
255    PasswordStorageSchemeCfg {
256
257    /** Private implementation. */
258    private ServerManagedObject<? extends PasswordStorageSchemeCfg> impl;
259
260    /** The value of the "enabled" property. */
261    private final boolean pEnabled;
262
263    /** The value of the "java-class" property. */
264    private final String pJavaClass;
265
266
267
268    /** Private constructor. */
269    private PasswordStorageSchemeCfgServerImpl(ServerManagedObject<? extends PasswordStorageSchemeCfg> impl) {
270      this.impl = impl;
271      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
272      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
273    }
274
275
276
277    /** {@inheritDoc} */
278    public void addChangeListener(
279        ConfigurationChangeListener<PasswordStorageSchemeCfg> listener) {
280      impl.registerChangeListener(listener);
281    }
282
283
284
285    /** {@inheritDoc} */
286    public void removeChangeListener(
287        ConfigurationChangeListener<PasswordStorageSchemeCfg> listener) {
288      impl.deregisterChangeListener(listener);
289    }
290
291
292
293    /** {@inheritDoc} */
294    public boolean isEnabled() {
295      return pEnabled;
296    }
297
298
299
300    /** {@inheritDoc} */
301    public String getJavaClass() {
302      return pJavaClass;
303    }
304
305
306
307    /** {@inheritDoc} */
308    public Class<? extends PasswordStorageSchemeCfg> configurationClass() {
309      return PasswordStorageSchemeCfg.class;
310    }
311
312
313
314    /** {@inheritDoc} */
315    public DN dn() {
316      return impl.getDN();
317    }
318
319
320
321    /** {@inheritDoc} */
322    public String toString() {
323      return impl.toString();
324    }
325  }
326}