Search in sources :

Example 1 with X509CertificateGenerator

use of com.thoughtworks.go.security.X509CertificateGenerator in project gocd by gocd.

the class FakeGoServer method createX509Certificate.

private void createX509Certificate(File keystore, File truststore, File agentKeystore) {
    final String principalDn = "ou=Cruise server webserver certificate, cn=" + getHostname();
    X509CertificateGenerator generator = new X509CertificateGenerator();
    generator.createAndStoreX509Certificates(keystore, truststore, agentKeystore, PASSWORD, principalDn);
}
Also used : X509CertificateGenerator(com.thoughtworks.go.security.X509CertificateGenerator)

Example 2 with X509CertificateGenerator

use of com.thoughtworks.go.security.X509CertificateGenerator in project gocd by gocd.

the class GoSslSocketConnector method ensureX509Certificates.

private void ensureX509Certificates() {
    String principalDn = "ou=Cruise server webserver certificate, cn=" + getHostname();
    X509CertificateGenerator generator = new X509CertificateGenerator();
    generator.createAndStoreX509Certificates(keystore, truststore, agentKeystore, password, principalDn);
}
Also used : X509CertificateGenerator(com.thoughtworks.go.security.X509CertificateGenerator)

Example 3 with X509CertificateGenerator

use of com.thoughtworks.go.security.X509CertificateGenerator in project gocd by gocd.

the class X509AuthoritiesPopulatorTest method shouldNotReturnUserDetailsIfCertificateHasNoOu.

@Test
public void shouldNotReturnUserDetailsIfCertificateHasNoOu() {
    X509Certificate agentCertificate = new X509CertificateGenerator().createCertificateWithDn("CN=hostname").getFirstCertificate();
    try {
        populator.getUserDetails(agentCertificate);
        Assert.fail("Oh dear. You should have thrown an exception, silly!");
    } catch (BadCredentialsException ignored) {
    }
}
Also used : BadCredentialsException(org.springframework.security.BadCredentialsException) X509Certificate(java.security.cert.X509Certificate) X509CertificateGenerator(com.thoughtworks.go.security.X509CertificateGenerator) Test(org.junit.Test)

Example 4 with X509CertificateGenerator

use of com.thoughtworks.go.security.X509CertificateGenerator in project gocd by gocd.

the class AgentCertificateMother method agentCertificate.

public static Registration agentCertificate() {
    File tempKeystoreFile = TestFileUtil.createUniqueTempFile(authorityKeystorePath);
    X509CertificateGenerator certificateGenerator = new X509CertificateGenerator();
    certificateGenerator.createAndStoreCACertificates(tempKeystoreFile);
    return certificateGenerator.createAgentCertificate(tempKeystoreFile, "blah");
}
Also used : File(java.io.File) X509CertificateGenerator(com.thoughtworks.go.security.X509CertificateGenerator)

Example 5 with X509CertificateGenerator

use of com.thoughtworks.go.security.X509CertificateGenerator in project gocd by gocd.

the class X509AuthoritiesPopulatorTest method shouldReturnUserDetailsWithCorrectAuthorityIfAgentCertificateHasOu.

@Test
public void shouldReturnUserDetailsWithCorrectAuthorityIfAgentCertificateHasOu() {
    X509Certificate agentCertificate = new X509CertificateGenerator().createCertificateWithDn("CN=hostname, OU=agent").getFirstCertificate();
    UserDetails userDetails = populator.getUserDetails(agentCertificate);
    GrantedAuthority[] actual = userDetails.getAuthorities();
    GrantedAuthority expected = new GrantedAuthorityImpl(ROLE_AGENT);
    assertThat(actual.length, is(1));
    assertThat(actual[0], is(expected));
}
Also used : UserDetails(org.springframework.security.userdetails.UserDetails) GrantedAuthorityImpl(org.springframework.security.GrantedAuthorityImpl) GrantedAuthority(org.springframework.security.GrantedAuthority) X509Certificate(java.security.cert.X509Certificate) X509CertificateGenerator(com.thoughtworks.go.security.X509CertificateGenerator) Test(org.junit.Test)

Aggregations

X509CertificateGenerator (com.thoughtworks.go.security.X509CertificateGenerator)6 X509Certificate (java.security.cert.X509Certificate)2 Test (org.junit.Test)2 Registration (com.thoughtworks.go.security.Registration)1 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)1 File (java.io.File)1 BadCredentialsException (org.springframework.security.BadCredentialsException)1 GrantedAuthority (org.springframework.security.GrantedAuthority)1 GrantedAuthorityImpl (org.springframework.security.GrantedAuthorityImpl)1 UserDetails (org.springframework.security.userdetails.UserDetails)1