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