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 java.util.Collection;
021import java.util.SortedSet;
022import java.util.TreeSet;
023import org.forgerock.opendj.config.AdministratorAction;
024import org.forgerock.opendj.config.AggregationPropertyDefinition;
025import org.forgerock.opendj.config.AliasDefaultBehaviorProvider;
026import org.forgerock.opendj.config.BooleanPropertyDefinition;
027import org.forgerock.opendj.config.ClassPropertyDefinition;
028import org.forgerock.opendj.config.client.ConcurrentModificationException;
029import org.forgerock.opendj.config.client.ManagedObject;
030import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
031import org.forgerock.opendj.config.client.OperationRejectedException;
032import org.forgerock.opendj.config.conditions.Conditions;
033import org.forgerock.opendj.config.DefaultBehaviorProvider;
034import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider;
035import org.forgerock.opendj.config.EnumPropertyDefinition;
036import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
037import org.forgerock.opendj.config.ManagedObjectDefinition;
038import org.forgerock.opendj.config.PropertyOption;
039import org.forgerock.opendj.config.PropertyProvider;
040import org.forgerock.opendj.config.server.ConfigurationChangeListener;
041import org.forgerock.opendj.config.server.ServerManagedObject;
042import org.forgerock.opendj.config.Tag;
043import org.forgerock.opendj.ldap.DN;
044import org.forgerock.opendj.ldap.LdapException;
045import org.forgerock.opendj.server.config.client.PasswordPolicyImportPluginCfgClient;
046import org.forgerock.opendj.server.config.client.PasswordStorageSchemeCfgClient;
047import org.forgerock.opendj.server.config.meta.PluginCfgDefn.PluginType;
048import org.forgerock.opendj.server.config.server.PasswordPolicyImportPluginCfg;
049import org.forgerock.opendj.server.config.server.PasswordStorageSchemeCfg;
050import org.forgerock.opendj.server.config.server.PluginCfg;
051
052
053
054/**
055 * An interface for querying the Password Policy Import Plugin managed
056 * object definition meta information.
057 * <p>
058 * The Password Policy Import Plugin ensures that clear-text passwords
059 * contained in LDIF entries are properly encoded before they are
060 * stored in the appropriate directory server backend.
061 */
062public final class PasswordPolicyImportPluginCfgDefn extends ManagedObjectDefinition<PasswordPolicyImportPluginCfgClient, PasswordPolicyImportPluginCfg> {
063
064  /** The singleton configuration definition instance. */
065  private static final PasswordPolicyImportPluginCfgDefn INSTANCE = new PasswordPolicyImportPluginCfgDefn();
066
067
068
069  /** The "default-auth-password-storage-scheme" property definition. */
070  private static final AggregationPropertyDefinition<PasswordStorageSchemeCfgClient, PasswordStorageSchemeCfg> PD_DEFAULT_AUTH_PASSWORD_STORAGE_SCHEME;
071
072
073
074  /** The "default-user-password-storage-scheme" property definition. */
075  private static final AggregationPropertyDefinition<PasswordStorageSchemeCfgClient, PasswordStorageSchemeCfg> PD_DEFAULT_USER_PASSWORD_STORAGE_SCHEME;
076
077
078
079  /** The "invoke-for-internal-operations" property definition. */
080  private static final BooleanPropertyDefinition PD_INVOKE_FOR_INTERNAL_OPERATIONS;
081
082
083
084  /** The "java-class" property definition. */
085  private static final ClassPropertyDefinition PD_JAVA_CLASS;
086
087
088
089  /** The "plugin-type" property definition. */
090  private static final EnumPropertyDefinition<PluginType> PD_PLUGIN_TYPE;
091
092
093
094  /** Build the "default-auth-password-storage-scheme" property definition. */
095  static {
096      AggregationPropertyDefinition.Builder<PasswordStorageSchemeCfgClient, PasswordStorageSchemeCfg> builder = AggregationPropertyDefinition.createBuilder(INSTANCE, "default-auth-password-storage-scheme");
097      builder.setOption(PropertyOption.MULTI_VALUED);
098      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "default-auth-password-storage-scheme"));
099      builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<String>(INSTANCE, "default-auth-password-storage-scheme"));
100      builder.setParentPath("/");
101      builder.setRelationDefinition("password-storage-scheme");
102      builder.setTargetNeedsEnablingCondition(Conditions.contains("enabled", "true"));
103      builder.setTargetIsEnabledCondition(Conditions.contains("enabled", "true"));
104      PD_DEFAULT_AUTH_PASSWORD_STORAGE_SCHEME = builder.getInstance();
105      INSTANCE.registerPropertyDefinition(PD_DEFAULT_AUTH_PASSWORD_STORAGE_SCHEME);
106      INSTANCE.registerConstraint(PD_DEFAULT_AUTH_PASSWORD_STORAGE_SCHEME.getSourceConstraint());
107  }
108
109
110
111  /** Build the "default-user-password-storage-scheme" property definition. */
112  static {
113      AggregationPropertyDefinition.Builder<PasswordStorageSchemeCfgClient, PasswordStorageSchemeCfg> builder = AggregationPropertyDefinition.createBuilder(INSTANCE, "default-user-password-storage-scheme");
114      builder.setOption(PropertyOption.MULTI_VALUED);
115      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "default-user-password-storage-scheme"));
116      builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<String>(INSTANCE, "default-user-password-storage-scheme"));
117      builder.setParentPath("/");
118      builder.setRelationDefinition("password-storage-scheme");
119      builder.setTargetNeedsEnablingCondition(Conditions.contains("enabled", "true"));
120      builder.setTargetIsEnabledCondition(Conditions.contains("enabled", "true"));
121      PD_DEFAULT_USER_PASSWORD_STORAGE_SCHEME = builder.getInstance();
122      INSTANCE.registerPropertyDefinition(PD_DEFAULT_USER_PASSWORD_STORAGE_SCHEME);
123      INSTANCE.registerConstraint(PD_DEFAULT_USER_PASSWORD_STORAGE_SCHEME.getSourceConstraint());
124  }
125
126
127
128  /** Build the "invoke-for-internal-operations" property definition. */
129  static {
130      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "invoke-for-internal-operations");
131      builder.setOption(PropertyOption.ADVANCED);
132      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "invoke-for-internal-operations"));
133      DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("false");
134      builder.setDefaultBehaviorProvider(provider);
135      PD_INVOKE_FOR_INTERNAL_OPERATIONS = builder.getInstance();
136      INSTANCE.registerPropertyDefinition(PD_INVOKE_FOR_INTERNAL_OPERATIONS);
137  }
138
139
140
141  /** Build the "java-class" property definition. */
142  static {
143      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
144      builder.setOption(PropertyOption.MANDATORY);
145      builder.setOption(PropertyOption.ADVANCED);
146      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
147      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.plugins.PasswordPolicyImportPlugin");
148      builder.setDefaultBehaviorProvider(provider);
149      builder.addInstanceOf("org.opends.server.api.plugin.DirectoryServerPlugin");
150      PD_JAVA_CLASS = builder.getInstance();
151      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
152  }
153
154
155
156  /** Build the "plugin-type" property definition. */
157  static {
158      EnumPropertyDefinition.Builder<PluginType> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "plugin-type");
159      builder.setOption(PropertyOption.MULTI_VALUED);
160      builder.setOption(PropertyOption.MANDATORY);
161      builder.setOption(PropertyOption.ADVANCED);
162      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "plugin-type"));
163      DefaultBehaviorProvider<PluginType> provider = new DefinedDefaultBehaviorProvider<PluginType>("ldifimport");
164      builder.setDefaultBehaviorProvider(provider);
165      builder.setEnumClass(PluginType.class);
166      PD_PLUGIN_TYPE = builder.getInstance();
167      INSTANCE.registerPropertyDefinition(PD_PLUGIN_TYPE);
168  }
169
170
171
172  // Register the tags associated with this managed object definition.
173  static {
174    INSTANCE.registerTag(Tag.valueOf("core-server"));
175  }
176
177
178
179  /**
180   * Get the Password Policy Import Plugin configuration definition
181   * singleton.
182   *
183   * @return Returns the Password Policy Import Plugin configuration
184   *         definition singleton.
185   */
186  public static PasswordPolicyImportPluginCfgDefn getInstance() {
187    return INSTANCE;
188  }
189
190
191
192  /**
193   * Private constructor.
194   */
195  private PasswordPolicyImportPluginCfgDefn() {
196    super("password-policy-import-plugin", PluginCfgDefn.getInstance());
197  }
198
199
200
201  /** {@inheritDoc} */
202  public PasswordPolicyImportPluginCfgClient createClientConfiguration(
203      ManagedObject<? extends PasswordPolicyImportPluginCfgClient> impl) {
204    return new PasswordPolicyImportPluginCfgClientImpl(impl);
205  }
206
207
208
209  /** {@inheritDoc} */
210  public PasswordPolicyImportPluginCfg createServerConfiguration(
211      ServerManagedObject<? extends PasswordPolicyImportPluginCfg> impl) {
212    return new PasswordPolicyImportPluginCfgServerImpl(impl);
213  }
214
215
216
217  /** {@inheritDoc} */
218  public Class<PasswordPolicyImportPluginCfg> getServerConfigurationClass() {
219    return PasswordPolicyImportPluginCfg.class;
220  }
221
222
223
224  /**
225   * Get the "default-auth-password-storage-scheme" property definition.
226   * <p>
227   * Specifies the names of password storage schemes that to be used
228   * for encoding passwords contained in attributes with the auth
229   * password syntax for entries that do not include the
230   * ds-pwp-password-policy-dn attribute specifying which password
231   * policy should be used to govern them.
232   *
233   * @return Returns the "default-auth-password-storage-scheme" property definition.
234   */
235  public AggregationPropertyDefinition<PasswordStorageSchemeCfgClient, PasswordStorageSchemeCfg> getDefaultAuthPasswordStorageSchemePropertyDefinition() {
236    return PD_DEFAULT_AUTH_PASSWORD_STORAGE_SCHEME;
237  }
238
239
240
241  /**
242   * Get the "default-user-password-storage-scheme" property definition.
243   * <p>
244   * Specifies the names of the password storage schemes to be used
245   * for encoding passwords contained in attributes with the user
246   * password syntax for entries that do not include the
247   * ds-pwp-password-policy-dn attribute specifying which password
248   * policy is to be used to govern them.
249   *
250   * @return Returns the "default-user-password-storage-scheme" property definition.
251   */
252  public AggregationPropertyDefinition<PasswordStorageSchemeCfgClient, PasswordStorageSchemeCfg> getDefaultUserPasswordStorageSchemePropertyDefinition() {
253    return PD_DEFAULT_USER_PASSWORD_STORAGE_SCHEME;
254  }
255
256
257
258  /**
259   * Get the "enabled" property definition.
260   * <p>
261   * Indicates whether the plug-in is enabled for use.
262   *
263   * @return Returns the "enabled" property definition.
264   */
265  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
266    return PluginCfgDefn.getInstance().getEnabledPropertyDefinition();
267  }
268
269
270
271  /**
272   * Get the "invoke-for-internal-operations" property definition.
273   * <p>
274   * Indicates whether the plug-in should be invoked for internal
275   * operations.
276   * <p>
277   * Any plug-in that can be invoked for internal operations must
278   * ensure that it does not create any new internal operatons that can
279   * cause the same plug-in to be re-invoked.
280   *
281   * @return Returns the "invoke-for-internal-operations" property definition.
282   */
283  public BooleanPropertyDefinition getInvokeForInternalOperationsPropertyDefinition() {
284    return PD_INVOKE_FOR_INTERNAL_OPERATIONS;
285  }
286
287
288
289  /**
290   * Get the "java-class" property definition.
291   * <p>
292   * Specifies the fully-qualified name of the Java class that
293   * provides the plug-in implementation.
294   *
295   * @return Returns the "java-class" property definition.
296   */
297  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
298    return PD_JAVA_CLASS;
299  }
300
301
302
303  /**
304   * Get the "plugin-type" property definition.
305   * <p>
306   * Specifies the set of plug-in types for the plug-in, which
307   * specifies the times at which the plug-in is invoked.
308   *
309   * @return Returns the "plugin-type" property definition.
310   */
311  public EnumPropertyDefinition<PluginType> getPluginTypePropertyDefinition() {
312    return PD_PLUGIN_TYPE;
313  }
314
315
316
317  /**
318   * Managed object client implementation.
319   */
320  private static class PasswordPolicyImportPluginCfgClientImpl implements
321    PasswordPolicyImportPluginCfgClient {
322
323    /** Private implementation. */
324    private ManagedObject<? extends PasswordPolicyImportPluginCfgClient> impl;
325
326
327
328    /** Private constructor. */
329    private PasswordPolicyImportPluginCfgClientImpl(
330        ManagedObject<? extends PasswordPolicyImportPluginCfgClient> impl) {
331      this.impl = impl;
332    }
333
334
335
336    /** {@inheritDoc} */
337    public SortedSet<String> getDefaultAuthPasswordStorageScheme() {
338      return impl.getPropertyValues(INSTANCE.getDefaultAuthPasswordStorageSchemePropertyDefinition());
339    }
340
341
342
343    /** {@inheritDoc} */
344    public void setDefaultAuthPasswordStorageScheme(Collection<String> values) {
345      impl.setPropertyValues(INSTANCE.getDefaultAuthPasswordStorageSchemePropertyDefinition(), values);
346    }
347
348
349
350    /** {@inheritDoc} */
351    public SortedSet<String> getDefaultUserPasswordStorageScheme() {
352      return impl.getPropertyValues(INSTANCE.getDefaultUserPasswordStorageSchemePropertyDefinition());
353    }
354
355
356
357    /** {@inheritDoc} */
358    public void setDefaultUserPasswordStorageScheme(Collection<String> values) {
359      impl.setPropertyValues(INSTANCE.getDefaultUserPasswordStorageSchemePropertyDefinition(), values);
360    }
361
362
363
364    /** {@inheritDoc} */
365    public Boolean isEnabled() {
366      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
367    }
368
369
370
371    /** {@inheritDoc} */
372    public void setEnabled(boolean value) {
373      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
374    }
375
376
377
378    /** {@inheritDoc} */
379    public boolean isInvokeForInternalOperations() {
380      return impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition());
381    }
382
383
384
385    /** {@inheritDoc} */
386    public void setInvokeForInternalOperations(Boolean value) {
387      impl.setPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition(), value);
388    }
389
390
391
392    /** {@inheritDoc} */
393    public String getJavaClass() {
394      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
395    }
396
397
398
399    /** {@inheritDoc} */
400    public void setJavaClass(String value) {
401      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
402    }
403
404
405
406    /** {@inheritDoc} */
407    public SortedSet<PluginType> getPluginType() {
408      return impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition());
409    }
410
411
412
413    /** {@inheritDoc} */
414    public void setPluginType(Collection<PluginType> values) {
415      impl.setPropertyValues(INSTANCE.getPluginTypePropertyDefinition(), values);
416    }
417
418
419
420    /** {@inheritDoc} */
421    public ManagedObjectDefinition<? extends PasswordPolicyImportPluginCfgClient, ? extends PasswordPolicyImportPluginCfg> definition() {
422      return INSTANCE;
423    }
424
425
426
427    /** {@inheritDoc} */
428    public PropertyProvider properties() {
429      return impl;
430    }
431
432
433
434    /** {@inheritDoc} */
435    public void commit() throws ManagedObjectAlreadyExistsException,
436        MissingMandatoryPropertiesException, ConcurrentModificationException,
437        OperationRejectedException, LdapException {
438      impl.commit();
439    }
440
441
442
443    /** {@inheritDoc} */
444    public String toString() {
445      return impl.toString();
446    }
447  }
448
449
450
451  /**
452   * Managed object server implementation.
453   */
454  private static class PasswordPolicyImportPluginCfgServerImpl implements
455    PasswordPolicyImportPluginCfg {
456
457    /** Private implementation. */
458    private ServerManagedObject<? extends PasswordPolicyImportPluginCfg> impl;
459
460    /** The value of the "default-auth-password-storage-scheme" property. */
461    private final SortedSet<String> pDefaultAuthPasswordStorageScheme;
462
463    /** The value of the "default-user-password-storage-scheme" property. */
464    private final SortedSet<String> pDefaultUserPasswordStorageScheme;
465
466    /** The value of the "enabled" property. */
467    private final boolean pEnabled;
468
469    /** The value of the "invoke-for-internal-operations" property. */
470    private final boolean pInvokeForInternalOperations;
471
472    /** The value of the "java-class" property. */
473    private final String pJavaClass;
474
475    /** The value of the "plugin-type" property. */
476    private final SortedSet<PluginType> pPluginType;
477
478
479
480    /** Private constructor. */
481    private PasswordPolicyImportPluginCfgServerImpl(ServerManagedObject<? extends PasswordPolicyImportPluginCfg> impl) {
482      this.impl = impl;
483      this.pDefaultAuthPasswordStorageScheme = impl.getPropertyValues(INSTANCE.getDefaultAuthPasswordStorageSchemePropertyDefinition());
484      this.pDefaultUserPasswordStorageScheme = impl.getPropertyValues(INSTANCE.getDefaultUserPasswordStorageSchemePropertyDefinition());
485      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
486      this.pInvokeForInternalOperations = impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition());
487      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
488      this.pPluginType = impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition());
489    }
490
491
492
493    /** {@inheritDoc} */
494    public void addPasswordPolicyImportChangeListener(
495        ConfigurationChangeListener<PasswordPolicyImportPluginCfg> listener) {
496      impl.registerChangeListener(listener);
497    }
498
499
500
501    /** {@inheritDoc} */
502    public void removePasswordPolicyImportChangeListener(
503        ConfigurationChangeListener<PasswordPolicyImportPluginCfg> listener) {
504      impl.deregisterChangeListener(listener);
505    }
506    /** {@inheritDoc} */
507    public void addChangeListener(
508        ConfigurationChangeListener<PluginCfg> listener) {
509      impl.registerChangeListener(listener);
510    }
511
512
513
514    /** {@inheritDoc} */
515    public void removeChangeListener(
516        ConfigurationChangeListener<PluginCfg> listener) {
517      impl.deregisterChangeListener(listener);
518    }
519
520
521
522    /** {@inheritDoc} */
523    public SortedSet<String> getDefaultAuthPasswordStorageScheme() {
524      return pDefaultAuthPasswordStorageScheme;
525    }
526
527
528
529    /**
530     * {@inheritDoc}
531     */
532    public SortedSet<DN> getDefaultAuthPasswordStorageSchemeDNs() {
533      SortedSet<String> values = getDefaultAuthPasswordStorageScheme();
534      SortedSet<DN> dnValues = new TreeSet<DN>();
535      for (String value : values) {
536        DN dn = INSTANCE.getDefaultAuthPasswordStorageSchemePropertyDefinition().getChildDN(value);
537        dnValues.add(dn);
538      }
539      return dnValues;
540    }
541
542
543
544    /** {@inheritDoc} */
545    public SortedSet<String> getDefaultUserPasswordStorageScheme() {
546      return pDefaultUserPasswordStorageScheme;
547    }
548
549
550
551    /**
552     * {@inheritDoc}
553     */
554    public SortedSet<DN> getDefaultUserPasswordStorageSchemeDNs() {
555      SortedSet<String> values = getDefaultUserPasswordStorageScheme();
556      SortedSet<DN> dnValues = new TreeSet<DN>();
557      for (String value : values) {
558        DN dn = INSTANCE.getDefaultUserPasswordStorageSchemePropertyDefinition().getChildDN(value);
559        dnValues.add(dn);
560      }
561      return dnValues;
562    }
563
564
565
566    /** {@inheritDoc} */
567    public boolean isEnabled() {
568      return pEnabled;
569    }
570
571
572
573    /** {@inheritDoc} */
574    public boolean isInvokeForInternalOperations() {
575      return pInvokeForInternalOperations;
576    }
577
578
579
580    /** {@inheritDoc} */
581    public String getJavaClass() {
582      return pJavaClass;
583    }
584
585
586
587    /** {@inheritDoc} */
588    public SortedSet<PluginType> getPluginType() {
589      return pPluginType;
590    }
591
592
593
594    /** {@inheritDoc} */
595    public Class<? extends PasswordPolicyImportPluginCfg> configurationClass() {
596      return PasswordPolicyImportPluginCfg.class;
597    }
598
599
600
601    /** {@inheritDoc} */
602    public DN dn() {
603      return impl.getDN();
604    }
605
606
607
608    /** {@inheritDoc} */
609    public String toString() {
610      return impl.toString();
611    }
612  }
613}