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 org.apache.ldap.server.jndi.EnvKeys;
21
22 import javax.naming.*;
23 import java.io.File;
24 import java.io.IOException;
25 import java.util.Hashtable;
26
27
28 /***
29 * A set of simple tests to make sure simple authentication is working as it
30 * should.
31 *
32 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
33 * @version $Rev: 165195 $
34 */
35 public class DisableAnonBindTest extends AbstractServerTest
36 {
37 /***
38 * Cleans up old database files on creation.
39 * @throws IOException
40 */
41 public DisableAnonBindTest() throws IOException
42 {
43 doDelete( new File( "target" + File.separator + "server" ) );
44 }
45
46
47 /***
48 * Customizes setup for each test case.
49 *
50 * @throws Exception
51 */
52 protected void setUp() throws Exception
53 {
54 if ( getName().equals( "testDisableAnonymousBinds" ) )
55 {
56 extras.put( EnvKeys.DISABLE_ANONYMOUS, "true" );
57 }
58
59 super.setUp();
60 }
61
62
63 /***
64 * Test to make sure anonymous binds are disabled when going through
65 * the wire protocol.
66 *
67 * @throws Exception if anything goes wrong
68 */
69 public void testDisableAnonymousBinds() throws Exception
70 {
71
72
73 final Hashtable env = new Hashtable();
74
75 env.put( Context.PROVIDER_URL, "ldap://localhost:" + port + "/ou=system" );
76
77 env.put( Context.SECURITY_AUTHENTICATION, "none" );
78
79 env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
80
81 InitialContext ctx = null;
82
83 try
84 {
85 ctx = new InitialContext( env );
86
87 fail( "If anonymous binds are disabled we should never get here!" );
88 }
89 catch ( NoPermissionException e )
90 {
91 assertNull( ctx );
92
93 assertNotNull( e );
94 }
95 }
96 }