Search in sources :

Example 6 with CertificateRepo

use of org.apache.cxf.xkms.x509.repo.CertificateRepo in project cxf by apache.

the class LDAPCertificateRepoTest method testFindUserCertForNonExistentDn.

@Test
public void testFindUserCertForNonExistentDn() throws URISyntaxException, NamingException, CertificateException {
    CertificateRepo persistenceManager = createLdapCertificateRepo();
    X509Certificate cert = persistenceManager.findBySubjectDn("CN=wrong");
    assertNull("Certificate should be null", cert);
}
Also used : LdapCertificateRepo(org.apache.cxf.xkms.x509.repo.ldap.LdapCertificateRepo) CertificateRepo(org.apache.cxf.xkms.x509.repo.CertificateRepo) X509Certificate(java.security.cert.X509Certificate) Test(org.junit.Test)

Example 7 with CertificateRepo

use of org.apache.cxf.xkms.x509.repo.CertificateRepo in project cxf by apache.

the class LDAPCertificateRepoTest method testSaveServiceCert.

@Test
public void testSaveServiceCert() throws Exception {
    CertificateRepo persistenceManager = createLdapCertificateRepo();
    URL url = this.getClass().getResource("cert1.cer");
    CertificateFactory factory = CertificateFactory.getInstance("X.509");
    X509Certificate cert = (X509Certificate) factory.generateCertificate(url.openStream());
    assertNotNull(cert);
    UseKeyWithType key = new UseKeyWithType();
    key.setApplication(Applications.SERVICE_NAME.getUri());
    key.setIdentifier(EXPECTED_SERVICE_URI);
    persistenceManager.saveCertificate(cert, key);
    // Search by DN
    X509Certificate foundCert = persistenceManager.findByServiceName(EXPECTED_SERVICE_URI);
    assertNotNull(foundCert);
    // Search by UID
    foundCert = persistenceManager.findByServiceName(cert.getSubjectX500Principal().getName());
    assertNotNull(foundCert);
}
Also used : UseKeyWithType(org.apache.cxf.xkms.model.xkms.UseKeyWithType) LdapCertificateRepo(org.apache.cxf.xkms.x509.repo.ldap.LdapCertificateRepo) CertificateRepo(org.apache.cxf.xkms.x509.repo.CertificateRepo) CertificateFactory(java.security.cert.CertificateFactory) URL(java.net.URL) X509Certificate(java.security.cert.X509Certificate) Test(org.junit.Test)

Example 8 with CertificateRepo

use of org.apache.cxf.xkms.x509.repo.CertificateRepo in project cxf by apache.

the class LDAPCertificateRepoTest method testFindUserCertForNonExistantDn.

@Test
@Ignore
public void testFindUserCertForNonExistantDn() throws URISyntaxException, NamingException, CertificateException {
    CertificateRepo persistenceManager = createLdapCertificateRepo();
    X509Certificate cert = persistenceManager.findBySubjectDn("CN=wrong");
    Assert.assertNull("Certifiacte should be null", cert);
}
Also used : CertificateRepo(org.apache.cxf.xkms.x509.repo.CertificateRepo) X509Certificate(java.security.cert.X509Certificate) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with CertificateRepo

use of org.apache.cxf.xkms.x509.repo.CertificateRepo in project cxf by apache.

the class LDAPCertificateRepoTest method testFindServiceCert.

@Test
@Ignore
public void testFindServiceCert() throws URISyntaxException, NamingException, CertificateException {
    CertificateRepo persistenceManager = createLdapCertificateRepo();
    String serviceUri = "cn=http:\\/\\/myservice.apache.org\\/MyServiceName,ou=services";
    X509Certificate cert = persistenceManager.findByServiceName(serviceUri);
    Assert.assertEquals(EXPECTED_SUBJECT_DN, cert.getSubjectDN().toString());
}
Also used : CertificateRepo(org.apache.cxf.xkms.x509.repo.CertificateRepo) X509Certificate(java.security.cert.X509Certificate) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with CertificateRepo

use of org.apache.cxf.xkms.x509.repo.CertificateRepo in project cxf by apache.

the class TrustedAuthorityValidatorTest method setUpCertificateRepo.

@Before
public void setUpCertificateRepo() throws CertificateException {
    File storageDir = new File("target/teststore_trusted_authority_validator");
    FileUtils.removeDir(storageDir);
    storageDir.mkdirs();
    certificateRepo = new FileCertificateRepo("target/teststore_trusted_authority_validator");
    UseKeyWithType rootKey = new UseKeyWithType();
    rootKey.setApplication(Applications.PKIX.getUri());
    String subjectDN = certificateRoot.getSubjectX500Principal().getName();
    rootKey.setIdentifier(subjectDN);
    certificateRepo.saveTrustedCACertificate(certificateRoot, rootKey);
    UseKeyWithType aliceKey = new UseKeyWithType();
    aliceKey.setApplication(Applications.PKIX.getUri());
    subjectDN = certificateAlice.getSubjectX500Principal().getName();
    aliceKey.setIdentifier(subjectDN);
    certificateRepo.saveCACertificate(certificateAlice, aliceKey);
}
Also used : UseKeyWithType(org.apache.cxf.xkms.model.xkms.UseKeyWithType) File(java.io.File) FileCertificateRepo(org.apache.cxf.xkms.x509.repo.file.FileCertificateRepo) Before(org.junit.Before)

Aggregations

CertificateRepo (org.apache.cxf.xkms.x509.repo.CertificateRepo)11 Test (org.junit.Test)11 X509Certificate (java.security.cert.X509Certificate)9 LdapCertificateRepo (org.apache.cxf.xkms.x509.repo.ldap.LdapCertificateRepo)7 UseKeyWithType (org.apache.cxf.xkms.model.xkms.UseKeyWithType)5 Ignore (org.junit.Ignore)4 File (java.io.File)3 CertificateFactory (java.security.cert.CertificateFactory)3 URL (java.net.URL)2 FileCertificateRepo (org.apache.cxf.xkms.x509.repo.file.FileCertificateRepo)2 Before (org.junit.Before)2 FileInputStream (java.io.FileInputStream)1 LocateRequestType (org.apache.cxf.xkms.model.xkms.LocateRequestType)1 UnverifiedKeyBindingType (org.apache.cxf.xkms.model.xkms.UnverifiedKeyBindingType)1 LdapSchemaConfig (org.apache.cxf.xkms.x509.repo.ldap.LdapSchemaConfig)1 LdapSearch (org.apache.cxf.xkms.x509.repo.ldap.LdapSearch)1