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  /**
191   * {@inheritDoc}
192   */
193  public SMTPAlertHandlerCfgClient createClientConfiguration(
194      ManagedObject<? extends SMTPAlertHandlerCfgClient> impl) {
195    return new SMTPAlertHandlerCfgClientImpl(impl);
196  }
197
198
199
200  /**
201   * {@inheritDoc}
202   */
203  public SMTPAlertHandlerCfg createServerConfiguration(
204      ServerManagedObject<? extends SMTPAlertHandlerCfg> impl) {
205    return new SMTPAlertHandlerCfgServerImpl(impl);
206  }
207
208
209
210  /**
211   * {@inheritDoc}
212   */
213  public Class<SMTPAlertHandlerCfg> getServerConfigurationClass() {
214    return SMTPAlertHandlerCfg.class;
215  }
216
217
218
219  /**
220   * Get the "disabled-alert-type" property definition.
221   * <p>
222   * Specifies the names of the alert types that are disabled for this
223   * alert handler.
224   * <p>
225   * If there are any values for this attribute, then no alerts with
226   * any of the specified types are allowed. If there are no values for
227   * this attribute, then only alerts with a type included in the set
228   * of enabled alert types are allowed, or if there are no values for
229   * the enabled alert types option, then all alert types are allowed.
230   *
231   * @return Returns the "disabled-alert-type" property definition.
232   */
233  public StringPropertyDefinition getDisabledAlertTypePropertyDefinition() {
234    return AlertHandlerCfgDefn.getInstance().getDisabledAlertTypePropertyDefinition();
235  }
236
237
238
239  /**
240   * Get the "enabled" property definition.
241   * <p>
242   * Indicates whether the SMTP Alert Handler is enabled.
243   *
244   * @return Returns the "enabled" property definition.
245   */
246  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
247    return AlertHandlerCfgDefn.getInstance().getEnabledPropertyDefinition();
248  }
249
250
251
252  /**
253   * Get the "enabled-alert-type" property definition.
254   * <p>
255   * Specifies the names of the alert types that are enabled for this
256   * alert handler.
257   * <p>
258   * If there are any values for this attribute, then only alerts with
259   * one of the specified types are allowed (unless they are also
260   * included in the disabled alert types). If there are no values for
261   * this attribute, then any alert with a type not included in the
262   * list of disabled alert types is allowed.
263   *
264   * @return Returns the "enabled-alert-type" property definition.
265   */
266  public StringPropertyDefinition getEnabledAlertTypePropertyDefinition() {
267    return AlertHandlerCfgDefn.getInstance().getEnabledAlertTypePropertyDefinition();
268  }
269
270
271
272  /**
273   * Get the "java-class" property definition.
274   * <p>
275   * Specifies the fully-qualified name of the Java class that
276   * provides the SMTP Alert Handler implementation.
277   *
278   * @return Returns the "java-class" property definition.
279   */
280  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
281    return PD_JAVA_CLASS;
282  }
283
284
285
286  /**
287   * Get the "message-body" property definition.
288   * <p>
289   * Specifies the body that should be used for email messages
290   * generated by this alert handler.
291   * <p>
292   * The token "%%%%alert-type%%%%" is dynamically replaced with the
293   * alert type string. The token "%%%%alert-id%%%%" is dynamically
294   * replaced with the alert ID value. The token
295   * "%%%%alert-message%%%%" is dynamically replaced with the alert
296   * message. The token "\\n" is replaced with an end-of-line marker.
297   *
298   * @return Returns the "message-body" property definition.
299   */
300  public StringPropertyDefinition getMessageBodyPropertyDefinition() {
301    return PD_MESSAGE_BODY;
302  }
303
304
305
306  /**
307   * Get the "message-subject" property definition.
308   * <p>
309   * Specifies the subject that should be used for email messages
310   * generated by this alert handler.
311   * <p>
312   * The token "%%%%alert-type%%%%" is dynamically replaced with the
313   * alert type string. The token "%%%%alert-id%%%%" is dynamically
314   * replaced with the alert ID value. The token
315   * "%%%%alert-message%%%%" is dynamically replaced with the alert
316   * message. The token "\\n" is replaced with an end-of-line marker.
317   *
318   * @return Returns the "message-subject" property definition.
319   */
320  public StringPropertyDefinition getMessageSubjectPropertyDefinition() {
321    return PD_MESSAGE_SUBJECT;
322  }
323
324
325
326  /**
327   * Get the "recipient-address" property definition.
328   * <p>
329   * Specifies an email address to which the messages should be sent.
330   * <p>
331   * Multiple values may be provided if there should be more than one
332   * recipient.
333   *
334   * @return Returns the "recipient-address" property definition.
335   */
336  public StringPropertyDefinition getRecipientAddressPropertyDefinition() {
337    return PD_RECIPIENT_ADDRESS;
338  }
339
340
341
342  /**
343   * Get the "sender-address" property definition.
344   * <p>
345   * Specifies the email address to use as the sender for messages
346   * generated by this alert handler.
347   *
348   * @return Returns the "sender-address" property definition.
349   */
350  public StringPropertyDefinition getSenderAddressPropertyDefinition() {
351    return PD_SENDER_ADDRESS;
352  }
353
354
355
356  /**
357   * Managed object client implementation.
358   */
359  private static class SMTPAlertHandlerCfgClientImpl implements
360    SMTPAlertHandlerCfgClient {
361
362    // Private implementation.
363    private ManagedObject<? extends SMTPAlertHandlerCfgClient> impl;
364
365
366
367    // Private constructor.
368    private SMTPAlertHandlerCfgClientImpl(
369        ManagedObject<? extends SMTPAlertHandlerCfgClient> impl) {
370      this.impl = impl;
371    }
372
373
374
375    /**
376     * {@inheritDoc}
377     */
378    public SortedSet<String> getDisabledAlertType() {
379      return impl.getPropertyValues(INSTANCE.getDisabledAlertTypePropertyDefinition());
380    }
381
382
383
384    /**
385     * {@inheritDoc}
386     */
387    public void setDisabledAlertType(Collection<String> values) {
388      impl.setPropertyValues(INSTANCE.getDisabledAlertTypePropertyDefinition(), values);
389    }
390
391
392
393    /**
394     * {@inheritDoc}
395     */
396    public Boolean isEnabled() {
397      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
398    }
399
400
401
402    /**
403     * {@inheritDoc}
404     */
405    public void setEnabled(boolean value) {
406      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
407    }
408
409
410
411    /**
412     * {@inheritDoc}
413     */
414    public SortedSet<String> getEnabledAlertType() {
415      return impl.getPropertyValues(INSTANCE.getEnabledAlertTypePropertyDefinition());
416    }
417
418
419
420    /**
421     * {@inheritDoc}
422     */
423    public void setEnabledAlertType(Collection<String> values) {
424      impl.setPropertyValues(INSTANCE.getEnabledAlertTypePropertyDefinition(), values);
425    }
426
427
428
429    /**
430     * {@inheritDoc}
431     */
432    public String getJavaClass() {
433      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
434    }
435
436
437
438    /**
439     * {@inheritDoc}
440     */
441    public void setJavaClass(String value) {
442      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
443    }
444
445
446
447    /**
448     * {@inheritDoc}
449     */
450    public String getMessageBody() {
451      return impl.getPropertyValue(INSTANCE.getMessageBodyPropertyDefinition());
452    }
453
454
455
456    /**
457     * {@inheritDoc}
458     */
459    public void setMessageBody(String value) {
460      impl.setPropertyValue(INSTANCE.getMessageBodyPropertyDefinition(), value);
461    }
462
463
464
465    /**
466     * {@inheritDoc}
467     */
468    public String getMessageSubject() {
469      return impl.getPropertyValue(INSTANCE.getMessageSubjectPropertyDefinition());
470    }
471
472
473
474    /**
475     * {@inheritDoc}
476     */
477    public void setMessageSubject(String value) {
478      impl.setPropertyValue(INSTANCE.getMessageSubjectPropertyDefinition(), value);
479    }
480
481
482
483    /**
484     * {@inheritDoc}
485     */
486    public SortedSet<String> getRecipientAddress() {
487      return impl.getPropertyValues(INSTANCE.getRecipientAddressPropertyDefinition());
488    }
489
490
491
492    /**
493     * {@inheritDoc}
494     */
495    public void setRecipientAddress(Collection<String> values) {
496      impl.setPropertyValues(INSTANCE.getRecipientAddressPropertyDefinition(), values);
497    }
498
499
500
501    /**
502     * {@inheritDoc}
503     */
504    public String getSenderAddress() {
505      return impl.getPropertyValue(INSTANCE.getSenderAddressPropertyDefinition());
506    }
507
508
509
510    /**
511     * {@inheritDoc}
512     */
513    public void setSenderAddress(String value) {
514      impl.setPropertyValue(INSTANCE.getSenderAddressPropertyDefinition(), value);
515    }
516
517
518
519    /**
520     * {@inheritDoc}
521     */
522    public ManagedObjectDefinition<? extends SMTPAlertHandlerCfgClient, ? extends SMTPAlertHandlerCfg> definition() {
523      return INSTANCE;
524    }
525
526
527
528    /**
529     * {@inheritDoc}
530     */
531    public PropertyProvider properties() {
532      return impl;
533    }
534
535
536
537    /**
538     * {@inheritDoc}
539     */
540    public void commit() throws ManagedObjectAlreadyExistsException,
541        MissingMandatoryPropertiesException, ConcurrentModificationException,
542        OperationRejectedException, LdapException {
543      impl.commit();
544    }
545
546  }
547
548
549
550  /**
551   * Managed object server implementation.
552   */
553  private static class SMTPAlertHandlerCfgServerImpl implements
554    SMTPAlertHandlerCfg {
555
556    // Private implementation.
557    private ServerManagedObject<? extends SMTPAlertHandlerCfg> impl;
558
559    // The value of the "disabled-alert-type" property.
560    private final SortedSet<String> pDisabledAlertType;
561
562    // The value of the "enabled" property.
563    private final boolean pEnabled;
564
565    // The value of the "enabled-alert-type" property.
566    private final SortedSet<String> pEnabledAlertType;
567
568    // The value of the "java-class" property.
569    private final String pJavaClass;
570
571    // The value of the "message-body" property.
572    private final String pMessageBody;
573
574    // The value of the "message-subject" property.
575    private final String pMessageSubject;
576
577    // The value of the "recipient-address" property.
578    private final SortedSet<String> pRecipientAddress;
579
580    // The value of the "sender-address" property.
581    private final String pSenderAddress;
582
583
584
585    // Private constructor.
586    private SMTPAlertHandlerCfgServerImpl(ServerManagedObject<? extends SMTPAlertHandlerCfg> impl) {
587      this.impl = impl;
588      this.pDisabledAlertType = impl.getPropertyValues(INSTANCE.getDisabledAlertTypePropertyDefinition());
589      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
590      this.pEnabledAlertType = impl.getPropertyValues(INSTANCE.getEnabledAlertTypePropertyDefinition());
591      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
592      this.pMessageBody = impl.getPropertyValue(INSTANCE.getMessageBodyPropertyDefinition());
593      this.pMessageSubject = impl.getPropertyValue(INSTANCE.getMessageSubjectPropertyDefinition());
594      this.pRecipientAddress = impl.getPropertyValues(INSTANCE.getRecipientAddressPropertyDefinition());
595      this.pSenderAddress = impl.getPropertyValue(INSTANCE.getSenderAddressPropertyDefinition());
596    }
597
598
599
600    /**
601     * {@inheritDoc}
602     */
603    public void addSMTPChangeListener(
604        ConfigurationChangeListener<SMTPAlertHandlerCfg> listener) {
605      impl.registerChangeListener(listener);
606    }
607
608
609
610    /**
611     * {@inheritDoc}
612     */
613    public void removeSMTPChangeListener(
614        ConfigurationChangeListener<SMTPAlertHandlerCfg> listener) {
615      impl.deregisterChangeListener(listener);
616    }
617    /**
618     * {@inheritDoc}
619     */
620    public void addChangeListener(
621        ConfigurationChangeListener<AlertHandlerCfg> listener) {
622      impl.registerChangeListener(listener);
623    }
624
625
626
627    /**
628     * {@inheritDoc}
629     */
630    public void removeChangeListener(
631        ConfigurationChangeListener<AlertHandlerCfg> listener) {
632      impl.deregisterChangeListener(listener);
633    }
634
635
636
637    /**
638     * {@inheritDoc}
639     */
640    public SortedSet<String> getDisabledAlertType() {
641      return pDisabledAlertType;
642    }
643
644
645
646    /**
647     * {@inheritDoc}
648     */
649    public boolean isEnabled() {
650      return pEnabled;
651    }
652
653
654
655    /**
656     * {@inheritDoc}
657     */
658    public SortedSet<String> getEnabledAlertType() {
659      return pEnabledAlertType;
660    }
661
662
663
664    /**
665     * {@inheritDoc}
666     */
667    public String getJavaClass() {
668      return pJavaClass;
669    }
670
671
672
673    /**
674     * {@inheritDoc}
675     */
676    public String getMessageBody() {
677      return pMessageBody;
678    }
679
680
681
682    /**
683     * {@inheritDoc}
684     */
685    public String getMessageSubject() {
686      return pMessageSubject;
687    }
688
689
690
691    /**
692     * {@inheritDoc}
693     */
694    public SortedSet<String> getRecipientAddress() {
695      return pRecipientAddress;
696    }
697
698
699
700    /**
701     * {@inheritDoc}
702     */
703    public String getSenderAddress() {
704      return pSenderAddress;
705    }
706
707
708
709    /**
710     * {@inheritDoc}
711     */
712    public Class<? extends SMTPAlertHandlerCfg> configurationClass() {
713      return SMTPAlertHandlerCfg.class;
714    }
715
716
717
718    /**
719     * {@inheritDoc}
720     */
721    public DN dn() {
722      return impl.getDN();
723    }
724
725  }
726}