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