1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ldap.server;
18
19
20 import java.util.Hashtable;
21
22 import javax.naming.Context;
23 import javax.naming.InitialContext;
24 import javax.naming.NoPermissionException;
25
26
27 /***
28 * A set of simple tests to make sure simple authentication is working as it
29 * should.
30 *
31 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
32 * @version $Rev: 264732 $
33 */
34 public class DisableAnonBindTest extends AbstractServerTest
35 {
36 /***
37 * Cleans up old database files on creation.
38 */
39 public DisableAnonBindTest()
40 {
41 }
42
43
44 /***
45 * Customizes setup for each test case.
46 *
47 * @throws Exception
48 */
49 public void setUp() throws Exception
50 {
51 configuration.setAllowAnonymousAccess( false );
52 super.setUp();
53 }
54
55
56 /***
57 * Test to make sure anonymous binds are disabled when going through
58 * the wire protocol.
59 *
60 * @throws Exception if anything goes wrong
61 */
62 public void testDisableAnonymousBinds() throws Exception
63 {
64
65
66 final Hashtable env = new Hashtable();
67
68 env.put( Context.PROVIDER_URL, "ldap://localhost:" + port + "/ou=system" );
69 env.put( Context.SECURITY_AUTHENTICATION, "none" );
70 env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
71
72 try
73 {
74 new InitialContext( env );
75 fail( "If anonymous binds are disabled we should never get here!" );
76 }
77 catch ( NoPermissionException e )
78 {
79 }
80 }
81 }