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
010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012 * See the License for the specific language governing permissions
013 * and limitations under the License.
014 *
015 * When distributing Covered Code, include this CDDL HEADER in each
016 * file and include the License file at
017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
018 * add the following below this CDDL HEADER, with the fields enclosed
019 * by brackets "[]" replaced with your own identifying information:
020 * Portions Copyright [yyyy] [name of copyright owner]
021 *
022 * CDDL HEADER END
023 *
024 *
025 * Copyright 2008 Sun Microsystems, Inc.
026 */
027 package org.opends.server.admin.std.meta;
028
029
030
031 import org.opends.server.admin.AdministratorAction;
032 import org.opends.server.admin.BooleanPropertyDefinition;
033 import org.opends.server.admin.ClassPropertyDefinition;
034 import org.opends.server.admin.client.AuthorizationException;
035 import org.opends.server.admin.client.CommunicationException;
036 import org.opends.server.admin.client.ConcurrentModificationException;
037 import org.opends.server.admin.client.ManagedObject;
038 import org.opends.server.admin.client.MissingMandatoryPropertiesException;
039 import org.opends.server.admin.client.OperationRejectedException;
040 import org.opends.server.admin.DefaultBehaviorProvider;
041 import org.opends.server.admin.DefinedDefaultBehaviorProvider;
042 import org.opends.server.admin.IntegerPropertyDefinition;
043 import org.opends.server.admin.ManagedObjectAlreadyExistsException;
044 import org.opends.server.admin.ManagedObjectDefinition;
045 import org.opends.server.admin.PropertyOption;
046 import org.opends.server.admin.PropertyProvider;
047 import org.opends.server.admin.server.ConfigurationChangeListener;
048 import org.opends.server.admin.server.ServerManagedObject;
049 import org.opends.server.admin.std.client.SimilarityBasedPasswordValidatorCfgClient;
050 import org.opends.server.admin.std.server.PasswordValidatorCfg;
051 import org.opends.server.admin.std.server.SimilarityBasedPasswordValidatorCfg;
052 import org.opends.server.admin.Tag;
053 import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
054 import org.opends.server.types.DN;
055
056
057
058 /**
059 * An interface for querying the Similarity Based Password Validator
060 * managed object definition meta information.
061 * <p>
062 * The Similarity Based Password Validator determines whether a
063 * proposed password is acceptable by measuring how similar it is to
064 * the user's current password.
065 */
066 public final class SimilarityBasedPasswordValidatorCfgDefn extends ManagedObjectDefinition<SimilarityBasedPasswordValidatorCfgClient, SimilarityBasedPasswordValidatorCfg> {
067
068 // The singleton configuration definition instance.
069 private static final SimilarityBasedPasswordValidatorCfgDefn INSTANCE = new SimilarityBasedPasswordValidatorCfgDefn();
070
071
072
073 // The "java-class" property definition.
074 private static final ClassPropertyDefinition PD_JAVA_CLASS;
075
076
077
078 // The "min-password-difference" property definition.
079 private static final IntegerPropertyDefinition PD_MIN_PASSWORD_DIFFERENCE;
080
081
082
083 // Build the "java-class" property definition.
084 static {
085 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
086 builder.setOption(PropertyOption.MANDATORY);
087 builder.setOption(PropertyOption.ADVANCED);
088 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
089 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.SimilarityBasedPasswordValidator");
090 builder.setDefaultBehaviorProvider(provider);
091 builder.addInstanceOf("org.opends.server.api.PasswordValidator");
092 PD_JAVA_CLASS = builder.getInstance();
093 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
094 }
095
096
097
098 // Build the "min-password-difference" property definition.
099 static {
100 IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "min-password-difference");
101 builder.setOption(PropertyOption.MANDATORY);
102 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "min-password-difference"));
103 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Integer>());
104 builder.setUpperLimit(2147483647);
105 builder.setLowerLimit(0);
106 PD_MIN_PASSWORD_DIFFERENCE = builder.getInstance();
107 INSTANCE.registerPropertyDefinition(PD_MIN_PASSWORD_DIFFERENCE);
108 }
109
110
111
112 // Register the tags associated with this managed object definition.
113 static {
114 INSTANCE.registerTag(Tag.valueOf("user-management"));
115 }
116
117
118
119 /**
120 * Get the Similarity Based Password Validator configuration
121 * definition singleton.
122 *
123 * @return Returns the Similarity Based Password Validator
124 * configuration definition singleton.
125 */
126 public static SimilarityBasedPasswordValidatorCfgDefn getInstance() {
127 return INSTANCE;
128 }
129
130
131
132 /**
133 * Private constructor.
134 */
135 private SimilarityBasedPasswordValidatorCfgDefn() {
136 super("similarity-based-password-validator", PasswordValidatorCfgDefn.getInstance());
137 }
138
139
140
141 /**
142 * {@inheritDoc}
143 */
144 public SimilarityBasedPasswordValidatorCfgClient createClientConfiguration(
145 ManagedObject<? extends SimilarityBasedPasswordValidatorCfgClient> impl) {
146 return new SimilarityBasedPasswordValidatorCfgClientImpl(impl);
147 }
148
149
150
151 /**
152 * {@inheritDoc}
153 */
154 public SimilarityBasedPasswordValidatorCfg createServerConfiguration(
155 ServerManagedObject<? extends SimilarityBasedPasswordValidatorCfg> impl) {
156 return new SimilarityBasedPasswordValidatorCfgServerImpl(impl);
157 }
158
159
160
161 /**
162 * {@inheritDoc}
163 */
164 public Class<SimilarityBasedPasswordValidatorCfg> getServerConfigurationClass() {
165 return SimilarityBasedPasswordValidatorCfg.class;
166 }
167
168
169
170 /**
171 * Get the "enabled" property definition.
172 * <p>
173 * Indicates whether the password validator is enabled for use.
174 *
175 * @return Returns the "enabled" property definition.
176 */
177 public BooleanPropertyDefinition getEnabledPropertyDefinition() {
178 return PasswordValidatorCfgDefn.getInstance().getEnabledPropertyDefinition();
179 }
180
181
182
183 /**
184 * Get the "java-class" property definition.
185 * <p>
186 * Specifies the fully-qualified name of the Java class that
187 * provides the password validator implementation.
188 *
189 * @return Returns the "java-class" property definition.
190 */
191 public ClassPropertyDefinition getJavaClassPropertyDefinition() {
192 return PD_JAVA_CLASS;
193 }
194
195
196
197 /**
198 * Get the "min-password-difference" property definition.
199 * <p>
200 * Specifies the minimum difference of new and old password.
201 * <p>
202 * A value of zero indicates that no difference between passwords is
203 * acceptable.
204 *
205 * @return Returns the "min-password-difference" property definition.
206 */
207 public IntegerPropertyDefinition getMinPasswordDifferencePropertyDefinition() {
208 return PD_MIN_PASSWORD_DIFFERENCE;
209 }
210
211
212
213 /**
214 * Managed object client implementation.
215 */
216 private static class SimilarityBasedPasswordValidatorCfgClientImpl implements
217 SimilarityBasedPasswordValidatorCfgClient {
218
219 // Private implementation.
220 private ManagedObject<? extends SimilarityBasedPasswordValidatorCfgClient> impl;
221
222
223
224 // Private constructor.
225 private SimilarityBasedPasswordValidatorCfgClientImpl(
226 ManagedObject<? extends SimilarityBasedPasswordValidatorCfgClient> impl) {
227 this.impl = impl;
228 }
229
230
231
232 /**
233 * {@inheritDoc}
234 */
235 public Boolean isEnabled() {
236 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
237 }
238
239
240
241 /**
242 * {@inheritDoc}
243 */
244 public void setEnabled(boolean value) {
245 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
246 }
247
248
249
250 /**
251 * {@inheritDoc}
252 */
253 public String getJavaClass() {
254 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
255 }
256
257
258
259 /**
260 * {@inheritDoc}
261 */
262 public void setJavaClass(String value) {
263 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
264 }
265
266
267
268 /**
269 * {@inheritDoc}
270 */
271 public Integer getMinPasswordDifference() {
272 return impl.getPropertyValue(INSTANCE.getMinPasswordDifferencePropertyDefinition());
273 }
274
275
276
277 /**
278 * {@inheritDoc}
279 */
280 public void setMinPasswordDifference(int value) {
281 impl.setPropertyValue(INSTANCE.getMinPasswordDifferencePropertyDefinition(), value);
282 }
283
284
285
286 /**
287 * {@inheritDoc}
288 */
289 public ManagedObjectDefinition<? extends SimilarityBasedPasswordValidatorCfgClient, ? extends SimilarityBasedPasswordValidatorCfg> definition() {
290 return INSTANCE;
291 }
292
293
294
295 /**
296 * {@inheritDoc}
297 */
298 public PropertyProvider properties() {
299 return impl;
300 }
301
302
303
304 /**
305 * {@inheritDoc}
306 */
307 public void commit() throws ManagedObjectAlreadyExistsException,
308 MissingMandatoryPropertiesException, ConcurrentModificationException,
309 OperationRejectedException, AuthorizationException,
310 CommunicationException {
311 impl.commit();
312 }
313
314 }
315
316
317
318 /**
319 * Managed object server implementation.
320 */
321 private static class SimilarityBasedPasswordValidatorCfgServerImpl implements
322 SimilarityBasedPasswordValidatorCfg {
323
324 // Private implementation.
325 private ServerManagedObject<? extends SimilarityBasedPasswordValidatorCfg> impl;
326
327 // The value of the "enabled" property.
328 private final boolean pEnabled;
329
330 // The value of the "java-class" property.
331 private final String pJavaClass;
332
333 // The value of the "min-password-difference" property.
334 private final int pMinPasswordDifference;
335
336
337
338 // Private constructor.
339 private SimilarityBasedPasswordValidatorCfgServerImpl(ServerManagedObject<? extends SimilarityBasedPasswordValidatorCfg> impl) {
340 this.impl = impl;
341 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
342 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
343 this.pMinPasswordDifference = impl.getPropertyValue(INSTANCE.getMinPasswordDifferencePropertyDefinition());
344 }
345
346
347
348 /**
349 * {@inheritDoc}
350 */
351 public void addSimilarityBasedChangeListener(
352 ConfigurationChangeListener<SimilarityBasedPasswordValidatorCfg> listener) {
353 impl.registerChangeListener(listener);
354 }
355
356
357
358 /**
359 * {@inheritDoc}
360 */
361 public void removeSimilarityBasedChangeListener(
362 ConfigurationChangeListener<SimilarityBasedPasswordValidatorCfg> listener) {
363 impl.deregisterChangeListener(listener);
364 }
365 /**
366 * {@inheritDoc}
367 */
368 public void addChangeListener(
369 ConfigurationChangeListener<PasswordValidatorCfg> listener) {
370 impl.registerChangeListener(listener);
371 }
372
373
374
375 /**
376 * {@inheritDoc}
377 */
378 public void removeChangeListener(
379 ConfigurationChangeListener<PasswordValidatorCfg> listener) {
380 impl.deregisterChangeListener(listener);
381 }
382
383
384
385 /**
386 * {@inheritDoc}
387 */
388 public boolean isEnabled() {
389 return pEnabled;
390 }
391
392
393
394 /**
395 * {@inheritDoc}
396 */
397 public String getJavaClass() {
398 return pJavaClass;
399 }
400
401
402
403 /**
404 * {@inheritDoc}
405 */
406 public int getMinPasswordDifference() {
407 return pMinPasswordDifference;
408 }
409
410
411
412 /**
413 * {@inheritDoc}
414 */
415 public Class<? extends SimilarityBasedPasswordValidatorCfg> configurationClass() {
416 return SimilarityBasedPasswordValidatorCfg.class;
417 }
418
419
420
421 /**
422 * {@inheritDoc}
423 */
424 public DN dn() {
425 return impl.getDN();
426 }
427
428 }
429 }