View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.directory.server.integ;
20  
21  
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  import org.apache.directory.server.core.DefaultDirectoryService;
26  import org.apache.directory.server.core.DirectoryService;
27  import org.apache.directory.server.core.integ.IntegrationUtils;
28  import org.apache.directory.server.ldap.LdapService;
29  import org.apache.directory.server.ldap.handlers.bind.MechanismHandler;
30  import org.apache.directory.server.ldap.handlers.bind.SimpleMechanismHandler;
31  import org.apache.directory.server.ldap.handlers.bind.cramMD5.CramMd5MechanismHandler;
32  import org.apache.directory.server.ldap.handlers.bind.digestMD5.DigestMd5MechanismHandler;
33  import org.apache.directory.server.ldap.handlers.bind.gssapi.GssapiMechanismHandler;
34  import org.apache.directory.server.ldap.handlers.bind.ntlm.NtlmMechanismHandler;
35  import org.apache.directory.server.ldap.handlers.extended.StartTlsHandler;
36  import org.apache.directory.server.ldap.handlers.extended.StoredProcedureExtendedOperationHandler;
37  import org.apache.directory.server.protocol.shared.SocketAcceptor;
38  import org.apache.directory.shared.ldap.constants.SupportedSaslMechanisms;
39  import org.apache.mina.util.AvailablePortFinder;
40  
41  
42  /**
43   * A factory used to generate differently configured DirectoryService objects.
44   * Since the DirectoryService itself is what is configured then a factory for
45   * these objects acts as a configurator.  Tests can provide different factory
46   * methods to be used.
47   *
48   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
49   * @version $Rev$, $Date$
50   */
51  public interface LdapServerFactory
52  {
53      /**
54       * The default factory returns stock instances of a directory
55       * service with smart defaults
56       */
57      LdapServerFactory DEFAULT = new LdapServerFactory()
58      {
59          public LdapService newInstance() throws Exception
60          {
61              DirectoryService service = new DefaultDirectoryService();
62              IntegrationUtils.doDelete( service.getWorkingDirectory() );
63              service.getChangeLog().setEnabled( true );
64              service.setShutdownHookEnabled( false );
65  
66              // change the working directory to something that is unique
67              // on the system and somewhere either under target directory
68              // or somewhere in a temp area of the machine.
69  
70              LdapService ldapService = new LdapService();
71              ldapService.setDirectoryService( service );
72              ldapService.setSocketAcceptor( new SocketAcceptor( null ) );
73              ldapService.setIpPort( AvailablePortFinder.getNextAvailable( 1024 ) );
74              ldapService.addExtendedOperationHandler( new StartTlsHandler() );
75              ldapService.addExtendedOperationHandler( new StoredProcedureExtendedOperationHandler() );
76  
77              // Setup SASL Mechanisms
78              
79              Map<String, MechanismHandler> mechanismHandlerMap = new HashMap<String,MechanismHandler>();
80              mechanismHandlerMap.put( SupportedSaslMechanisms.PLAIN, new SimpleMechanismHandler() );
81  
82              CramMd5MechanismHandler cramMd5MechanismHandler = new CramMd5MechanismHandler();
83              mechanismHandlerMap.put( SupportedSaslMechanisms.CRAM_MD5, cramMd5MechanismHandler );
84  
85              DigestMd5MechanismHandler digestMd5MechanismHandler = new DigestMd5MechanismHandler();
86              mechanismHandlerMap.put( SupportedSaslMechanisms.DIGEST_MD5, digestMd5MechanismHandler );
87  
88              GssapiMechanismHandler gssapiMechanismHandler = new GssapiMechanismHandler();
89              mechanismHandlerMap.put( SupportedSaslMechanisms.GSSAPI, gssapiMechanismHandler );
90  
91              NtlmMechanismHandler ntlmMechanismHandler = new NtlmMechanismHandler();
92              mechanismHandlerMap.put( SupportedSaslMechanisms.NTLM, ntlmMechanismHandler );
93              mechanismHandlerMap.put( SupportedSaslMechanisms.GSS_SPNEGO, ntlmMechanismHandler );
94  
95              ldapService.setSaslMechanismHandlers( mechanismHandlerMap );
96  
97              return ldapService;
98          }
99      };
100 
101     
102     LdapService newInstance() throws Exception;
103 }