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