Search in sources :

Example 6 with UseKeyWithType

use of org.apache.cxf.xkms.model.xkms.UseKeyWithType in project cxf by apache.

the class LDAPCertificateRepoTest method testSave.

@Test
@Ignore
public void testSave() throws Exception {
    CertificateRepo persistenceManager = createLdapCertificateRepo();
    File certFile = new File("src/test/java/cert1.cer");
    Assert.assertTrue(certFile.exists());
    FileInputStream fis = new FileInputStream(certFile);
    CertificateFactory factory = CertificateFactory.getInstance("X.509");
    X509Certificate cert = (X509Certificate) factory.generateCertificate(fis);
    fis.close();
    UseKeyWithType key = new UseKeyWithType();
    key.setApplication(Applications.PKIX.getUri());
    key.setIdentifier(EXPECTED_SUBJECT_DN);
    persistenceManager.saveCertificate(cert, key);
    testFindBySubjectDnInternal(persistenceManager);
}
Also used : UseKeyWithType(org.apache.cxf.xkms.model.xkms.UseKeyWithType) CertificateRepo(org.apache.cxf.xkms.x509.repo.CertificateRepo) File(java.io.File) CertificateFactory(java.security.cert.CertificateFactory) FileInputStream(java.io.FileInputStream) X509Certificate(java.security.cert.X509Certificate) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with UseKeyWithType

use of org.apache.cxf.xkms.model.xkms.UseKeyWithType in project cxf by apache.

the class LDAPCertificateRepoTest method testSaveUserCert.

@Test
public void testSaveUserCert() throws Exception {
    IMocksControl c = EasyMock.createControl();
    LdapSearch ldapSearch = c.createMock(LdapSearch.class);
    ldapSearch.bind(EasyMock.eq(EXPECTED_SUBJECT_DN2 + "," + ROOT_DN), EasyMock.anyObject(Attributes.class));
    EasyMock.expectLastCall().once();
    LdapCertificateRepo ldapCertRepo = new LdapCertificateRepo(ldapSearch, LDAP_CERT_CONFIG, ROOT_DN);
    X509Certificate cert = getTestCert();
    c.replay();
    UseKeyWithType key = new UseKeyWithType();
    key.setApplication(Applications.PKIX.getUri());
    key.setIdentifier(EXPECTED_SUBJECT_DN2);
    ldapCertRepo.saveCertificate(cert, key);
    c.verify();
}
Also used : IMocksControl(org.easymock.IMocksControl) Attributes(javax.naming.directory.Attributes) UseKeyWithType(org.apache.cxf.xkms.model.xkms.UseKeyWithType) X509Certificate(java.security.cert.X509Certificate) Test(org.junit.Test)

Example 8 with UseKeyWithType

use of org.apache.cxf.xkms.model.xkms.UseKeyWithType in project cxf by apache.

the class XKMSServiceTest method testLocatePKIX.

@Test
public void testLocatePKIX() throws URISyntaxException, Exception {
    LocateRequestType request = XKMS_OF.createLocateRequestType();
    setGenericRequestParams(request);
    QueryKeyBindingType queryKeyBindingType = XKMS_OF.createQueryKeyBindingType();
    UseKeyWithType useKeyWithType = XKMS_OF.createUseKeyWithType();
    useKeyWithType.setIdentifier("CN=Dave, OU=Apache, O=CXF, L=CGN, ST=NRW, C=DE");
    useKeyWithType.setApplication(Applications.PKIX.getUri());
    locateCertificate(request, queryKeyBindingType, useKeyWithType);
}
Also used : QueryKeyBindingType(org.apache.cxf.xkms.model.xkms.QueryKeyBindingType) UseKeyWithType(org.apache.cxf.xkms.model.xkms.UseKeyWithType) LocateRequestType(org.apache.cxf.xkms.model.xkms.LocateRequestType) BasicIntegrationTest(org.apache.cxf.xkms.itests.BasicIntegrationTest) Test(org.junit.Test)

