Search in sources :

Example 1 with LocateRequestType

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

the class XKMSTest method testRegisterUnitTest.

@org.junit.Test
public void testRegisterUnitTest() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = XKMSTest.class.getResource("client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    // XKMSTest.class.getResource("xkms.wsdl");
    URL wsdl = new URL("https://localhost:" + PORT2 + "/XKMS?wsdl");
    String ns = "http://www.w3.org/2002/03/xkms#wsdl";
    QName serviceQName = new QName(ns, "XKMSService");
    Service service = Service.create(wsdl, serviceQName);
    QName portQName = new QName(NAMESPACE, "XKMSPort");
    XKMSPortType port = service.getPort(portQName, XKMSPortType.class);
    // updateAddressPort(port, PORT2);
    // First try to locate - which should fail
    LocateRequestType locateRequest = new LocateRequestType();
    locateRequest.setId("_xyz");
    locateRequest.setService("http://cxf.apache.org/services/XKMS/");
    QueryKeyBindingType queryKeyBinding = new QueryKeyBindingType();
    UseKeyWithType useKeyWithType = new UseKeyWithType();
    useKeyWithType.setApplication("urn:ietf:rfc:2459");
    useKeyWithType.setIdentifier("CN=client");
    queryKeyBinding.getUseKeyWith().add(useKeyWithType);
    locateRequest.setQueryKeyBinding(queryKeyBinding);
    LocateResultType locateResultType = port.locate(locateRequest);
    assertTrue(locateResultType.getResultMajor().endsWith("Success"));
    assertTrue(locateResultType.getResultMinor().endsWith("NoMatch"));
    // Now register
    RegisterRequestType registerRequest = new RegisterRequestType();
    registerRequest.setId("_xyz");
    registerRequest.setService("http://cxf.apache.org/services/XKMS/");
    PrototypeKeyBindingType prototypeKeyBinding = new PrototypeKeyBindingType();
    CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
    InputStream certInputStream = ClassLoaderUtils.getResourceAsStream("xkmstest.cer", this.getClass());
    Certificate certificate = certificateFactory.generateCertificate(certInputStream);
    KeyInfoType keyInfo = X509Utils.getKeyInfo((X509Certificate) certificate);
    prototypeKeyBinding.setKeyInfo(keyInfo);
    prototypeKeyBinding.getUseKeyWith().add(useKeyWithType);
    registerRequest.setPrototypeKeyBinding(prototypeKeyBinding);
    RegisterResultType registerResult = port.register(registerRequest);
    assertTrue(registerResult.getResultMajor().endsWith("Success"));
    assertFalse(registerResult.getKeyBinding().isEmpty());
    // Now locate again - which should work
    locateResultType = port.locate(locateRequest);
    assertTrue(locateResultType.getResultMajor().endsWith("Success"));
    assertFalse(locateResultType.getUnverifiedKeyBinding().isEmpty());
    // Delete the certificate so that the test works when run again
    Path path = FileSystems.getDefault().getPath("target/test-classes/certs/xkms/CN-client.cer");
    Files.delete(path);
}
Also used : Path(java.nio.file.Path) Bus(org.apache.cxf.Bus) RegisterResultType(org.apache.cxf.xkms.model.xkms.RegisterResultType) PrototypeKeyBindingType(org.apache.cxf.xkms.model.xkms.PrototypeKeyBindingType) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) RegisterRequestType(org.apache.cxf.xkms.model.xkms.RegisterRequestType) UseKeyWithType(org.apache.cxf.xkms.model.xkms.UseKeyWithType) Service(javax.xml.ws.Service) XKMSPortType(org.w3._2002._03.xkms_wsdl.XKMSPortType) LocateRequestType(org.apache.cxf.xkms.model.xkms.LocateRequestType) CertificateFactory(java.security.cert.CertificateFactory) URL(java.net.URL) KeyInfoType(org.apache.cxf.xkms.model.xmldsig.KeyInfoType) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) QueryKeyBindingType(org.apache.cxf.xkms.model.xkms.QueryKeyBindingType) LocateResultType(org.apache.cxf.xkms.model.xkms.LocateResultType) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 2 with LocateRequestType

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

the class XKMSInvoker method prepareLocateXKMSRequest.

