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 org.forgerock.opendj.config.AdministratorAction;
031import org.forgerock.opendj.config.BooleanPropertyDefinition;
032import org.forgerock.opendj.config.ClassPropertyDefinition;
033import org.forgerock.opendj.config.client.ConcurrentModificationException;
034import org.forgerock.opendj.config.client.ManagedObject;
035import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
036import org.forgerock.opendj.config.client.OperationRejectedException;
037import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
038import org.forgerock.opendj.config.ManagedObjectDefinition;
039import org.forgerock.opendj.config.PropertyOption;
040import org.forgerock.opendj.config.PropertyProvider;
041import org.forgerock.opendj.config.server.ConfigurationChangeListener;
042import org.forgerock.opendj.config.server.ServerManagedObject;
043import org.forgerock.opendj.config.Tag;
044import org.forgerock.opendj.config.TopCfgDefn;
045import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
046import org.forgerock.opendj.ldap.DN;
047import org.forgerock.opendj.ldap.LdapException;
048import org.forgerock.opendj.server.config.client.IdentityMapperCfgClient;
049import org.forgerock.opendj.server.config.server.IdentityMapperCfg;
050
051
052
053/**
054 * An interface for querying the Identity Mapper managed object
055 * definition meta information.
056 * <p>
057 * Identity Mappers are responsible for establishing a mapping between
058 * an identifier string provided by a client, and the entry for the
059 * user that corresponds to that identifier. Identity Mappers are used
060 * to process several SASL mechanisms to map an authorization ID (e.g.,
061 * a Kerberos principal when using GSSAPI) to a directory user. They
062 * are also used when processing requests with the proxied
063 * authorization control.
064 */
065public final class IdentityMapperCfgDefn extends ManagedObjectDefinition<IdentityMapperCfgClient, IdentityMapperCfg> {
066
067  /** The singleton configuration definition instance. */
068  private static final IdentityMapperCfgDefn INSTANCE = new IdentityMapperCfgDefn();
069
070
071
072  /** The "enabled" property definition. */
073  private static final BooleanPropertyDefinition PD_ENABLED;
074
075
076
077  /** The "java-class" property definition. */
078  private static final ClassPropertyDefinition PD_JAVA_CLASS;
079
080
081
082  /** Build the "enabled" property definition. */
083  static {
084      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled");
085      builder.setOption(PropertyOption.MANDATORY);
086      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled"));
087      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>());
088      PD_ENABLED = builder.getInstance();
089      INSTANCE.registerPropertyDefinition(PD_ENABLED);
090  }
091
092
093
094  /** Build the "java-class" property definition. */
095  static {
096      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
097      builder.setOption(PropertyOption.MANDATORY);
098      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
099      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
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  // Register the tags associated with this managed object definition.
108  static {
109    INSTANCE.registerTag(Tag.valueOf("security"));
110    INSTANCE.registerTag(Tag.valueOf("user-management"));
111  }
112
113
114
115  /**
116   * Get the Identity Mapper configuration definition singleton.
117   *
118   * @return Returns the Identity Mapper configuration definition
119   *         singleton.
120   */
121  public static IdentityMapperCfgDefn getInstance() {
122    return INSTANCE;
123  }
124
125
126
127  /**
128   * Private constructor.
129   */
130  private IdentityMapperCfgDefn() {
131    super("identity-mapper", TopCfgDefn.getInstance());
132  }
133
134
135
136  /** {@inheritDoc} */
137  public IdentityMapperCfgClient createClientConfiguration(
138      ManagedObject<? extends IdentityMapperCfgClient> impl) {
139    return new IdentityMapperCfgClientImpl(impl);
140  }
141
142
143
144  /** {@inheritDoc} */
145  public IdentityMapperCfg createServerConfiguration(
146      ServerManagedObject<? extends IdentityMapperCfg> impl) {
147    return new IdentityMapperCfgServerImpl(impl);
148  }
149
150
151
152  /** {@inheritDoc} */
153  public Class<IdentityMapperCfg> getServerConfigurationClass() {
154    return IdentityMapperCfg.class;
155  }
156
157
158
159  /**
160   * Get the "enabled" property definition.
161   * <p>
162   * Indicates whether the Identity Mapper is enabled for use.
163   *
164   * @return Returns the "enabled" property definition.
165   */
166  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
167    return PD_ENABLED;
168  }
169
170
171
172  /**
173   * Get the "java-class" property definition.
174   * <p>
175   * Specifies the fully-qualified name of the Java class that
176   * provides the Identity Mapper implementation.
177   *
178   * @return Returns the "java-class" property definition.
179   */
180  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
181    return PD_JAVA_CLASS;
182  }
183
184
185
186  /**
187   * Managed object client implementation.
188   */
189  private static class IdentityMapperCfgClientImpl implements
190    IdentityMapperCfgClient {
191
192    /** Private implementation. */
193    private ManagedObject<? extends IdentityMapperCfgClient> impl;
194
195
196
197    /** Private constructor. */
198    private IdentityMapperCfgClientImpl(
199        ManagedObject<? extends IdentityMapperCfgClient> impl) {
200      this.impl = impl;
201    }
202
203
204
205    /** {@inheritDoc} */
206    public Boolean isEnabled() {
207      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
208    }
209
210
211
212    /** {@inheritDoc} */
213    public void setEnabled(boolean value) {
214      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
215    }
216
217
218
219    /** {@inheritDoc} */
220    public String getJavaClass() {
221      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
222    }
223
224
225
226    /** {@inheritDoc} */
227    public void setJavaClass(String value) {
228      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
229    }
230
231
232
233    /** {@inheritDoc} */
234    public ManagedObjectDefinition<? extends IdentityMapperCfgClient, ? extends IdentityMapperCfg> definition() {
235      return INSTANCE;
236    }
237
238
239
240    /** {@inheritDoc} */
241    public PropertyProvider properties() {
242      return impl;
243    }
244
245
246
247    /** {@inheritDoc} */
248    public void commit() throws ManagedObjectAlreadyExistsException,
249        MissingMandatoryPropertiesException, ConcurrentModificationException,
250        OperationRejectedException, LdapException {
251      impl.commit();
252    }
253
254
255
256    /** {@inheritDoc} */
257    public String toString() {
258      return impl.toString();
259    }
260  }
261
262
263
264  /**
265   * Managed object server implementation.
266   */
267  private static class IdentityMapperCfgServerImpl implements
268    IdentityMapperCfg {
269
270    /** Private implementation. */
271    private ServerManagedObject<? extends IdentityMapperCfg> impl;
272
273    /** The value of the "enabled" property. */
274    private final boolean pEnabled;
275
276    /** The value of the "java-class" property. */
277    private final String pJavaClass;
278
279
280
281    /** Private constructor. */
282    private IdentityMapperCfgServerImpl(ServerManagedObject<? extends IdentityMapperCfg> impl) {
283      this.impl = impl;
284      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
285      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
286    }
287
288
289
290    /** {@inheritDoc} */
291    public void addChangeListener(
292        ConfigurationChangeListener<IdentityMapperCfg> listener) {
293      impl.registerChangeListener(listener);
294    }
295
296
297
298    /** {@inheritDoc} */
299    public void removeChangeListener(
300        ConfigurationChangeListener<IdentityMapperCfg> listener) {
301      impl.deregisterChangeListener(listener);
302    }
303
304
305
306    /** {@inheritDoc} */
307    public boolean isEnabled() {
308      return pEnabled;
309    }
310
311
312
313    /** {@inheritDoc} */
314    public String getJavaClass() {
315      return pJavaClass;
316    }
317
318
319
320    /** {@inheritDoc} */
321    public Class<? extends IdentityMapperCfg> configurationClass() {
322      return IdentityMapperCfg.class;
323    }
324
325
326
327    /** {@inheritDoc} */
328    public DN dn() {
329      return impl.getDN();
330    }
331
332
333
334    /** {@inheritDoc} */
335    public String toString() {
336      return impl.toString();
337    }
338  }
339}