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

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

Introduction

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

Prototype

public void setCertificatePassord(String certificatePassord) 

Source Link

Document

Will set the certificate password on the underlying LdapServer .

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  w w  w  . j a  v a2 s. 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  ww  w  .ja v  a 2 s  .  co  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) {
        }
    }
}