protected LocateRequestType prepareLocateXKMSRequest(List<X509AppId> ids) {
    QueryKeyBindingType queryKeyBindingType = XKMS_OF.createQueryKeyBindingType();
    for (X509AppId id : ids) {
        UseKeyWithType useKeyWithType = XKMS_OF.createUseKeyWithType();
        useKeyWithType.setIdentifier(id.getId());
        useKeyWithType.setApplication(id.getApplication().getUri());
        queryKeyBindingType.getUseKeyWith().add(useKeyWithType);
    }
    LocateRequestType locateRequestType = XKMS_OF.createLocateRequestType();
    locateRequestType.setQueryKeyBinding(queryKeyBindingType);
    setGenericRequestParams(locateRequestType);
    return locateRequestType;
}
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)

Example 3 with LocateRequestType

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

the class X509LocatorTest method prepareLocateXKMSRequest.

private LocateRequestType prepareLocateXKMSRequest() {
    QueryKeyBindingType queryKeyBindingType = XKMS_OF.createQueryKeyBindingType();
    UseKeyWithType useKeyWithType = XKMS_OF.createUseKeyWithType();
    useKeyWithType.setIdentifier("alice");
    useKeyWithType.setApplication(Applications.PKIX.getUri());
    queryKeyBindingType.getUseKeyWith().add(useKeyWithType);
    LocateRequestType locateRequestType = XKMS_OF.createLocateRequestType();
    locateRequestType.setQueryKeyBinding(queryKeyBindingType);
    setGenericRequestParams(locateRequestType);
    return locateRequestType;
}
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)

Example 4 with LocateRequestType

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

the class X509LocatorTest method locate.

@Test
public void locate() throws CertificateException {
    CertificateRepo certRepo = EasyMock.createMock(CertificateRepo.class);
    EasyMock.expect(certRepo.findBySubjectDn(EasyMock.eq("alice"))).andReturn(getAliceCert());
    EasyMock.replay(certRepo);
    X509Locator locator = new X509Locator(certRepo);
    LocateRequestType request = prepareLocateXKMSRequest();
    UnverifiedKeyBindingType result = locator.locate(request);
    Assert.assertNotNull(result.getKeyInfo());
}
Also used : CertificateRepo(org.apache.cxf.xkms.x509.repo.CertificateRepo) LocateRequestType(org.apache.cxf.xkms.model.xkms.LocateRequestType) UnverifiedKeyBindingType(org.apache.cxf.xkms.model.xkms.UnverifiedKeyBindingType) Test(org.junit.Test)

Example 5 with LocateRequestType

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

the class XKMSInvoker method getCertificate.

public X509Certificate getCertificate(List<X509AppId> ids) {
    try {
        LocateRequestType locateRequestType = prepareLocateXKMSRequest(ids);
        LocateResultType locateResultType = xkmsConsumer.locate(locateRequestType);
        return parseLocateXKMSResponse(locateResultType, ids);
    } catch (RuntimeException e) {
        String msg = String.format("XKMS locate call fails for certificate: %s. Error: %s", ids, e.getMessage());
        LOG.warn(msg, e);
        throw new XKMSLocateException(msg, e);
    }
}
Also used : XKMSLocateException(org.apache.cxf.xkms.exception.XKMSLocateException) LocateResultType(org.apache.cxf.xkms.model.xkms.LocateResultType) LocateRequestType(org.apache.cxf.xkms.model.xkms.LocateRequestType)

Aggregations

LocateRequestType (org.apache.cxf.xkms.model.xkms.LocateRequestType)7 QueryKeyBindingType (org.apache.cxf.xkms.model.xkms.QueryKeyBindingType)5 UseKeyWithType (org.apache.cxf.xkms.model.xkms.UseKeyWithType)5 Test (org.junit.Test)3 BasicIntegrationTest (org.apache.cxf.xkms.itests.BasicIntegrationTest)2 LocateResultType (org.apache.cxf.xkms.model.xkms.LocateResultType)2 InputStream (java.io.InputStream)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 Certificate (java.security.cert.Certificate)1 CertificateFactory (java.security.cert.CertificateFactory)1 X509Certificate (java.security.cert.X509Certificate)1 QName (javax.xml.namespace.QName)1 Service (javax.xml.ws.Service)1 Bus (org.apache.cxf.Bus)1 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)1 XKMSLocateException (org.apache.cxf.xkms.exception.XKMSLocateException)1 PrototypeKeyBindingType (org.apache.cxf.xkms.model.xkms.PrototypeKeyBindingType)1 RegisterRequestType (org.apache.cxf.xkms.model.xkms.RegisterRequestType)1 RegisterResultType (org.apache.cxf.xkms.model.xkms.RegisterResultType)1