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 java.util.Collection;
032 import java.util.SortedSet;
033 import org.opends.server.admin.AdministratorAction;
034 import org.opends.server.admin.AliasDefaultBehaviorProvider;
035 import org.opends.server.admin.AttributeTypePropertyDefinition;
036 import org.opends.server.admin.BooleanPropertyDefinition;
037 import org.opends.server.admin.ClassPropertyDefinition;
038 import org.opends.server.admin.client.AuthorizationException;
039 import org.opends.server.admin.client.CommunicationException;
040 import org.opends.server.admin.client.ConcurrentModificationException;
041 import org.opends.server.admin.client.ManagedObject;
042 import org.opends.server.admin.client.MissingMandatoryPropertiesException;
043 import org.opends.server.admin.client.OperationRejectedException;
044 import org.opends.server.admin.DefaultBehaviorProvider;
045 import org.opends.server.admin.DefinedDefaultBehaviorProvider;
046 import org.opends.server.admin.ManagedObjectAlreadyExistsException;
047 import org.opends.server.admin.ManagedObjectDefinition;
048 import org.opends.server.admin.PropertyOption;
049 import org.opends.server.admin.PropertyProvider;
050 import org.opends.server.admin.server.ConfigurationChangeListener;
051 import org.opends.server.admin.server.ServerManagedObject;
052 import org.opends.server.admin.std.client.AttributeValuePasswordValidatorCfgClient;
053 import org.opends.server.admin.std.server.AttributeValuePasswordValidatorCfg;
054 import org.opends.server.admin.std.server.PasswordValidatorCfg;
055 import org.opends.server.admin.Tag;
056 import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
057 import org.opends.server.types.AttributeType;
058 import org.opends.server.types.DN;
059
060
061
062 /**
063 * An interface for querying the Attribute Value Password Validator
064 * managed object definition meta information.
065 * <p>
066 * The Attribute Value Password Validator attempts to determine
067 * whether a proposed password is acceptable for use by determining
068 * whether that password is contained in any attribute within the
069 * user's entry.
070 */
071 public final class AttributeValuePasswordValidatorCfgDefn extends ManagedObjectDefinition<AttributeValuePasswordValidatorCfgClient, AttributeValuePasswordValidatorCfg> {
072
073 // The singleton configuration definition instance.
074 private static final AttributeValuePasswordValidatorCfgDefn INSTANCE = new AttributeValuePasswordValidatorCfgDefn();
075
076
077
078 // The "java-class" property definition.
079 private static final ClassPropertyDefinition PD_JAVA_CLASS;
080
081
082
083 // The "match-attribute" property definition.
084 private static final AttributeTypePropertyDefinition PD_MATCH_ATTRIBUTE;
085
086
087
088 // The "test-reversed-password" property definition.
089 private static final BooleanPropertyDefinition PD_TEST_REVERSED_PASSWORD;
090
091
092
093 // Build the "java-class" property definition.
094 static {
095 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
096 builder.setOption(PropertyOption.MANDATORY);
097 builder.setOption(PropertyOption.ADVANCED);
098 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
099 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.AttributeValuePasswordValidator");
100 builder.setDefaultBehaviorProvider(provider);
101 builder.addInstanceOf("org.opends.server.api.PasswordValidator");
102 PD_JAVA_CLASS = builder.getInstance();
103 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
104 }
105
106
107
108 // Build the "match-attribute" property definition.
109 static {
110 AttributeTypePropertyDefinition.Builder builder = AttributeTypePropertyDefinition.createBuilder(INSTANCE, "match-attribute");
111 builder.setOption(PropertyOption.MULTI_VALUED);
112 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "match-attribute"));
113 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<AttributeType>(INSTANCE, "match-attribute"));
114 PD_MATCH_ATTRIBUTE = builder.getInstance();
115 INSTANCE.registerPropertyDefinition(PD_MATCH_ATTRIBUTE);
116 }
117
118
119
120 // Build the "test-reversed-password" property definition.
121 static {
122 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "test-reversed-password");
123 builder.setOption(PropertyOption.MANDATORY);
124 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "test-reversed-password"));
125 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>());
126 PD_TEST_REVERSED_PASSWORD = builder.getInstance();
127 INSTANCE.registerPropertyDefinition(PD_TEST_REVERSED_PASSWORD);
128 }
129
130
131
132 // Register the tags associated with this managed object definition.
133 static {
134 INSTANCE.registerTag(Tag.valueOf("user-management"));
135 }
136
137
138
139 /**
140 * Get the Attribute Value Password Validator configuration
141 * definition singleton.
142 *
143 * @return Returns the Attribute Value Password Validator
144 * configuration definition singleton.
145 */
146 public static AttributeValuePasswordValidatorCfgDefn getInstance() {
147 return INSTANCE;
148 }
149
150
151
152 /**
153 * Private constructor.
154 */
155 private AttributeValuePasswordValidatorCfgDefn() {
156 super("attribute-value-password-validator", PasswordValidatorCfgDefn.getInstance());
157 }
158
159
160
161 /**
162 * {@inheritDoc}
163 */
164 public AttributeValuePasswordValidatorCfgClient createClientConfiguration(
165 ManagedObject<? extends AttributeValuePasswordValidatorCfgClient> impl) {
166 return new AttributeValuePasswordValidatorCfgClientImpl(impl);
167 }
168
169
170
171 /**
172 * {@inheritDoc}
173 */
174 public AttributeValuePasswordValidatorCfg createServerConfiguration(
175 ServerManagedObject<? extends AttributeValuePasswordValidatorCfg> impl) {
176 return new AttributeValuePasswordValidatorCfgServerImpl(impl);
177 }
178
179
180
181 /**
182 * {@inheritDoc}
183 */
184 public Class<AttributeValuePasswordValidatorCfg> getServerConfigurationClass() {
185 return AttributeValuePasswordValidatorCfg.class;
186 }
187
188
189
190 /**
191 * Get the "enabled" property definition.
192 * <p>
193 * Indicates whether the password validator is enabled for use.
194 *
195 * @return Returns the "enabled" property definition.
196 */
197 public BooleanPropertyDefinition getEnabledPropertyDefinition() {
198 return PasswordValidatorCfgDefn.getInstance().getEnabledPropertyDefinition();
199 }
200
201
202
203 /**
204 * Get the "java-class" property definition.
205 * <p>
206 * Specifies the fully-qualified name of the Java class that
207 * provides the password validator implementation.
208 *
209 * @return Returns the "java-class" property definition.
210 */
211 public ClassPropertyDefinition getJavaClassPropertyDefinition() {
212 return PD_JAVA_CLASS;
213 }
214
215
216
217 /**
218 * Get the "match-attribute" property definition.
219 * <p>
220 * Specifies the name(s) of the attribute(s) whose values should be
221 * checked to determine whether they match the provided password. If
222 * no values are provided, then the server checks if the proposed
223 * password matches the value of any attribute in the user's entry.
224 *
225 * @return Returns the "match-attribute" property definition.
226 */
227 public AttributeTypePropertyDefinition getMatchAttributePropertyDefinition() {
228 return PD_MATCH_ATTRIBUTE;
229 }
230
231
232
233 /**
234 * Get the "test-reversed-password" property definition.
235 * <p>
236 * Indicates whether this password validator should test the
237 * reversed value of the provided password as well as the order in
238 * which it was given.
239 *
240 * @return Returns the "test-reversed-password" property definition.
241 */
242 public BooleanPropertyDefinition getTestReversedPasswordPropertyDefinition() {
243 return PD_TEST_REVERSED_PASSWORD;
244 }
245
246
247
248 /**
249 * Managed object client implementation.
250 */
251 private static class AttributeValuePasswordValidatorCfgClientImpl implements
252 AttributeValuePasswordValidatorCfgClient {
253
254 // Private implementation.
255 private ManagedObject<? extends AttributeValuePasswordValidatorCfgClient> impl;
256
257
258
259 // Private constructor.
260 private AttributeValuePasswordValidatorCfgClientImpl(
261 ManagedObject<? extends AttributeValuePasswordValidatorCfgClient> impl) {
262 this.impl = impl;
263 }
264
265
266
267 /**
268 * {@inheritDoc}
269 */
270 public Boolean isEnabled() {
271 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
272 }
273
274
275
276 /**
277 * {@inheritDoc}
278 */
279 public void setEnabled(boolean value) {
280 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
281 }
282
283
284
285 /**
286 * {@inheritDoc}
287 */
288 public String getJavaClass() {
289 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
290 }
291
292
293
294 /**
295 * {@inheritDoc}
296 */
297 public void setJavaClass(String value) {
298 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
299 }
300
301
302
303 /**
304 * {@inheritDoc}
305 */
306 public SortedSet<AttributeType> getMatchAttribute() {
307 return impl.getPropertyValues(INSTANCE.getMatchAttributePropertyDefinition());
308 }
309
310
311
312 /**
313 * {@inheritDoc}
314 */
315 public void setMatchAttribute(Collection<AttributeType> values) {
316 impl.setPropertyValues(INSTANCE.getMatchAttributePropertyDefinition(), values);
317 }
318
319
320
321 /**
322 * {@inheritDoc}
323 */
324 public Boolean isTestReversedPassword() {
325 return impl.getPropertyValue(INSTANCE.getTestReversedPasswordPropertyDefinition());
326 }
327
328
329
330 /**
331 * {@inheritDoc}
332 */
333 public void setTestReversedPassword(boolean value) {
334 impl.setPropertyValue(INSTANCE.getTestReversedPasswordPropertyDefinition(), value);
335 }
336
337
338
339 /**
340 * {@inheritDoc}
341 */
342 public ManagedObjectDefinition<? extends AttributeValuePasswordValidatorCfgClient, ? extends AttributeValuePasswordValidatorCfg> definition() {
343 return INSTANCE;
344 }
345
346
347
348 /**
349 * {@inheritDoc}
350 */
351 public PropertyProvider properties() {
352 return impl;
353 }
354
355
356
357 /**
358 * {@inheritDoc}
359 */
360 public void commit() throws ManagedObjectAlreadyExistsException,
361 MissingMandatoryPropertiesException, ConcurrentModificationException,
362 OperationRejectedException, AuthorizationException,
363 CommunicationException {
364 impl.commit();
365 }
366
367 }
368
369
370
371 /**
372 * Managed object server implementation.
373 */
374 private static class AttributeValuePasswordValidatorCfgServerImpl implements
375 AttributeValuePasswordValidatorCfg {
376
377 // Private implementation.
378 private ServerManagedObject<? extends AttributeValuePasswordValidatorCfg> impl;
379
380 // The value of the "enabled" property.
381 private final boolean pEnabled;
382
383 // The value of the "java-class" property.
384 private final String pJavaClass;
385
386 // The value of the "match-attribute" property.
387 private final SortedSet<AttributeType> pMatchAttribute;
388
389 // The value of the "test-reversed-password" property.
390 private final boolean pTestReversedPassword;
391
392
393
394 // Private constructor.
395 private AttributeValuePasswordValidatorCfgServerImpl(ServerManagedObject<? extends AttributeValuePasswordValidatorCfg> impl) {
396 this.impl = impl;
397 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
398 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
399 this.pMatchAttribute = impl.getPropertyValues(INSTANCE.getMatchAttributePropertyDefinition());
400 this.pTestReversedPassword = impl.getPropertyValue(INSTANCE.getTestReversedPasswordPropertyDefinition());
401 }
402
403
404
405 /**
406 * {@inheritDoc}
407 */
408 public void addAttributeValueChangeListener(
409 ConfigurationChangeListener<AttributeValuePasswordValidatorCfg> listener) {
410 impl.registerChangeListener(listener);
411 }
412
413
414
415 /**
416 * {@inheritDoc}
417 */
418 public void removeAttributeValueChangeListener(
419 ConfigurationChangeListener<AttributeValuePasswordValidatorCfg> listener) {
420 impl.deregisterChangeListener(listener);
421 }
422 /**
423 * {@inheritDoc}
424 */
425 public void addChangeListener(
426 ConfigurationChangeListener<PasswordValidatorCfg> listener) {
427 impl.registerChangeListener(listener);
428 }
429
430
431
432 /**
433 * {@inheritDoc}
434 */
435 public void removeChangeListener(
436 ConfigurationChangeListener<PasswordValidatorCfg> listener) {
437 impl.deregisterChangeListener(listener);
438 }
439
440
441
442 /**
443 * {@inheritDoc}
444 */
445 public boolean isEnabled() {
446 return pEnabled;
447 }
448
449
450
451 /**
452 * {@inheritDoc}
453 */
454 public String getJavaClass() {
455 return pJavaClass;
456 }
457
458
459
460 /**
461 * {@inheritDoc}
462 */
463 public SortedSet<AttributeType> getMatchAttribute() {
464 return pMatchAttribute;
465 }
466
467
468
469 /**
470 * {@inheritDoc}
471 */
472 public boolean isTestReversedPassword() {
473 return pTestReversedPassword;
474 }
475
476
477
478 /**
479 * {@inheritDoc}
480 */
481 public Class<? extends AttributeValuePasswordValidatorCfg> configurationClass() {
482 return AttributeValuePasswordValidatorCfg.class;
483 }
484
485
486
487 /**
488 * {@inheritDoc}
489 */
490 public DN dn() {
491 return impl.getDN();
492 }
493
494 }
495 }