Search in sources :

Example 1 with DoubleItPortTypeImpl

use of org.apache.cxf.systest.ws.common.DoubleItPortTypeImpl in project cxf by apache.

the class SecurityPolicyTest method init.

@BeforeClass
public static void init() throws Exception {
    URL wsdl = SecurityPolicyTest.class.getResource("DoubleIt.wsdl");
    createStaticBus(SecurityPolicyTest.class.getResource("https_config.xml").toString()).getExtension(PolicyEngine.class).setEnabled(true);
    getStaticBus().getOutInterceptors().add(new LoggingOutInterceptor());
    DoubleItPortTypeImpl implementor = new DoubleItPortTypeImpl();
    implementor.setEnforcePrincipal(false);
    EndpointImpl ep = (EndpointImpl) Endpoint.create(implementor);
    ep.setEndpointName(new QName("http://www.example.org/contract/DoubleIt", "DoubleItPortHttps"));
    ep.setWsdlLocation(wsdl.getPath());
    ep.setAddress(POLICY_HTTPS_ADDRESS);
    ep.publish();
    ep.getServer().getEndpoint().getEndpointInfo().setProperty(SecurityConstants.CALLBACK_HANDLER, new ServerPasswordCallback());
    Endpoint.publish(POLICY_ADDRESS, implementor);
    ep = (EndpointImpl) Endpoint.create(implementor);
    ep.setEndpointName(new QName("http://www.example.org/contract/DoubleIt", "DoubleItPortEncryptThenSign"));
    ep.setWsdlLocation(wsdl.getPath());
    ep.setAddress(POLICY_ENCSIGN_ADDRESS);
    ep.publish();
    EndpointInfo ei = ep.getServer().getEndpoint().getEndpointInfo();
    setCryptoProperties(ei, "bob.properties", "alice.properties");
    ep = (EndpointImpl) Endpoint.create(implementor);
    ep.setEndpointName(new QName("http://www.example.org/contract/DoubleIt", "DoubleItPortSignThenEncrypt"));
    ep.setWsdlLocation(wsdl.getPath());
    ep.setAddress(POLICY_SIGNENC_ADDRESS);
    ep.publish();
    ei = ep.getServer().getEndpoint().getEndpointInfo();
    setCryptoProperties(ei, "bob.properties", "alice.properties");
    ep = (EndpointImpl) Endpoint.create(implementor);
    ep.setEndpointName(new QName("http://www.example.org/contract/DoubleIt", "DoubleItPortSign"));
    ep.setWsdlLocation(wsdl.getPath());
    ep.setAddress(POLICY_SIGN_ADDRESS);
    ep.publish();
    ei = ep.getServer().getEndpoint().getEndpointInfo();
    setCryptoProperties(ei, "bob.properties", "alice.properties");
    ep = (EndpointImpl) Endpoint.create(implementor);
    ep.setEndpointName(new QName("http://www.example.org/contract/DoubleIt", "DoubleItPortXPath"));
    ep.setWsdlLocation(wsdl.getPath());
    ep.setAddress(POLICY_XPATH_ADDRESS);
    ep.publish();
    ei = ep.getServer().getEndpoint().getEndpointInfo();
    setCryptoProperties(ei, "alice.properties", "bob.properties");
    ep = (EndpointImpl) Endpoint.publish(POLICY_SIGNENC_PROVIDER_ADDRESS, new DoubleItProvider());
    ei = ep.getServer().getEndpoint().getEndpointInfo();
    setCryptoProperties(ei, "bob.properties", "alice.properties");
    ep = (EndpointImpl) Endpoint.publish(POLICY_FAULT_SIGNENC_PROVIDER_ADDRESS, new DoubleItFaultProvider());
    ei = ep.getServer().getEndpoint().getEndpointInfo();
    setCryptoProperties(ei, "bob.properties", "alice.properties");
    ep = (EndpointImpl) Endpoint.create(implementor);
    ep.setEndpointName(new QName("http://www.example.org/contract/DoubleIt", "DoubleItPortSignedOnly"));
    ep.setWsdlLocation(wsdl.getPath());
    ep.setAddress(POLICY_SIGNONLY_ADDRESS);
    ep.publish();
    ei = ep.getServer().getEndpoint().getEndpointInfo();
    setCryptoProperties(ei, "bob.properties", "alice.properties");
    ep = (EndpointImpl) Endpoint.create(implementor);
    ep.setEndpointName(new QName("http://www.example.org/contract/DoubleIt", "DoubleItPortCXF3041"));
    ep.setWsdlLocation(wsdl.getPath());
    ep.setAddress(POLICY_CXF3041_ADDRESS);
    ep.publish();
    ei = ep.getServer().getEndpoint().getEndpointInfo();
    setCryptoProperties(ei, "bob.properties", "alice.properties");
    ep = (EndpointImpl) Endpoint.create(implementor);
    ep.setEndpointName(new QName("http://www.example.org/contract/DoubleIt", "DoubleItPortCXF3042"));
    ep.setWsdlLocation(wsdl.getPath());
    ep.setAddress(POLICY_CXF3042_ADDRESS);
    ep.publish();
    ei = ep.getServer().getEndpoint().getEndpointInfo();
    setCryptoProperties(ei, "alice.properties", "alice.properties");
    ep = (EndpointImpl) Endpoint.create(implementor);
    ep.setEndpointName(new QName("http://www.example.org/contract/DoubleIt", "DoubleItPortCXF3452"));
    ep.setWsdlLocation(wsdl.getPath());
    ep.setAddress(POLICY_CXF3452_ADDRESS);
    ep.publish();
    ei = ep.getServer().getEndpoint().getEndpointInfo();
    setCryptoProperties(ei, "alice.properties", "alice.properties");
    ei.setProperty(Message.SCHEMA_VALIDATION_ENABLED, Boolean.TRUE);
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) DoubleItPortTypeImpl(org.apache.cxf.systest.ws.common.DoubleItPortTypeImpl) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) QName(javax.xml.namespace.QName) EndpointImpl(org.apache.cxf.jaxws.EndpointImpl) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) URL(java.net.URL) BeforeClass(org.junit.BeforeClass)

