Search in sources :

Example 6 with SAAJOutInterceptor

use of org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor in project tomee by apache.

the class CalculatorTest method testCalculatorViaWsInterface.

//END SNIPPET: setup
//START SNIPPET: webservice
public void testCalculatorViaWsInterface() throws Exception {
    final Service calcService = Service.create(new URL("http://localhost:" + port + "/webservice-ws-security/CalculatorImpl?wsdl"), new QName("http://superbiz.org/wsdl", "CalculatorWsService"));
    assertNotNull(calcService);
    final CalculatorWs calc = calcService.getPort(CalculatorWs.class);
    final Client client = ClientProxy.getClient(calc);
    final Endpoint endpoint = client.getEndpoint();
    endpoint.getOutInterceptors().add(new SAAJOutInterceptor());
    final Map<String, Object> outProps = new HashMap<>();
    outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
    outProps.put(WSHandlerConstants.USER, "jane");
    outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
    outProps.put(WSHandlerConstants.PW_CALLBACK_REF, new CallbackHandler() {

        @Override
        public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException {
            final WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
            pc.setPassword("waterfall");
        }
    });
    final WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
    endpoint.getOutInterceptors().add(wssOut);
    assertEquals(10, calc.sum(4, 6));
}
Also used : SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) CallbackHandler(javax.security.auth.callback.CallbackHandler) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) IOException(java.io.IOException) URL(java.net.URL) WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback) Callback(javax.security.auth.callback.Callback) Endpoint(org.apache.cxf.endpoint.Endpoint) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) Client(org.apache.cxf.endpoint.Client) WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback)

Example 7 with SAAJOutInterceptor

use of org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor in project tomee by apache.

the class ConfigureCxfSecurity method setupWSS4JChain.

public static final void setupWSS4JChain(InterceptorProvider endpoint, Map<String, Object> inProps, Map<String, Object> outProps) {
    if (null != inProps && !inProps.isEmpty()) {
        endpoint.getInInterceptors().add(new SAAJInInterceptor());
        endpoint.getInInterceptors().add(new WSS4JInInterceptor(inProps));
        // if WS Security is used with a JAX-WS handler (See EjbInterceptor), we have to deal with mustUnderstand flag
        // in WS Security headers. So, let's add an interceptor
        endpoint.getInInterceptors().add(new WSSPassThroughInterceptor());
    }
    if (null != outProps && !outProps.isEmpty()) {
        endpoint.getOutInterceptors().add(new SAAJOutInterceptor());
        endpoint.getOutInterceptors().add(new WSS4JOutInterceptor(outProps));
    }
}
Also used : SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) WSS4JInInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)

Example 8 with SAAJOutInterceptor

use of org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor in project tomee by apache.

the class CalculatorTest method testCalculatorViaWsInterfaceWithTimestamp2ways.

public void testCalculatorViaWsInterfaceWithTimestamp2ways() throws Exception {
    final Service calcService = Service.create(new URL("http://localhost:" + port + "/webservice-ws-security/CalculatorImplTimestamp2ways?wsdl"), new QName("http://superbiz.org/wsdl", "CalculatorWsService"));
    assertNotNull(calcService);
    // for debugging (ie. TCPMon)
    calcService.addPort(new QName("http://superbiz.org/wsdl", "CalculatorWsService2"), SOAPBinding.SOAP12HTTP_BINDING, "http://127.0.0.1:8204/CalculatorImplTimestamp2ways");
    //        CalculatorWs calc = calcService.getPort(
    //        	new QName("http://superbiz.org/wsdl", "CalculatorWsService2"),
    //		CalculatorWs.class);
    final CalculatorWs calc = calcService.getPort(CalculatorWs.class);
    final Client client = ClientProxy.getClient(calc);
    final Endpoint endpoint = client.getEndpoint();
    endpoint.getOutInterceptors().add(new SAAJOutInterceptor());
    endpoint.getInInterceptors().add(new SAAJInInterceptor());
    final Map<String, Object> outProps = new HashMap<String, Object>();
    outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.TIMESTAMP);
    final WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
    endpoint.getOutInterceptors().add(wssOut);
    final Map<String, Object> inProps = new HashMap<String, Object>();
    inProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.TIMESTAMP);
    final WSS4JInInterceptor wssIn = new WSS4JInInterceptor(inProps);
    endpoint.getInInterceptors().add(wssIn);
    assertEquals(12, calc.multiply(3, 4));
}
Also used : SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) Endpoint(org.apache.cxf.endpoint.Endpoint) WSS4JInInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) Client(org.apache.cxf.endpoint.Client)

