Search in sources :

Example 6 with ServiceIface

use of org.jboss.test.ws.jaxws.samples.wsse.policy.trust.service.ServiceIface in project jbossws-cxf by jbossws.

the class WSTrustTestCase method testNoSignatureUsername.

/**
 * No SIGNATURE_USERNAME is provided to the service.  Service will use the
 * client's keystore alias in its place.
 *
 * @throws Exception
 */
@Test
@RunAsClient
@OperateOnDeployment(SERVER_DEP)
@WrapThreadContextClassLoader
public void testNoSignatureUsername() throws Exception {
    Bus bus = BusFactory.newInstance().createBus();
    try {
        BusFactory.setThreadDefaultBus(bus);
        final QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/wssecuritypolicy", "SecurityService");
        final URL wsdlURL = new URL(serviceURL + "SecurityService?wsdl");
        Service service = Service.create(wsdlURL, serviceName);
        ServiceIface proxy = (ServiceIface) service.getPort(ServiceIface.class);
        final QName stsServiceName = new QName("http://docs.oasis-open.org/ws-sx/ws-trust/200512/", "SecurityTokenService");
        final QName stsPortName = new QName("http://docs.oasis-open.org/ws-sx/ws-trust/200512/", "UT_Port");
        URL stsURL = new URL(serviceURL.getProtocol(), serviceURL.getHost(), serviceURL.getPort(), "/jaxws-samples-wsse-policy-trust-sts/SecurityTokenService?wsdl");
        WSTrustTestUtils.setupWsseAndSTSClientNoSignatureUsername(proxy, bus, stsURL.toString(), stsServiceName, stsPortName);
        assertEquals("WS-Trust Hello World!", proxy.sayHello());
    } finally {
        bus.shutdown(true);
    }
}
Also used : Bus(org.apache.cxf.Bus) ServiceIface(org.jboss.test.ws.jaxws.samples.wsse.policy.trust.service.ServiceIface) ActAsServiceIface(org.jboss.test.ws.jaxws.samples.wsse.policy.trust.actas.ActAsServiceIface) OnBehalfOfServiceIface(org.jboss.test.ws.jaxws.samples.wsse.policy.trust.onbehalfof.OnBehalfOfServiceIface) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest) WrapThreadContextClassLoader(org.jboss.wsf.test.WrapThreadContextClassLoader)

Example 7 with ServiceIface

use of org.jboss.test.ws.jaxws.samples.wsse.policy.trust.service.ServiceIface in project jbossws-cxf by jbossws.

the class ActAsServiceImpl method sayHello.

public String sayHello(String host, String port) {
    Bus bus = BusFactory.newInstance().createBus();
    try {
        BusFactory.setThreadDefaultBus(bus);
        final String serviceURL = "http://" + host + ":" + port + "/jaxws-samples-wsse-policy-trust/SecurityService";
        final QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/wssecuritypolicy", "SecurityService");
        final URL wsdlURL = new URL(serviceURL + "?wsdl");
        Service service = Service.create(wsdlURL, serviceName);
        ServiceIface proxy = (ServiceIface) service.getPort(ServiceIface.class);
        Map<String, Object> ctx = ((BindingProvider) proxy).getRequestContext();
        ctx.put(SecurityConstants.CALLBACK_HANDLER, new ActAsCallbackHandler());
        ctx.put(SecurityConstants.SIGNATURE_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("actasKeystore.properties"));
        ctx.put(SecurityConstants.SIGNATURE_USERNAME, "myactaskey");
        ctx.put(SecurityConstants.ENCRYPT_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("../../META-INF/clientKeystore.properties"));
        ctx.put(SecurityConstants.ENCRYPT_USERNAME, "myservicekey");
        STSClient stsClient = new STSClient(bus);
        Map<String, Object> props = stsClient.getProperties();
        props.put(SecurityConstants.USERNAME, "alice");
        props.put(SecurityConstants.ENCRYPT_USERNAME, "mystskey");
        props.put(SecurityConstants.STS_TOKEN_USERNAME, "myactaskey");
        props.put(SecurityConstants.STS_TOKEN_PROPERTIES, Thread.currentThread().getContextClassLoader().getResource("actasKeystore.properties"));
        props.put(SecurityConstants.STS_TOKEN_USE_CERT_FOR_KEYINFO, "true");
        ctx.put(SecurityConstants.STS_CLIENT, stsClient);
        return "ActAs " + proxy.sayHello();
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return null;
    } finally {
        bus.shutdown(true);
    }
}
Also used : Bus(org.apache.cxf.Bus) STSClient(org.apache.cxf.ws.security.trust.STSClient) MalformedURLException(java.net.MalformedURLException) ServiceIface(org.jboss.test.ws.jaxws.samples.wsse.policy.trust.service.ServiceIface) QName(javax.xml.namespace.QName) WebService(javax.jws.WebService) Service(javax.xml.ws.Service) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL)

Aggregations

QName (javax.xml.namespace.QName)7 Service (javax.xml.ws.Service)7 Bus (org.apache.cxf.Bus)7 ServiceIface (org.jboss.test.ws.jaxws.samples.wsse.policy.trust.service.ServiceIface)7 URL (java.net.URL)6 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)5 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)5 ActAsServiceIface (org.jboss.test.ws.jaxws.samples.wsse.policy.trust.actas.ActAsServiceIface)5 OnBehalfOfServiceIface (org.jboss.test.ws.jaxws.samples.wsse.policy.trust.onbehalfof.OnBehalfOfServiceIface)5 JBossWSTest (org.jboss.wsf.test.JBossWSTest)5 WrapThreadContextClassLoader (org.jboss.wsf.test.WrapThreadContextClassLoader)5 Test (org.junit.Test)5 WebService (javax.jws.WebService)2 BindingProvider (javax.xml.ws.BindingProvider)2 STSClient (org.apache.cxf.ws.security.trust.STSClient)2 MalformedURLException (java.net.MalformedURLException)1