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