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.opends.server.admin.std.meta;
027
028
029
030import java.util.Collection;
031import java.util.SortedSet;
032import org.opends.server.admin.AdministratorAction;
033import org.opends.server.admin.AliasDefaultBehaviorProvider;
034import org.opends.server.admin.BooleanPropertyDefinition;
035import org.opends.server.admin.ClassPropertyDefinition;
036import org.opends.server.admin.client.AuthorizationException;
037import org.opends.server.admin.client.CommunicationException;
038import org.opends.server.admin.client.ConcurrentModificationException;
039import org.opends.server.admin.client.ManagedObject;
040import org.opends.server.admin.client.MissingMandatoryPropertiesException;
041import org.opends.server.admin.client.OperationRejectedException;
042import org.opends.server.admin.DefaultBehaviorProvider;
043import org.opends.server.admin.DefinedDefaultBehaviorProvider;
044import org.opends.server.admin.DNPropertyDefinition;
045import org.opends.server.admin.EnumPropertyDefinition;
046import org.opends.server.admin.ManagedObjectAlreadyExistsException;
047import org.opends.server.admin.ManagedObjectDefinition;
048import org.opends.server.admin.PropertyOption;
049import org.opends.server.admin.PropertyProvider;
050import org.opends.server.admin.server.ConfigurationChangeListener;
051import org.opends.server.admin.server.ServerManagedObject;
052import org.opends.server.admin.std.client.SambaPasswordPluginCfgClient;
053import org.opends.server.admin.std.meta.PluginCfgDefn.PluginType;
054import org.opends.server.admin.std.server.PluginCfg;
055import org.opends.server.admin.std.server.SambaPasswordPluginCfg;
056import org.opends.server.admin.Tag;
057import org.opends.server.types.DN;
058
059
060
061/**
062 * An interface for querying the Samba Password Plugin managed object
063 * definition meta information.
064 * <p>
065 * Samba Password Synchronization Plugin.
066 */
067public final class SambaPasswordPluginCfgDefn extends ManagedObjectDefinition<SambaPasswordPluginCfgClient, SambaPasswordPluginCfg> {
068
069  // The singleton configuration definition instance.
070  private static final SambaPasswordPluginCfgDefn INSTANCE = new SambaPasswordPluginCfgDefn();
071
072
073
074  /**
075   * Defines the set of permissable values for the "pwd-sync-policy" property.
076   * <p>
077   * Specifies which Samba passwords should be kept synchronized.
078   */
079  public static enum PwdSyncPolicy {
080
081    /**
082     * Synchronize the LanMan password attribute "sambaLMPassword"
083     */
084    SYNC_LM_PASSWORD("sync-lm-password"),
085
086
087
088    /**
089     * Synchronize the NT password attribute "sambaNTPassword"
090     */
091    SYNC_NT_PASSWORD("sync-nt-password");
092
093
094
095    // String representation of the value.
096    private final String name;
097
098
099
100    // Private constructor.
101    private PwdSyncPolicy(String name) { this.name = name; }
102
103
104
105    /**
106     * {@inheritDoc}
107     */
108    public String toString() { return name; }
109
110  }
111
112
113
114  // The "java-class" property definition.
115  private static final ClassPropertyDefinition PD_JAVA_CLASS;
116
117
118
119  // The "plugin-type" property definition.
120  private static final EnumPropertyDefinition<PluginType> PD_PLUGIN_TYPE;
121
122
123
124  // The "pwd-sync-policy" property definition.
125  private static final EnumPropertyDefinition<PwdSyncPolicy> PD_PWD_SYNC_POLICY;
126
127
128
129  // The "samba-administrator-dn" property definition.
130  private static final DNPropertyDefinition PD_SAMBA_ADMINISTRATOR_DN;
131
132
133
134  // Build the "java-class" property definition.
135  static {
136      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
137      builder.setOption(PropertyOption.MANDATORY);
138      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
139      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.plugins.SambaPasswordPlugin");
140      builder.setDefaultBehaviorProvider(provider);
141      builder.addInstanceOf("org.opends.server.api.plugin.DirectoryServerPlugin");
142      PD_JAVA_CLASS = builder.getInstance();
143      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
144  }
145
146
147
148  // Build the "plugin-type" property definition.
149  static {
150      EnumPropertyDefinition.Builder<PluginType> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "plugin-type");
151      builder.setOption(PropertyOption.MULTI_VALUED);
152      builder.setOption(PropertyOption.MANDATORY);
153      builder.setOption(PropertyOption.ADVANCED);
154      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "plugin-type"));
155      DefaultBehaviorProvider<PluginType> provider = new DefinedDefaultBehaviorProvider<PluginType>("preoperationmodify", "postoperationextended");
156      builder.setDefaultBehaviorProvider(provider);
157      builder.setEnumClass(PluginType.class);
158      PD_PLUGIN_TYPE = builder.getInstance();
159      INSTANCE.registerPropertyDefinition(PD_PLUGIN_TYPE);
160  }
161
162
163
164  // Build the "pwd-sync-policy" property definition.
165  static {
166      EnumPropertyDefinition.Builder<PwdSyncPolicy> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "pwd-sync-policy");
167      builder.setOption(PropertyOption.MULTI_VALUED);
168      builder.setOption(PropertyOption.MANDATORY);
169      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "pwd-sync-policy"));
170      DefaultBehaviorProvider<PwdSyncPolicy> provider = new DefinedDefaultBehaviorProvider<PwdSyncPolicy>("sync-nt-password");
171      builder.setDefaultBehaviorProvider(provider);
172      builder.setEnumClass(PwdSyncPolicy.class);
173      PD_PWD_SYNC_POLICY = builder.getInstance();
174      INSTANCE.registerPropertyDefinition(PD_PWD_SYNC_POLICY);
175  }
176
177
178
179  // Build the "samba-administrator-dn" property definition.
180  static {
181      DNPropertyDefinition.Builder builder = DNPropertyDefinition.createBuilder(INSTANCE, "samba-administrator-dn");
182      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "samba-administrator-dn"));
183      builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<DN>(INSTANCE, "samba-administrator-dn"));
184      PD_SAMBA_ADMINISTRATOR_DN = builder.getInstance();
185      INSTANCE.registerPropertyDefinition(PD_SAMBA_ADMINISTRATOR_DN);
186  }
187
188
189
190  // Register the tags associated with this managed object definition.
191  static {
192    INSTANCE.registerTag(Tag.valueOf("core-server"));
193  }
194
195
196
197  /**
198   * Get the Samba Password Plugin configuration definition singleton.
199   *
200   * @return Returns the Samba Password Plugin configuration
201   *         definition singleton.
202   */
203  public static SambaPasswordPluginCfgDefn getInstance() {
204    return INSTANCE;
205  }
206
207
208
209  /**
210   * Private constructor.
211   */
212  private SambaPasswordPluginCfgDefn() {
213    super("samba-password-plugin", PluginCfgDefn.getInstance());
214  }
215
216
217
218  /**
219   * {@inheritDoc}
220   */
221  public SambaPasswordPluginCfgClient createClientConfiguration(
222      ManagedObject<? extends SambaPasswordPluginCfgClient> impl) {
223    return new SambaPasswordPluginCfgClientImpl(impl);
224  }
225
226
227
228  /**
229   * {@inheritDoc}
230   */
231  public SambaPasswordPluginCfg createServerConfiguration(
232      ServerManagedObject<? extends SambaPasswordPluginCfg> impl) {
233    return new SambaPasswordPluginCfgServerImpl(impl);
234  }
235
236
237
238  /**
239   * {@inheritDoc}
240   */
241  public Class<SambaPasswordPluginCfg> getServerConfigurationClass() {
242    return SambaPasswordPluginCfg.class;
243  }
244
245
246
247  /**
248   * Get the "enabled" property definition.
249   * <p>
250   * Indicates whether the plug-in is enabled for use.
251   *
252   * @return Returns the "enabled" property definition.
253   */
254  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
255    return PluginCfgDefn.getInstance().getEnabledPropertyDefinition();
256  }
257
258
259
260  /**
261   * Get the "invoke-for-internal-operations" property definition.
262   * <p>
263   * Indicates whether the plug-in should be invoked for internal
264   * operations.
265   * <p>
266   * Any plug-in that can be invoked for internal operations must
267   * ensure that it does not create any new internal operatons that can
268   * cause the same plug-in to be re-invoked.
269   *
270   * @return Returns the "invoke-for-internal-operations" property definition.
271   */
272  public BooleanPropertyDefinition getInvokeForInternalOperationsPropertyDefinition() {
273    return PluginCfgDefn.getInstance().getInvokeForInternalOperationsPropertyDefinition();
274  }
275
276
277
278  /**
279   * Get the "java-class" property definition.
280   * <p>
281   * Specifies the fully-qualified name of the Java class that
282   * provides the plug-in implementation.
283   *
284   * @return Returns the "java-class" property definition.
285   */
286  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
287    return PD_JAVA_CLASS;
288  }
289
290
291
292  /**
293   * Get the "plugin-type" property definition.
294   * <p>
295   * Specifies the set of plug-in types for the plug-in, which
296   * specifies the times at which the plug-in is invoked.
297   *
298   * @return Returns the "plugin-type" property definition.
299   */
300  public EnumPropertyDefinition<PluginType> getPluginTypePropertyDefinition() {
301    return PD_PLUGIN_TYPE;
302  }
303
304
305
306  /**
307   * Get the "pwd-sync-policy" property definition.
308   * <p>
309   * Specifies which Samba passwords should be kept synchronized.
310   *
311   * @return Returns the "pwd-sync-policy" property definition.
312   */
313  public EnumPropertyDefinition<PwdSyncPolicy> getPwdSyncPolicyPropertyDefinition() {
314    return PD_PWD_SYNC_POLICY;
315  }
316
317
318
319  /**
320   * Get the "samba-administrator-dn" property definition.
321   * <p>
322   * Specifies the distinguished name of the user which Samba uses to
323   * perform Password Modify extended operations against this directory
324   * server in order to synchronize the userPassword attribute after
325   * the LanMan or NT passwords have been updated.
326   * <p>
327   * The user must have the 'password-reset' privilege and should not
328   * be a root user. This user name can be used in order to identify
329   * Samba connections and avoid double re-synchronization of the same
330   * password. If this property is left undefined, then no password
331   * updates will be skipped.
332   *
333   * @return Returns the "samba-administrator-dn" property definition.
334   */
335  public DNPropertyDefinition getSambaAdministratorDNPropertyDefinition() {
336    return PD_SAMBA_ADMINISTRATOR_DN;
337  }
338
339
340
341  /**
342   * Managed object client implementation.
343   */
344  private static class SambaPasswordPluginCfgClientImpl implements
345    SambaPasswordPluginCfgClient {
346
347    // Private implementation.
348    private ManagedObject<? extends SambaPasswordPluginCfgClient> impl;
349
350
351
352    // Private constructor.
353    private SambaPasswordPluginCfgClientImpl(
354        ManagedObject<? extends SambaPasswordPluginCfgClient> impl) {
355      this.impl = impl;
356    }
357
358
359
360    /**
361     * {@inheritDoc}
362     */
363    public Boolean isEnabled() {
364      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
365    }
366
367
368
369    /**
370     * {@inheritDoc}
371     */
372    public void setEnabled(boolean value) {
373      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
374    }
375
376
377
378    /**
379     * {@inheritDoc}
380     */
381    public boolean isInvokeForInternalOperations() {
382      return impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition());
383    }
384
385
386
387    /**
388     * {@inheritDoc}
389     */
390    public void setInvokeForInternalOperations(Boolean value) {
391      impl.setPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition(), value);
392    }
393
394
395
396    /**
397     * {@inheritDoc}
398     */
399    public String getJavaClass() {
400      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
401    }
402
403
404
405    /**
406     * {@inheritDoc}
407     */
408    public void setJavaClass(String value) {
409      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
410    }
411
412
413
414    /**
415     * {@inheritDoc}
416     */
417    public SortedSet<PluginType> getPluginType() {
418      return impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition());
419    }
420
421
422
423    /**
424     * {@inheritDoc}
425     */
426    public void setPluginType(Collection<PluginType> values) {
427      impl.setPropertyValues(INSTANCE.getPluginTypePropertyDefinition(), values);
428    }
429
430
431
432    /**
433     * {@inheritDoc}
434     */
435    public SortedSet<PwdSyncPolicy> getPwdSyncPolicy() {
436      return impl.getPropertyValues(INSTANCE.getPwdSyncPolicyPropertyDefinition());
437    }
438
439
440
441    /**
442     * {@inheritDoc}
443     */
444    public void setPwdSyncPolicy(Collection<PwdSyncPolicy> values) {
445      impl.setPropertyValues(INSTANCE.getPwdSyncPolicyPropertyDefinition(), values);
446    }
447
448
449
450    /**
451     * {@inheritDoc}
452     */
453    public DN getSambaAdministratorDN() {
454      return impl.getPropertyValue(INSTANCE.getSambaAdministratorDNPropertyDefinition());
455    }
456
457
458
459    /**
460     * {@inheritDoc}
461     */
462    public void setSambaAdministratorDN(DN value) {
463      impl.setPropertyValue(INSTANCE.getSambaAdministratorDNPropertyDefinition(), value);
464    }
465
466
467
468    /**
469     * {@inheritDoc}
470     */
471    public ManagedObjectDefinition<? extends SambaPasswordPluginCfgClient, ? extends SambaPasswordPluginCfg> definition() {
472      return INSTANCE;
473    }
474
475
476
477    /**
478     * {@inheritDoc}
479     */
480    public PropertyProvider properties() {
481      return impl;
482    }
483
484
485
486    /**
487     * {@inheritDoc}
488     */
489    public void commit() throws ManagedObjectAlreadyExistsException,
490        MissingMandatoryPropertiesException, ConcurrentModificationException,
491        OperationRejectedException, AuthorizationException,
492        CommunicationException {
493      impl.commit();
494    }
495
496
497
498    /** {@inheritDoc} */
499    public String toString() {
500      return impl.toString();
501    }
502  }
503
504
505
506  /**
507   * Managed object server implementation.
508   */
509  private static class SambaPasswordPluginCfgServerImpl implements
510    SambaPasswordPluginCfg {
511
512    // Private implementation.
513    private ServerManagedObject<? extends SambaPasswordPluginCfg> impl;
514
515    // The value of the "enabled" property.
516    private final boolean pEnabled;
517
518    // The value of the "invoke-for-internal-operations" property.
519    private final boolean pInvokeForInternalOperations;
520
521    // The value of the "java-class" property.
522    private final String pJavaClass;
523
524    // The value of the "plugin-type" property.
525    private final SortedSet<PluginType> pPluginType;
526
527    // The value of the "pwd-sync-policy" property.
528    private final SortedSet<PwdSyncPolicy> pPwdSyncPolicy;
529
530    // The value of the "samba-administrator-dn" property.
531    private final DN pSambaAdministratorDN;
532
533
534
535    // Private constructor.
536    private SambaPasswordPluginCfgServerImpl(ServerManagedObject<? extends SambaPasswordPluginCfg> impl) {
537      this.impl = impl;
538      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
539      this.pInvokeForInternalOperations = impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition());
540      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
541      this.pPluginType = impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition());
542      this.pPwdSyncPolicy = impl.getPropertyValues(INSTANCE.getPwdSyncPolicyPropertyDefinition());
543      this.pSambaAdministratorDN = impl.getPropertyValue(INSTANCE.getSambaAdministratorDNPropertyDefinition());
544    }
545
546
547
548    /**
549     * {@inheritDoc}
550     */
551    public void addSambaPasswordChangeListener(
552        ConfigurationChangeListener<SambaPasswordPluginCfg> listener) {
553      impl.registerChangeListener(listener);
554    }
555
556
557
558    /**
559     * {@inheritDoc}
560     */
561    public void removeSambaPasswordChangeListener(
562        ConfigurationChangeListener<SambaPasswordPluginCfg> listener) {
563      impl.deregisterChangeListener(listener);
564    }
565    /**
566     * {@inheritDoc}
567     */
568    public void addChangeListener(
569        ConfigurationChangeListener<PluginCfg> listener) {
570      impl.registerChangeListener(listener);
571    }
572
573
574
575    /**
576     * {@inheritDoc}
577     */
578    public void removeChangeListener(
579        ConfigurationChangeListener<PluginCfg> listener) {
580      impl.deregisterChangeListener(listener);
581    }
582
583
584
585    /**
586     * {@inheritDoc}
587     */
588    public boolean isEnabled() {
589      return pEnabled;
590    }
591
592
593
594    /**
595     * {@inheritDoc}
596     */
597    public boolean isInvokeForInternalOperations() {
598      return pInvokeForInternalOperations;
599    }
600
601
602
603    /**
604     * {@inheritDoc}
605     */
606    public String getJavaClass() {
607      return pJavaClass;
608    }
609
610
611
612    /**
613     * {@inheritDoc}
614     */
615    public SortedSet<PluginType> getPluginType() {
616      return pPluginType;
617    }
618
619
620
621    /**
622     * {@inheritDoc}
623     */
624    public SortedSet<PwdSyncPolicy> getPwdSyncPolicy() {
625      return pPwdSyncPolicy;
626    }
627
628
629
630    /**
631     * {@inheritDoc}
632     */
633    public DN getSambaAdministratorDN() {
634      return pSambaAdministratorDN;
635    }
636
637
638
639    /**
640     * {@inheritDoc}
641     */
642    public Class<? extends SambaPasswordPluginCfg> configurationClass() {
643      return SambaPasswordPluginCfg.class;
644    }
645
646
647
648    /**
649     * {@inheritDoc}
650     */
651    public DN dn() {
652      return impl.getDN();
653    }
654
655
656
657    /** {@inheritDoc} */
658    public String toString() {
659      return impl.toString();
660    }
661  }
662}