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.ManagedObjectAlreadyExistsException;
043 import org.opends.server.admin.ManagedObjectDefinition;
044 import org.opends.server.admin.PropertyOption;
045 import org.opends.server.admin.PropertyProvider;
046 import org.opends.server.admin.server.ConfigurationChangeListener;
047 import org.opends.server.admin.server.ServerManagedObject;
048 import org.opends.server.admin.std.client.DictionaryPasswordValidatorCfgClient;
049 import org.opends.server.admin.std.server.DictionaryPasswordValidatorCfg;
050 import org.opends.server.admin.std.server.PasswordValidatorCfg;
051 import org.opends.server.admin.StringPropertyDefinition;
052 import org.opends.server.admin.Tag;
053 import org.opends.server.types.DN;
054
055
056
057 /**
058 * An interface for querying the Dictionary Password Validator managed
059 * object definition meta information.
060 * <p>
061 * The Dictionary Password Validator determines whether a proposed
062 * password is acceptable based on whether the given password value
063 * appears in a provided dictionary file.
064 */
065 public final class DictionaryPasswordValidatorCfgDefn extends ManagedObjectDefinition<DictionaryPasswordValidatorCfgClient, DictionaryPasswordValidatorCfg> {
066
067 // The singleton configuration definition instance.
068 private static final DictionaryPasswordValidatorCfgDefn INSTANCE = new DictionaryPasswordValidatorCfgDefn();
069
070
071
072 // The "case-sensitive-validation" property definition.
073 private static final BooleanPropertyDefinition PD_CASE_SENSITIVE_VALIDATION;
074
075
076
077 // The "dictionary-file" property definition.
078 private static final StringPropertyDefinition PD_DICTIONARY_FILE;
079
080
081
082 // The "java-class" property definition.
083 private static final ClassPropertyDefinition PD_JAVA_CLASS;
084
085
086
087 // The "test-reversed-password" property definition.
088 private static final BooleanPropertyDefinition PD_TEST_REVERSED_PASSWORD;
089
090
091
092 // Build the "case-sensitive-validation" property definition.
093 static {
094 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "case-sensitive-validation");
095 builder.setOption(PropertyOption.MANDATORY);
096 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "case-sensitive-validation"));
097 DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("false");
098 builder.setDefaultBehaviorProvider(provider);
099 PD_CASE_SENSITIVE_VALIDATION = builder.getInstance();
100 INSTANCE.registerPropertyDefinition(PD_CASE_SENSITIVE_VALIDATION);
101 }
102
103
104
105 // Build the "dictionary-file" property definition.
106 static {
107 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "dictionary-file");
108 builder.setOption(PropertyOption.MANDATORY);
109 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "dictionary-file"));
110 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("For Unix and Linux systems: config/wordlist.txt. For Windows systems: config\\wordlist.txt");
111 builder.setDefaultBehaviorProvider(provider);
112 builder.setPattern(".*", "FILE");
113 PD_DICTIONARY_FILE = builder.getInstance();
114 INSTANCE.registerPropertyDefinition(PD_DICTIONARY_FILE);
115 }
116
117
118
119 // Build the "java-class" property definition.
120 static {
121 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
122 builder.setOption(PropertyOption.MANDATORY);
123 builder.setOption(PropertyOption.ADVANCED);
124 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
125 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.DictionaryPasswordValidator");
126 builder.setDefaultBehaviorProvider(provider);
127 builder.addInstanceOf("org.opends.server.api.PasswordValidator");
128 PD_JAVA_CLASS = builder.getInstance();
129 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
130 }
131
132
133
134 // Build the "test-reversed-password" property definition.
135 static {
136 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "test-reversed-password");
137 builder.setOption(PropertyOption.MANDATORY);
138 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "test-reversed-password"));
139 DefaultBehaviorProvider<Boolean> provider = new DefinedDefaultBehaviorProvider<Boolean>("true");
140 builder.setDefaultBehaviorProvider(provider);
141 PD_TEST_REVERSED_PASSWORD = builder.getInstance();
142 INSTANCE.registerPropertyDefinition(PD_TEST_REVERSED_PASSWORD);
143 }
144
145
146
147 // Register the tags associated with this managed object definition.
148 static {
149 INSTANCE.registerTag(Tag.valueOf("user-management"));
150 }
151
152
153
154 /**
155 * Get the Dictionary Password Validator configuration definition
156 * singleton.
157 *
158 * @return Returns the Dictionary Password Validator configuration
159 * definition singleton.
160 */
161 public static DictionaryPasswordValidatorCfgDefn getInstance() {
162 return INSTANCE;
163 }
164
165
166
167 /**
168 * Private constructor.
169 */
170 private DictionaryPasswordValidatorCfgDefn() {
171 super("dictionary-password-validator", PasswordValidatorCfgDefn.getInstance());
172 }
173
174
175
176 /**
177 * {@inheritDoc}
178 */
179 public DictionaryPasswordValidatorCfgClient createClientConfiguration(
180 ManagedObject<? extends DictionaryPasswordValidatorCfgClient> impl) {
181 return new DictionaryPasswordValidatorCfgClientImpl(impl);
182 }
183
184
185
186 /**
187 * {@inheritDoc}
188 */
189 public DictionaryPasswordValidatorCfg createServerConfiguration(
190 ServerManagedObject<? extends DictionaryPasswordValidatorCfg> impl) {
191 return new DictionaryPasswordValidatorCfgServerImpl(impl);
192 }
193
194
195
196 /**
197 * {@inheritDoc}
198 */
199 public Class<DictionaryPasswordValidatorCfg> getServerConfigurationClass() {
200 return DictionaryPasswordValidatorCfg.class;
201 }
202
203
204
205 /**
206 * Get the "case-sensitive-validation" property definition.
207 * <p>
208 * Indicates whether this password validator is to treat password
209 * characters in a case-sensitive manner.
210 * <p>
211 * If it is set to true, then the validator rejects a password only
212 * if it appears in the dictionary with exactly the same
213 * capitalization as provided by the user.
214 *
215 * @return Returns the "case-sensitive-validation" property definition.
216 */
217 public BooleanPropertyDefinition getCaseSensitiveValidationPropertyDefinition() {
218 return PD_CASE_SENSITIVE_VALIDATION;
219 }
220
221
222
223 /**
224 * Get the "dictionary-file" property definition.
225 * <p>
226 * Specifies the path to the file containing a list of words that
227 * cannot be used as passwords.
228 * <p>
229 * It should be formatted with one word per line. The value can be
230 * an absolute path or a path that is relative to the OpenDS
231 * Directory Server instance root.
232 *
233 * @return Returns the "dictionary-file" property definition.
234 */
235 public StringPropertyDefinition getDictionaryFilePropertyDefinition() {
236 return PD_DICTIONARY_FILE;
237 }
238
239
240
241 /**
242 * Get the "enabled" property definition.
243 * <p>
244 * Indicates whether the password validator is enabled for use.
245 *
246 * @return Returns the "enabled" property definition.
247 */
248 public BooleanPropertyDefinition getEnabledPropertyDefinition() {
249 return PasswordValidatorCfgDefn.getInstance().getEnabledPropertyDefinition();
250 }
251
252
253
254 /**
255 * Get the "java-class" property definition.
256 * <p>
257 * Specifies the fully-qualified name of the Java class that
258 * provides the password validator implementation.
259 *
260 * @return Returns the "java-class" property definition.
261 */
262 public ClassPropertyDefinition getJavaClassPropertyDefinition() {
263 return PD_JAVA_CLASS;
264 }
265
266
267
268 /**
269 * Get the "test-reversed-password" property definition.
270 * <p>
271 * Indicates whether this password validator is to test the reversed
272 * value of the provided password as well as the order in which it
273 * was given.
274 * <p>
275 * For example, if the user provides a new password of "password"
276 * and this configuration attribute is set to true, then the value
277 * "drowssap" is also tested against attribute values in the user's
278 * entry.
279 *
280 * @return Returns the "test-reversed-password" property definition.
281 */
282 public BooleanPropertyDefinition getTestReversedPasswordPropertyDefinition() {
283 return PD_TEST_REVERSED_PASSWORD;
284 }
285
286
287
288 /**
289 * Managed object client implementation.
290 */
291 private static class DictionaryPasswordValidatorCfgClientImpl implements
292 DictionaryPasswordValidatorCfgClient {
293
294 // Private implementation.
295 private ManagedObject<? extends DictionaryPasswordValidatorCfgClient> impl;
296
297
298
299 // Private constructor.
300 private DictionaryPasswordValidatorCfgClientImpl(
301 ManagedObject<? extends DictionaryPasswordValidatorCfgClient> impl) {
302 this.impl = impl;
303 }
304
305
306
307 /**
308 * {@inheritDoc}
309 */
310 public boolean isCaseSensitiveValidation() {
311 return impl.getPropertyValue(INSTANCE.getCaseSensitiveValidationPropertyDefinition());
312 }
313
314
315
316 /**
317 * {@inheritDoc}
318 */
319 public void setCaseSensitiveValidation(boolean value) {
320 impl.setPropertyValue(INSTANCE.getCaseSensitiveValidationPropertyDefinition(), value);
321 }
322
323
324
325 /**
326 * {@inheritDoc}
327 */
328 public String getDictionaryFile() {
329 return impl.getPropertyValue(INSTANCE.getDictionaryFilePropertyDefinition());
330 }
331
332
333
334 /**
335 * {@inheritDoc}
336 */
337 public void setDictionaryFile(String value) {
338 impl.setPropertyValue(INSTANCE.getDictionaryFilePropertyDefinition(), value);
339 }
340
341
342
343 /**
344 * {@inheritDoc}
345 */
346 public Boolean isEnabled() {
347 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
348 }
349
350
351
352 /**
353 * {@inheritDoc}
354 */
355 public void setEnabled(boolean value) {
356 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
357 }
358
359
360
361 /**
362 * {@inheritDoc}
363 */
364 public String getJavaClass() {
365 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
366 }
367
368
369
370 /**
371 * {@inheritDoc}
372 */
373 public void setJavaClass(String value) {
374 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
375 }
376
377
378
379 /**
380 * {@inheritDoc}
381 */
382 public boolean isTestReversedPassword() {
383 return impl.getPropertyValue(INSTANCE.getTestReversedPasswordPropertyDefinition());
384 }
385
386
387
388 /**
389 * {@inheritDoc}
390 */
391 public void setTestReversedPassword(boolean value) {
392 impl.setPropertyValue(INSTANCE.getTestReversedPasswordPropertyDefinition(), value);
393 }
394
395
396
397 /**
398 * {@inheritDoc}
399 */
400 public ManagedObjectDefinition<? extends DictionaryPasswordValidatorCfgClient, ? extends DictionaryPasswordValidatorCfg> definition() {
401 return INSTANCE;
402 }
403
404
405
406 /**
407 * {@inheritDoc}
408 */
409 public PropertyProvider properties() {
410 return impl;
411 }
412
413
414
415 /**
416 * {@inheritDoc}
417 */
418 public void commit() throws ManagedObjectAlreadyExistsException,
419 MissingMandatoryPropertiesException, ConcurrentModificationException,
420 OperationRejectedException, AuthorizationException,
421 CommunicationException {
422 impl.commit();
423 }
424
425 }
426
427
428
429 /**
430 * Managed object server implementation.
431 */
432 private static class DictionaryPasswordValidatorCfgServerImpl implements
433 DictionaryPasswordValidatorCfg {
434
435 // Private implementation.
436 private ServerManagedObject<? extends DictionaryPasswordValidatorCfg> impl;
437
438 // The value of the "case-sensitive-validation" property.
439 private final boolean pCaseSensitiveValidation;
440
441 // The value of the "dictionary-file" property.
442 private final String pDictionaryFile;
443
444 // The value of the "enabled" property.
445 private final boolean pEnabled;
446
447 // The value of the "java-class" property.
448 private final String pJavaClass;
449
450 // The value of the "test-reversed-password" property.
451 private final boolean pTestReversedPassword;
452
453
454
455 // Private constructor.
456 private DictionaryPasswordValidatorCfgServerImpl(ServerManagedObject<? extends DictionaryPasswordValidatorCfg> impl) {
457 this.impl = impl;
458 this.pCaseSensitiveValidation = impl.getPropertyValue(INSTANCE.getCaseSensitiveValidationPropertyDefinition());
459 this.pDictionaryFile = impl.getPropertyValue(INSTANCE.getDictionaryFilePropertyDefinition());
460 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
461 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
462 this.pTestReversedPassword = impl.getPropertyValue(INSTANCE.getTestReversedPasswordPropertyDefinition());
463 }
464
465
466
467 /**
468 * {@inheritDoc}
469 */
470 public void addDictionaryChangeListener(
471 ConfigurationChangeListener<DictionaryPasswordValidatorCfg> listener) {
472 impl.registerChangeListener(listener);
473 }
474
475
476
477 /**
478 * {@inheritDoc}
479 */
480 public void removeDictionaryChangeListener(
481 ConfigurationChangeListener<DictionaryPasswordValidatorCfg> listener) {
482 impl.deregisterChangeListener(listener);
483 }
484 /**
485 * {@inheritDoc}
486 */
487 public void addChangeListener(
488 ConfigurationChangeListener<PasswordValidatorCfg> listener) {
489 impl.registerChangeListener(listener);
490 }
491
492
493
494 /**
495 * {@inheritDoc}
496 */
497 public void removeChangeListener(
498 ConfigurationChangeListener<PasswordValidatorCfg> listener) {
499 impl.deregisterChangeListener(listener);
500 }
501
502
503
504 /**
505 * {@inheritDoc}
506 */
507 public boolean isCaseSensitiveValidation() {
508 return pCaseSensitiveValidation;
509 }
510
511
512
513 /**
514 * {@inheritDoc}
515 */
516 public String getDictionaryFile() {
517 return pDictionaryFile;
518 }
519
520
521
522 /**
523 * {@inheritDoc}
524 */
525 public boolean isEnabled() {
526 return pEnabled;
527 }
528
529
530
531 /**
532 * {@inheritDoc}
533 */
534 public String getJavaClass() {
535 return pJavaClass;
536 }
537
538
539
540 /**
541 * {@inheritDoc}
542 */
543 public boolean isTestReversedPassword() {
544 return pTestReversedPassword;
545 }
546
547
548
549 /**
550 * {@inheritDoc}
551 */
552 public Class<? extends DictionaryPasswordValidatorCfg> configurationClass() {
553 return DictionaryPasswordValidatorCfg.class;
554 }
555
556
557
558 /**
559 * {@inheritDoc}
560 */
561 public DN dn() {
562 return impl.getDN();
563 }
564
565 }
566 }