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