Java Code Examples for org.apache.cxf.endpoint.Client#getEndpoint()
The following examples show how to use
org.apache.cxf.endpoint.Client#getEndpoint() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PerUserPerServiceClientFactory.java From yes-cart with Apache License 2.0 | 6 votes |
private void configureClient(final String userName, final String passw, final long timeout, final Client client) { final HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setConnectionTimeout(timeout); httpClientPolicy.setAllowChunking(false); httpClientPolicy.setReceiveTimeout(timeout); ((HTTPConduit) client.getConduit()).setClient(httpClientPolicy); final Endpoint endpoint = client.getEndpoint(); final WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(new HashMap<String, Object>() {{ put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN); put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT); put(WSHandlerConstants.USER, userName); put(WSHandlerConstants.PW_CALLBACK_REF, new PWCallbackHandler(passw)); }}); endpoint.getOutInterceptors().add(wssOut); }
Example 2
Source File: CalculatorTest.java From tomee with Apache License 2.0 | 5 votes |
public void testCalculatorViaWsInterfaceWithSign() throws Exception { final Service calcService = Service.create(new URL("http://localhost:" + port + "/webservice-ws-security/CalculatorImplSign?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/CalculatorImplSign"); // 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.SIGNATURE); outProps.put(WSHandlerConstants.USER, "clientalias"); 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("clientPassword"); } }); outProps.put(WSHandlerConstants.SIG_PROP_FILE, "META-INF/CalculatorImplSign-client.properties"); outProps.put(WSHandlerConstants.SIG_KEY_ID, "IssuerSerial"); final WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps); endpoint.getOutInterceptors().add(wssOut); assertEquals(24, calc.multiply(4, 6)); }
Example 3
Source File: CalculatorTest.java From tomee with Apache License 2.0 | 5 votes |
public void testCalculatorViaWsInterfaceWithUsernameTokenHashedPassword() throws Exception { final Service calcService = Service.create(new URL("http://localhost:" + port + "/webservice-ws-security/CalculatorImplUsernameTokenHashedPassword?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/CalculatorImplUsernameTokenHashedPassword"); // 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); outProps.put(WSHandlerConstants.USER, "jane"); outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST); 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)); }
Example 4
Source File: CachingTest.java From cxf with Apache License 2.0 | 5 votes |
@org.junit.Test public void testImminentExpiry() throws Exception { SpringBusFactory bf = new SpringBusFactory(); URL busFile = CachingTest.class.getResource("cxf-client.xml"); Bus bus = bf.createBus(busFile.toString()); BusFactory.setDefaultBus(bus); BusFactory.setThreadDefaultBus(bus); URL wsdl = CachingTest.class.getResource("DoubleIt.wsdl"); Service service = Service.create(wsdl, SERVICE_QNAME); QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML1Port"); DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class); ((BindingProvider)port).getRequestContext().put("thread.local.request.context", "true"); updateAddressPort(port, PORT); // Make a successful invocation doubleIt(port, 25); Client client = ClientProxy.getClient(port); Endpoint ep = client.getEndpoint(); String id = (String)ep.get(SecurityConstants.TOKEN_ID); TokenStore store = (TokenStore)ep.getEndpointInfo().getProperty(TokenStore.class.getName()); SecurityToken tok = store.getToken(id); assertNotNull(tok); // Make the token "about to expire" tok.setExpires(Instant.now().plusSeconds(5L)); assertTrue(tok.isAboutToExpire(10L)); doubleIt(port, 25); ((java.io.Closeable)port).close(); bus.shutdown(true); }
Example 5
Source File: TokenTestUtils.java From cxf with Apache License 2.0 | 5 votes |
public static void verifyToken(DoubleItPortType port) throws Exception { Client client = ClientProxy.getClient(port); Endpoint ep = client.getEndpoint(); String id = (String)ep.get(SecurityConstants.TOKEN_ID); TokenStore store = (TokenStore)ep.getEndpointInfo().getProperty(TokenStore.class.getName()); org.apache.cxf.ws.security.tokenstore.SecurityToken tok = store.getToken(id); assertNotNull(tok); STSClient sts = (STSClient)ep.get(SecurityConstants.STS_CLIENT); List<SecurityToken> validTokens = sts.validateSecurityToken(tok); assertTrue(validTokens != null && !validTokens.isEmpty()); //mess with the token a bit to force it to fail to validate Element e = tok.getToken(); Element e2 = DOMUtils.getFirstChildWithName(e, e.getNamespaceURI(), "Conditions"); String nb = e2.getAttributeNS(null, "NotBefore"); String noa = e2.getAttributeNS(null, "NotOnOrAfter"); nb = "2010" + nb.substring(4); noa = "2010" + noa.substring(4); e2.setAttributeNS(null, "NotBefore", nb); e2.setAttributeNS(null, "NotOnOrAfter", noa); try { sts.validateSecurityToken(tok); fail("Failure expected on an invalid token"); } catch (org.apache.cxf.ws.security.trust.TrustException ex) { // expected } }
Example 6
Source File: DispatchImpl.java From cxf with Apache License 2.0 | 5 votes |
DispatchImpl(Client client, Service.Mode m, JAXBContext ctx, Class<T> clazz) { this.binding = ((JaxWsEndpointImpl)client.getEndpoint()).getJaxwsBinding(); this.builder = new EndpointReferenceBuilder((JaxWsEndpointImpl)client.getEndpoint()); this.client = client; this.mode = m; context = ctx; cl = clazz; setupEndpointAddressContext(client.getEndpoint()); addInvokeOperation(false); addInvokeOperation(true); if (m == Service.Mode.MESSAGE && binding instanceof SOAPBinding) { if (DataSource.class.isAssignableFrom(clazz)) { error = new Message("DISPATCH_OBJECT_NOT_SUPPORTED", LOG, "DataSource", m, "SOAP/HTTP"); } else if (m == Service.Mode.MESSAGE) { SAAJOutInterceptor saajOut = new SAAJOutInterceptor(); client.getOutInterceptors().add(saajOut); client.getOutInterceptors(). add(new MessageModeOutInterceptor(saajOut, client.getEndpoint() .getBinding().getBindingInfo().getName())); client.getInInterceptors().add(new SAAJInInterceptor()); client.getInInterceptors() .add(new MessageModeInInterceptor(clazz, client.getEndpoint() .getBinding().getBindingInfo().getName())); } } else if (m == Service.Mode.PAYLOAD && binding instanceof SOAPBinding && SOAPMessage.class.isAssignableFrom(clazz)) { error = new Message("DISPATCH_OBJECT_NOT_SUPPORTED", LOG, "SOAPMessage", m, "SOAP/HTTP"); } }
Example 7
Source File: CalculatorTest.java From tomee with Apache License 2.0 | 5 votes |
public void testCalculatorViaWsInterfaceWithUsernameTokenPlainPassword() throws Exception { final Service calcService = Service.create(new URL("http://localhost:" + port + "/webservice-ws-security/CalculatorImplUsernameTokenPlainPassword?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/CalculatorImplUsernameTokenPlainPassword"); // 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); 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)); }
Example 8
Source File: ConfiguredEndpointTest.java From cxf with Apache License 2.0 | 5 votes |
private void doTestConfiguredClientEndpoint() { javax.xml.ws.Service service = new SOAPService(); Greeter greeter = service.getPort(PORT_NAME, Greeter.class); JaxWsClientProxy eih = (JaxWsClientProxy)Proxy.getInvocationHandler(greeter); Client client = eih.getClient(); JaxWsEndpointImpl endpoint = (JaxWsEndpointImpl)client.getEndpoint(); org.apache.cxf.service.ServiceImpl svc = (org.apache.cxf.service.ServiceImpl)endpoint.getService(); assertEquals("Unexpected bean name.", SERVICE_NAME.toString(), svc.getBeanName()); List<Interceptor<? extends Message>> interceptors = svc.getInInterceptors(); assertEquals("Unexpected number of interceptors: " + interceptors, 1, interceptors.size()); assertEquals("Unexpected interceptor id.", "service-in", findTestInterceptor(interceptors).getId()); interceptors = svc.getOutInterceptors(); assertEquals("Unexpected number of interceptors: " + interceptors, 1, interceptors.size()); assertEquals("Unexpected interceptor id.", "service-out", findTestInterceptor(interceptors).getId()); interceptors = svc.getInFaultInterceptors(); assertEquals("Unexpected number of interceptors: " + interceptors, 1, interceptors.size()); assertEquals("Unexpected interceptor id.", "service-in-fault", findTestInterceptor(interceptors).getId()); interceptors = svc.getOutFaultInterceptors(); assertEquals("Unexpected number of interceptors: " + interceptors, 1, interceptors.size()); assertEquals("Unexpected interceptor id.", "service-out-fault", findTestInterceptor(interceptors).getId()); }
Example 9
Source File: WSPolicyFeature.java From cxf with Apache License 2.0 | 5 votes |
@Override public void initialize(Client client, Bus bus) { Endpoint endpoint = client.getEndpoint(); Policy p = initializeEndpointPolicy(endpoint, bus); PolicyEngine pe = bus.getExtension(PolicyEngine.class); EndpointInfo ei = endpoint.getEndpointInfo(); EndpointPolicy ep = pe.getClientEndpointPolicy(ei, null, null); pe.setClientEndpointPolicy(ei, ep.updatePolicy(p, createMessage(endpoint, bus))); }
Example 10
Source File: CalculatorTest.java From tomee with Apache License 2.0 | 5 votes |
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)); }
Example 11
Source File: CalculatorTest.java From tomee with Apache License 2.0 | 5 votes |
public void testCalculatorViaWsInterfaceFactoryBean() throws Exception { final JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setServiceClass(CalculatorWs.class); factory.setAddress("http://localhost:" + port + "/webservice-ws-security/CalculatorImpl"); final CalculatorWs calc = (CalculatorWs) factory.create(); 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)); }
Example 12
Source File: CalculatorTest.java From tomee with Apache License 2.0 | 5 votes |
public void testCalculatorViaWsInterfaceWithTimestamp1way() throws Exception { final Service calcService = Service.create(new URL("http://localhost:" + port + "/webservice-ws-security/CalculatorImplTimestamp1way?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/CalculatorImplTimestamp1way"); // 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.TIMESTAMP); final WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps); endpoint.getOutInterceptors().add(wssOut); assertEquals(12, calc.multiply(3, 4)); }
Example 13
Source File: CalculatorTest.java From tomee with Apache License 2.0 | 5 votes |
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)); }
Example 14
Source File: ClientProxy.java From cxf with Apache License 2.0 | 4 votes |
public ClientProxy(Client c) { endpoint = c.getEndpoint(); client = c; }
Example 15
Source File: CalculatorTest.java From tomee with Apache License 2.0 | 4 votes |
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)); }
Example 16
Source File: ConfiguredEndpointTest.java From cxf with Apache License 2.0 | 4 votes |
private void doTestDefaultClientEndpoint() { javax.xml.ws.Service service = new SOAPService(); Greeter greeter = service.getPort(PORT_NAME, Greeter.class); JaxWsClientProxy eih = (JaxWsClientProxy)Proxy.getInvocationHandler(greeter); Client client = eih.getClient(); JaxWsEndpointImpl endpoint = (JaxWsEndpointImpl)client.getEndpoint(); assertEquals("Unexpected bean name", PORT_NAME.toString() + ".endpoint", endpoint.getBeanName()); assertFalse("Unexpected value for property validating", Boolean.TRUE.equals(endpoint.get(Message.SCHEMA_VALIDATION_ENABLED))); // System.out.println("endpoint interceptors"); List<Interceptor<? extends Message>> interceptors = endpoint.getInInterceptors(); printInterceptors("in", interceptors); assertNull("Unexpected test interceptor", findTestInterceptor(interceptors)); interceptors = endpoint.getOutInterceptors(); printInterceptors("out", interceptors); assertNull("Unexpected test interceptor", findTestInterceptor(interceptors)); interceptors = endpoint.getInFaultInterceptors(); printInterceptors("inFault", interceptors); assertNull("Unexpected test interceptor", findTestInterceptor(interceptors)); interceptors = endpoint.getOutFaultInterceptors(); printInterceptors("outFault", interceptors); assertNull("Unexpected test interceptor", findTestInterceptor(interceptors)); // System.out.println("service interceptors"); org.apache.cxf.service.ServiceImpl svc = (org.apache.cxf.service.ServiceImpl)endpoint.getService(); assertEquals("Unexpected bean name", SERVICE_NAME.toString(), svc.getBeanName()); interceptors = svc.getInInterceptors(); printInterceptors("in", interceptors); assertNull("Unexpected test interceptor", findTestInterceptor(interceptors)); interceptors = svc.getOutInterceptors(); printInterceptors("out", interceptors); assertNull("Unexpected test interceptor", findTestInterceptor(interceptors)); interceptors = svc.getInFaultInterceptors(); printInterceptors("inFault", interceptors); assertNull("Unexpected test interceptor", findTestInterceptor(interceptors)); interceptors = svc.getOutFaultInterceptors(); printInterceptors("outFault", interceptors); assertNull("Unexpected test interceptor", findTestInterceptor(interceptors)); }
Example 17
Source File: CachingTest.java From cxf with Apache License 2.0 | 4 votes |
@org.junit.Test public void testSTSClientCaching() throws Exception { SpringBusFactory bf = new SpringBusFactory(); URL busFile = CachingTest.class.getResource("cxf-client.xml"); Bus bus = bf.createBus(busFile.toString()); BusFactory.setDefaultBus(bus); BusFactory.setThreadDefaultBus(bus); URL wsdl = CachingTest.class.getResource("DoubleIt.wsdl"); Service service = Service.create(wsdl, SERVICE_QNAME); QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML1Port"); DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class); ((BindingProvider)port).getRequestContext().put("thread.local.request.context", "true"); updateAddressPort(port, PORT); // Make a successful invocation doubleIt(port, 25); // Change the STSClient so that it can no longer find the STS BindingProvider p = (BindingProvider)port; clearSTSClient(p, bus); // This should succeed as the token is cached doubleIt(port, 30); // This should fail as the cached token is manually removed Client client = ClientProxy.getClient(port); Endpoint ep = client.getEndpoint(); ep.remove(SecurityConstants.TOKEN_ID); ep.remove(SecurityConstants.TOKEN); try { doubleIt(port, 35); fail("Expected failure on clearing the cache"); } catch (SOAPFaultException ex) { // Expected } ((java.io.Closeable)port).close(); bus.shutdown(true); }
Example 18
Source File: ServerCachingTest.java From cxf with Apache License 2.0 | 4 votes |
@org.junit.Test public void testServerSideSAMLTokenCaching() throws Exception { SpringBusFactory bf = new SpringBusFactory(); URL busFile = ServerCachingTest.class.getResource("cxf-client.xml"); Bus bus = bf.createBus(busFile.toString()); BusFactory.setDefaultBus(bus); BusFactory.setThreadDefaultBus(bus); URL wsdl = ServerCachingTest.class.getResource("DoubleIt.wsdl"); Service service = Service.create(wsdl, SERVICE_QNAME); QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML1AlternativePort"); DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class); ((BindingProvider)port).getRequestContext().put("thread.local.request.context", "true"); updateAddressPort(port, PORT); // Make an initial successful invocation doubleIt(port, 25); // Store the SAML Assertion that was obtained from the STS Client client = ClientProxy.getClient(port); Endpoint ep = client.getEndpoint(); String id = (String)ep.get(SecurityConstants.TOKEN_ID); TokenStore store = (TokenStore)ep.getEndpointInfo().getProperty(TokenStore.class.getName()); SecurityToken tok = store.getToken(id); assertNotNull(tok); Element storedToken = tok.getToken(); // Get another security token by invoking on the STS directly and save it on the client port SecurityToken token = requestSecurityToken(SAML1_TOKEN_TYPE, PUBLIC_KEY_KEYTYPE, bus, DEFAULT_ADDRESS); assertNotNull(token); tok.setToken(token.getToken()); // Try another invocation - this will fail as the STSClient on the server side is disabled // after the first invocation try { doubleIt(port, 30); fail("Failure expected as the STSClient on the server side is null"); } catch (Exception ex) { // expected } // Try again using the original SAML token - this should work as it should be cached by the service tok.setToken(storedToken); doubleIt(port, 35); ((java.io.Closeable)port).close(); bus.shutdown(true); }
Example 19
Source File: JAXRSHttpsBookTest.java From cxf with Apache License 2.0 | 4 votes |
@Override public void clientCreated(Client client) { this.ep = client.getEndpoint(); }