use of org.apache.cxf.Bus in project cxf by apache.
the class CustomParameterTest method testCustomParameterToRESTInterface.
@org.junit.Test
public void testCustomParameterToRESTInterface() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = CustomParameterTest.class.getResource("cxf-client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
String address = "https://localhost:" + STSPORT + "/SecurityTokenServiceREST/token";
WebClient client = WebClient.create(address, busFile.toString());
client.type("application/xml").accept("application/xml");
// Create RequestSecurityToken
W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
String namespace = STSUtils.WST_NS_05_12;
writer.writeStartElement("wst", "RequestSecurityToken", namespace);
writer.writeNamespace("wst", namespace);
writer.writeStartElement("wst", "RequestType", namespace);
writer.writeCharacters(namespace + "/Issue");
writer.writeEndElement();
writer.writeStartElement("wst", "TokenType", namespace);
writer.writeCharacters(SAML2_TOKEN_TYPE);
writer.writeEndElement();
writer.writeStartElement("wst", "Claims", namespace);
writer.writeAttribute("Dialect", "http://schemas.xmlsoap.org/ws/2005/05/identity");
writer.writeStartElement("ic", "ClaimType", "http://schemas.xmlsoap.org/ws/2005/05/identity");
writer.writeAttribute("Uri", "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role");
writer.writeEndElement();
writer.writeEndElement();
// Add custom content to the RST
writer.writeStartElement("", "realm", "http://cxf.apache.org/custom");
writer.writeCharacters("custom-realm");
writer.writeEndElement();
writer.writeEndElement();
Response response = client.post(new DOMSource(writer.getDocument().getDocumentElement()));
RequestSecurityTokenResponseType securityResponse = response.readEntity(RequestSecurityTokenResponseType.class);
Element assertion = validateSAMLSecurityTokenResponse(securityResponse, true);
assertTrue(DOM2Writer.nodeToString(assertion).contains("admin-user"));
bus.shutdown(true);
}
use of org.apache.cxf.Bus in project cxf by apache.
the class CustomParameterTest method testCustomParameterInRST2Validator.
// Here the custom parameter in the RST is parsed by the CustomUTValidator
@org.junit.Test
public void testCustomParameterInRST2Validator() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = CustomParameterTest.class.getResource("cxf-client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = CustomParameterTest.class.getResource("DoubleIt.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItTransportCustomParameterPort");
DoubleItPortType transportClaimsPort = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(transportClaimsPort, PORT);
TokenTestUtils.updateSTSPort((BindingProvider) transportClaimsPort, STSPORT);
STSClient stsClient = new STSClient(bus);
stsClient.setWsdlLocation("https://localhost:" + STSPORT + "/SecurityTokenService/UT?wsdl");
stsClient.setServiceName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}SecurityTokenService");
stsClient.setEndpointName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}UT_Port");
Map<String, Object> properties = new HashMap<>();
properties.put(SecurityConstants.USERNAME, "alice");
properties.put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.sts.common.CommonCallbackHandler");
properties.put("security.sts.token.username", "myclientkey");
properties.put("security.sts.token.properties", "clientKeystore.properties");
properties.put("security.sts.token.usecert", "true");
stsClient.setProperties(properties);
((BindingProvider) transportClaimsPort).getRequestContext().put(SecurityConstants.STS_CLIENT, stsClient);
// Failing test
// Add custom content to the RST
stsClient.setCustomContent("<realm xmlns=\"http://cxf.apache.org/custom\">custom-unknown-realm</realm>");
try {
doubleIt(transportClaimsPort, 25);
fail("Failure expected on the wrong realm");
} catch (Exception ex) {
// expected
}
((java.io.Closeable) transportClaimsPort).close();
bus.shutdown(true);
}
use of org.apache.cxf.Bus in project cxf by apache.
the class CustomParameterTest method testCustomParameterInRSTClaimsHandler.
// Here the custom parameter in the RST is parsed by the CustomClaimsHandler
@org.junit.Test
public void testCustomParameterInRSTClaimsHandler() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = CustomParameterTest.class.getResource("cxf-client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = CustomParameterTest.class.getResource("DoubleIt.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItTransportCustomParameterClaimsPort");
DoubleItPortType transportClaimsPort = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(transportClaimsPort, PORT);
TokenTestUtils.updateSTSPort((BindingProvider) transportClaimsPort, STSPORT);
STSClient stsClient = new STSClient(bus);
stsClient.setWsdlLocation("https://localhost:" + STSPORT + "/SecurityTokenService/Transport?wsdl");
stsClient.setServiceName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}SecurityTokenService");
stsClient.setEndpointName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}Transport_Port");
Map<String, Object> properties = new HashMap<>();
properties.put(SecurityConstants.USERNAME, "alice");
properties.put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.sts.common.CommonCallbackHandler");
properties.put("security.sts.token.username", "myclientkey");
properties.put("security.sts.token.properties", "clientKeystore.properties");
properties.put("security.sts.token.usecert", "true");
stsClient.setProperties(properties);
((BindingProvider) transportClaimsPort).getRequestContext().put(SecurityConstants.STS_CLIENT, stsClient);
// Successful test
// Add custom content to the RST
stsClient.setCustomContent("<realm xmlns=\"http://cxf.apache.org/custom\">custom-realm</realm>");
doubleIt(transportClaimsPort, 25);
((java.io.Closeable) transportClaimsPort).close();
bus.shutdown(true);
}
use of org.apache.cxf.Bus in project cxf by apache.
the class CustomParameterTest method testCustomParameterInRSTValidator.
// Here the custom parameter in the RST is parsed by the CustomUTValidator
@org.junit.Test
public void testCustomParameterInRSTValidator() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = CustomParameterTest.class.getResource("cxf-client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = CustomParameterTest.class.getResource("DoubleIt.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItTransportCustomParameterPort");
DoubleItPortType transportClaimsPort = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(transportClaimsPort, PORT);
TokenTestUtils.updateSTSPort((BindingProvider) transportClaimsPort, STSPORT);
STSClient stsClient = new STSClient(bus);
stsClient.setWsdlLocation("https://localhost:" + STSPORT + "/SecurityTokenService/UT?wsdl");
stsClient.setServiceName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}SecurityTokenService");
stsClient.setEndpointName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}UT_Port");
Map<String, Object> properties = new HashMap<>();
properties.put(SecurityConstants.USERNAME, "alice");
properties.put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.sts.common.CommonCallbackHandler");
properties.put("security.sts.token.username", "myclientkey");
properties.put("security.sts.token.properties", "clientKeystore.properties");
properties.put("security.sts.token.usecert", "true");
stsClient.setProperties(properties);
((BindingProvider) transportClaimsPort).getRequestContext().put(SecurityConstants.STS_CLIENT, stsClient);
// Successful test
// Add custom content to the RST
stsClient.setCustomContent("<realm xmlns=\"http://cxf.apache.org/custom\">custom-realm</realm>");
doubleIt(transportClaimsPort, 25);
((java.io.Closeable) transportClaimsPort).close();
bus.shutdown(true);
}
use of org.apache.cxf.Bus in project cxf by apache.
the class CustomOnBehalfOfTest method testUsernameOnBehalfOfLocal.
@org.junit.Test
public void testUsernameOnBehalfOfLocal() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = CustomOnBehalfOfTest.class.getResource("cxf-client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = CustomOnBehalfOfTest.class.getResource("DoubleIt.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItTransportCustomBSTLocalPort");
DoubleItPortType transportPort = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(transportPort, PORT);
// Transport port
((BindingProvider) transportPort).getRequestContext().put(SecurityConstants.USERNAME, "alice");
doubleIt(transportPort, 25);
((java.io.Closeable) transportPort).close();
bus.shutdown(true);
}
Aggregations