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

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

Introduction

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

Prototype

public void setKeyStoreFile(File keyStoreFile) 

Source Link

Document

The keyStore must not be null and must be a valid file.

Usage

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

@Test
public void startWithLdapOverSslWithWrongPassword() 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));//from   ww  w  .  j a v a  2s  . c o  m

    server.setLdapOverSslEnabled(true);
    server.setKeyStoreFile(temporaryKeyStoreFile);
    server.setCertificatePassord("incorrect-password");

    try {
        server.afterPropertiesSet();
        fail("Expected a RuntimeException to be thrown.");
    } catch (RuntimeException e) {
        assertThat(e).hasMessage("Server startup failed");
        assertThat(e).hasRootCauseInstanceOf(UnrecoverableKeyException.class);
    }
}

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   w w w .j a  v  a 2s.  c o m
 *
 * <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) {
        }
    }
}