KEYCLOAK-2281 added ldap tests over ssl
This commit is contained in:
parent
a73dd537f3
commit
e2ad7608c8
3 changed files with 35 additions and 3 deletions
|
@ -21,6 +21,7 @@ import java.util.Map;
|
|||
import java.util.Properties;
|
||||
|
||||
import org.junit.rules.ExternalResource;
|
||||
import org.keycloak.models.LDAPConstants;
|
||||
import org.keycloak.util.ldap.LDAPEmbeddedServer;
|
||||
|
||||
/**
|
||||
|
@ -30,6 +31,14 @@ public class LDAPRule extends ExternalResource {
|
|||
|
||||
public static final String LDAP_CONNECTION_PROPERTIES_LOCATION = "classpath:ldap/ldap-connection.properties";
|
||||
|
||||
private static final String PROPERTY_ENABLE_SSL = "enableSSL";
|
||||
|
||||
private static final String PROPERTY_KEYSTORE_FILE = "keystoreFile";
|
||||
|
||||
private static final String PRIVATE_KEY = "keystore/keycloak.jks";
|
||||
|
||||
private static final String PROPERTY_CERTIFICATE_PASSWORD = "certificatePassword";
|
||||
|
||||
protected LDAPTestConfiguration ldapTestConfiguration;
|
||||
protected LDAPEmbeddedServer ldapEmbeddedServer;
|
||||
|
||||
|
@ -66,6 +75,11 @@ public class LDAPRule extends ExternalResource {
|
|||
Properties defaultProperties = new Properties();
|
||||
defaultProperties.setProperty(LDAPEmbeddedServer.PROPERTY_DSF, LDAPEmbeddedServer.DSF_INMEMORY);
|
||||
defaultProperties.setProperty(LDAPEmbeddedServer.PROPERTY_LDIF_FILE, "classpath:ldap/users.ldif");
|
||||
defaultProperties.setProperty(LDAPConstants.CONNECTION_URL, "ldaps://localhost:10636");
|
||||
defaultProperties.setProperty(LDAPEmbeddedServer.PROPERTY_BIND_PORT, "10636");
|
||||
defaultProperties.setProperty(PROPERTY_ENABLE_SSL, "true");
|
||||
defaultProperties.setProperty(PROPERTY_CERTIFICATE_PASSWORD, "secret");
|
||||
defaultProperties.setProperty(PROPERTY_KEYSTORE_FILE, this.getClass().getClassLoader().getResource(LDAPRule.PRIVATE_KEY).getFile());
|
||||
|
||||
return new LDAPEmbeddedServer(defaultProperties);
|
||||
}
|
||||
|
|
|
@ -57,6 +57,22 @@ public class UserFederationLdapConnectionTest extends AbstractAdminTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLdapConnectionsSsl() {
|
||||
|
||||
Response response = realm.testLDAPConnection(LDAPConnectionTestManager.TEST_CONNECTION, "ldaps://localhost:10636", "foo", "bar", "false");
|
||||
assertStatus(response, 204);
|
||||
|
||||
response = realm.testLDAPConnection(LDAPConnectionTestManager.TEST_CONNECTION, "ldaps://localhostt:10636", "foo", "bar", "false");
|
||||
assertStatus(response, 400);
|
||||
|
||||
response = realm.testLDAPConnection(LDAPConnectionTestManager.TEST_AUTHENTICATION, "ldaps://localhost:10636", "foo", "bar", "false");
|
||||
assertStatus(response, 400);
|
||||
|
||||
response = realm.testLDAPConnection(LDAPConnectionTestManager.TEST_AUTHENTICATION, "ldaps://localhost:10636", "uid=admin,ou=system", "secret", "true");
|
||||
assertStatus(response, 204);
|
||||
}
|
||||
|
||||
private void assertStatus(Response response, int status) {
|
||||
Assert.assertEquals(status, response.getStatus());
|
||||
response.close();
|
||||
|
|
|
@ -219,13 +219,15 @@ public class LDAPEmbeddedServer {
|
|||
ldapServer.setSearchBaseDn(this.baseDN);
|
||||
|
||||
// Read the transports
|
||||
Transport ldap = new TcpTransport(this.bindHost, this.bindPort, 3, 50);
|
||||
Transport ldaps = new TcpTransport(this.bindHost, this.bindPort, 3, 50);
|
||||
if (enableSSL) {
|
||||
ldap.setEnableSSL(true);
|
||||
ldaps.setEnableSSL(true);
|
||||
ldapServer.setKeystoreFile(keystoreFile);
|
||||
ldapServer.setCertificatePassword(certPassword);
|
||||
Transport ldap = new TcpTransport(this.bindHost, 10389, 3, 50);
|
||||
ldapServer.addTransports( ldap );
|
||||
}
|
||||
ldapServer.addTransports( ldap );
|
||||
ldapServer.addTransports( ldaps );
|
||||
|
||||
// Associate the DS to this LdapServer
|
||||
ldapServer.setDirectoryService( directoryService );
|
||||
|
|
Loading…
Reference in a new issue