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.AliasDefaultBehaviorProvider; 034import org.forgerock.opendj.config.BooleanPropertyDefinition; 035import org.forgerock.opendj.config.ClassPropertyDefinition; 036import org.forgerock.opendj.config.client.ConcurrentModificationException; 037import org.forgerock.opendj.config.client.ManagedObject; 038import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 039import org.forgerock.opendj.config.client.OperationRejectedException; 040import org.forgerock.opendj.config.DefaultBehaviorProvider; 041import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; 042import org.forgerock.opendj.config.DNPropertyDefinition; 043import org.forgerock.opendj.config.EnumPropertyDefinition; 044import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 045import org.forgerock.opendj.config.ManagedObjectDefinition; 046import org.forgerock.opendj.config.PropertyOption; 047import org.forgerock.opendj.config.PropertyProvider; 048import org.forgerock.opendj.config.server.ConfigurationChangeListener; 049import org.forgerock.opendj.config.server.ServerManagedObject; 050import org.forgerock.opendj.config.Tag; 051import org.forgerock.opendj.ldap.DN; 052import org.forgerock.opendj.ldap.LdapException; 053import org.forgerock.opendj.server.config.client.SambaPasswordPluginCfgClient; 054import org.forgerock.opendj.server.config.meta.PluginCfgDefn.PluginType; 055import org.forgerock.opendj.server.config.server.PluginCfg; 056import org.forgerock.opendj.server.config.server.SambaPasswordPluginCfg; 057 058 059 060/** 061 * An interface for querying the Samba Password Plugin managed object 062 * definition meta information. 063 * <p> 064 * Samba Password Synchronization Plugin. 065 */ 066public final class SambaPasswordPluginCfgDefn extends ManagedObjectDefinition<SambaPasswordPluginCfgClient, SambaPasswordPluginCfg> { 067 068 // The singleton configuration definition instance. 069 private static final SambaPasswordPluginCfgDefn INSTANCE = new SambaPasswordPluginCfgDefn(); 070 071 072 073 /** 074 * Defines the set of permissable values for the "pwd-sync-policy" property. 075 * <p> 076 * Specifies which Samba passwords should be kept synchronized. 077 */ 078 public static enum PwdSyncPolicy { 079 080 /** 081 * Synchronize the LanMan password attribute "sambaLMPassword" 082 */ 083 SYNC_LM_PASSWORD("sync-lm-password"), 084 085 086 087 /** 088 * Synchronize the NT password attribute "sambaNTPassword" 089 */ 090 SYNC_NT_PASSWORD("sync-nt-password"); 091 092 093 094 // String representation of the value. 095 private final String name; 096 097 098 099 // Private constructor. 100 private PwdSyncPolicy(String name) { this.name = name; } 101 102 103 104 /** 105 * {@inheritDoc} 106 */ 107 public String toString() { return name; } 108 109 } 110 111 112 113 // The "java-class" property definition. 114 private static final ClassPropertyDefinition PD_JAVA_CLASS; 115 116 117 118 // The "plugin-type" property definition. 119 private static final EnumPropertyDefinition<PluginType> PD_PLUGIN_TYPE; 120 121 122 123 // The "pwd-sync-policy" property definition. 124 private static final EnumPropertyDefinition<PwdSyncPolicy> PD_PWD_SYNC_POLICY; 125 126 127 128 // The "samba-administrator-dn" property definition. 129 private static final DNPropertyDefinition PD_SAMBA_ADMINISTRATOR_DN; 130 131 132 133 // Build the "java-class" property definition. 134 static { 135 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 136 builder.setOption(PropertyOption.MANDATORY); 137 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class")); 138 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.plugins.SambaPasswordPlugin"); 139 builder.setDefaultBehaviorProvider(provider); 140 builder.addInstanceOf("org.opends.server.api.plugin.DirectoryServerPlugin"); 141 PD_JAVA_CLASS = builder.getInstance(); 142 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 143 } 144 145 146 147 // Build the "plugin-type" property definition. 148 static { 149 EnumPropertyDefinition.Builder<PluginType> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "plugin-type"); 150 builder.setOption(PropertyOption.MULTI_VALUED); 151 builder.setOption(PropertyOption.MANDATORY); 152 builder.setOption(PropertyOption.ADVANCED); 153 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "plugin-type")); 154 DefaultBehaviorProvider<PluginType> provider = new DefinedDefaultBehaviorProvider<PluginType>("preoperationmodify", "postoperationextended"); 155 builder.setDefaultBehaviorProvider(provider); 156 builder.setEnumClass(PluginType.class); 157 PD_PLUGIN_TYPE = builder.getInstance(); 158 INSTANCE.registerPropertyDefinition(PD_PLUGIN_TYPE); 159 } 160 161 162 163 // Build the "pwd-sync-policy" property definition. 164 static { 165 EnumPropertyDefinition.Builder<PwdSyncPolicy> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "pwd-sync-policy"); 166 builder.setOption(PropertyOption.MULTI_VALUED); 167 builder.setOption(PropertyOption.MANDATORY); 168 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "pwd-sync-policy")); 169 DefaultBehaviorProvider<PwdSyncPolicy> provider = new DefinedDefaultBehaviorProvider<PwdSyncPolicy>("sync-nt-password"); 170 builder.setDefaultBehaviorProvider(provider); 171 builder.setEnumClass(PwdSyncPolicy.class); 172 PD_PWD_SYNC_POLICY = builder.getInstance(); 173 INSTANCE.registerPropertyDefinition(PD_PWD_SYNC_POLICY); 174 } 175 176 177 178 // Build the "samba-administrator-dn" property definition. 179 static { 180 DNPropertyDefinition.Builder builder = DNPropertyDefinition.createBuilder(INSTANCE, "samba-administrator-dn"); 181 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "samba-administrator-dn")); 182 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<DN>(INSTANCE, "samba-administrator-dn")); 183 PD_SAMBA_ADMINISTRATOR_DN = builder.getInstance(); 184 INSTANCE.registerPropertyDefinition(PD_SAMBA_ADMINISTRATOR_DN); 185 } 186 187 188 189 // Register the tags associated with this managed object definition. 190 static { 191 INSTANCE.registerTag(Tag.valueOf("core-server")); 192 } 193 194 195 196 /** 197 * Get the Samba Password Plugin configuration definition singleton. 198 * 199 * @return Returns the Samba Password Plugin configuration 200 * definition singleton. 201 */ 202 public static SambaPasswordPluginCfgDefn getInstance() { 203 return INSTANCE; 204 } 205 206 207 208 /** 209 * Private constructor. 210 */ 211 private SambaPasswordPluginCfgDefn() { 212 super("samba-password-plugin", PluginCfgDefn.getInstance()); 213 } 214 215 216 217 /** 218 * {@inheritDoc} 219 */ 220 public SambaPasswordPluginCfgClient createClientConfiguration( 221 ManagedObject<? extends SambaPasswordPluginCfgClient> impl) { 222 return new SambaPasswordPluginCfgClientImpl(impl); 223 } 224 225 226 227 /** 228 * {@inheritDoc} 229 */ 230 public SambaPasswordPluginCfg createServerConfiguration( 231 ServerManagedObject<? extends SambaPasswordPluginCfg> impl) { 232 return new SambaPasswordPluginCfgServerImpl(impl); 233 } 234 235 236 237 /** 238 * {@inheritDoc} 239 */ 240 public Class<SambaPasswordPluginCfg> getServerConfigurationClass() { 241 return SambaPasswordPluginCfg.class; 242 } 243 244 245 246 /** 247 * Get the "enabled" property definition. 248 * <p> 249 * Indicates whether the plug-in is enabled for use. 250 * 251 * @return Returns the "enabled" property definition. 252 */ 253 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 254 return PluginCfgDefn.getInstance().getEnabledPropertyDefinition(); 255 } 256 257 258 259 /** 260 * Get the "invoke-for-internal-operations" property definition. 261 * <p> 262 * Indicates whether the plug-in should be invoked for internal 263 * operations. 264 * <p> 265 * Any plug-in that can be invoked for internal operations must 266 * ensure that it does not create any new internal operatons that can 267 * cause the same plug-in to be re-invoked. 268 * 269 * @return Returns the "invoke-for-internal-operations" property definition. 270 */ 271 public BooleanPropertyDefinition getInvokeForInternalOperationsPropertyDefinition() { 272 return PluginCfgDefn.getInstance().getInvokeForInternalOperationsPropertyDefinition(); 273 } 274 275 276 277 /** 278 * Get the "java-class" property definition. 279 * <p> 280 * Specifies the fully-qualified name of the Java class that 281 * provides the plug-in implementation. 282 * 283 * @return Returns the "java-class" property definition. 284 */ 285 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 286 return PD_JAVA_CLASS; 287 } 288 289 290 291 /** 292 * Get the "plugin-type" property definition. 293 * <p> 294 * Specifies the set of plug-in types for the plug-in, which 295 * specifies the times at which the plug-in is invoked. 296 * 297 * @return Returns the "plugin-type" property definition. 298 */ 299 public EnumPropertyDefinition<PluginType> getPluginTypePropertyDefinition() { 300 return PD_PLUGIN_TYPE; 301 } 302 303 304 305 /** 306 * Get the "pwd-sync-policy" property definition. 307 * <p> 308 * Specifies which Samba passwords should be kept synchronized. 309 * 310 * @return Returns the "pwd-sync-policy" property definition. 311 */ 312 public EnumPropertyDefinition<PwdSyncPolicy> getPwdSyncPolicyPropertyDefinition() { 313 return PD_PWD_SYNC_POLICY; 314 } 315 316 317 318 /** 319 * Get the "samba-administrator-dn" property definition. 320 * <p> 321 * Specifies the distinguished name of the user which Samba uses to 322 * perform Password Modify extended operations against this directory 323 * server in order to synchronize the userPassword attribute after 324 * the LanMan or NT passwords have been updated. 325 * <p> 326 * The user must have the 'password-reset' privilege and should not 327 * be a root user. This user name can be used in order to identify 328 * Samba connections and avoid double re-synchronization of the same 329 * password. If this property is left undefined, then no password 330 * updates will be skipped. 331 * 332 * @return Returns the "samba-administrator-dn" property definition. 333 */ 334 public DNPropertyDefinition getSambaAdministratorDNPropertyDefinition() { 335 return PD_SAMBA_ADMINISTRATOR_DN; 336 } 337 338 339 340 /** 341 * Managed object client implementation. 342 */ 343 private static class SambaPasswordPluginCfgClientImpl implements 344 SambaPasswordPluginCfgClient { 345 346 // Private implementation. 347 private ManagedObject<? extends SambaPasswordPluginCfgClient> impl; 348 349 350 351 // Private constructor. 352 private SambaPasswordPluginCfgClientImpl( 353 ManagedObject<? extends SambaPasswordPluginCfgClient> impl) { 354 this.impl = impl; 355 } 356 357 358 359 /** 360 * {@inheritDoc} 361 */ 362 public Boolean isEnabled() { 363 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 364 } 365 366 367 368 /** 369 * {@inheritDoc} 370 */ 371 public void setEnabled(boolean value) { 372 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 373 } 374 375 376 377 /** 378 * {@inheritDoc} 379 */ 380 public boolean isInvokeForInternalOperations() { 381 return impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition()); 382 } 383 384 385 386 /** 387 * {@inheritDoc} 388 */ 389 public void setInvokeForInternalOperations(Boolean value) { 390 impl.setPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition(), value); 391 } 392 393 394 395 /** 396 * {@inheritDoc} 397 */ 398 public String getJavaClass() { 399 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 400 } 401 402 403 404 /** 405 * {@inheritDoc} 406 */ 407 public void setJavaClass(String value) { 408 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 409 } 410 411 412 413 /** 414 * {@inheritDoc} 415 */ 416 public SortedSet<PluginType> getPluginType() { 417 return impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition()); 418 } 419 420 421 422 /** 423 * {@inheritDoc} 424 */ 425 public void setPluginType(Collection<PluginType> values) { 426 impl.setPropertyValues(INSTANCE.getPluginTypePropertyDefinition(), values); 427 } 428 429 430 431 /** 432 * {@inheritDoc} 433 */ 434 public SortedSet<PwdSyncPolicy> getPwdSyncPolicy() { 435 return impl.getPropertyValues(INSTANCE.getPwdSyncPolicyPropertyDefinition()); 436 } 437 438 439 440 /** 441 * {@inheritDoc} 442 */ 443 public void setPwdSyncPolicy(Collection<PwdSyncPolicy> values) { 444 impl.setPropertyValues(INSTANCE.getPwdSyncPolicyPropertyDefinition(), values); 445 } 446 447 448 449 /** 450 * {@inheritDoc} 451 */ 452 public DN getSambaAdministratorDN() { 453 return impl.getPropertyValue(INSTANCE.getSambaAdministratorDNPropertyDefinition()); 454 } 455 456 457 458 /** 459 * {@inheritDoc} 460 */ 461 public void setSambaAdministratorDN(DN value) { 462 impl.setPropertyValue(INSTANCE.getSambaAdministratorDNPropertyDefinition(), value); 463 } 464 465 466 467 /** 468 * {@inheritDoc} 469 */ 470 public ManagedObjectDefinition<? extends SambaPasswordPluginCfgClient, ? extends SambaPasswordPluginCfg> definition() { 471 return INSTANCE; 472 } 473 474 475 476 /** 477 * {@inheritDoc} 478 */ 479 public PropertyProvider properties() { 480 return impl; 481 } 482 483 484 485 /** 486 * {@inheritDoc} 487 */ 488 public void commit() throws ManagedObjectAlreadyExistsException, 489 MissingMandatoryPropertiesException, ConcurrentModificationException, 490 OperationRejectedException, LdapException { 491 impl.commit(); 492 } 493 494 } 495 496 497 498 /** 499 * Managed object server implementation. 500 */ 501 private static class SambaPasswordPluginCfgServerImpl implements 502 SambaPasswordPluginCfg { 503 504 // Private implementation. 505 private ServerManagedObject<? extends SambaPasswordPluginCfg> impl; 506 507 // The value of the "enabled" property. 508 private final boolean pEnabled; 509 510 // The value of the "invoke-for-internal-operations" property. 511 private final boolean pInvokeForInternalOperations; 512 513 // The value of the "java-class" property. 514 private final String pJavaClass; 515 516 // The value of the "plugin-type" property. 517 private final SortedSet<PluginType> pPluginType; 518 519 // The value of the "pwd-sync-policy" property. 520 private final SortedSet<PwdSyncPolicy> pPwdSyncPolicy; 521 522 // The value of the "samba-administrator-dn" property. 523 private final DN pSambaAdministratorDN; 524 525 526 527 // Private constructor. 528 private SambaPasswordPluginCfgServerImpl(ServerManagedObject<? extends SambaPasswordPluginCfg> impl) { 529 this.impl = impl; 530 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 531 this.pInvokeForInternalOperations = impl.getPropertyValue(INSTANCE.getInvokeForInternalOperationsPropertyDefinition()); 532 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 533 this.pPluginType = impl.getPropertyValues(INSTANCE.getPluginTypePropertyDefinition()); 534 this.pPwdSyncPolicy = impl.getPropertyValues(INSTANCE.getPwdSyncPolicyPropertyDefinition()); 535 this.pSambaAdministratorDN = impl.getPropertyValue(INSTANCE.getSambaAdministratorDNPropertyDefinition()); 536 } 537 538 539 540 /** 541 * {@inheritDoc} 542 */ 543 public void addSambaPasswordChangeListener( 544 ConfigurationChangeListener<SambaPasswordPluginCfg> listener) { 545 impl.registerChangeListener(listener); 546 } 547 548 549 550 /** 551 * {@inheritDoc} 552 */ 553 public void removeSambaPasswordChangeListener( 554 ConfigurationChangeListener<SambaPasswordPluginCfg> listener) { 555 impl.deregisterChangeListener(listener); 556 } 557 /** 558 * {@inheritDoc} 559 */ 560 public void addChangeListener( 561 ConfigurationChangeListener<PluginCfg> listener) { 562 impl.registerChangeListener(listener); 563 } 564 565 566 567 /** 568 * {@inheritDoc} 569 */ 570 public void removeChangeListener( 571 ConfigurationChangeListener<PluginCfg> listener) { 572 impl.deregisterChangeListener(listener); 573 } 574 575 576 577 /** 578 * {@inheritDoc} 579 */ 580 public boolean isEnabled() { 581 return pEnabled; 582 } 583 584 585 586 /** 587 * {@inheritDoc} 588 */ 589 public boolean isInvokeForInternalOperations() { 590 return pInvokeForInternalOperations; 591 } 592 593 594 595 /** 596 * {@inheritDoc} 597 */ 598 public String getJavaClass() { 599 return pJavaClass; 600 } 601 602 603 604 /** 605 * {@inheritDoc} 606 */ 607 public SortedSet<PluginType> getPluginType() { 608 return pPluginType; 609 } 610 611 612 613 /** 614 * {@inheritDoc} 615 */ 616 public SortedSet<PwdSyncPolicy> getPwdSyncPolicy() { 617 return pPwdSyncPolicy; 618 } 619 620 621 622 /** 623 * {@inheritDoc} 624 */ 625 public DN getSambaAdministratorDN() { 626 return pSambaAdministratorDN; 627 } 628 629 630 631 /** 632 * {@inheritDoc} 633 */ 634 public Class<? extends SambaPasswordPluginCfg> configurationClass() { 635 return SambaPasswordPluginCfg.class; 636 } 637 638 639 640 /** 641 * {@inheritDoc} 642 */ 643 public DN dn() { 644 return impl.getDN(); 645 } 646 647 } 648}