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 * http://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.extended.ads_impl.whoAmI.WhoAmIFactory; 073import org.apache.directory.api.ldap.extras.intermediate.syncrepl_impl.SyncInfoValueFactory; 074import org.apache.directory.api.ldap.model.message.Control; 075import org.slf4j.Logger; 076import org.slf4j.LoggerFactory; 077 078 079/** 080 * A utility class for adding Codec and extended operation factories. 081 * 082 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 083 */ 084public final class ExtrasCodecFactoryUtil 085{ 086 private static final Logger LOG = LoggerFactory.getLogger( ExtrasCodecFactoryUtil.class ); 087 088 089 private ExtrasCodecFactoryUtil() 090 { 091 } 092 093 094 /** 095 * Loads the extras controls. 096 * 097 * @param apiService The LDAP Service instance to use 098 */ 099 public static void loadExtrasControls( LdapApiService apiService ) 100 { 101 Map<String, ControlFactory<? extends Control>> requestControlFactories = apiService 102 .getRequestControlFactories(); 103 Map<String, ControlFactory<? extends Control>> responseControlFactories = apiService 104 .getResponseControlFactories(); 105 106 // Extra controls 107 // AdDirSync request 108 ControlFactory<AdDirSyncRequest> adDirSyncRequestFactory = new AdDirSyncRequestFactory( apiService ); 109 requestControlFactories.put( adDirSyncRequestFactory.getOid(), adDirSyncRequestFactory ); 110 111 if ( LOG.isInfoEnabled() ) 112 { 113 LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, adDirSyncRequestFactory.getOid() ) ); 114 } 115 116 // AdDirSync response 117 ControlFactory<AdDirSyncResponse> adDirSyncResponseFactory = new AdDirSyncResponseFactory( apiService ); 118 responseControlFactories.put( adDirSyncResponseFactory.getOid(), adDirSyncResponseFactory ); 119 120 if ( LOG.isInfoEnabled() ) 121 { 122 LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, adDirSyncRequestFactory.getOid() ) ); 123 } 124 125 // AdPolicyHints 126 ControlFactory<AdPolicyHints> adPolicyHintsFactory = new AdPolicyHintsFactory( apiService ); 127 requestControlFactories.put( adPolicyHintsFactory.getOid(), adPolicyHintsFactory ); 128 129 if ( LOG.isInfoEnabled() ) 130 { 131 LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, adPolicyHintsFactory.getOid() ) ); 132 } 133 134 // AdShowDelete 135 ControlFactory<AdShowDeleted> adShowDeletedFactory = new AdShowDeletedFactory( apiService ); 136 requestControlFactories.put( adShowDeletedFactory.getOid(), adShowDeletedFactory ); 137 138 // TreeDelete 139 ControlFactory<TreeDelete> treeDeleteFactory = new TreeDeleteFactory( apiService ); 140 requestControlFactories.put( treeDeleteFactory.getOid(), treeDeleteFactory ); 141 142 if ( LOG.isInfoEnabled() ) 143 { 144 LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, adShowDeletedFactory.getOid() ) ); 145 } 146 147 // ChangeNotification 148 ControlFactory<ChangeNotifications> changeNotificationsFactory = new ChangeNotificationsFactory( apiService ); 149 requestControlFactories.put( changeNotificationsFactory.getOid(), changeNotificationsFactory ); 150 responseControlFactories.put( changeNotificationsFactory.getOid(), changeNotificationsFactory ); 151 152 if ( LOG.isInfoEnabled() ) 153 { 154 LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, changeNotificationsFactory.getOid() ) ); 155 } 156 157 // PasswordExpired response 158 ControlFactory<PasswordExpiredResponse> passwordExpiredResponseFactory = new PasswordExpiredResponseFactory( apiService ); 159 responseControlFactories.put( passwordExpiredResponseFactory.getOid(), passwordExpiredResponseFactory ); 160 161 if ( LOG.isInfoEnabled() ) 162 { 163 LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, passwordExpiredResponseFactory.getOid() ) ); 164 } 165 166 // PasswordPolicy request 167 ControlFactory<PasswordPolicyRequest> passwordPolicyRequestFactory = new PasswordPolicyRequestFactory( apiService ); 168 requestControlFactories.put( passwordPolicyRequestFactory.getOid(), passwordPolicyRequestFactory ); 169 170 if ( LOG.isInfoEnabled() ) 171 { 172 LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, passwordPolicyRequestFactory.getOid() ) ); 173 } 174 175 // PasswordPolicy response 176 ControlFactory<PasswordPolicyResponse> passwordPolicyResponseFactory = new PasswordPolicyResponseFactory( apiService ); 177 responseControlFactories.put( passwordPolicyResponseFactory.getOid(), passwordPolicyResponseFactory ); 178 179 if ( LOG.isInfoEnabled() ) 180 { 181 LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, passwordPolicyResponseFactory.getOid() ) ); 182 } 183 184 // PermissiveModify 185 ControlFactory<PermissiveModify> permissiveModifyFactory = new PermissiveModifyFactory( apiService ); 186 requestControlFactories.put( permissiveModifyFactory.getOid(), permissiveModifyFactory ); 187 188 if ( LOG.isInfoEnabled() ) 189 { 190 LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, permissiveModifyFactory.getOid() ) ); 191 } 192 193 // SyncDoneValue 194 ControlFactory<SyncDoneValue> syncDoneValueFactory = new SyncDoneValueFactory( apiService ); 195 responseControlFactories.put( syncDoneValueFactory.getOid(), syncDoneValueFactory ); 196 197 if ( LOG.isInfoEnabled() ) 198 { 199 LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, syncDoneValueFactory.getOid() ) ); 200 } 201 202 // SyncRequestValue 203 ControlFactory<SyncRequestValue> syncRequestValueFactory = new SyncRequestValueFactory( apiService ); 204 requestControlFactories.put( syncRequestValueFactory.getOid(), syncRequestValueFactory ); 205 206 if ( LOG.isInfoEnabled() ) 207 { 208 LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, syncRequestValueFactory.getOid() ) ); 209 } 210 211 // SyncStateValue 212 ControlFactory<SyncStateValue> syncStateValueFactory = new SyncStateValueFactory( apiService ); 213 requestControlFactories.put( syncStateValueFactory.getOid(), syncStateValueFactory ); 214 responseControlFactories.put( syncStateValueFactory.getOid(), syncStateValueFactory ); 215 216 if ( LOG.isInfoEnabled() ) 217 { 218 LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, syncStateValueFactory.getOid() ) ); 219 } 220 221 // TransactionSpecification 222 ControlFactory<TransactionSpecification> transactionSpecificationFactory = new TransactionSpecificationFactory( apiService ); 223 requestControlFactories.put( transactionSpecificationFactory.getOid(), transactionSpecificationFactory ); 224 225 if ( LOG.isInfoEnabled() ) 226 { 227 LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, transactionSpecificationFactory.getOid() ) ); 228 } 229 230 // VirtualListViewRequest 231 ControlFactory<VirtualListViewRequest> virtualListViewRequestFactory = new VirtualListViewRequestFactory( 232 apiService ); 233 requestControlFactories.put( virtualListViewRequestFactory.getOid(), virtualListViewRequestFactory ); 234 235 if ( LOG.isInfoEnabled() ) 236 { 237 LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, virtualListViewRequestFactory.getOid() ) ); 238 } 239 240 // VirtualListViewResponse 241 ControlFactory<VirtualListViewResponse> virtualListViewResponseFactory = new VirtualListViewResponseFactory( 242 apiService ); 243 responseControlFactories.put( virtualListViewResponseFactory.getOid(), virtualListViewResponseFactory ); 244 245 if ( LOG.isInfoEnabled() ) 246 { 247 LOG.info( I18n.msg( I18n.MSG_06000_REGISTERED_CONTROL_FACTORY, virtualListViewResponseFactory.getOid() ) ); 248 } 249 } 250 251 252 /** 253 * Load the extras extended operations : 254 * <ul> 255 * <li>cancel</li> 256 * <li>certGeneration</li> 257 * <li>gracefuShutdown</li> 258 * <li>storedProcedure</li> 259 * <li>gracefulDisconnect</li> 260 * <li>passwordModify</li> 261 * <li>whoAmI</li> 262 * <li>startTls</li> 263 * <li>startTransaction</li> 264 * </ul> 265 * 266 * @param apiService The LdapApiService to use 267 */ 268 public static void loadExtrasExtendedOperations( LdapApiService apiService ) 269 { 270 Map<String, ExtendedOperationFactory> extendedRequestFactories = apiService.getExtendedRequestFactories(); 271 Map<String, ExtendedOperationFactory> extendedResponseFactories = apiService.getExtendedResponseFactories(); 272 273 CancelFactory cancelFactory = new CancelFactory( apiService ); 274 extendedRequestFactories.put( cancelFactory.getOid(), cancelFactory ); 275 extendedResponseFactories.put( cancelFactory.getOid(), cancelFactory ); 276 277 if ( LOG.isInfoEnabled() ) 278 { 279 LOG.info( I18n.msg( I18n.MSG_06001_REGISTERED_EXTENDED_OP_FACTORY, cancelFactory.getOid() ) ); 280 } 281 282 CertGenerationFactory certGenerationFactory = new CertGenerationFactory( apiService ); 283 extendedRequestFactories.put( certGenerationFactory.getOid(), certGenerationFactory ); 284 extendedResponseFactories.put( certGenerationFactory.getOid(), certGenerationFactory ); 285 286 if ( LOG.isInfoEnabled() ) 287 { 288 LOG.info( I18n.msg( I18n.MSG_06001_REGISTERED_EXTENDED_OP_FACTORY, certGenerationFactory.getOid() ) ); 289 } 290 291 EndTransactionFactory endTransactionFactory = new EndTransactionFactory( apiService ); 292 extendedRequestFactories.put( endTransactionFactory.getOid(), endTransactionFactory ); 293 extendedResponseFactories.put( endTransactionFactory.getOid(), endTransactionFactory ); 294 295 if ( LOG.isInfoEnabled() ) 296 { 297 LOG.info( I18n.msg( I18n.MSG_06001_REGISTERED_EXTENDED_OP_FACTORY, endTransactionFactory.getOid() ) ); 298 } 299 300 GracefulDisconnectFactory gracefulDisconnectFactory = new GracefulDisconnectFactory( apiService ); 301 extendedResponseFactories.put( gracefulDisconnectFactory.getOid(), gracefulDisconnectFactory ); 302 303 if ( LOG.isInfoEnabled() ) 304 { 305 LOG.info( I18n.msg( I18n.MSG_06001_REGISTERED_EXTENDED_OP_FACTORY, gracefulDisconnectFactory.getOid() ) ); 306 } 307 308 GracefulShutdownFactory gracefulShutdownFactory = new GracefulShutdownFactory( apiService ); 309 extendedRequestFactories.put( gracefulShutdownFactory.getOid(), gracefulShutdownFactory ); 310 extendedResponseFactories.put( gracefulShutdownFactory.getOid(), gracefulShutdownFactory ); 311 312 313 if ( LOG.isInfoEnabled() ) 314 { 315 LOG.info( I18n.msg( I18n.MSG_06001_REGISTERED_EXTENDED_OP_FACTORY, gracefulShutdownFactory.getOid() ) ); 316 } 317 318 NoDFactory noticeOfDisconnectFactory = new NoDFactory( apiService ); 319 extendedResponseFactories.put( noticeOfDisconnectFactory.getOid(), noticeOfDisconnectFactory ); 320 321 if ( LOG.isInfoEnabled() ) 322 { 323 LOG.info( I18n.msg( I18n.MSG_06001_REGISTERED_EXTENDED_OP_FACTORY, noticeOfDisconnectFactory.getOid() ) ); 324 } 325 326 PasswordModifyFactory passwordModifyFactory = new PasswordModifyFactory( apiService ); 327 extendedRequestFactories.put( passwordModifyFactory.getOid(), passwordModifyFactory ); 328 extendedResponseFactories.put( passwordModifyFactory.getOid(), passwordModifyFactory ); 329 330 if ( LOG.isInfoEnabled() ) 331 { 332 LOG.info( I18n.msg( I18n.MSG_06001_REGISTERED_EXTENDED_OP_FACTORY, passwordModifyFactory.getOid() ) ); 333 } 334 335 StartTlsFactory startTlsFactory = new StartTlsFactory( apiService ); 336 extendedRequestFactories.put( startTlsFactory.getOid(), startTlsFactory ); 337 extendedResponseFactories.put( startTlsFactory.getOid(), startTlsFactory ); 338 339 if ( LOG.isInfoEnabled() ) 340 { 341 LOG.info( I18n.msg( I18n.MSG_06001_REGISTERED_EXTENDED_OP_FACTORY, startTlsFactory.getOid() ) ); 342 } 343 344 StartTransactionFactory startTransactionFactory = new StartTransactionFactory( apiService ); 345 extendedRequestFactories.put( startTransactionFactory.getOid(), startTransactionFactory ); 346 extendedResponseFactories.put( startTransactionFactory.getOid(), startTransactionFactory ); 347 348 if ( LOG.isInfoEnabled() ) 349 { 350 LOG.info( I18n.msg( I18n.MSG_06001_REGISTERED_EXTENDED_OP_FACTORY, startTransactionFactory.getOid() ) ); 351 } 352 353 StoredProcedureFactory storedProcedureFactory = new StoredProcedureFactory( apiService ); 354 extendedRequestFactories.put( storedProcedureFactory.getOid(), storedProcedureFactory ); 355 extendedResponseFactories.put( storedProcedureFactory.getOid(), storedProcedureFactory ); 356 357 if ( LOG.isInfoEnabled() ) 358 { 359 LOG.info( I18n.msg( I18n.MSG_06001_REGISTERED_EXTENDED_OP_FACTORY, storedProcedureFactory.getOid() ) ); 360 } 361 362 WhoAmIFactory whoAmIFactory = new WhoAmIFactory( apiService ); 363 extendedRequestFactories.put( whoAmIFactory.getOid(), whoAmIFactory ); 364 extendedResponseFactories.put( whoAmIFactory.getOid(), whoAmIFactory ); 365 366 if ( LOG.isInfoEnabled() ) 367 { 368 LOG.info( I18n.msg( I18n.MSG_06001_REGISTERED_EXTENDED_OP_FACTORY, whoAmIFactory.getOid() ) ); 369 } 370 } 371 372 373 /** 374 * Load the extras intermediate responses : 375 * <ul> 376 * <li>syncInfovalue</li> 377 * </ul> 378 * 379 * @param apiService The LdapApiService to use 380 */ 381 public static void loadExtrasIntermediateResponses( LdapApiService apiService ) 382 { 383 Map<String, IntermediateOperationFactory> intermediateResponseFactories = apiService 384 .getIntermediateResponseFactories(); 385 386 SyncInfoValueFactory syncInfoValueFactory = new SyncInfoValueFactory(); 387 intermediateResponseFactories.put( syncInfoValueFactory.getOid(), syncInfoValueFactory ); 388 389 if ( LOG.isInfoEnabled() ) 390 { 391 LOG.info( I18n.msg( I18n.MSG_06002_REGISTERED_INTERMEDIATE_FACTORY, syncInfoValueFactory.getOid() ) ); 392 } 393 } 394}