Search in sources :

Example 6 with Number

use of org.apache.coheigea.cxf.jaxrs.xmlsecurity.common.Number in project testcases by coheigea.

the class XMLSignatureStaxTest method testXMLSignature.

@org.junit.Test
public void testXMLSignature() throws Exception {
    URL busFile = XMLSignatureStaxTest.class.getResource("cxf-client.xml");
    String address = "http://localhost:" + STAX_PORT + "/doubleit/services";
    WebClient client = WebClient.create(address, busFile.toString());
    client = client.type("application/xml");
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("ws-security.callback-handler", "org.apache.coheigea.cxf.jaxrs.xmlsecurity.common.CommonCallbackHandler");
    properties.put("ws-security.signature.username", "myclientkey");
    properties.put("ws-security.signature.properties", "clientKeystore.properties");
    WebClient.getConfig(client).getRequestContext().putAll(properties);
    XmlSecOutInterceptor sigInterceptor = new XmlSecOutInterceptor();
    sigInterceptor.setSignRequest(true);
    WebClient.getConfig(client).getOutInterceptors().add(sigInterceptor);
    Number numberToDouble = new Number();
    numberToDouble.setDescription("This is the number to double");
    numberToDouble.setNumber(25);
    Response response = client.post(numberToDouble);
    assertEquals(response.getStatus(), 200);
    assertEquals(response.readEntity(Number.class).getNumber(), 50);
}
Also used : Response(javax.ws.rs.core.Response) Number(org.apache.coheigea.cxf.jaxrs.xmlsecurity.common.Number) HashMap(java.util.HashMap) XmlSecOutInterceptor(org.apache.cxf.rs.security.xml.XmlSecOutInterceptor) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Example 7 with Number

use of org.apache.coheigea.cxf.jaxrs.xmlsecurity.common.Number in project testcases by coheigea.

the class AuthenticationTest method testUnauthenticatedRequest.

@org.junit.Test
public void testUnauthenticatedRequest() throws Exception {
    URL busFile = AuthenticationTest.class.getResource("cxf-client.xml");
    String address = "http://localhost:" + PORT + "/doubleit/services";
    WebClient client = WebClient.create(address, busFile.toString());
    client = client.type("application/xml");
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("ws-security.callback-handler", "org.apache.coheigea.cxf.jaxrs.xmlsecurity.common.CommonCallbackHandler");
    properties.put("ws-security.signature.username", "imposter");
    properties.put("ws-security.signature.properties", "imposterKeystore.properties");
    WebClient.getConfig(client).getRequestContext().putAll(properties);
    XmlSigOutInterceptor sigInterceptor = new XmlSigOutInterceptor();
    WebClient.getConfig(client).getOutInterceptors().add(sigInterceptor);
    Number numberToDouble = new Number();
    numberToDouble.setDescription("This is the number to double");
    numberToDouble.setNumber(25);
    Response response = client.post(numberToDouble);
    assertEquals(response.getStatus(), 400);
}
Also used : Response(javax.ws.rs.core.Response) XmlSigOutInterceptor(org.apache.cxf.rs.security.xml.XmlSigOutInterceptor) Number(org.apache.coheigea.cxf.jaxrs.xmlsecurity.common.Number) HashMap(java.util.HashMap) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Example 8 with Number

use of org.apache.coheigea.cxf.jaxrs.xmlsecurity.common.Number in project testcases by coheigea.

the class AuthenticationTest method testAuthenticatedRequest.

@org.junit.Test
public void testAuthenticatedRequest() throws Exception {
    URL busFile = AuthenticationTest.class.getResource("cxf-client.xml");
    String address = "http://localhost:" + PORT + "/doubleit/services";
    WebClient client = WebClient.create(address, busFile.toString());
    client = client.type("application/xml");
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("ws-security.callback-handler", "org.apache.coheigea.cxf.jaxrs.xmlsecurity.common.CommonCallbackHandler");
    properties.put("ws-security.signature.username", "myclientkey");
    properties.put("ws-security.signature.properties", "clientKeystore.properties");
    WebClient.getConfig(client).getRequestContext().putAll(properties);
    XmlSigOutInterceptor sigInterceptor = new XmlSigOutInterceptor();
    WebClient.getConfig(client).getOutInterceptors().add(sigInterceptor);
    Number numberToDouble = new Number();
    numberToDouble.setDescription("This is the number to double");
    numberToDouble.setNumber(25);
    Response response = client.post(numberToDouble);
    assertEquals(response.getStatus(), 200);
    assertEquals(response.readEntity(Number.class).getNumber(), 50);
}
Also used : Response(javax.ws.rs.core.Response) XmlSigOutInterceptor(org.apache.cxf.rs.security.xml.XmlSigOutInterceptor) Number(org.apache.coheigea.cxf.jaxrs.xmlsecurity.common.Number) HashMap(java.util.HashMap) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Aggregations

URL (java.net.URL)8 HashMap (java.util.HashMap)8 Response (javax.ws.rs.core.Response)8 Number (org.apache.coheigea.cxf.jaxrs.xmlsecurity.common.Number)8 WebClient (org.apache.cxf.jaxrs.client.WebClient)8 XmlSecOutInterceptor (org.apache.cxf.rs.security.xml.XmlSecOutInterceptor)4 XmlSigOutInterceptor (org.apache.cxf.rs.security.xml.XmlSigOutInterceptor)4 XmlEncInInterceptor (org.apache.cxf.rs.security.xml.XmlEncInInterceptor)2 XmlEncOutInterceptor (org.apache.cxf.rs.security.xml.XmlEncOutInterceptor)2 XmlSecInInterceptor (org.apache.cxf.rs.security.xml.XmlSecInInterceptor)2