Example 9 with SAAJOutInterceptor

use of org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor in project tomee by apache.

the class CalculatorTest method testCalculatorViaWsInterfaceWithUsernameTokenPlainPasswordEncrypt.

public void testCalculatorViaWsInterfaceWithUsernameTokenPlainPasswordEncrypt() throws Exception {
    final Service calcService = Service.create(new URL("http://localhost:" + port + "/webservice-ws-security/CalculatorImplUsernameTokenPlainPasswordEncrypt?wsdl"), new QName("http://superbiz.org/wsdl", "CalculatorWsService"));
    assertNotNull(calcService);
    // for debugging (ie. TCPMon)
    calcService.addPort(new QName("http://superbiz.org/wsdl", "CalculatorWsService2"), SOAPBinding.SOAP12HTTP_BINDING, "http://127.0.0.1:8204/CalculatorImplUsernameTokenPlainPasswordEncrypt");
    //        CalculatorWs calc = calcService.getPort(
    //        	new QName("http://superbiz.org/wsdl", "CalculatorWsService2"),
    //        	CalculatorWs.class);
    final CalculatorWs calc = calcService.getPort(CalculatorWs.class);
    final Client client = ClientProxy.getClient(calc);
    final Endpoint endpoint = client.getEndpoint();
    endpoint.getOutInterceptors().add(new SAAJOutInterceptor());
    final Map<String, Object> outProps = new HashMap<String, Object>();
    outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN + " " + WSHandlerConstants.ENCRYPT);
    outProps.put(WSHandlerConstants.USER, "jane");
    outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
    outProps.put(WSHandlerConstants.PW_CALLBACK_REF, new CallbackHandler() {

        @Override
        public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException {
            final WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
            pc.setPassword("waterfall");
        }
    });
    outProps.put(WSHandlerConstants.ENC_PROP_FILE, "META-INF/CalculatorImplUsernameTokenPlainPasswordEncrypt-client.properties");
    outProps.put(WSHandlerConstants.ENCRYPTION_USER, "serveralias");
    final WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
    endpoint.getOutInterceptors().add(wssOut);
    assertEquals(10, calc.sum(4, 6));
}
Also used : SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) CallbackHandler(javax.security.auth.callback.CallbackHandler) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) IOException(java.io.IOException) URL(java.net.URL) WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback) Callback(javax.security.auth.callback.Callback) Endpoint(org.apache.cxf.endpoint.Endpoint) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) Client(org.apache.cxf.endpoint.Client) WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback)

Aggregations

SAAJOutInterceptor (org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor)9 WSS4JOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)8 URL (java.net.URL)7 HashMap (java.util.HashMap)7 QName (javax.xml.namespace.QName)7 Service (javax.xml.ws.Service)7 Client (org.apache.cxf.endpoint.Client)7 Endpoint (org.apache.cxf.endpoint.Endpoint)7 IOException (java.io.IOException)5 Callback (javax.security.auth.callback.Callback)5 CallbackHandler (javax.security.auth.callback.CallbackHandler)5 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)5 WSPasswordCallback (org.apache.wss4j.common.ext.WSPasswordCallback)5 SAAJInInterceptor (org.apache.cxf.binding.soap.saaj.SAAJInInterceptor)3 WSS4JInInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor)2 Source (javax.xml.transform.Source)1 CxfMessageSoapHeaderOutInterceptor (org.apache.camel.component.cxf.interceptors.CxfMessageSoapHeaderOutInterceptor)1 SoapBinding (org.apache.cxf.binding.soap.SoapBinding)1 MessageModeInInterceptor (org.apache.cxf.jaxws.interceptors.MessageModeInInterceptor)1 MessageModeOutInterceptor (org.apache.cxf.jaxws.interceptors.MessageModeOutInterceptor)1