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.EnumPropertyDefinition;
042import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
043import org.forgerock.opendj.config.ManagedObjectDefinition;
044import org.forgerock.opendj.config.PropertyOption;
045import org.forgerock.opendj.config.PropertyProvider;
046import org.forgerock.opendj.config.server.ConfigurationChangeListener;
047import org.forgerock.opendj.config.server.ServerManagedObject;
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.ErrorLogAccountStatusNotificationHandlerCfgClient;
053import org.forgerock.opendj.server.config.server.AccountStatusNotificationHandlerCfg;
054import org.forgerock.opendj.server.config.server.ErrorLogAccountStatusNotificationHandlerCfg;
055
056
057
058/**
059 * An interface for querying the Error Log Account Status Notification
060 * Handler managed object definition meta information.
061 * <p>
062 * The Error Log Account Status Notification Handler is a notification
063 * handler that writes information to the server error log whenever an
064 * appropriate account status event occurs.
065 */
066public final class ErrorLogAccountStatusNotificationHandlerCfgDefn extends ManagedObjectDefinition<ErrorLogAccountStatusNotificationHandlerCfgClient, ErrorLogAccountStatusNotificationHandlerCfg> {
067
068  /** The singleton configuration definition instance. */
069  private static final ErrorLogAccountStatusNotificationHandlerCfgDefn INSTANCE = new ErrorLogAccountStatusNotificationHandlerCfgDefn();
070
071
072
073  /**
074   * Defines the set of permissable values for the "account-status-notification-type" property.
075   * <p>
076   * Indicates which types of event can trigger an account status
077   * notification.
078   */
079  public static enum AccountStatusNotificationType {
080
081    /**
082     * Generate a notification whenever a user account has been
083     * disabled by an administrator.
084     */
085    ACCOUNT_DISABLED("account-disabled"),
086
087
088
089    /**
090     * Generate a notification whenever a user account has been
091     * enabled by an administrator.
092     */
093    ACCOUNT_ENABLED("account-enabled"),
094
095
096
097    /**
098     * Generate a notification whenever a user authentication has
099     * failed because the account has expired.
100     */
101    ACCOUNT_EXPIRED("account-expired"),
102
103
104
105    /**
106     * Generate a notification whenever a user account has been locked
107     * because it was idle for too long.
108     */
109    ACCOUNT_IDLE_LOCKED("account-idle-locked"),
110
111
112
113    /**
114     * Generate a notification whenever a user account has been
115     * permanently locked after too many failed attempts.
116     */
117    ACCOUNT_PERMANENTLY_LOCKED("account-permanently-locked"),
118
119
120
121    /**
122     * Generate a notification whenever a user account has been
123     * locked, because the password had been reset by an administrator
124     * but not changed by the user within the required interval.
125     */
126    ACCOUNT_RESET_LOCKED("account-reset-locked"),
127
128
129
130    /**
131     * Generate a notification whenever a user account has been
132     * temporarily locked after too many failed attempts.
133     */
134    ACCOUNT_TEMPORARILY_LOCKED("account-temporarily-locked"),
135
136
137
138    /**
139     * Generate a notification whenever a user account has been
140     * unlocked by an administrator.
141     */
142    ACCOUNT_UNLOCKED("account-unlocked"),
143
144
145
146    /**
147     * Generate a notification whenever a user changes his/her own
148     * password.
149     */
150    PASSWORD_CHANGED("password-changed"),
151
152
153
154    /**
155     * Generate a notification whenever a user authentication has
156     * failed because the password has expired.
157     */
158    PASSWORD_EXPIRED("password-expired"),
159
160
161
162    /**
163     * Generate a notification whenever a password expiration warning
164     * is encountered for a user password for the first time.
165     */
166    PASSWORD_EXPIRING("password-expiring"),
167
168
169
170    /**
171     * Generate a notification whenever a user's password is reset by
172     * an administrator.
173     */
174    PASSWORD_RESET("password-reset");
175
176
177
178    /** String representation of the value. */
179    private final String name;
180
181
182
183    /** Private constructor. */
184    private AccountStatusNotificationType(String name) { this.name = name; }
185
186
187
188    /** {@inheritDoc} */
189    public String toString() { return name; }
190
191  }
192
193
194
195  /** The "account-status-notification-type" property definition. */
196  private static final EnumPropertyDefinition<AccountStatusNotificationType> PD_ACCOUNT_STATUS_NOTIFICATION_TYPE;
197
198
199
200  /** The "java-class" property definition. */
201  private static final ClassPropertyDefinition PD_JAVA_CLASS;
202
203
204
205  /** Build the "account-status-notification-type" property definition. */
206  static {
207      EnumPropertyDefinition.Builder<AccountStatusNotificationType> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "account-status-notification-type");
208      builder.setOption(PropertyOption.MULTI_VALUED);
209      builder.setOption(PropertyOption.MANDATORY);
210      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "account-status-notification-type"));
211      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<AccountStatusNotificationType>());
212      builder.setEnumClass(AccountStatusNotificationType.class);
213      PD_ACCOUNT_STATUS_NOTIFICATION_TYPE = builder.getInstance();
214      INSTANCE.registerPropertyDefinition(PD_ACCOUNT_STATUS_NOTIFICATION_TYPE);
215  }
216
217
218
219  /** Build the "java-class" property definition. */
220  static {
221      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
222      builder.setOption(PropertyOption.MANDATORY);
223      builder.setOption(PropertyOption.ADVANCED);
224      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
225      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.ErrorLogAccountStatusNotificationHandler");
226      builder.setDefaultBehaviorProvider(provider);
227      builder.addInstanceOf("org.opends.server.api.AccountStatusNotificationHandler");
228      PD_JAVA_CLASS = builder.getInstance();
229      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
230  }
231
232
233
234  // Register the tags associated with this managed object definition.
235  static {
236    INSTANCE.registerTag(Tag.valueOf("user-management"));
237  }
238
239
240
241  /**
242   * Get the Error Log Account Status Notification Handler
243   * configuration definition singleton.
244   *
245   * @return Returns the Error Log Account Status Notification Handler
246   *         configuration definition singleton.
247   */
248  public static ErrorLogAccountStatusNotificationHandlerCfgDefn getInstance() {
249    return INSTANCE;
250  }
251
252
253
254  /**
255   * Private constructor.
256   */
257  private ErrorLogAccountStatusNotificationHandlerCfgDefn() {
258    super("error-log-account-status-notification-handler", AccountStatusNotificationHandlerCfgDefn.getInstance());
259  }
260
261
262
263  /** {@inheritDoc} */
264  public ErrorLogAccountStatusNotificationHandlerCfgClient createClientConfiguration(
265      ManagedObject<? extends ErrorLogAccountStatusNotificationHandlerCfgClient> impl) {
266    return new ErrorLogAccountStatusNotificationHandlerCfgClientImpl(impl);
267  }
268
269
270
271  /** {@inheritDoc} */
272  public ErrorLogAccountStatusNotificationHandlerCfg createServerConfiguration(
273      ServerManagedObject<? extends ErrorLogAccountStatusNotificationHandlerCfg> impl) {
274    return new ErrorLogAccountStatusNotificationHandlerCfgServerImpl(impl);
275  }
276
277
278
279  /** {@inheritDoc} */
280  public Class<ErrorLogAccountStatusNotificationHandlerCfg> getServerConfigurationClass() {
281    return ErrorLogAccountStatusNotificationHandlerCfg.class;
282  }
283
284
285
286  /**
287   * Get the "account-status-notification-type" property definition.
288   * <p>
289   * Indicates which types of event can trigger an account status
290   * notification.
291   *
292   * @return Returns the "account-status-notification-type" property definition.
293   */
294  public EnumPropertyDefinition<AccountStatusNotificationType> getAccountStatusNotificationTypePropertyDefinition() {
295    return PD_ACCOUNT_STATUS_NOTIFICATION_TYPE;
296  }
297
298
299
300  /**
301   * Get the "enabled" property definition.
302   * <p>
303   * Indicates whether the Error Log Account Status Notification
304   * Handler is enabled. Only enabled handlers are invoked whenever a
305   * related event occurs in the server.
306   *
307   * @return Returns the "enabled" property definition.
308   */
309  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
310    return AccountStatusNotificationHandlerCfgDefn.getInstance().getEnabledPropertyDefinition();
311  }
312
313
314
315  /**
316   * Get the "java-class" property definition.
317   * <p>
318   * Specifies the fully-qualified name of the Java class that
319   * provides the Error Log Account Status Notification Handler
320   * implementation.
321   *
322   * @return Returns the "java-class" property definition.
323   */
324  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
325    return PD_JAVA_CLASS;
326  }
327
328
329
330  /**
331   * Managed object client implementation.
332   */
333  private static class ErrorLogAccountStatusNotificationHandlerCfgClientImpl implements
334    ErrorLogAccountStatusNotificationHandlerCfgClient {
335
336    /** Private implementation. */
337    private ManagedObject<? extends ErrorLogAccountStatusNotificationHandlerCfgClient> impl;
338
339
340
341    /** Private constructor. */
342    private ErrorLogAccountStatusNotificationHandlerCfgClientImpl(
343        ManagedObject<? extends ErrorLogAccountStatusNotificationHandlerCfgClient> impl) {
344      this.impl = impl;
345    }
346
347
348
349    /** {@inheritDoc} */
350    public SortedSet<AccountStatusNotificationType> getAccountStatusNotificationType() {
351      return impl.getPropertyValues(INSTANCE.getAccountStatusNotificationTypePropertyDefinition());
352    }
353
354
355
356    /** {@inheritDoc} */
357    public void setAccountStatusNotificationType(Collection<AccountStatusNotificationType> values) {
358      impl.setPropertyValues(INSTANCE.getAccountStatusNotificationTypePropertyDefinition(), values);
359    }
360
361
362
363    /** {@inheritDoc} */
364    public Boolean isEnabled() {
365      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
366    }
367
368
369
370    /** {@inheritDoc} */
371    public void setEnabled(boolean value) {
372      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
373    }
374
375
376
377    /** {@inheritDoc} */
378    public String getJavaClass() {
379      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
380    }
381
382
383
384    /** {@inheritDoc} */
385    public void setJavaClass(String value) {
386      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
387    }
388
389
390
391    /** {@inheritDoc} */
392    public ManagedObjectDefinition<? extends ErrorLogAccountStatusNotificationHandlerCfgClient, ? extends ErrorLogAccountStatusNotificationHandlerCfg> definition() {
393      return INSTANCE;
394    }
395
396
397
398    /** {@inheritDoc} */
399    public PropertyProvider properties() {
400      return impl;
401    }
402
403
404
405    /** {@inheritDoc} */
406    public void commit() throws ManagedObjectAlreadyExistsException,
407        MissingMandatoryPropertiesException, ConcurrentModificationException,
408        OperationRejectedException, LdapException {
409      impl.commit();
410    }
411
412
413
414    /** {@inheritDoc} */
415    public String toString() {
416      return impl.toString();
417    }
418  }
419
420
421
422  /**
423   * Managed object server implementation.
424   */
425  private static class ErrorLogAccountStatusNotificationHandlerCfgServerImpl implements
426    ErrorLogAccountStatusNotificationHandlerCfg {
427
428    /** Private implementation. */
429    private ServerManagedObject<? extends ErrorLogAccountStatusNotificationHandlerCfg> impl;
430
431    /** The value of the "account-status-notification-type" property. */
432    private final SortedSet<AccountStatusNotificationType> pAccountStatusNotificationType;
433
434    /** The value of the "enabled" property. */
435    private final boolean pEnabled;
436
437    /** The value of the "java-class" property. */
438    private final String pJavaClass;
439
440
441
442    /** Private constructor. */
443    private ErrorLogAccountStatusNotificationHandlerCfgServerImpl(ServerManagedObject<? extends ErrorLogAccountStatusNotificationHandlerCfg> impl) {
444      this.impl = impl;
445      this.pAccountStatusNotificationType = impl.getPropertyValues(INSTANCE.getAccountStatusNotificationTypePropertyDefinition());
446      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
447      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
448    }
449
450
451
452    /** {@inheritDoc} */
453    public void addErrorLogChangeListener(
454        ConfigurationChangeListener<ErrorLogAccountStatusNotificationHandlerCfg> listener) {
455      impl.registerChangeListener(listener);
456    }
457
458
459
460    /** {@inheritDoc} */
461    public void removeErrorLogChangeListener(
462        ConfigurationChangeListener<ErrorLogAccountStatusNotificationHandlerCfg> listener) {
463      impl.deregisterChangeListener(listener);
464    }
465    /** {@inheritDoc} */
466    public void addChangeListener(
467        ConfigurationChangeListener<AccountStatusNotificationHandlerCfg> listener) {
468      impl.registerChangeListener(listener);
469    }
470
471
472
473    /** {@inheritDoc} */
474    public void removeChangeListener(
475        ConfigurationChangeListener<AccountStatusNotificationHandlerCfg> listener) {
476      impl.deregisterChangeListener(listener);
477    }
478
479
480
481    /** {@inheritDoc} */
482    public SortedSet<AccountStatusNotificationType> getAccountStatusNotificationType() {
483      return pAccountStatusNotificationType;
484    }
485
486
487
488    /** {@inheritDoc} */
489    public boolean isEnabled() {
490      return pEnabled;
491    }
492
493
494
495    /** {@inheritDoc} */
496    public String getJavaClass() {
497      return pJavaClass;
498    }
499
500
501
502    /** {@inheritDoc} */
503    public Class<? extends ErrorLogAccountStatusNotificationHandlerCfg> configurationClass() {
504      return ErrorLogAccountStatusNotificationHandlerCfg.class;
505    }
506
507
508
509    /** {@inheritDoc} */
510    public DN dn() {
511      return impl.getDN();
512    }
513
514
515
516    /** {@inheritDoc} */
517    public String toString() {
518      return impl.toString();
519    }
520  }
521}