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.opends.server.admin.std.meta;
027
028
029
030import java.util.Collection;
031import java.util.SortedSet;
032import org.opends.server.admin.AdministratorAction;
033import org.opends.server.admin.AliasDefaultBehaviorProvider;
034import org.opends.server.admin.AttributeTypePropertyDefinition;
035import org.opends.server.admin.BooleanPropertyDefinition;
036import org.opends.server.admin.ClassPropertyDefinition;
037import org.opends.server.admin.client.AuthorizationException;
038import org.opends.server.admin.client.CommunicationException;
039import org.opends.server.admin.client.ConcurrentModificationException;
040import org.opends.server.admin.client.ManagedObject;
041import org.opends.server.admin.client.MissingMandatoryPropertiesException;
042import org.opends.server.admin.client.OperationRejectedException;
043import org.opends.server.admin.DefaultBehaviorProvider;
044import org.opends.server.admin.DefinedDefaultBehaviorProvider;
045import org.opends.server.admin.DNPropertyDefinition;
046import org.opends.server.admin.ManagedObjectAlreadyExistsException;
047import org.opends.server.admin.ManagedObjectDefinition;
048import org.opends.server.admin.PropertyOption;
049import org.opends.server.admin.PropertyProvider;
050import org.opends.server.admin.server.ConfigurationChangeListener;
051import org.opends.server.admin.server.ServerManagedObject;
052import org.opends.server.admin.std.client.ExactMatchIdentityMapperCfgClient;
053import org.opends.server.admin.std.server.ExactMatchIdentityMapperCfg;
054import org.opends.server.admin.std.server.IdentityMapperCfg;
055import org.opends.server.admin.Tag;
056import org.opends.server.types.AttributeType;
057import org.opends.server.types.DN;
058
059
060
061/**
062 * An interface for querying the Exact Match Identity Mapper managed
063 * object definition meta information.
064 * <p>
065 * The Exact Match Identity Mapper maps an identifier string to user
066 * entries by searching for the entry containing a specified attribute
067 * whose value is the provided identifier. For example, the username
068 * provided by the client for DIGEST-MD5 authentication must match the
069 * value of the uid attribute
070 */
071public final class ExactMatchIdentityMapperCfgDefn extends ManagedObjectDefinition<ExactMatchIdentityMapperCfgClient, ExactMatchIdentityMapperCfg> {
072
073  // The singleton configuration definition instance.
074  private static final ExactMatchIdentityMapperCfgDefn INSTANCE = new ExactMatchIdentityMapperCfgDefn();
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 "match-base-dn" property definition.
089  private static final DNPropertyDefinition PD_MATCH_BASE_DN;
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.ExactMatchIdentityMapper");
100      builder.setDefaultBehaviorProvider(provider);
101      builder.addInstanceOf("org.opends.server.api.IdentityMapper");
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.setOption(PropertyOption.MANDATORY);
113      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "match-attribute"));
114      DefaultBehaviorProvider<AttributeType> provider = new DefinedDefaultBehaviorProvider<AttributeType>("uid");
115      builder.setDefaultBehaviorProvider(provider);
116      PD_MATCH_ATTRIBUTE = builder.getInstance();
117      INSTANCE.registerPropertyDefinition(PD_MATCH_ATTRIBUTE);
118  }
119
120
121
122  // Build the "match-base-dn" property definition.
123  static {
124      DNPropertyDefinition.Builder builder = DNPropertyDefinition.createBuilder(INSTANCE, "match-base-dn");
125      builder.setOption(PropertyOption.MULTI_VALUED);
126      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "match-base-dn"));
127      builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<DN>(INSTANCE, "match-base-dn"));
128      PD_MATCH_BASE_DN = builder.getInstance();
129      INSTANCE.registerPropertyDefinition(PD_MATCH_BASE_DN);
130  }
131
132
133
134  // Register the tags associated with this managed object definition.
135  static {
136    INSTANCE.registerTag(Tag.valueOf("security"));
137    INSTANCE.registerTag(Tag.valueOf("user-management"));
138  }
139
140
141
142  /**
143   * Get the Exact Match Identity Mapper configuration definition
144   * singleton.
145   *
146   * @return Returns the Exact Match Identity Mapper configuration
147   *         definition singleton.
148   */
149  public static ExactMatchIdentityMapperCfgDefn getInstance() {
150    return INSTANCE;
151  }
152
153
154
155  /**
156   * Private constructor.
157   */
158  private ExactMatchIdentityMapperCfgDefn() {
159    super("exact-match-identity-mapper", IdentityMapperCfgDefn.getInstance());
160  }
161
162
163
164  /**
165   * {@inheritDoc}
166   */
167  public ExactMatchIdentityMapperCfgClient createClientConfiguration(
168      ManagedObject<? extends ExactMatchIdentityMapperCfgClient> impl) {
169    return new ExactMatchIdentityMapperCfgClientImpl(impl);
170  }
171
172
173
174  /**
175   * {@inheritDoc}
176   */
177  public ExactMatchIdentityMapperCfg createServerConfiguration(
178      ServerManagedObject<? extends ExactMatchIdentityMapperCfg> impl) {
179    return new ExactMatchIdentityMapperCfgServerImpl(impl);
180  }
181
182
183
184  /**
185   * {@inheritDoc}
186   */
187  public Class<ExactMatchIdentityMapperCfg> getServerConfigurationClass() {
188    return ExactMatchIdentityMapperCfg.class;
189  }
190
191
192
193  /**
194   * Get the "enabled" property definition.
195   * <p>
196   * Indicates whether the Exact Match Identity Mapper is enabled for
197   * use.
198   *
199   * @return Returns the "enabled" property definition.
200   */
201  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
202    return IdentityMapperCfgDefn.getInstance().getEnabledPropertyDefinition();
203  }
204
205
206
207  /**
208   * Get the "java-class" property definition.
209   * <p>
210   * Specifies the fully-qualified name of the Java class that
211   * provides the Exact Match Identity Mapper implementation.
212   *
213   * @return Returns the "java-class" property definition.
214   */
215  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
216    return PD_JAVA_CLASS;
217  }
218
219
220
221  /**
222   * Get the "match-attribute" property definition.
223   * <p>
224   * Specifies the attribute whose value should exactly match the ID
225   * string provided to this identity mapper.
226   * <p>
227   * At least one value must be provided. All values must refer to the
228   * name or OID of an attribute type defined in the directory server
229   * schema. If multiple attributes or OIDs are provided, at least one
230   * of those attributes must contain the provided ID string value in
231   * exactly one entry. The internal search performed includes a
232   * logical OR across all of these values.
233   *
234   * @return Returns the "match-attribute" property definition.
235   */
236  public AttributeTypePropertyDefinition getMatchAttributePropertyDefinition() {
237    return PD_MATCH_ATTRIBUTE;
238  }
239
240
241
242  /**
243   * Get the "match-base-dn" property definition.
244   * <p>
245   * Specifies the set of base DNs below which to search for users.
246   * <p>
247   * The base DNs will be used when performing searches to map the
248   * provided ID string to a user entry. If multiple values are given,
249   * searches are performed below all specified base DNs.
250   *
251   * @return Returns the "match-base-dn" property definition.
252   */
253  public DNPropertyDefinition getMatchBaseDNPropertyDefinition() {
254    return PD_MATCH_BASE_DN;
255  }
256
257
258
259  /**
260   * Managed object client implementation.
261   */
262  private static class ExactMatchIdentityMapperCfgClientImpl implements
263    ExactMatchIdentityMapperCfgClient {
264
265    // Private implementation.
266    private ManagedObject<? extends ExactMatchIdentityMapperCfgClient> impl;
267
268
269
270    // Private constructor.
271    private ExactMatchIdentityMapperCfgClientImpl(
272        ManagedObject<? extends ExactMatchIdentityMapperCfgClient> impl) {
273      this.impl = impl;
274    }
275
276
277
278    /**
279     * {@inheritDoc}
280     */
281    public Boolean isEnabled() {
282      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
283    }
284
285
286
287    /**
288     * {@inheritDoc}
289     */
290    public void setEnabled(boolean value) {
291      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
292    }
293
294
295
296    /**
297     * {@inheritDoc}
298     */
299    public String getJavaClass() {
300      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
301    }
302
303
304
305    /**
306     * {@inheritDoc}
307     */
308    public void setJavaClass(String value) {
309      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
310    }
311
312
313
314    /**
315     * {@inheritDoc}
316     */
317    public SortedSet<AttributeType> getMatchAttribute() {
318      return impl.getPropertyValues(INSTANCE.getMatchAttributePropertyDefinition());
319    }
320
321
322
323    /**
324     * {@inheritDoc}
325     */
326    public void setMatchAttribute(Collection<AttributeType> values) {
327      impl.setPropertyValues(INSTANCE.getMatchAttributePropertyDefinition(), values);
328    }
329
330
331
332    /**
333     * {@inheritDoc}
334     */
335    public SortedSet<DN> getMatchBaseDN() {
336      return impl.getPropertyValues(INSTANCE.getMatchBaseDNPropertyDefinition());
337    }
338
339
340
341    /**
342     * {@inheritDoc}
343     */
344    public void setMatchBaseDN(Collection<DN> values) {
345      impl.setPropertyValues(INSTANCE.getMatchBaseDNPropertyDefinition(), values);
346    }
347
348
349
350    /**
351     * {@inheritDoc}
352     */
353    public ManagedObjectDefinition<? extends ExactMatchIdentityMapperCfgClient, ? extends ExactMatchIdentityMapperCfg> definition() {
354      return INSTANCE;
355    }
356
357
358
359    /**
360     * {@inheritDoc}
361     */
362    public PropertyProvider properties() {
363      return impl;
364    }
365
366
367
368    /**
369     * {@inheritDoc}
370     */
371    public void commit() throws ManagedObjectAlreadyExistsException,
372        MissingMandatoryPropertiesException, ConcurrentModificationException,
373        OperationRejectedException, AuthorizationException,
374        CommunicationException {
375      impl.commit();
376    }
377
378
379
380    /** {@inheritDoc} */
381    public String toString() {
382      return impl.toString();
383    }
384  }
385
386
387
388  /**
389   * Managed object server implementation.
390   */
391  private static class ExactMatchIdentityMapperCfgServerImpl implements
392    ExactMatchIdentityMapperCfg {
393
394    // Private implementation.
395    private ServerManagedObject<? extends ExactMatchIdentityMapperCfg> impl;
396
397    // The value of the "enabled" property.
398    private final boolean pEnabled;
399
400    // The value of the "java-class" property.
401    private final String pJavaClass;
402
403    // The value of the "match-attribute" property.
404    private final SortedSet<AttributeType> pMatchAttribute;
405
406    // The value of the "match-base-dn" property.
407    private final SortedSet<DN> pMatchBaseDN;
408
409
410
411    // Private constructor.
412    private ExactMatchIdentityMapperCfgServerImpl(ServerManagedObject<? extends ExactMatchIdentityMapperCfg> impl) {
413      this.impl = impl;
414      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
415      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
416      this.pMatchAttribute = impl.getPropertyValues(INSTANCE.getMatchAttributePropertyDefinition());
417      this.pMatchBaseDN = impl.getPropertyValues(INSTANCE.getMatchBaseDNPropertyDefinition());
418    }
419
420
421
422    /**
423     * {@inheritDoc}
424     */
425    public void addExactMatchChangeListener(
426        ConfigurationChangeListener<ExactMatchIdentityMapperCfg> listener) {
427      impl.registerChangeListener(listener);
428    }
429
430
431
432    /**
433     * {@inheritDoc}
434     */
435    public void removeExactMatchChangeListener(
436        ConfigurationChangeListener<ExactMatchIdentityMapperCfg> listener) {
437      impl.deregisterChangeListener(listener);
438    }
439    /**
440     * {@inheritDoc}
441     */
442    public void addChangeListener(
443        ConfigurationChangeListener<IdentityMapperCfg> listener) {
444      impl.registerChangeListener(listener);
445    }
446
447
448
449    /**
450     * {@inheritDoc}
451     */
452    public void removeChangeListener(
453        ConfigurationChangeListener<IdentityMapperCfg> listener) {
454      impl.deregisterChangeListener(listener);
455    }
456
457
458
459    /**
460     * {@inheritDoc}
461     */
462    public boolean isEnabled() {
463      return pEnabled;
464    }
465
466
467
468    /**
469     * {@inheritDoc}
470     */
471    public String getJavaClass() {
472      return pJavaClass;
473    }
474
475
476
477    /**
478     * {@inheritDoc}
479     */
480    public SortedSet<AttributeType> getMatchAttribute() {
481      return pMatchAttribute;
482    }
483
484
485
486    /**
487     * {@inheritDoc}
488     */
489    public SortedSet<DN> getMatchBaseDN() {
490      return pMatchBaseDN;
491    }
492
493
494
495    /**
496     * {@inheritDoc}
497     */
498    public Class<? extends ExactMatchIdentityMapperCfg> configurationClass() {
499      return ExactMatchIdentityMapperCfg.class;
500    }
501
502
503
504    /**
505     * {@inheritDoc}
506     */
507    public DN dn() {
508      return impl.getDN();
509    }
510
511
512
513    /** {@inheritDoc} */
514    public String toString() {
515      return impl.toString();
516    }
517  }
518}