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