Example 9 with UseKeyWithType

use of org.apache.cxf.xkms.model.xkms.UseKeyWithType in project cxf by apache.

the class XKMSServiceTest method testLocateByEndpoint.

@Test
public void testLocateByEndpoint() throws URISyntaxException, Exception {
    LocateRequestType request = XKMS_OF.createLocateRequestType();
    setGenericRequestParams(request);
    QueryKeyBindingType queryKeyBindingType = XKMS_OF.createQueryKeyBindingType();
    UseKeyWithType useKeyWithType = XKMS_OF.createUseKeyWithType();
    useKeyWithType.setIdentifier("http://localhost:8080/services/TestService");
    useKeyWithType.setApplication(Applications.SERVICE_ENDPOINT.getUri());
    locateCertificate(request, queryKeyBindingType, useKeyWithType);
}
Also used : QueryKeyBindingType(org.apache.cxf.xkms.model.xkms.QueryKeyBindingType) UseKeyWithType(org.apache.cxf.xkms.model.xkms.UseKeyWithType) LocateRequestType(org.apache.cxf.xkms.model.xkms.LocateRequestType) BasicIntegrationTest(org.apache.cxf.xkms.itests.BasicIntegrationTest) Test(org.junit.Test)

Example 10 with UseKeyWithType

use of org.apache.cxf.xkms.model.xkms.UseKeyWithType in project cxf by apache.

the class X509Locator method locate.

@Override
public UnverifiedKeyBindingType locate(LocateRequestType request) {
    List<UseKeyWithType> keyIDs = parse(request);
    X509Certificate cert;
    try {
        cert = findCertificate(keyIDs);
        if (cert == null) {
            return null;
        }
        UnverifiedKeyBindingType result = new UnverifiedKeyBindingType();
        result.setKeyInfo(X509Utils.getKeyInfo(cert));
        return result;
    } catch (CertificateEncodingException e) {
        throw new XKMSCertificateException("Cannot encode certificate: " + e.getMessage(), e);
    } catch (CertificateException e1) {
        throw new XKMSCertificateException(e1.getMessage(), e1);
    }
}
Also used : XKMSCertificateException(org.apache.cxf.xkms.exception.XKMSCertificateException) UseKeyWithType(org.apache.cxf.xkms.model.xkms.UseKeyWithType) CertificateEncodingException(java.security.cert.CertificateEncodingException) XKMSCertificateException(org.apache.cxf.xkms.exception.XKMSCertificateException) CertificateException(java.security.cert.CertificateException) X509Certificate(java.security.cert.X509Certificate) UnverifiedKeyBindingType(org.apache.cxf.xkms.model.xkms.UnverifiedKeyBindingType)

Aggregations

UseKeyWithType (org.apache.cxf.xkms.model.xkms.UseKeyWithType)14 X509Certificate (java.security.cert.X509Certificate)6 Test (org.junit.Test)6 QueryKeyBindingType (org.apache.cxf.xkms.model.xkms.QueryKeyBindingType)5 File (java.io.File)4 LocateRequestType (org.apache.cxf.xkms.model.xkms.LocateRequestType)4 FileInputStream (java.io.FileInputStream)2 CertificateException (java.security.cert.CertificateException)2 ArrayList (java.util.ArrayList)2 Attributes (javax.naming.directory.Attributes)2 BasicIntegrationTest (org.apache.cxf.xkms.itests.BasicIntegrationTest)2 FileCertificateRepo (org.apache.cxf.xkms.x509.repo.file.FileCertificateRepo)2 IMocksControl (org.easymock.IMocksControl)2 Before (org.junit.Before)2 InputStream (java.io.InputStream)1 CertificateEncodingException (java.security.cert.CertificateEncodingException)1 CertificateFactory (java.security.cert.CertificateFactory)1 List (java.util.List)1 JAXBElement (javax.xml.bind.JAXBElement)1 XKMSCertificateException (org.apache.cxf.xkms.exception.XKMSCertificateException)1