Example usage for org.springframework.security.ldap.server ApacheDSContainer destroy

List of usage examples for org.springframework.security.ldap.server ApacheDSContainer destroy

Introduction

In this page you can find the example usage for org.springframework.security.ldap.server ApacheDSContainer destroy.

Prototype

public void destroy() throws Exception 

Source Link

Usage

From source file:org.springframework.security.ldap.server.ApacheDSContainerTests.java

@Test
public void failsToStartThrowsException() throws Exception {
    ApacheDSContainer server1 = new ApacheDSContainer("dc=springframework,dc=org",
            "classpath:test-server.ldif");
    ApacheDSContainer server2 = new ApacheDSContainer("dc=springframework,dc=org", "classpath:missing.ldif");
    List<Integer> ports = getDefaultPorts(1);
    server1.setPort(ports.get(0));/* w  w  w .j  a  v  a 2 s.co m*/
    server2.setPort(ports.get(0));
    try {
        server1.afterPropertiesSet();
        try {
            server2.afterPropertiesSet();
            fail("Expected Exception");
        } catch (RuntimeException success) {
        }
    } finally {
        try {
            server1.destroy();
        } catch (Throwable t) {
        }
        try {
            server2.destroy();
        } catch (Throwable t) {
        }
    }
}

From source file:org.springframework.security.ldap.server.ApacheDSContainerTests.java

@Test
public void multipleInstancesSimultanciously() throws Exception {
    ApacheDSContainer server1 = new ApacheDSContainer("dc=springframework,dc=org",
            "classpath:test-server.ldif");
    ApacheDSContainer server2 = new ApacheDSContainer("dc=springframework,dc=org",
            "classpath:test-server.ldif");
    List<Integer> ports = getDefaultPorts(2);
    server1.setPort(ports.get(0));/*from  w ww. j  a v a2 s .  c om*/
    server2.setPort(ports.get(1));
    try {
        server1.afterPropertiesSet();
        server2.afterPropertiesSet();
    } finally {
        try {
            server1.destroy();
        } catch (Throwable t) {
        }
        try {
            server2.destroy();
        } catch (Throwable t) {
        }
    }
}

From source file:org.springframework.security.ldap.server.ApacheDSContainerTests.java

/**
 * This test starts an LDAP server using LDAPs (LDAP over SSL). A self-signed certificate is being used, which was
 * previously generated with:/*from   ww w .  java 2  s.com*/
 *
 * <pre>
 * {@code
 * keytool -genkey -alias spring -keyalg RSA -keystore spring.keystore -validity 3650 -storetype JKS \
 * -dname "CN=localhost, OU=Spring, O=Pivotal, L=Kailua-Kona, ST=HI, C=US" -keypass spring -storepass spring
 * }
 * </pre>
 * @throws Exception
 */
@Test
public void startWithLdapOverSsl() throws Exception {

    final ClassPathResource keyStoreResource = new ClassPathResource(
            "/org/springframework/security/ldap/server/spring.keystore");
    final File temporaryKeyStoreFile = new File(temporaryFolder.getRoot(), "spring.keystore");
    FileCopyUtils.copy(keyStoreResource.getInputStream(), new FileOutputStream(temporaryKeyStoreFile));

    assertThat(temporaryKeyStoreFile).isFile();

    ApacheDSContainer server = new ApacheDSContainer("dc=springframework,dc=org", "classpath:test-server.ldif");

    List<Integer> ports = getDefaultPorts(1);
    server.setPort(ports.get(0));

    server.setLdapOverSslEnabled(true);
    server.setKeyStoreFile(temporaryKeyStoreFile);
    server.setCertificatePassord("spring");

    try {
        server.afterPropertiesSet();
    } finally {
        try {
            server.destroy();
        } catch (Throwable t) {
        }
    }
}