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
010     * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011     * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012     * See the License for the specific language governing permissions
013     * and limitations under the License.
014     *
015     * When distributing Covered Code, include this CDDL HEADER in each
016     * file and include the License file at
017     * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
018     * add the following below this CDDL HEADER, with the fields enclosed
019     * by brackets "[]" replaced with your own identifying information:
020     *      Portions Copyright [yyyy] [name of copyright owner]
021     *
022     * CDDL HEADER END
023     *
024     *
025     *      Copyright 2008 Sun Microsystems, Inc.
026     */
027    package org.opends.server.admin.std.meta;
028    
029    
030    
031    import org.opends.server.admin.AdministratorAction;
032    import org.opends.server.admin.AggregationPropertyDefinition;
033    import org.opends.server.admin.BooleanPropertyDefinition;
034    import org.opends.server.admin.ClassPropertyDefinition;
035    import org.opends.server.admin.client.AuthorizationException;
036    import org.opends.server.admin.client.CommunicationException;
037    import org.opends.server.admin.client.ConcurrentModificationException;
038    import org.opends.server.admin.client.ManagedObject;
039    import org.opends.server.admin.client.MissingMandatoryPropertiesException;
040    import org.opends.server.admin.client.OperationRejectedException;
041    import org.opends.server.admin.DefaultBehaviorProvider;
042    import org.opends.server.admin.DefinedDefaultBehaviorProvider;
043    import org.opends.server.admin.ManagedObjectAlreadyExistsException;
044    import org.opends.server.admin.ManagedObjectDefinition;
045    import org.opends.server.admin.PropertyOption;
046    import org.opends.server.admin.PropertyProvider;
047    import org.opends.server.admin.server.ConfigurationChangeListener;
048    import org.opends.server.admin.server.ServerManagedObject;
049    import org.opends.server.admin.std.client.IdentityMapperCfgClient;
050    import org.opends.server.admin.std.client.PlainSASLMechanismHandlerCfgClient;
051    import org.opends.server.admin.std.server.IdentityMapperCfg;
052    import org.opends.server.admin.std.server.PlainSASLMechanismHandlerCfg;
053    import org.opends.server.admin.std.server.SASLMechanismHandlerCfg;
054    import org.opends.server.admin.Tag;
055    import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
056    import org.opends.server.types.DN;
057    
058    
059    
060    /**
061     * An interface for querying the Plain SASL Mechanism Handler managed
062     * object definition meta information.
063     * <p>
064     * The Plain SASL Mechanism Handler performs all processing related to
065     * SASL PLAIN authentication.
066     */
067    public final class PlainSASLMechanismHandlerCfgDefn extends ManagedObjectDefinition<PlainSASLMechanismHandlerCfgClient, PlainSASLMechanismHandlerCfg> {
068    
069      // The singleton configuration definition instance.
070      private static final PlainSASLMechanismHandlerCfgDefn INSTANCE = new PlainSASLMechanismHandlerCfgDefn();
071    
072    
073    
074      // The "identity-mapper" property definition.
075      private static final AggregationPropertyDefinition<IdentityMapperCfgClient, IdentityMapperCfg> PD_IDENTITY_MAPPER;
076    
077    
078    
079      // The "java-class" property definition.
080      private static final ClassPropertyDefinition PD_JAVA_CLASS;
081    
082    
083    
084      // Build the "identity-mapper" property definition.
085      static {
086          AggregationPropertyDefinition.Builder<IdentityMapperCfgClient, IdentityMapperCfg> builder = AggregationPropertyDefinition.createBuilder(INSTANCE, "identity-mapper");
087          builder.setOption(PropertyOption.MANDATORY);
088          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "identity-mapper"));
089          builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
090          builder.setParentPath("/");
091          builder.setRelationDefinition("identity-mapper");
092          PD_IDENTITY_MAPPER = builder.getInstance();
093          INSTANCE.registerPropertyDefinition(PD_IDENTITY_MAPPER);
094          INSTANCE.registerConstraint(PD_IDENTITY_MAPPER.getSourceConstraint());
095      }
096    
097    
098    
099      // Build the "java-class" property definition.
100      static {
101          ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
102          builder.setOption(PropertyOption.MANDATORY);
103          builder.setOption(PropertyOption.ADVANCED);
104          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
105          DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.PlainSASLMechanismHandler");
106          builder.setDefaultBehaviorProvider(provider);
107          builder.addInstanceOf("org.opends.server.api.SASLMechanismHandler");
108          PD_JAVA_CLASS = builder.getInstance();
109          INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
110      }
111    
112    
113    
114      // Register the tags associated with this managed object definition.
115      static {
116        INSTANCE.registerTag(Tag.valueOf("security"));
117      }
118    
119    
120    
121      /**
122       * Get the Plain SASL Mechanism Handler configuration definition
123       * singleton.
124       *
125       * @return Returns the Plain SASL Mechanism Handler configuration
126       *         definition singleton.
127       */
128      public static PlainSASLMechanismHandlerCfgDefn getInstance() {
129        return INSTANCE;
130      }
131    
132    
133    
134      /**
135       * Private constructor.
136       */
137      private PlainSASLMechanismHandlerCfgDefn() {
138        super("plain-sasl-mechanism-handler", SASLMechanismHandlerCfgDefn.getInstance());
139      }
140    
141    
142    
143      /**
144       * {@inheritDoc}
145       */
146      public PlainSASLMechanismHandlerCfgClient createClientConfiguration(
147          ManagedObject<? extends PlainSASLMechanismHandlerCfgClient> impl) {
148        return new PlainSASLMechanismHandlerCfgClientImpl(impl);
149      }
150    
151    
152    
153      /**
154       * {@inheritDoc}
155       */
156      public PlainSASLMechanismHandlerCfg createServerConfiguration(
157          ServerManagedObject<? extends PlainSASLMechanismHandlerCfg> impl) {
158        return new PlainSASLMechanismHandlerCfgServerImpl(impl);
159      }
160    
161    
162    
163      /**
164       * {@inheritDoc}
165       */
166      public Class<PlainSASLMechanismHandlerCfg> getServerConfigurationClass() {
167        return PlainSASLMechanismHandlerCfg.class;
168      }
169    
170    
171    
172      /**
173       * Get the "enabled" property definition.
174       * <p>
175       * Indicates whether the SASL mechanism handler is enabled for use.
176       *
177       * @return Returns the "enabled" property definition.
178       */
179      public BooleanPropertyDefinition getEnabledPropertyDefinition() {
180        return SASLMechanismHandlerCfgDefn.getInstance().getEnabledPropertyDefinition();
181      }
182    
183    
184    
185      /**
186       * Get the "identity-mapper" property definition.
187       * <p>
188       * Specifies the name of the identity mapper that is to be used with
189       * this SASL mechanism handler to match the authentication or
190       * authorization ID included in the SASL bind request to the
191       * corresponding user in the directory.
192       *
193       * @return Returns the "identity-mapper" property definition.
194       */
195      public AggregationPropertyDefinition<IdentityMapperCfgClient, IdentityMapperCfg> getIdentityMapperPropertyDefinition() {
196        return PD_IDENTITY_MAPPER;
197      }
198    
199    
200    
201      /**
202       * Get the "java-class" property definition.
203       * <p>
204       * Specifies the fully-qualified name of the Java class that
205       * provides the SASL mechanism handler implementation.
206       *
207       * @return Returns the "java-class" property definition.
208       */
209      public ClassPropertyDefinition getJavaClassPropertyDefinition() {
210        return PD_JAVA_CLASS;
211      }
212    
213    
214    
215      /**
216       * Managed object client implementation.
217       */
218      private static class PlainSASLMechanismHandlerCfgClientImpl implements
219        PlainSASLMechanismHandlerCfgClient {
220    
221        // Private implementation.
222        private ManagedObject<? extends PlainSASLMechanismHandlerCfgClient> impl;
223    
224    
225    
226        // Private constructor.
227        private PlainSASLMechanismHandlerCfgClientImpl(
228            ManagedObject<? extends PlainSASLMechanismHandlerCfgClient> impl) {
229          this.impl = impl;
230        }
231    
232    
233    
234        /**
235         * {@inheritDoc}
236         */
237        public Boolean isEnabled() {
238          return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
239        }
240    
241    
242    
243        /**
244         * {@inheritDoc}
245         */
246        public void setEnabled(boolean value) {
247          impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
248        }
249    
250    
251    
252        /**
253         * {@inheritDoc}
254         */
255        public String getIdentityMapper() {
256          return impl.getPropertyValue(INSTANCE.getIdentityMapperPropertyDefinition());
257        }
258    
259    
260    
261        /**
262         * {@inheritDoc}
263         */
264        public void setIdentityMapper(String value) {
265          impl.setPropertyValue(INSTANCE.getIdentityMapperPropertyDefinition(), value);
266        }
267    
268    
269    
270        /**
271         * {@inheritDoc}
272         */
273        public String getJavaClass() {
274          return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
275        }
276    
277    
278    
279        /**
280         * {@inheritDoc}
281         */
282        public void setJavaClass(String value) {
283          impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
284        }
285    
286    
287    
288        /**
289         * {@inheritDoc}
290         */
291        public ManagedObjectDefinition<? extends PlainSASLMechanismHandlerCfgClient, ? extends PlainSASLMechanismHandlerCfg> definition() {
292          return INSTANCE;
293        }
294    
295    
296    
297        /**
298         * {@inheritDoc}
299         */
300        public PropertyProvider properties() {
301          return impl;
302        }
303    
304    
305    
306        /**
307         * {@inheritDoc}
308         */
309        public void commit() throws ManagedObjectAlreadyExistsException,
310            MissingMandatoryPropertiesException, ConcurrentModificationException,
311            OperationRejectedException, AuthorizationException,
312            CommunicationException {
313          impl.commit();
314        }
315    
316      }
317    
318    
319    
320      /**
321       * Managed object server implementation.
322       */
323      private static class PlainSASLMechanismHandlerCfgServerImpl implements
324        PlainSASLMechanismHandlerCfg {
325    
326        // Private implementation.
327        private ServerManagedObject<? extends PlainSASLMechanismHandlerCfg> impl;
328    
329        // The value of the "enabled" property.
330        private final boolean pEnabled;
331    
332        // The value of the "identity-mapper" property.
333        private final String pIdentityMapper;
334    
335        // The value of the "java-class" property.
336        private final String pJavaClass;
337    
338    
339    
340        // Private constructor.
341        private PlainSASLMechanismHandlerCfgServerImpl(ServerManagedObject<? extends PlainSASLMechanismHandlerCfg> impl) {
342          this.impl = impl;
343          this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
344          this.pIdentityMapper = impl.getPropertyValue(INSTANCE.getIdentityMapperPropertyDefinition());
345          this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
346        }
347    
348    
349    
350        /**
351         * {@inheritDoc}
352         */
353        public void addPlainChangeListener(
354            ConfigurationChangeListener<PlainSASLMechanismHandlerCfg> listener) {
355          impl.registerChangeListener(listener);
356        }
357    
358    
359    
360        /**
361         * {@inheritDoc}
362         */
363        public void removePlainChangeListener(
364            ConfigurationChangeListener<PlainSASLMechanismHandlerCfg> listener) {
365          impl.deregisterChangeListener(listener);
366        }
367        /**
368         * {@inheritDoc}
369         */
370        public void addChangeListener(
371            ConfigurationChangeListener<SASLMechanismHandlerCfg> listener) {
372          impl.registerChangeListener(listener);
373        }
374    
375    
376    
377        /**
378         * {@inheritDoc}
379         */
380        public void removeChangeListener(
381            ConfigurationChangeListener<SASLMechanismHandlerCfg> listener) {
382          impl.deregisterChangeListener(listener);
383        }
384    
385    
386    
387        /**
388         * {@inheritDoc}
389         */
390        public boolean isEnabled() {
391          return pEnabled;
392        }
393    
394    
395    
396        /**
397         * {@inheritDoc}
398         */
399        public String getIdentityMapper() {
400          return pIdentityMapper;
401        }
402    
403    
404    
405        /**
406         * {@inheritDoc}
407         */
408        public DN getIdentityMapperDN() {
409          String value = getIdentityMapper();
410          if (value == null) return null;
411          return INSTANCE.getIdentityMapperPropertyDefinition().getChildDN(value);
412        }
413    
414    
415    
416        /**
417         * {@inheritDoc}
418         */
419        public String getJavaClass() {
420          return pJavaClass;
421        }
422    
423    
424    
425        /**
426         * {@inheritDoc}
427         */
428        public Class<? extends PlainSASLMechanismHandlerCfg> configurationClass() {
429          return PlainSASLMechanismHandlerCfg.class;
430        }
431    
432    
433    
434        /**
435         * {@inheritDoc}
436         */
437        public DN dn() {
438          return impl.getDN();
439        }
440    
441      }
442    }