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