001/*
002 *   Licensed to the Apache Software Foundation (ASF) under one
003 *   or more contributor license agreements.  See the NOTICE file
004 *   distributed with apiService work for additional information
005 *   regarding copyright ownership.  The ASF licenses apiService file
006 *   to you under the Apache License, Version 2.0 (the
007 *   "License"); you may not use apiService file except in compliance
008 *   with the License.  You may obtain a copy of the License at
009 *
010 *     https://www.apache.org/licenses/LICENSE-2.0
011 *
012 *   Unless required by applicable law or agreed to in writing,
013 *   software distributed under the License is distributed on an
014 *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *   KIND, either express or implied.  See the License for the
016 *   specific language governing permissions and limitations
017 *   under the License.
018 *
019 */
020package org.apache.directory.api.ldap.extras;
021
022
023import java.util.Map;
024
025import org.apache.directory.api.i18n.I18n;
026import org.apache.directory.api.ldap.codec.api.ControlFactory;
027import org.apache.directory.api.ldap.codec.api.ExtendedOperationFactory;
028import org.apache.directory.api.ldap.codec.api.IntermediateOperationFactory;
029import org.apache.directory.api.ldap.codec.api.LdapApiService;
030import org.apache.directory.api.ldap.extras.controls.ad.AdDirSyncRequest;
031import org.apache.directory.api.ldap.extras.controls.ad.AdDirSyncResponse;
032import org.apache.directory.api.ldap.extras.controls.ad.AdPolicyHints;
033import org.apache.directory.api.ldap.extras.controls.ad.AdShowDeleted;
034import org.apache.directory.api.ldap.extras.controls.ad.TreeDelete;
035import org.apache.directory.api.ldap.extras.controls.ad_impl.AdDirSyncRequestFactory;
036import org.apache.directory.api.ldap.extras.controls.ad_impl.AdDirSyncResponseFactory;
037import org.apache.directory.api.ldap.extras.controls.ad_impl.AdPolicyHintsFactory;
038import org.apache.directory.api.ldap.extras.controls.ad_impl.AdShowDeletedFactory;
039import org.apache.directory.api.ldap.extras.controls.ad_impl.TreeDeleteFactory;
040import org.apache.directory.api.ldap.extras.controls.changeNotifications.ChangeNotifications;
041import org.apache.directory.api.ldap.extras.controls.changeNotifications_impl.ChangeNotificationsFactory;
042import org.apache.directory.api.ldap.extras.controls.passwordExpired.PasswordExpiredResponse;
043import org.apache.directory.api.ldap.extras.controls.passwordExpired_impl.PasswordExpiredResponseFactory;
044import org.apache.directory.api.ldap.extras.controls.permissiveModify.PermissiveModify;
045import org.apache.directory.api.ldap.extras.controls.permissiveModify_impl.PermissiveModifyFactory;
046import org.apache.directory.api.ldap.extras.controls.ppolicy.PasswordPolicyRequest;
047import org.apache.directory.api.ldap.extras.controls.ppolicy.PasswordPolicyResponse;
048import org.apache.directory.api.ldap.extras.controls.ppolicy_impl.PasswordPolicyRequestFactory;
049import org.apache.directory.api.ldap.extras.controls.ppolicy_impl.PasswordPolicyResponseFactory;
050import org.apache.directory.api.ldap.extras.controls.syncrepl.syncDone.SyncDoneValue;
051import org.apache.directory.api.ldap.extras.controls.syncrepl.syncRequest.SyncRequestValue;
052import org.apache.directory.api.ldap.extras.controls.syncrepl.syncState.SyncStateValue;
053import org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncDoneValueFactory;
054import org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncRequestValueFactory;
055import org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncStateValueFactory;
056import org.apache.directory.api.ldap.extras.controls.transaction.TransactionSpecification;
057import org.apache.directory.api.ldap.extras.controls.transaction_impl.TransactionSpecificationFactory;
058import org.apache.directory.api.ldap.extras.controls.vlv.VirtualListViewRequest;
059import org.apache.directory.api.ldap.extras.controls.vlv.VirtualListViewResponse;
060import org.apache.directory.api.ldap.extras.controls.vlv_impl.VirtualListViewRequestFactory;
061import org.apache.directory.api.ldap.extras.controls.vlv_impl.VirtualListViewResponseFactory;
062import org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelFactory;
063import org.apache.directory.api.ldap.extras.extended.ads_impl.certGeneration.CertGenerationFactory;
064import org.apache.directory.api.ldap.extras.extended.ads_impl.endTransaction.EndTransactionFactory;
065import org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulDisconnectFactory;
066import org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownFactory;
067import org.apache.directory.api.ldap.extras.extended.ads_impl.nod.NoDFactory;
068import org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyFactory;
069import org.apache.directory.api.ldap.extras.extended.ads_impl.startTls.StartTlsFactory;
070import org.apache.directory.api.ldap.extras.extended.ads_impl.startTransaction.StartTransactionFactory;
071import org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureFactory;
072import org.apache.directory.api.ldap.extras.controls.relax.RelaxControl;
073import org.apache.directory.api.ldap.extras.controls.relax_impl.RelaxControlFactory;
074import org.apache.directory.api.ldap.extras.extended.ads_impl.whoAmI.WhoAmIFactory;
075import org.apache.directory.api.ldap.extras.intermediate.syncrepl_impl.SyncInfoValueFactory;
076import org.apache.directory.api.ldap.model.message.Control;
077import org.slf4j.Logger;
078import org.slf4j.LoggerFactory;
079
080
081
082/**
083 * A utility class for adding Codec and extended operation factories.
084 *
085 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
086 */
087public final class ExtrasCodecFactoryUtil
088{
089    private static final Logger LOG = LoggerFactory.getLogger( ExtrasCodecFactoryUtil.class );
090
091
092    private ExtrasCodecFactoryUtil()
093    {
094    }
095
096
097    /**
098     * Loads the extras controls.
099     *
100     * @param apiService The LDAP Service instance to use
101     */
102    public static void loadExtrasControls( LdapApiService apiService )
103    {
104        Map<String, ControlFactory<? extends Control>> requestControlFactories = apiService
105            .getRequestControlFactories();
106        Map<String, ControlFactory<? extends Control>> responseControlFactories = apiService
107            .getResponseControlFactories();
108
109        // Extra controls
110        // AdDirSync request
111        ControlFactory<AdDirSyncRequest> adDirSyncRequestFactory = new AdDirSyncRequestFactory( apiService );
112        requestControlFactories.put( adDirSyncRequestFactory.getOid(), adDirSyncRequestFactory );
113
114        if ( LOG.isInfoEnabled() )
115        {
116            LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, adDirSyncRequestFactory.getOid() ) );
117        }
118
119        // AdDirSync response
120        ControlFactory<AdDirSyncResponse> adDirSyncResponseFactory = new AdDirSyncResponseFactory( apiService );
121        responseControlFactories.put( adDirSyncResponseFactory.getOid(), adDirSyncResponseFactory );
122
123        if ( LOG.isInfoEnabled() )
124        {
125            LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, adDirSyncRequestFactory.getOid() ) );
126        }
127
128        // AdPolicyHints
129        ControlFactory<AdPolicyHints> adPolicyHintsFactory = new AdPolicyHintsFactory( apiService );
130        requestControlFactories.put( adPolicyHintsFactory.getOid(), adPolicyHintsFactory );
131
132        if ( LOG.isInfoEnabled() )
133        {
134            LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, adPolicyHintsFactory.getOid() ) );
135        }
136
137        // AdShowDelete
138        ControlFactory<AdShowDeleted> adShowDeletedFactory = new AdShowDeletedFactory( apiService );
139        requestControlFactories.put( adShowDeletedFactory.getOid(), adShowDeletedFactory );
140
141        // TreeDelete
142        ControlFactory<TreeDelete> treeDeleteFactory = new TreeDeleteFactory( apiService );
143        requestControlFactories.put( treeDeleteFactory.getOid(), treeDeleteFactory );
144
145        if ( LOG.isInfoEnabled() )
146        {
147            LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, adShowDeletedFactory.getOid() ) );
148        }
149
150        // ChangeNotification
151        ControlFactory<ChangeNotifications> changeNotificationsFactory = new ChangeNotificationsFactory( apiService );
152        requestControlFactories.put( changeNotificationsFactory.getOid(), changeNotificationsFactory );
153        responseControlFactories.put( changeNotificationsFactory.getOid(), changeNotificationsFactory );
154
155        if ( LOG.isInfoEnabled() )
156        {
157            LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, changeNotificationsFactory.getOid() ) );
158        }
159
160        // PasswordExpired response
161        ControlFactory<PasswordExpiredResponse> passwordExpiredResponseFactory = new PasswordExpiredResponseFactory( apiService );
162        responseControlFactories.put( passwordExpiredResponseFactory.getOid(), passwordExpiredResponseFactory );
163
164        if ( LOG.isInfoEnabled() )
165        {
166            LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, passwordExpiredResponseFactory.getOid() ) );
167        }
168
169        // PasswordPolicy request
170        ControlFactory<PasswordPolicyRequest> passwordPolicyRequestFactory = new PasswordPolicyRequestFactory( apiService );
171        requestControlFactories.put( passwordPolicyRequestFactory.getOid(), passwordPolicyRequestFactory );
172
173        if ( LOG.isInfoEnabled() )
174        {
175            LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, passwordPolicyRequestFactory.getOid() ) );
176        }
177
178        // PasswordPolicy response
179        ControlFactory<PasswordPolicyResponse> passwordPolicyResponseFactory = new PasswordPolicyResponseFactory( apiService );
180        responseControlFactories.put( passwordPolicyResponseFactory.getOid(), passwordPolicyResponseFactory );
181
182        if ( LOG.isInfoEnabled() )
183        {
184            LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, passwordPolicyResponseFactory.getOid() ) );
185        }
186
187        // PermissiveModify
188        ControlFactory<PermissiveModify> permissiveModifyFactory = new PermissiveModifyFactory( apiService );
189        requestControlFactories.put( permissiveModifyFactory.getOid(), permissiveModifyFactory );
190
191        if ( LOG.isInfoEnabled() )
192        {
193            LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, permissiveModifyFactory.getOid() ) );
194        }
195
196        // SyncDoneValue
197        ControlFactory<SyncDoneValue> syncDoneValueFactory = new SyncDoneValueFactory( apiService );
198        responseControlFactories.put( syncDoneValueFactory.getOid(), syncDoneValueFactory );
199
200        if ( LOG.isInfoEnabled() )
201        {
202            LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, syncDoneValueFactory.getOid() ) );
203        }
204
205        // SyncRequestValue
206        ControlFactory<SyncRequestValue> syncRequestValueFactory = new SyncRequestValueFactory( apiService );
207        requestControlFactories.put( syncRequestValueFactory.getOid(), syncRequestValueFactory );
208
209        if ( LOG.isInfoEnabled() )
210        {
211            LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, syncRequestValueFactory.getOid() ) );
212        }
213
214        // SyncStateValue
215        ControlFactory<SyncStateValue> syncStateValueFactory = new SyncStateValueFactory( apiService );
216        requestControlFactories.put( syncStateValueFactory.getOid(), syncStateValueFactory );
217        responseControlFactories.put( syncStateValueFactory.getOid(), syncStateValueFactory );
218
219        if ( LOG.isInfoEnabled() )
220        {
221            LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, syncStateValueFactory.getOid() ) );
222        }
223
224        // TransactionSpecification
225        ControlFactory<TransactionSpecification> transactionSpecificationFactory = new TransactionSpecificationFactory( apiService );
226        requestControlFactories.put( transactionSpecificationFactory.getOid(), transactionSpecificationFactory );
227
228        if ( LOG.isInfoEnabled() )
229        {
230            LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, transactionSpecificationFactory.getOid() ) );
231        }
232
233        // VirtualListViewRequest
234        ControlFactory<VirtualListViewRequest> virtualListViewRequestFactory = new VirtualListViewRequestFactory(
235            apiService );
236        requestControlFactories.put( virtualListViewRequestFactory.getOid(), virtualListViewRequestFactory );
237
238        if ( LOG.isInfoEnabled() )
239        {
240            LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, virtualListViewRequestFactory.getOid() ) );
241        }
242
243        // VirtualListViewResponse
244        ControlFactory<VirtualListViewResponse> virtualListViewResponseFactory = new VirtualListViewResponseFactory(
245            apiService );
246        responseControlFactories.put( virtualListViewResponseFactory.getOid(), virtualListViewResponseFactory );
247
248        if ( LOG.isInfoEnabled() )
249        {
250            LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, virtualListViewResponseFactory.getOid() ) );
251        }
252
253        // RelaxControl
254        ControlFactory<RelaxControl> relaxControlFactory = new RelaxControlFactory( apiService );
255        requestControlFactories.put( relaxControlFactory.getOid(), relaxControlFactory );
256
257        if ( LOG.isInfoEnabled() )
258        {
259            LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, relaxControlFactory.getOid() ) );
260        }
261    }
262
263
264    /**
265     * Load the extras extended operations :
266     * <ul>
267     * <li>cancel</li>
268     * <li>certGeneration</li>
269     * <li>gracefuShutdown</li>
270     * <li>storedProcedure</li>
271     * <li>gracefulDisconnect</li>
272     * <li>passwordModify</li>
273     * <li>whoAmI</li>
274     * <li>startTls</li>
275     * <li>startTransaction</li>
276     * </ul>
277     *
278     * @param apiService The LdapApiService to use
279     */
280    public static void loadExtrasExtendedOperations( LdapApiService apiService )
281    {
282        Map<String, ExtendedOperationFactory> extendedRequestFactories = apiService.getExtendedRequestFactories();
283        Map<String, ExtendedOperationFactory> extendedResponseFactories = apiService.getExtendedResponseFactories();
284        
285        CancelFactory cancelFactory = new CancelFactory( apiService );
286        extendedRequestFactories.put( cancelFactory.getOid(), cancelFactory );
287        extendedResponseFactories.put( cancelFactory.getOid(), cancelFactory );
288
289        if ( LOG.isInfoEnabled() )
290        {
291            LOG.info( I18n.msg( I18n.MSG_06001_REGISTERED_EXTENDED_OP_FACTORY, cancelFactory.getOid() ) );
292        }
293
294        CertGenerationFactory certGenerationFactory = new CertGenerationFactory( apiService );
295        extendedRequestFactories.put( certGenerationFactory.getOid(), certGenerationFactory );
296        extendedResponseFactories.put( certGenerationFactory.getOid(), certGenerationFactory );
297
298        if ( LOG.isInfoEnabled() )
299        {
300            LOG.info( I18n.msg( I18n.MSG_06001_REGISTERED_EXTENDED_OP_FACTORY, certGenerationFactory.getOid() ) );
301        }
302
303        EndTransactionFactory endTransactionFactory = new EndTransactionFactory( apiService );
304        extendedRequestFactories.put( endTransactionFactory.getOid(), endTransactionFactory );
305        extendedResponseFactories.put( endTransactionFactory.getOid(), endTransactionFactory );
306
307        if ( LOG.isInfoEnabled() )
308        {
309            LOG.info( I18n.msg( I18n.MSG_06001_REGISTERED_EXTENDED_OP_FACTORY, endTransactionFactory.getOid() ) );
310        }
311
312        GracefulDisconnectFactory gracefulDisconnectFactory = new GracefulDisconnectFactory( apiService );
313        extendedResponseFactories.put( gracefulDisconnectFactory.getOid(), gracefulDisconnectFactory );
314
315        if ( LOG.isInfoEnabled() )
316        {
317            LOG.info( I18n.msg( I18n.MSG_06001_REGISTERED_EXTENDED_OP_FACTORY, gracefulDisconnectFactory.getOid() ) );
318        }
319
320        GracefulShutdownFactory gracefulShutdownFactory = new GracefulShutdownFactory( apiService );
321        extendedRequestFactories.put( gracefulShutdownFactory.getOid(), gracefulShutdownFactory );
322        extendedResponseFactories.put( gracefulShutdownFactory.getOid(), gracefulShutdownFactory );
323
324        
325        if ( LOG.isInfoEnabled() )
326        {
327            LOG.info( I18n.msg( I18n.MSG_06001_REGISTERED_EXTENDED_OP_FACTORY, gracefulShutdownFactory.getOid() ) );
328        }
329
330        NoDFactory noticeOfDisconnectFactory = new NoDFactory( apiService );
331        extendedResponseFactories.put( noticeOfDisconnectFactory.getOid(), noticeOfDisconnectFactory );
332
333        if ( LOG.isInfoEnabled() )
334        {
335            LOG.info( I18n.msg( I18n.MSG_06001_REGISTERED_EXTENDED_OP_FACTORY, noticeOfDisconnectFactory.getOid() ) );
336        }
337
338        PasswordModifyFactory passwordModifyFactory = new PasswordModifyFactory( apiService );
339        extendedRequestFactories.put( passwordModifyFactory.getOid(), passwordModifyFactory );
340        extendedResponseFactories.put( passwordModifyFactory.getOid(), passwordModifyFactory );
341
342        if ( LOG.isInfoEnabled() )
343        {
344            LOG.info( I18n.msg( I18n.MSG_06001_REGISTERED_EXTENDED_OP_FACTORY, passwordModifyFactory.getOid() ) );
345        }
346
347        StartTlsFactory startTlsFactory = new StartTlsFactory( apiService );
348        extendedRequestFactories.put( startTlsFactory.getOid(), startTlsFactory );
349        extendedResponseFactories.put( startTlsFactory.getOid(), startTlsFactory );
350
351        if ( LOG.isInfoEnabled() )
352        {
353            LOG.info( I18n.msg( I18n.MSG_06001_REGISTERED_EXTENDED_OP_FACTORY, startTlsFactory.getOid() ) );
354        }
355
356        StartTransactionFactory startTransactionFactory = new StartTransactionFactory( apiService );
357        extendedRequestFactories.put( startTransactionFactory.getOid(), startTransactionFactory );
358        extendedResponseFactories.put( startTransactionFactory.getOid(), startTransactionFactory );
359
360        if ( LOG.isInfoEnabled() )
361        {
362            LOG.info( I18n.msg( I18n.MSG_06001_REGISTERED_EXTENDED_OP_FACTORY, startTransactionFactory.getOid() ) );
363        }
364
365        StoredProcedureFactory storedProcedureFactory = new StoredProcedureFactory( apiService );
366        extendedRequestFactories.put( storedProcedureFactory.getOid(), storedProcedureFactory );
367        extendedResponseFactories.put( storedProcedureFactory.getOid(), storedProcedureFactory );
368
369        if ( LOG.isInfoEnabled() )
370        {
371            LOG.info( I18n.msg( I18n.MSG_06001_REGISTERED_EXTENDED_OP_FACTORY, storedProcedureFactory.getOid() ) );
372        }
373
374        WhoAmIFactory whoAmIFactory = new WhoAmIFactory( apiService );
375        extendedRequestFactories.put( whoAmIFactory.getOid(), whoAmIFactory );
376        extendedResponseFactories.put( whoAmIFactory.getOid(), whoAmIFactory );
377
378        if ( LOG.isInfoEnabled() )
379        {
380            LOG.info( I18n.msg( I18n.MSG_06001_REGISTERED_EXTENDED_OP_FACTORY, whoAmIFactory.getOid() ) );
381        }
382    }
383
384
385    /**
386     * Load the extras intermediate responses :
387     * <ul>
388     * <li>syncInfovalue</li>
389     * </ul>
390     *
391     * @param apiService The LdapApiService to use
392     */
393    public static void loadExtrasIntermediateResponses( LdapApiService apiService )
394    {
395        Map<String, IntermediateOperationFactory> intermediateResponseFactories = apiService
396            .getIntermediateResponseFactories();
397
398        SyncInfoValueFactory syncInfoValueFactory = new SyncInfoValueFactory();
399        intermediateResponseFactories.put( syncInfoValueFactory.getOid(), syncInfoValueFactory );
400
401        if ( LOG.isInfoEnabled() )
402        {
403            LOG.info( I18n.msg( I18n.MSG_06002_REGISTERED_INTERMEDIATE_FACTORY, syncInfoValueFactory.getOid() ) );
404        }
405    }
406}