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);
}
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);
}
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);
}
Aggregations