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