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