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