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