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