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    /**
189     * {@inheritDoc}
190     */
191    public String toString() { return name; }
192
193  }
194
195
196
197  // The "account-status-notification-type" property definition.
198  private static final EnumPropertyDefinition<AccountStatusNotificationType> PD_ACCOUNT_STATUS_NOTIFICATION_TYPE;
199
200
201
202  // The "java-class" property definition.
203  private static final ClassPropertyDefinition PD_JAVA_CLASS;
204
205
206
207  // Build the "account-status-notification-type" property definition.
208  static {
209      EnumPropertyDefinition.Builder<AccountStatusNotificationType> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "account-status-notification-type");
210      builder.setOption(PropertyOption.MULTI_VALUED);
211      builder.setOption(PropertyOption.MANDATORY);
212      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "account-status-notification-type"));
213      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<AccountStatusNotificationType>());
214      builder.setEnumClass(AccountStatusNotificationType.class);
215      PD_ACCOUNT_STATUS_NOTIFICATION_TYPE = builder.getInstance();
216      INSTANCE.registerPropertyDefinition(PD_ACCOUNT_STATUS_NOTIFICATION_TYPE);
217  }
218
219
220
221  // Build the "java-class" property definition.
222  static {
223      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
224      builder.setOption(PropertyOption.MANDATORY);
225      builder.setOption(PropertyOption.ADVANCED);
226      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
227      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.ErrorLogAccountStatusNotificationHandler");
228      builder.setDefaultBehaviorProvider(provider);
229      builder.addInstanceOf("org.opends.server.api.AccountStatusNotificationHandler");
230      PD_JAVA_CLASS = builder.getInstance();
231      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
232  }
233
234
235
236  // Register the tags associated with this managed object definition.
237  static {
238    INSTANCE.registerTag(Tag.valueOf("user-management"));
239  }
240
241
242
243  /**
244   * Get the Error Log Account Status Notification Handler
245   * configuration definition singleton.
246   *
247   * @return Returns the Error Log Account Status Notification Handler
248   *         configuration definition singleton.
249   */
250  public static ErrorLogAccountStatusNotificationHandlerCfgDefn getInstance() {
251    return INSTANCE;
252  }
253
254
255
256  /**
257   * Private constructor.
258   */
259  private ErrorLogAccountStatusNotificationHandlerCfgDefn() {
260    super("error-log-account-status-notification-handler", AccountStatusNotificationHandlerCfgDefn.getInstance());
261  }
262
263
264
265  /**
266   * {@inheritDoc}
267   */
268  public ErrorLogAccountStatusNotificationHandlerCfgClient createClientConfiguration(
269      ManagedObject<? extends ErrorLogAccountStatusNotificationHandlerCfgClient> impl) {
270    return new ErrorLogAccountStatusNotificationHandlerCfgClientImpl(impl);
271  }
272
273
274
275  /**
276   * {@inheritDoc}
277   */
278  public ErrorLogAccountStatusNotificationHandlerCfg createServerConfiguration(
279      ServerManagedObject<? extends ErrorLogAccountStatusNotificationHandlerCfg> impl) {
280    return new ErrorLogAccountStatusNotificationHandlerCfgServerImpl(impl);
281  }
282
283
284
285  /**
286   * {@inheritDoc}
287   */
288  public Class<ErrorLogAccountStatusNotificationHandlerCfg> getServerConfigurationClass() {
289    return ErrorLogAccountStatusNotificationHandlerCfg.class;
290  }
291
292
293
294  /**
295   * Get the "account-status-notification-type" property definition.
296   * <p>
297   * Indicates which types of event can trigger an account status
298   * notification.
299   *
300   * @return Returns the "account-status-notification-type" property definition.
301   */
302  public EnumPropertyDefinition<AccountStatusNotificationType> getAccountStatusNotificationTypePropertyDefinition() {
303    return PD_ACCOUNT_STATUS_NOTIFICATION_TYPE;
304  }
305
306
307
308  /**
309   * Get the "enabled" property definition.
310   * <p>
311   * Indicates whether the Error Log Account Status Notification
312   * Handler is enabled. Only enabled handlers are invoked whenever a
313   * related event occurs in the server.
314   *
315   * @return Returns the "enabled" property definition.
316   */
317  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
318    return AccountStatusNotificationHandlerCfgDefn.getInstance().getEnabledPropertyDefinition();
319  }
320
321
322
323  /**
324   * Get the "java-class" property definition.
325   * <p>
326   * Specifies the fully-qualified name of the Java class that
327   * provides the Error Log Account Status Notification Handler
328   * implementation.
329   *
330   * @return Returns the "java-class" property definition.
331   */
332  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
333    return PD_JAVA_CLASS;
334  }
335
336
337
338  /**
339   * Managed object client implementation.
340   */
341  private static class ErrorLogAccountStatusNotificationHandlerCfgClientImpl implements
342    ErrorLogAccountStatusNotificationHandlerCfgClient {
343
344    // Private implementation.
345    private ManagedObject<? extends ErrorLogAccountStatusNotificationHandlerCfgClient> impl;
346
347
348
349    // Private constructor.
350    private ErrorLogAccountStatusNotificationHandlerCfgClientImpl(
351        ManagedObject<? extends ErrorLogAccountStatusNotificationHandlerCfgClient> impl) {
352      this.impl = impl;
353    }
354
355
356
357    /**
358     * {@inheritDoc}
359     */
360    public SortedSet<AccountStatusNotificationType> getAccountStatusNotificationType() {
361      return impl.getPropertyValues(INSTANCE.getAccountStatusNotificationTypePropertyDefinition());
362    }
363
364
365
366    /**
367     * {@inheritDoc}
368     */
369    public void setAccountStatusNotificationType(Collection<AccountStatusNotificationType> values) {
370      impl.setPropertyValues(INSTANCE.getAccountStatusNotificationTypePropertyDefinition(), values);
371    }
372
373
374
375    /**
376     * {@inheritDoc}
377     */
378    public Boolean isEnabled() {
379      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
380    }
381
382
383
384    /**
385     * {@inheritDoc}
386     */
387    public void setEnabled(boolean value) {
388      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
389    }
390
391
392
393    /**
394     * {@inheritDoc}
395     */
396    public String getJavaClass() {
397      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
398    }
399
400
401
402    /**
403     * {@inheritDoc}
404     */
405    public void setJavaClass(String value) {
406      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
407    }
408
409
410
411    /**
412     * {@inheritDoc}
413     */
414    public ManagedObjectDefinition<? extends ErrorLogAccountStatusNotificationHandlerCfgClient, ? extends ErrorLogAccountStatusNotificationHandlerCfg> definition() {
415      return INSTANCE;
416    }
417
418
419
420    /**
421     * {@inheritDoc}
422     */
423    public PropertyProvider properties() {
424      return impl;
425    }
426
427
428
429    /**
430     * {@inheritDoc}
431     */
432    public void commit() throws ManagedObjectAlreadyExistsException,
433        MissingMandatoryPropertiesException, ConcurrentModificationException,
434        OperationRejectedException, LdapException {
435      impl.commit();
436    }
437
438  }
439
440
441
442  /**
443   * Managed object server implementation.
444   */
445  private static class ErrorLogAccountStatusNotificationHandlerCfgServerImpl implements
446    ErrorLogAccountStatusNotificationHandlerCfg {
447
448    // Private implementation.
449    private ServerManagedObject<? extends ErrorLogAccountStatusNotificationHandlerCfg> impl;
450
451    // The value of the "account-status-notification-type" property.
452    private final SortedSet<AccountStatusNotificationType> pAccountStatusNotificationType;
453
454    // The value of the "enabled" property.
455    private final boolean pEnabled;
456
457    // The value of the "java-class" property.
458    private final String pJavaClass;
459
460
461
462    // Private constructor.
463    private ErrorLogAccountStatusNotificationHandlerCfgServerImpl(ServerManagedObject<? extends ErrorLogAccountStatusNotificationHandlerCfg> impl) {
464      this.impl = impl;
465      this.pAccountStatusNotificationType = impl.getPropertyValues(INSTANCE.getAccountStatusNotificationTypePropertyDefinition());
466      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
467      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
468    }
469
470
471
472    /**
473     * {@inheritDoc}
474     */
475    public void addErrorLogChangeListener(
476        ConfigurationChangeListener<ErrorLogAccountStatusNotificationHandlerCfg> listener) {
477      impl.registerChangeListener(listener);
478    }
479
480
481
482    /**
483     * {@inheritDoc}
484     */
485    public void removeErrorLogChangeListener(
486        ConfigurationChangeListener<ErrorLogAccountStatusNotificationHandlerCfg> listener) {
487      impl.deregisterChangeListener(listener);
488    }
489    /**
490     * {@inheritDoc}
491     */
492    public void addChangeListener(
493        ConfigurationChangeListener<AccountStatusNotificationHandlerCfg> listener) {
494      impl.registerChangeListener(listener);
495    }
496
497
498
499    /**
500     * {@inheritDoc}
501     */
502    public void removeChangeListener(
503        ConfigurationChangeListener<AccountStatusNotificationHandlerCfg> listener) {
504      impl.deregisterChangeListener(listener);
505    }
506
507
508
509    /**
510     * {@inheritDoc}
511     */
512    public SortedSet<AccountStatusNotificationType> getAccountStatusNotificationType() {
513      return pAccountStatusNotificationType;
514    }
515
516
517
518    /**
519     * {@inheritDoc}
520     */
521    public boolean isEnabled() {
522      return pEnabled;
523    }
524
525
526
527    /**
528     * {@inheritDoc}
529     */
530    public String getJavaClass() {
531      return pJavaClass;
532    }
533
534
535
536    /**
537     * {@inheritDoc}
538     */
539    public Class<? extends ErrorLogAccountStatusNotificationHandlerCfg> configurationClass() {
540      return ErrorLogAccountStatusNotificationHandlerCfg.class;
541    }
542
543
544
545    /**
546     * {@inheritDoc}
547     */
548    public DN dn() {
549      return impl.getDN();
550    }
551
552  }
553}