Example 2 with DoubleItPortTypeImpl

use of org.apache.cxf.systest.ws.common.DoubleItPortTypeImpl in project cxf by apache.

the class SecurityPolicyTest method testCXF4122.

@Test
public void testCXF4122() throws Exception {
    Bus epBus = BusFactory.newInstance().createBus();
    BusFactory.setDefaultBus(epBus);
    URL wsdl = SecurityPolicyTest.class.getResource("DoubleIt.wsdl");
    DoubleItPortTypeImpl implementor = new DoubleItPortTypeImpl();
    implementor.setEnforcePrincipal(false);
    EndpointImpl ep = (EndpointImpl) Endpoint.create(implementor);
    ep.setEndpointName(new QName("http://www.example.org/contract/DoubleIt", "DoubleItPortCXF4122"));
    ep.setWsdlLocation(wsdl.getPath());
    ep.setAddress(POLICY_CXF4122_ADDRESS);
    ep.publish();
    EndpointInfo ei = ep.getServer().getEndpoint().getEndpointInfo();
    setCryptoProperties(ei, "bob.properties", "revocation.properties");
    ei.setProperty(SecurityConstants.ENABLE_REVOCATION, Boolean.TRUE);
    SpringBusFactory bf = new SpringBusFactory();
    Bus bus = bf.createBus();
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItPortCXF4122");
    DoubleItPortType pt = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(pt, PORT);
    ((BindingProvider) pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER, new KeystorePasswordCallback());
    ((BindingProvider) pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES, "revocation.properties");
    ((BindingProvider) pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES, "bob.properties");
    // DOM
    try {
        pt.doubleIt(5);
        fail("should fail on server side when do signature validation due the revoked certificates");
    } catch (Exception ex) {
    // expected
    }
    // TODO See WSS-464
    /*
        SecurityTestUtil.enableStreaming(pt);
        try {
            pt.doubleIt(5);
            fail("should fail on server side when do signature validation due the revoked certificates");
        } catch (Exception ex) {
            String errorMessage = ex.getMessage();
            // Different errors using different JDKs...
            System.out.println("ERR1: " + errorMessage);
        }
        */
    ((java.io.Closeable) pt).close();
    ep.stop();
    epBus.shutdown(true);
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) DoubleItPortTypeImpl(org.apache.cxf.systest.ws.common.DoubleItPortTypeImpl) QName(javax.xml.namespace.QName) EndpointImpl(org.apache.cxf.jaxws.EndpointImpl) Service(javax.xml.ws.Service) URL(java.net.URL) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) IOException(java.io.IOException) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) KeystorePasswordCallback(org.apache.cxf.systest.ws.common.KeystorePasswordCallback) Test(org.junit.Test)

