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.BooleanPropertyDefinition;
034import org.forgerock.opendj.config.ClassPropertyDefinition;
035import org.forgerock.opendj.config.client.ConcurrentModificationException;
036import org.forgerock.opendj.config.client.ManagedObject;
037import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
038import org.forgerock.opendj.config.client.OperationRejectedException;
039import org.forgerock.opendj.config.DefaultBehaviorProvider;
040import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider;
041import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
042import org.forgerock.opendj.config.ManagedObjectDefinition;
043import org.forgerock.opendj.config.PropertyOption;
044import org.forgerock.opendj.config.PropertyProvider;
045import org.forgerock.opendj.config.server.ConfigurationChangeListener;
046import org.forgerock.opendj.config.server.ServerManagedObject;
047import org.forgerock.opendj.config.StringPropertyDefinition;
048import org.forgerock.opendj.config.Tag;
049import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
050import org.forgerock.opendj.ldap.DN;
051import org.forgerock.opendj.ldap.LdapException;
052import org.forgerock.opendj.server.config.client.SMTPAlertHandlerCfgClient;
053import org.forgerock.opendj.server.config.server.AlertHandlerCfg;
054import org.forgerock.opendj.server.config.server.SMTPAlertHandlerCfg;
055
056
057
058/**
059 * An interface for querying the SMTP Alert Handler managed object
060 * definition meta information.
061 * <p>
062 * The SMTP Alert Handler may be used to send e-mail messages to
063 * notify administrators of significant events that occur within the
064 * server.
065 */
066public final class SMTPAlertHandlerCfgDefn extends ManagedObjectDefinition<SMTPAlertHandlerCfgClient, SMTPAlertHandlerCfg> {
067
068  /** The singleton configuration definition instance. */
069  private static final SMTPAlertHandlerCfgDefn INSTANCE = new SMTPAlertHandlerCfgDefn();
070
071
072
073  /** The "java-class" property definition. */
074  private static final ClassPropertyDefinition PD_JAVA_CLASS;
075
076
077
078  /** The "message-body" property definition. */
079  private static final StringPropertyDefinition PD_MESSAGE_BODY;
080
081
082
083  /** The "message-subject" property definition. */
084  private static final StringPropertyDefinition PD_MESSAGE_SUBJECT;
085
086
087
088  /** The "recipient-address" property definition. */
089  private static final StringPropertyDefinition PD_RECIPIENT_ADDRESS;
090
091
092
093  /** The "sender-address" property definition. */
094  private static final StringPropertyDefinition PD_SENDER_ADDRESS;
095
096
097
098  /** Build the "java-class" property definition. */
099  static {
100      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
101      builder.setOption(PropertyOption.MANDATORY);
102      builder.setOption(PropertyOption.ADVANCED);
103      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
104      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.SMTPAlertHandler");
105      builder.setDefaultBehaviorProvider(provider);
106      builder.addInstanceOf("org.opends.server.api.AlertHandler");
107      PD_JAVA_CLASS = builder.getInstance();
108      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
109  }
110
111
112
113  /** Build the "message-body" property definition. */
114  static {
115      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "message-body");
116      builder.setOption(PropertyOption.MANDATORY);
117      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "message-body"));
118      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
119      PD_MESSAGE_BODY = builder.getInstance();
120      INSTANCE.registerPropertyDefinition(PD_MESSAGE_BODY);
121  }
122
123
124
125  /** Build the "message-subject" property definition. */
126  static {
127      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "message-subject");
128      builder.setOption(PropertyOption.MANDATORY);
129      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "message-subject"));
130      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
131      PD_MESSAGE_SUBJECT = builder.getInstance();
132      INSTANCE.registerPropertyDefinition(PD_MESSAGE_SUBJECT);
133  }
134
135
136
137  /** Build the "recipient-address" property definition. */
138  static {
139      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "recipient-address");
140      builder.setOption(PropertyOption.MULTI_VALUED);
141      builder.setOption(PropertyOption.MANDATORY);
142      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "recipient-address"));
143      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
144      PD_RECIPIENT_ADDRESS = builder.getInstance();
145      INSTANCE.registerPropertyDefinition(PD_RECIPIENT_ADDRESS);
146  }
147
148
149
150  /** Build the "sender-address" property definition. */
151  static {
152      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "sender-address");
153      builder.setOption(PropertyOption.MANDATORY);
154      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "sender-address"));
155      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
156      PD_SENDER_ADDRESS = builder.getInstance();
157      INSTANCE.registerPropertyDefinition(PD_SENDER_ADDRESS);
158  }
159
160
161
162  // Register the tags associated with this managed object definition.
163  static {
164    INSTANCE.registerTag(Tag.valueOf("core-server"));
165  }
166
167
168
169  /**
170   * Get the SMTP Alert Handler configuration definition singleton.
171   *
172   * @return Returns the SMTP Alert Handler configuration definition
173   *         singleton.
174   */
175  public static SMTPAlertHandlerCfgDefn getInstance() {
176    return INSTANCE;
177  }
178
179
180
181  /**
182   * Private constructor.
183   */
184  private SMTPAlertHandlerCfgDefn() {
185    super("smtp-alert-handler", AlertHandlerCfgDefn.getInstance());
186  }
187
188
189
190  /** {@inheritDoc} */
191  public SMTPAlertHandlerCfgClient createClientConfiguration(
192      ManagedObject<? extends SMTPAlertHandlerCfgClient> impl) {
193    return new SMTPAlertHandlerCfgClientImpl(impl);
194  }
195
196
197
198  /** {@inheritDoc} */
199  public SMTPAlertHandlerCfg createServerConfiguration(
200      ServerManagedObject<? extends SMTPAlertHandlerCfg> impl) {
201    return new SMTPAlertHandlerCfgServerImpl(impl);
202  }
203
204
205
206  /** {@inheritDoc} */
207  public Class<SMTPAlertHandlerCfg> getServerConfigurationClass() {
208    return SMTPAlertHandlerCfg.class;
209  }
210
211
212
213  /**
214   * Get the "disabled-alert-type" property definition.
215   * <p>
216   * Specifies the names of the alert types that are disabled for this
217   * alert handler.
218   * <p>
219   * If there are any values for this attribute, then no alerts with
220   * any of the specified types are allowed. If there are no values for
221   * this attribute, then only alerts with a type included in the set
222   * of enabled alert types are allowed, or if there are no values for
223   * the enabled alert types option, then all alert types are allowed.
224   *
225   * @return Returns the "disabled-alert-type" property definition.
226   */
227  public StringPropertyDefinition getDisabledAlertTypePropertyDefinition() {
228    return AlertHandlerCfgDefn.getInstance().getDisabledAlertTypePropertyDefinition();
229  }
230
231
232
233  /**
234   * Get the "enabled" property definition.
235   * <p>
236   * Indicates whether the SMTP Alert Handler is enabled.
237   *
238   * @return Returns the "enabled" property definition.
239   */
240  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
241    return AlertHandlerCfgDefn.getInstance().getEnabledPropertyDefinition();
242  }
243
244
245
246  /**
247   * Get the "enabled-alert-type" property definition.
248   * <p>
249   * Specifies the names of the alert types that are enabled for this
250   * alert handler.
251   * <p>
252   * If there are any values for this attribute, then only alerts with
253   * one of the specified types are allowed (unless they are also
254   * included in the disabled alert types). If there are no values for
255   * this attribute, then any alert with a type not included in the
256   * list of disabled alert types is allowed.
257   *
258   * @return Returns the "enabled-alert-type" property definition.
259   */
260  public StringPropertyDefinition getEnabledAlertTypePropertyDefinition() {
261    return AlertHandlerCfgDefn.getInstance().getEnabledAlertTypePropertyDefinition();
262  }
263
264
265
266  /**
267   * Get the "java-class" property definition.
268   * <p>
269   * Specifies the fully-qualified name of the Java class that
270   * provides the SMTP Alert Handler implementation.
271   *
272   * @return Returns the "java-class" property definition.
273   */
274  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
275    return PD_JAVA_CLASS;
276  }
277
278
279
280  /**
281   * Get the "message-body" property definition.
282   * <p>
283   * Specifies the body that should be used for email messages
284   * generated by this alert handler.
285   * <p>
286   * The token "%%%%alert-type%%%%" is dynamically replaced with the
287   * alert type string. The token "%%%%alert-id%%%%" is dynamically
288   * replaced with the alert ID value. The token
289   * "%%%%alert-message%%%%" is dynamically replaced with the alert
290   * message. The token "\\n" is replaced with an end-of-line marker.
291   *
292   * @return Returns the "message-body" property definition.
293   */
294  public StringPropertyDefinition getMessageBodyPropertyDefinition() {
295    return PD_MESSAGE_BODY;
296  }
297
298
299
300  /**
301   * Get the "message-subject" property definition.
302   * <p>
303   * Specifies the subject that should be used for email messages
304   * generated by this alert handler.
305   * <p>
306   * The token "%%%%alert-type%%%%" is dynamically replaced with the
307   * alert type string. The token "%%%%alert-id%%%%" is dynamically
308   * replaced with the alert ID value. The token
309   * "%%%%alert-message%%%%" is dynamically replaced with the alert
310   * message. The token "\\n" is replaced with an end-of-line marker.
311   *
312   * @return Returns the "message-subject" property definition.
313   */
314  public StringPropertyDefinition getMessageSubjectPropertyDefinition() {
315    return PD_MESSAGE_SUBJECT;
316  }
317
318
319
320  /**
321   * Get the "recipient-address" property definition.
322   * <p>
323   * Specifies an email address to which the messages should be sent.
324   * <p>
325   * Multiple values may be provided if there should be more than one
326   * recipient.
327   *
328   * @return Returns the "recipient-address" property definition.
329   */
330  public StringPropertyDefinition getRecipientAddressPropertyDefinition() {
331    return PD_RECIPIENT_ADDRESS;
332  }
333
334
335
336  /**
337   * Get the "sender-address" property definition.
338   * <p>
339   * Specifies the email address to use as the sender for messages
340   * generated by this alert handler.
341   *
342   * @return Returns the "sender-address" property definition.
343   */
344  public StringPropertyDefinition getSenderAddressPropertyDefinition() {
345    return PD_SENDER_ADDRESS;
346  }
347
348
349
350  /**
351   * Managed object client implementation.
352   */
353  private static class SMTPAlertHandlerCfgClientImpl implements
354    SMTPAlertHandlerCfgClient {
355
356    /** Private implementation. */
357    private ManagedObject<? extends SMTPAlertHandlerCfgClient> impl;
358
359
360
361    /** Private constructor. */
362    private SMTPAlertHandlerCfgClientImpl(
363        ManagedObject<? extends SMTPAlertHandlerCfgClient> impl) {
364      this.impl = impl;
365    }
366
367
368
369    /** {@inheritDoc} */
370    public SortedSet<String> getDisabledAlertType() {
371      return impl.getPropertyValues(INSTANCE.getDisabledAlertTypePropertyDefinition());
372    }
373
374
375
376    /** {@inheritDoc} */
377    public void setDisabledAlertType(Collection<String> values) {
378      impl.setPropertyValues(INSTANCE.getDisabledAlertTypePropertyDefinition(), values);
379    }
380
381
382
383    /** {@inheritDoc} */
384    public Boolean isEnabled() {
385      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
386    }
387
388
389
390    /** {@inheritDoc} */
391    public void setEnabled(boolean value) {
392      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
393    }
394
395
396
397    /** {@inheritDoc} */
398    public SortedSet<String> getEnabledAlertType() {
399      return impl.getPropertyValues(INSTANCE.getEnabledAlertTypePropertyDefinition());
400    }
401
402
403
404    /** {@inheritDoc} */
405    public void setEnabledAlertType(Collection<String> values) {
406      impl.setPropertyValues(INSTANCE.getEnabledAlertTypePropertyDefinition(), values);
407    }
408
409
410
411    /** {@inheritDoc} */
412    public String getJavaClass() {
413      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
414    }
415
416
417
418    /** {@inheritDoc} */
419    public void setJavaClass(String value) {
420      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
421    }
422
423
424
425    /** {@inheritDoc} */
426    public String getMessageBody() {
427      return impl.getPropertyValue(INSTANCE.getMessageBodyPropertyDefinition());
428    }
429
430
431
432    /** {@inheritDoc} */
433    public void setMessageBody(String value) {
434      impl.setPropertyValue(INSTANCE.getMessageBodyPropertyDefinition(), value);
435    }
436
437
438
439    /** {@inheritDoc} */
440    public String getMessageSubject() {
441      return impl.getPropertyValue(INSTANCE.getMessageSubjectPropertyDefinition());
442    }
443
444
445
446    /** {@inheritDoc} */
447    public void setMessageSubject(String value) {
448      impl.setPropertyValue(INSTANCE.getMessageSubjectPropertyDefinition(), value);
449    }
450
451
452
453    /** {@inheritDoc} */
454    public SortedSet<String> getRecipientAddress() {
455      return impl.getPropertyValues(INSTANCE.getRecipientAddressPropertyDefinition());
456    }
457
458
459
460    /** {@inheritDoc} */
461    public void setRecipientAddress(Collection<String> values) {
462      impl.setPropertyValues(INSTANCE.getRecipientAddressPropertyDefinition(), values);
463    }
464
465
466
467    /** {@inheritDoc} */
468    public String getSenderAddress() {
469      return impl.getPropertyValue(INSTANCE.getSenderAddressPropertyDefinition());
470    }
471
472
473
474    /** {@inheritDoc} */
475    public void setSenderAddress(String value) {
476      impl.setPropertyValue(INSTANCE.getSenderAddressPropertyDefinition(), value);
477    }
478
479
480
481    /** {@inheritDoc} */
482    public ManagedObjectDefinition<? extends SMTPAlertHandlerCfgClient, ? extends SMTPAlertHandlerCfg> definition() {
483      return INSTANCE;
484    }
485
486
487
488    /** {@inheritDoc} */
489    public PropertyProvider properties() {
490      return impl;
491    }
492
493
494
495    /** {@inheritDoc} */
496    public void commit() throws ManagedObjectAlreadyExistsException,
497        MissingMandatoryPropertiesException, ConcurrentModificationException,
498        OperationRejectedException, LdapException {
499      impl.commit();
500    }
501
502
503
504    /** {@inheritDoc} */
505    public String toString() {
506      return impl.toString();
507    }
508  }
509
510
511
512  /**
513   * Managed object server implementation.
514   */
515  private static class SMTPAlertHandlerCfgServerImpl implements
516    SMTPAlertHandlerCfg {
517
518    /** Private implementation. */
519    private ServerManagedObject<? extends SMTPAlertHandlerCfg> impl;
520
521    /** The value of the "disabled-alert-type" property. */
522    private final SortedSet<String> pDisabledAlertType;
523
524    /** The value of the "enabled" property. */
525    private final boolean pEnabled;
526
527    /** The value of the "enabled-alert-type" property. */
528    private final SortedSet<String> pEnabledAlertType;
529
530    /** The value of the "java-class" property. */
531    private final String pJavaClass;
532
533    /** The value of the "message-body" property. */
534    private final String pMessageBody;
535
536    /** The value of the "message-subject" property. */
537    private final String pMessageSubject;
538
539    /** The value of the "recipient-address" property. */
540    private final SortedSet<String> pRecipientAddress;
541
542    /** The value of the "sender-address" property. */
543    private final String pSenderAddress;
544
545
546
547    /** Private constructor. */
548    private SMTPAlertHandlerCfgServerImpl(ServerManagedObject<? extends SMTPAlertHandlerCfg> impl) {
549      this.impl = impl;
550      this.pDisabledAlertType = impl.getPropertyValues(INSTANCE.getDisabledAlertTypePropertyDefinition());
551      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
552      this.pEnabledAlertType = impl.getPropertyValues(INSTANCE.getEnabledAlertTypePropertyDefinition());
553      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
554      this.pMessageBody = impl.getPropertyValue(INSTANCE.getMessageBodyPropertyDefinition());
555      this.pMessageSubject = impl.getPropertyValue(INSTANCE.getMessageSubjectPropertyDefinition());
556      this.pRecipientAddress = impl.getPropertyValues(INSTANCE.getRecipientAddressPropertyDefinition());
557      this.pSenderAddress = impl.getPropertyValue(INSTANCE.getSenderAddressPropertyDefinition());
558    }
559
560
561
562    /** {@inheritDoc} */
563    public void addSMTPChangeListener(
564        ConfigurationChangeListener<SMTPAlertHandlerCfg> listener) {
565      impl.registerChangeListener(listener);
566    }
567
568
569
570    /** {@inheritDoc} */
571    public void removeSMTPChangeListener(
572        ConfigurationChangeListener<SMTPAlertHandlerCfg> listener) {
573      impl.deregisterChangeListener(listener);
574    }
575    /** {@inheritDoc} */
576    public void addChangeListener(
577        ConfigurationChangeListener<AlertHandlerCfg> listener) {
578      impl.registerChangeListener(listener);
579    }
580
581
582
583    /** {@inheritDoc} */
584    public void removeChangeListener(
585        ConfigurationChangeListener<AlertHandlerCfg> listener) {
586      impl.deregisterChangeListener(listener);
587    }
588
589
590
591    /** {@inheritDoc} */
592    public SortedSet<String> getDisabledAlertType() {
593      return pDisabledAlertType;
594    }
595
596
597
598    /** {@inheritDoc} */
599    public boolean isEnabled() {
600      return pEnabled;
601    }
602
603
604
605    /** {@inheritDoc} */
606    public SortedSet<String> getEnabledAlertType() {
607      return pEnabledAlertType;
608    }
609
610
611
612    /** {@inheritDoc} */
613    public String getJavaClass() {
614      return pJavaClass;
615    }
616
617
618
619    /** {@inheritDoc} */
620    public String getMessageBody() {
621      return pMessageBody;
622    }
623
624
625
626    /** {@inheritDoc} */
627    public String getMessageSubject() {
628      return pMessageSubject;
629    }
630
631
632
633    /** {@inheritDoc} */
634    public SortedSet<String> getRecipientAddress() {
635      return pRecipientAddress;
636    }
637
638
639
640    /** {@inheritDoc} */
641    public String getSenderAddress() {
642      return pSenderAddress;
643    }
644
645
646
647    /** {@inheritDoc} */
648    public Class<? extends SMTPAlertHandlerCfg> configurationClass() {
649      return SMTPAlertHandlerCfg.class;
650    }
651
652
653
654    /** {@inheritDoc} */
655    public DN dn() {
656      return impl.getDN();
657    }
658
659
660
661    /** {@inheritDoc} */
662    public String toString() {
663      return impl.toString();
664    }
665  }
666}