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 org.forgerock.opendj.config.AdministratorAction; 031import org.forgerock.opendj.config.BooleanPropertyDefinition; 032import org.forgerock.opendj.config.ClassPropertyDefinition; 033import org.forgerock.opendj.config.client.ConcurrentModificationException; 034import org.forgerock.opendj.config.client.ManagedObject; 035import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 036import org.forgerock.opendj.config.client.OperationRejectedException; 037import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 038import org.forgerock.opendj.config.ManagedObjectDefinition; 039import org.forgerock.opendj.config.PropertyOption; 040import org.forgerock.opendj.config.PropertyProvider; 041import org.forgerock.opendj.config.server.ConfigurationChangeListener; 042import org.forgerock.opendj.config.server.ServerManagedObject; 043import org.forgerock.opendj.config.Tag; 044import org.forgerock.opendj.config.TopCfgDefn; 045import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider; 046import org.forgerock.opendj.ldap.DN; 047import org.forgerock.opendj.ldap.LdapException; 048import org.forgerock.opendj.server.config.client.PasswordStorageSchemeCfgClient; 049import org.forgerock.opendj.server.config.server.PasswordStorageSchemeCfg; 050 051 052 053/** 054 * An interface for querying the Password Storage Scheme managed 055 * object definition meta information. 056 * <p> 057 * Password Storage Schemes encode new passwords provided by users so 058 * that they are stored in an encoded manner. This makes it difficult 059 * or impossible for someone to determine the clear-text passwords from 060 * the encoded values. 061 */ 062public final class PasswordStorageSchemeCfgDefn extends ManagedObjectDefinition<PasswordStorageSchemeCfgClient, PasswordStorageSchemeCfg> { 063 064 /** The singleton configuration definition instance. */ 065 private static final PasswordStorageSchemeCfgDefn INSTANCE = new PasswordStorageSchemeCfgDefn(); 066 067 068 069 /** The "enabled" property definition. */ 070 private static final BooleanPropertyDefinition PD_ENABLED; 071 072 073 074 /** The "java-class" property definition. */ 075 private static final ClassPropertyDefinition PD_JAVA_CLASS; 076 077 078 079 /** Build the "enabled" property definition. */ 080 static { 081 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled"); 082 builder.setOption(PropertyOption.MANDATORY); 083 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled")); 084 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>()); 085 PD_ENABLED = builder.getInstance(); 086 INSTANCE.registerPropertyDefinition(PD_ENABLED); 087 } 088 089 090 091 /** Build the "java-class" property definition. */ 092 static { 093 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 094 builder.setOption(PropertyOption.MANDATORY); 095 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class")); 096 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 097 builder.addInstanceOf("org.opends.server.api.PasswordStorageScheme"); 098 PD_JAVA_CLASS = builder.getInstance(); 099 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 100 } 101 102 103 104 // Register the tags associated with this managed object definition. 105 static { 106 INSTANCE.registerTag(Tag.valueOf("user-management")); 107 } 108 109 110 111 /** 112 * Get the Password Storage Scheme configuration definition 113 * singleton. 114 * 115 * @return Returns the Password Storage Scheme configuration 116 * definition singleton. 117 */ 118 public static PasswordStorageSchemeCfgDefn getInstance() { 119 return INSTANCE; 120 } 121 122 123 124 /** 125 * Private constructor. 126 */ 127 private PasswordStorageSchemeCfgDefn() { 128 super("password-storage-scheme", TopCfgDefn.getInstance()); 129 } 130 131 132 133 /** {@inheritDoc} */ 134 public PasswordStorageSchemeCfgClient createClientConfiguration( 135 ManagedObject<? extends PasswordStorageSchemeCfgClient> impl) { 136 return new PasswordStorageSchemeCfgClientImpl(impl); 137 } 138 139 140 141 /** {@inheritDoc} */ 142 public PasswordStorageSchemeCfg createServerConfiguration( 143 ServerManagedObject<? extends PasswordStorageSchemeCfg> impl) { 144 return new PasswordStorageSchemeCfgServerImpl(impl); 145 } 146 147 148 149 /** {@inheritDoc} */ 150 public Class<PasswordStorageSchemeCfg> getServerConfigurationClass() { 151 return PasswordStorageSchemeCfg.class; 152 } 153 154 155 156 /** 157 * Get the "enabled" property definition. 158 * <p> 159 * Indicates whether the Password Storage Scheme is enabled for use. 160 * 161 * @return Returns the "enabled" property definition. 162 */ 163 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 164 return PD_ENABLED; 165 } 166 167 168 169 /** 170 * Get the "java-class" property definition. 171 * <p> 172 * Specifies the fully-qualified name of the Java class that 173 * provides the Password Storage Scheme implementation. 174 * 175 * @return Returns the "java-class" property definition. 176 */ 177 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 178 return PD_JAVA_CLASS; 179 } 180 181 182 183 /** 184 * Managed object client implementation. 185 */ 186 private static class PasswordStorageSchemeCfgClientImpl implements 187 PasswordStorageSchemeCfgClient { 188 189 /** Private implementation. */ 190 private ManagedObject<? extends PasswordStorageSchemeCfgClient> impl; 191 192 193 194 /** Private constructor. */ 195 private PasswordStorageSchemeCfgClientImpl( 196 ManagedObject<? extends PasswordStorageSchemeCfgClient> impl) { 197 this.impl = impl; 198 } 199 200 201 202 /** {@inheritDoc} */ 203 public Boolean isEnabled() { 204 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 205 } 206 207 208 209 /** {@inheritDoc} */ 210 public void setEnabled(boolean value) { 211 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 212 } 213 214 215 216 /** {@inheritDoc} */ 217 public String getJavaClass() { 218 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 219 } 220 221 222 223 /** {@inheritDoc} */ 224 public void setJavaClass(String value) { 225 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 226 } 227 228 229 230 /** {@inheritDoc} */ 231 public ManagedObjectDefinition<? extends PasswordStorageSchemeCfgClient, ? extends PasswordStorageSchemeCfg> definition() { 232 return INSTANCE; 233 } 234 235 236 237 /** {@inheritDoc} */ 238 public PropertyProvider properties() { 239 return impl; 240 } 241 242 243 244 /** {@inheritDoc} */ 245 public void commit() throws ManagedObjectAlreadyExistsException, 246 MissingMandatoryPropertiesException, ConcurrentModificationException, 247 OperationRejectedException, LdapException { 248 impl.commit(); 249 } 250 251 252 253 /** {@inheritDoc} */ 254 public String toString() { 255 return impl.toString(); 256 } 257 } 258 259 260 261 /** 262 * Managed object server implementation. 263 */ 264 private static class PasswordStorageSchemeCfgServerImpl implements 265 PasswordStorageSchemeCfg { 266 267 /** Private implementation. */ 268 private ServerManagedObject<? extends PasswordStorageSchemeCfg> impl; 269 270 /** The value of the "enabled" property. */ 271 private final boolean pEnabled; 272 273 /** The value of the "java-class" property. */ 274 private final String pJavaClass; 275 276 277 278 /** Private constructor. */ 279 private PasswordStorageSchemeCfgServerImpl(ServerManagedObject<? extends PasswordStorageSchemeCfg> impl) { 280 this.impl = impl; 281 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 282 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 283 } 284 285 286 287 /** {@inheritDoc} */ 288 public void addChangeListener( 289 ConfigurationChangeListener<PasswordStorageSchemeCfg> listener) { 290 impl.registerChangeListener(listener); 291 } 292 293 294 295 /** {@inheritDoc} */ 296 public void removeChangeListener( 297 ConfigurationChangeListener<PasswordStorageSchemeCfg> listener) { 298 impl.deregisterChangeListener(listener); 299 } 300 301 302 303 /** {@inheritDoc} */ 304 public boolean isEnabled() { 305 return pEnabled; 306 } 307 308 309 310 /** {@inheritDoc} */ 311 public String getJavaClass() { 312 return pJavaClass; 313 } 314 315 316 317 /** {@inheritDoc} */ 318 public Class<? extends PasswordStorageSchemeCfg> configurationClass() { 319 return PasswordStorageSchemeCfg.class; 320 } 321 322 323 324 /** {@inheritDoc} */ 325 public DN dn() { 326 return impl.getDN(); 327 } 328 329 330 331 /** {@inheritDoc} */ 332 public String toString() { 333 return impl.toString(); 334 } 335 } 336}