Example 3 with DoubleItPortTypeImpl

use of org.apache.cxf.systest.ws.common.DoubleItPortTypeImpl in project cxf by apache.

the class ActionTest method testAsymmetricActionToPolicyServerFactory.

// Here the client is using "Actions", where the server is using an AsymmetricBinding policy,
// and we are building the service in code using JaxWsServerFactoryBean instead of Spring
@org.junit.Test
public void testAsymmetricActionToPolicyServerFactory() throws Exception {
    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
    URL serviceWSDL = ActionTest.class.getResource("DoubleItActionPolicy.wsdl");
    svrFactory.setWsdlLocation(serviceWSDL.toString());
    String address = "http://localhost:" + PORT2 + "/DoubleItAsymmetric";
    svrFactory.setAddress(address);
    DoubleItPortTypeImpl serviceBean = new DoubleItPortTypeImpl();
    serviceBean.setEnforcePrincipal(false);
    svrFactory.setServiceBean(serviceBean);
    QName portQName = new QName(NAMESPACE, "DoubleItAsymmetricPort");
    svrFactory.setEndpointName(portQName);
    Map<String, Object> props = new HashMap<>();
    props.put("security.callback-handler", "org.apache.cxf.systest.ws.common.KeystorePasswordCallback");
    props.put("security.signature.properties", "bob.properties");
    props.put("security.encryption.properties", "alice.properties");
    props.put("security.encryption.username", "alice");
    svrFactory.setProperties(props);
    org.apache.cxf.endpoint.Server server = svrFactory.create();
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = ActionTest.class.getResource("client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = ActionTest.class.getResource("DoubleItAction.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, PORT2);
    // Successful call
    assertEquals(50, port.doubleIt(25));
    ((java.io.Closeable) port).close();
    server.destroy();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) DoubleItPortTypeImpl(org.apache.cxf.systest.ws.common.DoubleItPortTypeImpl) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean)

Example 4 with DoubleItPortTypeImpl

use of org.apache.cxf.systest.ws.common.DoubleItPortTypeImpl in project cxf by apache.

the class UTServer method run.

protected void run() {
    DoubleItPortTypeImpl implementor = new DoubleItPortTypeImpl();
    implementor.setEnforcePrincipal(false);
    String address = "http://localhost:" + PORT + "/DoubleItUsernameToken3";
    EndpointImpl jaxWsEndpoint = (EndpointImpl) Endpoint.publish(address, implementor);
    Map<String, Object> properties = new HashMap<>();
    properties.put("action", "UsernameToken");
    properties.put("passwordCallbackClass", "org.apache.cxf.systest.ws.common.UTPasswordCallback");
    WSS4JInInterceptor wss4jInInterceptor = new WSS4JInInterceptor(properties);
    jaxWsEndpoint.getServer().getEndpoint().getInInterceptors().add(wss4jInInterceptor);
}
Also used : DoubleItPortTypeImpl(org.apache.cxf.systest.ws.common.DoubleItPortTypeImpl) HashMap(java.util.HashMap) EndpointImpl(org.apache.cxf.jaxws.EndpointImpl) WSS4JInInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor)

Aggregations

DoubleItPortTypeImpl (org.apache.cxf.systest.ws.common.DoubleItPortTypeImpl)4 URL (java.net.URL)3 QName (javax.xml.namespace.QName)3 EndpointImpl (org.apache.cxf.jaxws.EndpointImpl)3 HashMap (java.util.HashMap)2 Service (javax.xml.ws.Service)2 Bus (org.apache.cxf.Bus)2 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)2 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)2 DoubleItPortType (org.example.contract.doubleit.DoubleItPortType)2 IOException (java.io.IOException)1 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)1 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)1 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)1 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)1 KeystorePasswordCallback (org.apache.cxf.systest.ws.common.KeystorePasswordCallback)1 PolicyEngine (org.apache.cxf.ws.policy.PolicyEngine)1 WSS4JInInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1