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