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.opends.server.admin.std.meta; 027 028 029 030import org.opends.server.admin.AdministratorAction; 031import org.opends.server.admin.BooleanPropertyDefinition; 032import org.opends.server.admin.ClassPropertyDefinition; 033import org.opends.server.admin.client.AuthorizationException; 034import org.opends.server.admin.client.CommunicationException; 035import org.opends.server.admin.client.ConcurrentModificationException; 036import org.opends.server.admin.client.ManagedObject; 037import org.opends.server.admin.client.MissingMandatoryPropertiesException; 038import org.opends.server.admin.client.OperationRejectedException; 039import org.opends.server.admin.DefaultBehaviorProvider; 040import org.opends.server.admin.DefinedDefaultBehaviorProvider; 041import org.opends.server.admin.IntegerPropertyDefinition; 042import org.opends.server.admin.ManagedObjectAlreadyExistsException; 043import org.opends.server.admin.ManagedObjectDefinition; 044import org.opends.server.admin.PropertyOption; 045import org.opends.server.admin.PropertyProvider; 046import org.opends.server.admin.server.ConfigurationChangeListener; 047import org.opends.server.admin.server.ServerManagedObject; 048import org.opends.server.admin.std.client.PBKDF2PasswordStorageSchemeCfgClient; 049import org.opends.server.admin.std.server.PasswordStorageSchemeCfg; 050import org.opends.server.admin.std.server.PBKDF2PasswordStorageSchemeCfg; 051import org.opends.server.admin.Tag; 052import org.opends.server.types.DN; 053 054 055 056/** 057 * An interface for querying the PBKDF2 Password Storage Scheme 058 * managed object definition meta information. 059 * <p> 060 * The PBKDF2 Password Storage Scheme provides a mechanism for 061 * encoding user passwords using the PBKDF2 message digest algorithm. 062 */ 063public final class PBKDF2PasswordStorageSchemeCfgDefn extends ManagedObjectDefinition<PBKDF2PasswordStorageSchemeCfgClient, PBKDF2PasswordStorageSchemeCfg> { 064 065 // The singleton configuration definition instance. 066 private static final PBKDF2PasswordStorageSchemeCfgDefn INSTANCE = new PBKDF2PasswordStorageSchemeCfgDefn(); 067 068 069 070 // The "java-class" property definition. 071 private static final ClassPropertyDefinition PD_JAVA_CLASS; 072 073 074 075 // The "pbkdf2-iterations" property definition. 076 private static final IntegerPropertyDefinition PD_PBKDF2_ITERATIONS; 077 078 079 080 // Build the "java-class" property definition. 081 static { 082 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 083 builder.setOption(PropertyOption.MANDATORY); 084 builder.setOption(PropertyOption.ADVANCED); 085 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class")); 086 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.PBKDF2PasswordStorageScheme"); 087 builder.setDefaultBehaviorProvider(provider); 088 builder.addInstanceOf("org.opends.server.api.PasswordStorageScheme"); 089 PD_JAVA_CLASS = builder.getInstance(); 090 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 091 } 092 093 094 095 // Build the "pbkdf2-iterations" property definition. 096 static { 097 IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "pbkdf2-iterations"); 098 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "pbkdf2-iterations")); 099 DefaultBehaviorProvider<Integer> provider = new DefinedDefaultBehaviorProvider<Integer>("10000"); 100 builder.setDefaultBehaviorProvider(provider); 101 builder.setLowerLimit(1); 102 PD_PBKDF2_ITERATIONS = builder.getInstance(); 103 INSTANCE.registerPropertyDefinition(PD_PBKDF2_ITERATIONS); 104 } 105 106 107 108 // Register the tags associated with this managed object definition. 109 static { 110 INSTANCE.registerTag(Tag.valueOf("user-management")); 111 } 112 113 114 115 /** 116 * Get the PBKDF2 Password Storage Scheme configuration definition 117 * singleton. 118 * 119 * @return Returns the PBKDF2 Password Storage Scheme configuration 120 * definition singleton. 121 */ 122 public static PBKDF2PasswordStorageSchemeCfgDefn getInstance() { 123 return INSTANCE; 124 } 125 126 127 128 /** 129 * Private constructor. 130 */ 131 private PBKDF2PasswordStorageSchemeCfgDefn() { 132 super("pbkdf2-password-storage-scheme", PasswordStorageSchemeCfgDefn.getInstance()); 133 } 134 135 136 137 /** 138 * {@inheritDoc} 139 */ 140 public PBKDF2PasswordStorageSchemeCfgClient createClientConfiguration( 141 ManagedObject<? extends PBKDF2PasswordStorageSchemeCfgClient> impl) { 142 return new PBKDF2PasswordStorageSchemeCfgClientImpl(impl); 143 } 144 145 146 147 /** 148 * {@inheritDoc} 149 */ 150 public PBKDF2PasswordStorageSchemeCfg createServerConfiguration( 151 ServerManagedObject<? extends PBKDF2PasswordStorageSchemeCfg> impl) { 152 return new PBKDF2PasswordStorageSchemeCfgServerImpl(impl); 153 } 154 155 156 157 /** 158 * {@inheritDoc} 159 */ 160 public Class<PBKDF2PasswordStorageSchemeCfg> getServerConfigurationClass() { 161 return PBKDF2PasswordStorageSchemeCfg.class; 162 } 163 164 165 166 /** 167 * Get the "enabled" property definition. 168 * <p> 169 * Indicates whether the PBKDF2 Password Storage Scheme is enabled 170 * for use. 171 * 172 * @return Returns the "enabled" property definition. 173 */ 174 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 175 return PasswordStorageSchemeCfgDefn.getInstance().getEnabledPropertyDefinition(); 176 } 177 178 179 180 /** 181 * Get the "java-class" property definition. 182 * <p> 183 * Specifies the fully-qualified name of the Java class that 184 * provides the PBKDF2 Password Storage Scheme implementation. 185 * 186 * @return Returns the "java-class" property definition. 187 */ 188 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 189 return PD_JAVA_CLASS; 190 } 191 192 193 194 /** 195 * Get the "pbkdf2-iterations" property definition. 196 * <p> 197 * The number of algorithm iterations to make. NIST recommends at 198 * least 1000. 199 * 200 * @return Returns the "pbkdf2-iterations" property definition. 201 */ 202 public IntegerPropertyDefinition getPBKDF2IterationsPropertyDefinition() { 203 return PD_PBKDF2_ITERATIONS; 204 } 205 206 207 208 /** 209 * Managed object client implementation. 210 */ 211 private static class PBKDF2PasswordStorageSchemeCfgClientImpl implements 212 PBKDF2PasswordStorageSchemeCfgClient { 213 214 // Private implementation. 215 private ManagedObject<? extends PBKDF2PasswordStorageSchemeCfgClient> impl; 216 217 218 219 // Private constructor. 220 private PBKDF2PasswordStorageSchemeCfgClientImpl( 221 ManagedObject<? extends PBKDF2PasswordStorageSchemeCfgClient> impl) { 222 this.impl = impl; 223 } 224 225 226 227 /** 228 * {@inheritDoc} 229 */ 230 public Boolean isEnabled() { 231 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 232 } 233 234 235 236 /** 237 * {@inheritDoc} 238 */ 239 public void setEnabled(boolean value) { 240 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 241 } 242 243 244 245 /** 246 * {@inheritDoc} 247 */ 248 public String getJavaClass() { 249 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 250 } 251 252 253 254 /** 255 * {@inheritDoc} 256 */ 257 public void setJavaClass(String value) { 258 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 259 } 260 261 262 263 /** 264 * {@inheritDoc} 265 */ 266 public int getPBKDF2Iterations() { 267 return impl.getPropertyValue(INSTANCE.getPBKDF2IterationsPropertyDefinition()); 268 } 269 270 271 272 /** 273 * {@inheritDoc} 274 */ 275 public void setPBKDF2Iterations(Integer value) { 276 impl.setPropertyValue(INSTANCE.getPBKDF2IterationsPropertyDefinition(), value); 277 } 278 279 280 281 /** 282 * {@inheritDoc} 283 */ 284 public ManagedObjectDefinition<? extends PBKDF2PasswordStorageSchemeCfgClient, ? extends PBKDF2PasswordStorageSchemeCfg> definition() { 285 return INSTANCE; 286 } 287 288 289 290 /** 291 * {@inheritDoc} 292 */ 293 public PropertyProvider properties() { 294 return impl; 295 } 296 297 298 299 /** 300 * {@inheritDoc} 301 */ 302 public void commit() throws ManagedObjectAlreadyExistsException, 303 MissingMandatoryPropertiesException, ConcurrentModificationException, 304 OperationRejectedException, AuthorizationException, 305 CommunicationException { 306 impl.commit(); 307 } 308 309 310 311 /** {@inheritDoc} */ 312 public String toString() { 313 return impl.toString(); 314 } 315 } 316 317 318 319 /** 320 * Managed object server implementation. 321 */ 322 private static class PBKDF2PasswordStorageSchemeCfgServerImpl implements 323 PBKDF2PasswordStorageSchemeCfg { 324 325 // Private implementation. 326 private ServerManagedObject<? extends PBKDF2PasswordStorageSchemeCfg> impl; 327 328 // The value of the "enabled" property. 329 private final boolean pEnabled; 330 331 // The value of the "java-class" property. 332 private final String pJavaClass; 333 334 // The value of the "pbkdf2-iterations" property. 335 private final int pPBKDF2Iterations; 336 337 338 339 // Private constructor. 340 private PBKDF2PasswordStorageSchemeCfgServerImpl(ServerManagedObject<? extends PBKDF2PasswordStorageSchemeCfg> impl) { 341 this.impl = impl; 342 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 343 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 344 this.pPBKDF2Iterations = impl.getPropertyValue(INSTANCE.getPBKDF2IterationsPropertyDefinition()); 345 } 346 347 348 349 /** 350 * {@inheritDoc} 351 */ 352 public void addPBKDF2ChangeListener( 353 ConfigurationChangeListener<PBKDF2PasswordStorageSchemeCfg> listener) { 354 impl.registerChangeListener(listener); 355 } 356 357 358 359 /** 360 * {@inheritDoc} 361 */ 362 public void removePBKDF2ChangeListener( 363 ConfigurationChangeListener<PBKDF2PasswordStorageSchemeCfg> listener) { 364 impl.deregisterChangeListener(listener); 365 } 366 /** 367 * {@inheritDoc} 368 */ 369 public void addChangeListener( 370 ConfigurationChangeListener<PasswordStorageSchemeCfg> listener) { 371 impl.registerChangeListener(listener); 372 } 373 374 375 376 /** 377 * {@inheritDoc} 378 */ 379 public void removeChangeListener( 380 ConfigurationChangeListener<PasswordStorageSchemeCfg> listener) { 381 impl.deregisterChangeListener(listener); 382 } 383 384 385 386 /** 387 * {@inheritDoc} 388 */ 389 public boolean isEnabled() { 390 return pEnabled; 391 } 392 393 394 395 /** 396 * {@inheritDoc} 397 */ 398 public String getJavaClass() { 399 return pJavaClass; 400 } 401 402 403 404 /** 405 * {@inheritDoc} 406 */ 407 public int getPBKDF2Iterations() { 408 return pPBKDF2Iterations; 409 } 410 411 412 413 /** 414 * {@inheritDoc} 415 */ 416 public Class<? extends PBKDF2PasswordStorageSchemeCfg> configurationClass() { 417 return PBKDF2PasswordStorageSchemeCfg.class; 418 } 419 420 421 422 /** 423 * {@inheritDoc} 424 */ 425 public DN dn() { 426 return impl.getDN(); 427 } 428 429 430 431 /** {@inheritDoc} */ 432 public String toString() { 433 return impl.toString(); 434 } 435 } 436}