Search in sources :

Example 76 with Bus

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);
}
Also used : Response(javax.ws.rs.core.Response) Bus(org.apache.cxf.Bus) W3CDOMStreamWriter(org.apache.cxf.staxutils.W3CDOMStreamWriter) DOMSource(javax.xml.transform.dom.DOMSource) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) RequestSecurityTokenResponseType(org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenResponseType) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Example 77 with Bus

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);
}
Also used : Bus(org.apache.cxf.Bus) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) STSClient(org.apache.cxf.ws.security.trust.STSClient) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType)

Example 78 with Bus

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);
}
Also used : Bus(org.apache.cxf.Bus) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) STSClient(org.apache.cxf.ws.security.trust.STSClient) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType)

Example 79 with Bus

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);
}
Also used : Bus(org.apache.cxf.Bus) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) STSClient(org.apache.cxf.ws.security.trust.STSClient) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType)

Example 80 with Bus

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);
}
Also used : Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) URL(java.net.URL)

Aggregations

Bus (org.apache.cxf.Bus)1144 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)800 URL (java.net.URL)748 QName (javax.xml.namespace.QName)436 Service (javax.xml.ws.Service)400 DoubleItPortType (org.example.contract.doubleit.DoubleItPortType)354 Test (org.junit.Test)219 HashMap (java.util.HashMap)63 Message (org.apache.cxf.message.Message)60 WebClient (org.apache.cxf.jaxrs.client.WebClient)50 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)48 Client (org.apache.cxf.endpoint.Client)43 Greeter (org.apache.hello_world.Greeter)42 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)41 SOAPService (org.apache.hello_world.services.SOAPService)41 JAXRSClientFactoryBean (org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean)40 Endpoint (org.apache.cxf.endpoint.Endpoint)38 ExtensionManagerBus (org.apache.cxf.bus.extension.ExtensionManagerBus)36 STSClient (org.apache.cxf.ws.security.trust.STSClient)36 Document (org.w3c.dom.Document)36