Use dynamic port selection for LDAP listeners in LDAP tests.

Instead of using fixed ports for the listeners of the in-memory
LDAP server, let the listeners select ports and then save them in
the authentication mode instance. This way we prevent port collisions,
which especially showed up under Windows.
diff --git a/src/test/java/com/gitblit/tests/LdapBasedUnitTest.java b/src/test/java/com/gitblit/tests/LdapBasedUnitTest.java
index cf3ab1f..7aec50e 100644
--- a/src/test/java/com/gitblit/tests/LdapBasedUnitTest.java
+++ b/src/test/java/com/gitblit/tests/LdapBasedUnitTest.java
@@ -74,9 +74,9 @@
 	 *
 	 */
 	protected enum AuthMode {
-		ANONYMOUS(1389),
-		DS_MANAGER(2389),
-		USR_MANAGER(3389);
+		ANONYMOUS,
+		DS_MANAGER,
+		USR_MANAGER;
 
 
 		private int ldapPort;
@@ -84,7 +84,7 @@
 		private InMemoryDirectoryServerSnapshot dsSnapshot;
 		private BindTracker bindTracker;
 
-		AuthMode(int port) {
+		void setLdapPort(int port) {
 			this.ldapPort = port;
 		}
 
@@ -151,23 +151,26 @@
 	public static void ldapInit() throws Exception {
 		InMemoryDirectoryServer ds;
 		InMemoryDirectoryServerConfig config = createInMemoryLdapServerConfig(AuthMode.ANONYMOUS);
-		config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("default", AuthMode.ANONYMOUS.ldapPort()));
+		config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("anonymous"));
 		ds = createInMemoryLdapServer(config);
 		AuthMode.ANONYMOUS.setDS(ds);
+		AuthMode.ANONYMOUS.setLdapPort(ds.getListenPort("anonymous"));
 
 
 		config = createInMemoryLdapServerConfig(AuthMode.DS_MANAGER);
-		config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("default", AuthMode.DS_MANAGER.ldapPort()));
+		config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("ds_manager"));
 		config.setAuthenticationRequiredOperationTypes(EnumSet.allOf(OperationType.class));
 		ds = createInMemoryLdapServer(config);
 		AuthMode.DS_MANAGER.setDS(ds);
+		AuthMode.DS_MANAGER.setLdapPort(ds.getListenPort("ds_manager"));
 
 
 		config = createInMemoryLdapServerConfig(AuthMode.USR_MANAGER);
-		config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("default", AuthMode.USR_MANAGER.ldapPort()));
+		config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("usr_manager"));
 		config.setAuthenticationRequiredOperationTypes(EnumSet.allOf(OperationType.class));
 		ds = createInMemoryLdapServer(config);
 		AuthMode.USR_MANAGER.setDS(ds);
+		AuthMode.USR_MANAGER.setLdapPort(ds.getListenPort("usr_manager"));
 
 	}
 
@@ -220,19 +223,17 @@
 	protected MemorySettings getSettings() {
 		Map<String, Object> backingMap = new HashMap<String, Object>();
 		backingMap.put(Keys.realm.userService, usersConf.getAbsolutePath());
+		backingMap.put(Keys.realm.ldap.server, "ldap://localhost:" + authMode.ldapPort());
 		switch(authMode) {
 		case ANONYMOUS:
-			backingMap.put(Keys.realm.ldap.server, "ldap://localhost:" + authMode.ldapPort());
 			backingMap.put(Keys.realm.ldap.username, "");
 			backingMap.put(Keys.realm.ldap.password, "");
 			break;
 		case DS_MANAGER:
-			backingMap.put(Keys.realm.ldap.server, "ldap://localhost:" + authMode.ldapPort());
 			backingMap.put(Keys.realm.ldap.username, DIRECTORY_MANAGER);
 			backingMap.put(Keys.realm.ldap.password, "password");
 			break;
 		case USR_MANAGER:
-			backingMap.put(Keys.realm.ldap.server, "ldap://localhost:" + authMode.ldapPort());
 			backingMap.put(Keys.realm.ldap.username, USER_MANAGER);
 			backingMap.put(Keys.realm.ldap.password, "passwd");
 			break;