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