Java Code Examples for org.apache.cxf.frontend.ClientProxy#getClient()
The following examples show how to use
org.apache.cxf.frontend.ClientProxy#getClient() .
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: TransformFeatureTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testClientOutTransformationOnConnectionRefused() throws IOException { Service service = Service.create(SERVICE_NAME); ServerSocket socket = new ServerSocket(0); String endpoint = "http://127.0.0.1:" + socket.getLocalPort() + "/"; socket.close(); service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpoint); Echo port = service.getPort(PORT_NAME, Echo.class); Client client = ClientProxy.getClient(port); HTTPConduit httpConduit = (HTTPConduit) client.getConduit(); // We need to disable chunking to make the client write directly to the connection OutputStream httpConduit.getClient().setAllowChunking(false); XSLTOutInterceptor outInterceptor = new XSLTOutInterceptor(XSLT_REQUEST_PATH); client.getOutInterceptors().add(outInterceptor); try { port.echo("test"); fail("Connection refused expected"); } catch (Exception e) { String exceptionMessage = e.getMessage(); assertTrue(exceptionMessage.toLowerCase().contains("connection refused")); } }
Example 2
Source File: StaxRoundTripTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testEncryptUsernameTokenConfig() throws Exception { // Create + configure service Service service = createService(); Map<String, Object> inConfig = new HashMap<>(); inConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback()); inConfig.put(ConfigurationConstants.DEC_PROP_FILE, "insecurity.properties"); WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inConfig); service.getInInterceptors().add(inhandler); // Create + configure client Echo echo = createClientProxy(); Client client = ClientProxy.getClient(echo); client.getInInterceptors().add(new LoggingInInterceptor()); client.getOutInterceptors().add(new LoggingOutInterceptor()); Map<String, Object> outConfig = new HashMap<>(); outConfig.put( ConfigurationConstants.ACTION, ConfigurationConstants.USERNAME_TOKEN + " " + ConfigurationConstants.ENCRYPTION ); outConfig.put( ConfigurationConstants.ENCRYPTION_PARTS, "{Element}{" + WSSConstants.NS_WSSE10 + "}UsernameToken" ); outConfig.put(ConfigurationConstants.USER, "username"); outConfig.put(ConfigurationConstants.ENCRYPTION_USER, "myalias"); outConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback()); outConfig.put(ConfigurationConstants.ENC_PROP_FILE, "outsecurity.properties"); outConfig.put(ConfigurationConstants.ENC_SYM_ALGO, XMLSecurityConstants.NS_XENC_AES128); WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(outConfig); client.getOutInterceptors().add(ohandler); assertEquals("test", echo.echo("test")); }
Example 3
Source File: StaxRoundTripTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testSignature() throws Exception { // Create + configure service Service service = createService(); WSSSecurityProperties inProperties = new WSSSecurityProperties(); inProperties.setCallbackHandler(new TestPwdCallback()); Properties cryptoProperties = CryptoFactory.getProperties("insecurity.properties", this.getClass().getClassLoader()); inProperties.setSignatureVerificationCryptoProperties(cryptoProperties); WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties); WSS4JPrincipalInterceptor principalInterceptor = new WSS4JPrincipalInterceptor(); principalInterceptor.setPrincipalName("CN=myAlias"); service.getInInterceptors().add(inhandler); service.getInInterceptors().add(principalInterceptor); // Create + configure client Echo echo = createClientProxy(); Client client = ClientProxy.getClient(echo); client.getInInterceptors().add(new LoggingInInterceptor()); client.getOutInterceptors().add(new LoggingOutInterceptor()); WSSSecurityProperties properties = new WSSSecurityProperties(); List<WSSConstants.Action> actions = new ArrayList<>(); actions.add(XMLSecurityConstants.SIGNATURE); properties.setActions(actions); properties.setSignatureUser("myalias"); Properties outCryptoProperties = CryptoFactory.getProperties("outsecurity.properties", this.getClass().getClassLoader()); properties.setSignatureCryptoProperties(outCryptoProperties); properties.setCallbackHandler(new TestPwdCallback()); WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties); client.getOutInterceptors().add(ohandler); assertEquals("test", echo.echo("test")); }
Example 4
Source File: WebServiceProtocol.java From dubbox with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcException { ClientProxyFactoryBean proxyFactoryBean = new ClientProxyFactoryBean(); proxyFactoryBean.setAddress(url.setProtocol("http").toIdentityString()); proxyFactoryBean.setServiceClass(serviceType); proxyFactoryBean.setBus(bus); T ref = (T) proxyFactoryBean.create(); Client proxy = ClientProxy.getClient(ref); HTTPConduit conduit = (HTTPConduit) proxy.getConduit(); HTTPClientPolicy policy = new HTTPClientPolicy(); policy.setConnectionTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT)); policy.setReceiveTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)); conduit.setClient(policy); return ref; }
Example 5
Source File: WebServiceProtocol.java From dubbox with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcException { ClientProxyFactoryBean proxyFactoryBean = new ClientProxyFactoryBean(); proxyFactoryBean.setAddress(url.setProtocol("http").toIdentityString()); proxyFactoryBean.setServiceClass(serviceType); proxyFactoryBean.setBus(bus); T ref = (T) proxyFactoryBean.create(); Client proxy = ClientProxy.getClient(ref); HTTPConduit conduit = (HTTPConduit) proxy.getConduit(); HTTPClientPolicy policy = new HTTPClientPolicy(); policy.setConnectionTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT)); policy.setReceiveTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)); conduit.setClient(policy); return ref; }
Example 6
Source File: DOMToStaxEncryptionIdentifierTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testEncryptDirectReference() throws Exception { // Create + configure service Service service = createService(); WSSSecurityProperties inProperties = new WSSSecurityProperties(); inProperties.setCallbackHandler(new TestPwdCallback()); Properties cryptoProperties = CryptoFactory.getProperties("insecurity.properties", this.getClass().getClassLoader()); inProperties.setDecryptionCryptoProperties(cryptoProperties); WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties); service.getInInterceptors().add(inhandler); // Create + configure client Echo echo = createClientProxy(); Client client = ClientProxy.getClient(echo); client.getInInterceptors().add(new LoggingInInterceptor()); client.getOutInterceptors().add(new LoggingOutInterceptor()); Map<String, Object> properties = new HashMap<>(); properties.put(ConfigurationConstants.ACTION, ConfigurationConstants.ENCRYPTION); properties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback()); properties.put(ConfigurationConstants.ENC_PROP_FILE, "outsecurity.properties"); properties.put(ConfigurationConstants.USER, "myalias"); properties.put(ConfigurationConstants.ENC_KEY_ID, "DirectReference"); WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor(properties); client.getOutInterceptors().add(ohandler); assertEquals("test", echo.echo("test")); }
Example 7
Source File: StaxToDOMRoundTripTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testSignaturePKI() throws Exception { // Create + configure service Service service = createService(); Map<String, Object> inProperties = new HashMap<>(); inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SIGNATURE); inProperties.put(ConfigurationConstants.PW_CALLBACK_REF, new KeystorePasswordCallback()); inProperties.put(ConfigurationConstants.SIG_VER_PROP_FILE, "cxfca.properties"); WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties); service.getInInterceptors().add(inInterceptor); // Create + configure client Echo echo = createClientProxy(); Client client = ClientProxy.getClient(echo); client.getInInterceptors().add(new LoggingInInterceptor()); client.getOutInterceptors().add(new LoggingOutInterceptor()); WSSSecurityProperties properties = new WSSSecurityProperties(); List<WSSConstants.Action> actions = new ArrayList<>(); actions.add(XMLSecurityConstants.SIGNATURE); properties.setActions(actions); properties.setSignatureUser("alice"); Properties cryptoProperties = CryptoFactory.getProperties("alice.properties", this.getClass().getClassLoader()); properties.setSignatureCryptoProperties(cryptoProperties); properties.setCallbackHandler(new KeystorePasswordCallback()); properties.setUseSingleCert(true); properties.setSignatureKeyIdentifier( WSSecurityTokenConstants.KEYIDENTIFIER_SECURITY_TOKEN_DIRECT_REFERENCE ); WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties); client.getOutInterceptors().add(ohandler); assertEquals("test", echo.echo("test")); }
Example 8
Source File: ProtocolVariationsTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testRM10WSA15() throws Exception { init("org/apache/cxf/systest/ws/rm/rminterceptors.xml", false); // WS-RM 1.0, but using the WS-A 1.0 namespace Client client = ClientProxy.getClient(greeter); client.getRequestContext().put(RMManager.WSRM_WSA_VERSION_PROPERTY, Names.WSA_NAMESPACE_NAME); assertEquals("ONE", greeter.greetMe("one")); assertEquals("TWO", greeter.greetMe("two")); assertEquals("THREE", greeter.greetMe("three")); verifyTwowayNonAnonymous(Names.WSA_NAMESPACE_NAME, RM10Constants.INSTANCE); }
Example 9
Source File: RemoteTestHarness.java From rice with Educational Community License v2.0 | 5 votes |
@SuppressWarnings("unchecked") /** * Creates a published endpoint from the passed in serviceImplementation and also returns a proxy implementation * of the passed in interface for clients to use to hit the created endpoint. */ public <T> T publishEndpointAndReturnProxy(Class<T> jaxWsAnnotatedInterface, T serviceImplementation) { if (jaxWsAnnotatedInterface.isInterface() && jaxWsAnnotatedInterface.getAnnotation(WebService.class) != null && jaxWsAnnotatedInterface.isInstance(serviceImplementation)) { String endpointUrl = getAvailableEndpointUrl(); LOG.info("Publishing service to: " + endpointUrl); endpoint = Endpoint.publish(endpointUrl, serviceImplementation); JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setServiceClass(jaxWsAnnotatedInterface); factory.setAddress(endpointUrl); T serviceProxy = (T) factory.create(); /* Add the ImmutableCollectionsInInterceptor to mimic interceptors added in the KSB */ Client cxfClient = ClientProxy.getClient(serviceProxy); cxfClient.getInInterceptors().add(new ImmutableCollectionsInInterceptor()); return serviceProxy; } else { throw new IllegalArgumentException("Passed in interface class type must be annotated with @WebService " + "and object reference must be an implementing class of that interface."); } }
Example 10
Source File: StaxToDOMRoundTripTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testEncryptConfig() throws Exception { // Create + configure service Service service = createService(); Map<String, Object> inProperties = new HashMap<>(); inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.ENCRYPTION); inProperties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback()); inProperties.put(ConfigurationConstants.DEC_PROP_FILE, "insecurity.properties"); WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties); service.getInInterceptors().add(inInterceptor); // Create + configure client Echo echo = createClientProxy(); Client client = ClientProxy.getClient(echo); client.getInInterceptors().add(new LoggingInInterceptor()); client.getOutInterceptors().add(new LoggingOutInterceptor()); Map<String, Object> outConfig = new HashMap<>(); outConfig.put(ConfigurationConstants.ACTION, ConfigurationConstants.ENCRYPTION); outConfig.put(ConfigurationConstants.ENCRYPTION_USER, "myalias"); outConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback()); outConfig.put(ConfigurationConstants.ENC_PROP_FILE, "outsecurity.properties"); outConfig.put(ConfigurationConstants.ENC_SYM_ALGO, XMLSecurityConstants.NS_XENC_AES128); WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(outConfig); client.getOutInterceptors().add(ohandler); assertEquals("test", echo.echo("test")); }
Example 11
Source File: StaxToDOMEncryptionIdentifierTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testEncryptDirectReference() throws Exception { // Create + configure service Service service = createService(); Map<String, Object> inProperties = new HashMap<>(); inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.ENCRYPTION); inProperties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback()); inProperties.put(ConfigurationConstants.DEC_PROP_FILE, "insecurity.properties"); WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties); service.getInInterceptors().add(inInterceptor); // Create + configure client Echo echo = createClientProxy(); Client client = ClientProxy.getClient(echo); client.getInInterceptors().add(new LoggingInInterceptor()); client.getOutInterceptors().add(new LoggingOutInterceptor()); WSSSecurityProperties properties = new WSSSecurityProperties(); List<WSSConstants.Action> actions = new ArrayList<>(); actions.add(XMLSecurityConstants.ENCRYPTION); properties.setActions(actions); properties.setEncryptionUser("myalias"); properties.setEncryptionKeyIdentifier( WSSecurityTokenConstants.KEYIDENTIFIER_SECURITY_TOKEN_DIRECT_REFERENCE ); properties.setEncryptionSymAlgorithm(XMLSecurityConstants.NS_XENC_AES128); Properties cryptoProperties = CryptoFactory.getProperties("outsecurity.properties", this.getClass().getClassLoader()); properties.setEncryptionCryptoProperties(cryptoProperties); properties.setCallbackHandler(new TestPwdCallback()); WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties); client.getOutInterceptors().add(ohandler); assertEquals("test", echo.echo("test")); }
Example 12
Source File: StaxRoundTripActionTest.java From cxf with Apache License 2.0 | 4 votes |
@Test public void testUsernameToken() throws Exception { // Create + configure service Service service = createService(); WSSSecurityProperties inProperties = new WSSSecurityProperties(); List<WSSConstants.Action> actions = new ArrayList<>(); actions.add(WSSConstants.USERNAMETOKEN); inProperties.setActions(actions); inProperties.setCallbackHandler(new TestPwdCallback()); WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties); WSS4JPrincipalInterceptor principalInterceptor = new WSS4JPrincipalInterceptor(); principalInterceptor.setPrincipalName("username"); service.getInInterceptors().add(inhandler); service.getInInterceptors().add(principalInterceptor); // Create + configure client Echo echo = createClientProxy(); Client client = ClientProxy.getClient(echo); client.getInInterceptors().add(new LoggingInInterceptor()); client.getOutInterceptors().add(new LoggingOutInterceptor()); WSSSecurityProperties properties = new WSSSecurityProperties(); actions = new ArrayList<>(); actions.add(WSSConstants.USERNAMETOKEN); properties.setActions(actions); properties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_TEXT); properties.setTokenUser("username"); properties.setCallbackHandler(new TestPwdCallback()); WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties); client.getOutInterceptors().add(ohandler); assertEquals("test", echo.echo("test")); actions = new ArrayList<>(); actions.add(WSSConstants.USERNAMETOKEN); actions.add(XMLSecurityConstants.ENCRYPTION); inProperties.setActions(actions); try { echo.echo("test"); fail("Failure expected on the wrong action"); } catch (javax.xml.ws.soap.SOAPFaultException ex) { // expected assertTrue(ex.getMessage().contains(WSSecurityException.UNIFIED_SECURITY_ERR)); } }
Example 13
Source File: RoundTripTest.java From steady with Apache License 2.0 | 4 votes |
@Before public void setUpService() throws Exception { JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean(); factory.setServiceBean(new EchoImpl()); factory.setAddress("local://Echo"); factory.setTransportId(LocalTransportFactory.TRANSPORT_ID); Server server = factory.create(); Service service = server.getEndpoint().getService(); service.getInInterceptors().add(new SAAJInInterceptor()); service.getInInterceptors().add(new LoggingInInterceptor()); service.getOutInterceptors().add(new SAAJOutInterceptor()); service.getOutInterceptors().add(new LoggingOutInterceptor()); wsIn = new WSS4JInInterceptor(); wsIn.setProperty(WSHandlerConstants.SIG_PROP_FILE, "insecurity.properties"); wsIn.setProperty(WSHandlerConstants.DEC_PROP_FILE, "insecurity.properties"); wsIn.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName()); service.getInInterceptors().add(wsIn); wsOut = new WSS4JOutInterceptor(); wsOut.setProperty(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties"); wsOut.setProperty(WSHandlerConstants.ENC_PROP_FILE, "outsecurity.properties"); wsOut.setProperty(WSHandlerConstants.USER, "myalias"); wsOut.setProperty("password", "myAliasPassword"); wsOut.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName()); service.getOutInterceptors().add(wsOut); // Create the client JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean(); proxyFac.setServiceClass(Echo.class); proxyFac.setAddress("local://Echo"); proxyFac.getClientFactoryBean().setTransportId(LocalTransportFactory.TRANSPORT_ID); echo = (Echo)proxyFac.create(); client = ClientProxy.getClient(echo); client.getInInterceptors().add(new LoggingInInterceptor()); client.getInInterceptors().add(wsIn); client.getInInterceptors().add(new SAAJInInterceptor()); client.getOutInterceptors().add(new LoggingOutInterceptor()); client.getOutInterceptors().add(wsOut); client.getOutInterceptors().add(new SAAJOutInterceptor()); }
Example 14
Source File: ClientAuthTest.java From cxf with Apache License 2.0 | 4 votes |
@org.junit.Test public void testDirectTrustUsingSSLContext() throws Exception { URL url = SOAPService.WSDL_LOCATION; SOAPService service = new SOAPService(url, SOAPService.SERVICE); assertNotNull("Service is null", service); final Greeter port = service.getHttpsPort(); assertNotNull("Port is null", port); updateAddressPort(port, PORT); // Enable Async if (async) { ((BindingProvider)port).getRequestContext().put("use.async.http.conduit", true); } // Set up KeyManagers/TrustManagers KeyStore ts = KeyStore.getInstance("JKS"); try (InputStream trustStore = ClassLoaderUtils.getResourceAsStream("keys/Truststore.jks", ClientAuthTest.class)) { ts.load(trustStore, "password".toCharArray()); } TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); tmf.init(ts); KeyStore ks = KeyStore.getInstance("JKS"); try (InputStream keyStore = ClassLoaderUtils.getResourceAsStream("keys/Morpit.jks", ClientAuthTest.class)) { ks.load(keyStore, "password".toCharArray()); } KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmf.init(ks, "password".toCharArray()); SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), new java.security.SecureRandom()); TLSClientParameters tlsParams = new TLSClientParameters(); tlsParams.setSslContext(sslContext); tlsParams.setDisableCNCheck(true); Client client = ClientProxy.getClient(port); HTTPConduit http = (HTTPConduit) client.getConduit(); http.setTlsClientParameters(tlsParams); assertEquals(port.greetMe("Kitty"), "Hello Kitty"); // Enable Async ((BindingProvider)port).getRequestContext().put("use.async.http.conduit", true); assertEquals(port.greetMe("Kitty"), "Hello Kitty"); ((java.io.Closeable)port).close(); }
Example 15
Source File: DOMToStaxSamlTest.java From cxf with Apache License 2.0 | 4 votes |
@Test public void testSaml1TokenHOK() throws Exception { // Create + configure service Service service = createService(); WSSSecurityProperties inProperties = new WSSSecurityProperties(); Properties cryptoProperties = CryptoFactory.getProperties("insecurity.properties", this.getClass().getClassLoader()); inProperties.setSignatureVerificationCryptoProperties(cryptoProperties); CustomStaxSamlValidator validator = new CustomStaxSamlValidator(); inProperties.addValidator(WSConstants.SAML_TOKEN, validator); inProperties.addValidator(WSConstants.SAML2_TOKEN, validator); WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties); service.getInInterceptors().add(inhandler); // Create + configure client Echo echo = createClientProxy(); Client client = ClientProxy.getClient(echo); client.getInInterceptors().add(new LoggingInInterceptor()); client.getOutInterceptors().add(new LoggingOutInterceptor()); Map<String, Object> properties = new HashMap<>(); properties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_SIGNED); SAML1CallbackHandler callbackHandler = new SAML1CallbackHandler(); callbackHandler.setConfirmationMethod(SAML1Constants.CONF_HOLDER_KEY); callbackHandler.setSignAssertion(true); properties.put(ConfigurationConstants.SAML_CALLBACK_REF, callbackHandler); properties.put(ConfigurationConstants.SIG_KEY_ID, "DirectReference"); properties.put(ConfigurationConstants.USER, "alice"); properties.put(ConfigurationConstants.PW_CALLBACK_REF, new PasswordCallbackHandler()); properties.put(ConfigurationConstants.SIG_PROP_FILE, "alice.properties"); WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor(properties); client.getOutInterceptors().add(ohandler); try { echo.echo("test"); fail("Failure expected on receiving sender vouches instead of HOK"); } catch (javax.xml.ws.soap.SOAPFaultException ex) { // expected } validator.setRequireSenderVouches(false); assertEquals("test", echo.echo("test")); }
Example 16
Source File: TrustManagerTest.java From cxf with Apache License 2.0 | 4 votes |
@org.junit.Test public void testInvalidServerCertX509TrustManager() throws Exception { SpringBusFactory bf = new SpringBusFactory(); URL busFile = TrustManagerTest.class.getResource("client-trust.xml"); Bus bus = bf.createBus(busFile.toString()); BusFactory.setDefaultBus(bus); BusFactory.setThreadDefaultBus(bus); URL url = SOAPService.WSDL_LOCATION; SOAPService service = new SOAPService(url, SOAPService.SERVICE); assertNotNull("Service is null", service); final Greeter port = service.getHttpsPort(); assertNotNull("Port is null", port); updateAddressPort(port, PORT); // Enable Async if (async) { ((BindingProvider)port).getRequestContext().put("use.async.http.conduit", true); } String invalidPrincipalName = "CN=Bethal2,OU=Bethal,O=ApacheTest,L=Syracuse,C=US"; TLSClientParameters tlsParams = new TLSClientParameters(); X509TrustManager trustManager = new ServerCertX509TrustManager(invalidPrincipalName); TrustManager[] trustManagers = new TrustManager[1]; trustManagers[0] = trustManager; tlsParams.setTrustManagers(trustManagers); tlsParams.setDisableCNCheck(true); Client client = ClientProxy.getClient(port); HTTPConduit http = (HTTPConduit) client.getConduit(); http.setTlsClientParameters(tlsParams); try { port.greetMe("Kitty"); fail("Failure expected on an invalid principal name"); } catch (Exception ex) { // expected } ((java.io.Closeable)port).close(); bus.shutdown(true); }
Example 17
Source File: InterceptorFaultTest.java From cxf with Apache License 2.0 | 4 votes |
private void setupGreeter(String cfgResource, boolean useDecoupledEndpoint) throws NumberFormatException, MalformedURLException { SpringBusFactory bf = new SpringBusFactory(); controlBus = bf.createBus(); BusFactory.setDefaultBus(controlBus); ControlService cs = new ControlService(); control = cs.getControlPort(); updateAddressPort(control, PORT); assertTrue("Failed to start greeter", control.startGreeter(cfgResource)); greeterBus = bf.createBus(cfgResource); BusFactory.setDefaultBus(greeterBus); LOG.fine("Initialised greeter bus with configuration: " + cfgResource); if (null == comparator) { comparator = new PhaseComparator(); } if (null == inPhases) { inPhases = new ArrayList<>(); inPhases.addAll(greeterBus.getExtension(PhaseManager.class).getInPhases()); Collections.sort(inPhases, comparator); } if (null == postUnMarshalPhase) { postUnMarshalPhase = getPhase(Phase.POST_UNMARSHAL); } GreeterService gs = new GreeterService(); greeter = gs.getGreeterPort(); updateAddressPort(greeter, PORT); LOG.fine("Created greeter client."); if (!useDecoupledEndpoint) { return; } // programatically configure decoupled endpoint that is guaranteed to // be unique across all test cases decoupledEndpointPort++; decoupledEndpoint = "http://localhost:" + allocatePort("decoupled-" + decoupledEndpointPort) + "/decoupled_endpoint"; Client c = ClientProxy.getClient(greeter); HTTPConduit hc = (HTTPConduit)(c.getConduit()); HTTPClientPolicy cp = hc.getClient(); cp.setDecoupledEndpoint(decoupledEndpoint); LOG.fine("Using decoupled endpoint: " + cp.getDecoupledEndpoint()); }
Example 18
Source File: StaxToDOMRoundTripTest.java From cxf with Apache License 2.0 | 4 votes |
@Test public void testEncryptUsernameTokenConfig() throws Exception { // Create + configure service Service service = createService(); Map<String, Object> inProperties = new HashMap<>(); inProperties.put( ConfigurationConstants.ACTION, ConfigurationConstants.USERNAME_TOKEN + " " + ConfigurationConstants.ENCRYPTION ); inProperties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback()); inProperties.put(ConfigurationConstants.DEC_PROP_FILE, "insecurity.properties"); WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties); service.getInInterceptors().add(inInterceptor); // Create + configure client Echo echo = createClientProxy(); Client client = ClientProxy.getClient(echo); client.getInInterceptors().add(new LoggingInInterceptor()); client.getOutInterceptors().add(new LoggingOutInterceptor()); Map<String, Object> outConfig = new HashMap<>(); outConfig.put( ConfigurationConstants.ACTION, ConfigurationConstants.USERNAME_TOKEN + " " + ConfigurationConstants.ENCRYPTION ); outConfig.put( ConfigurationConstants.ENCRYPTION_PARTS, "{Element}{" + WSSConstants.NS_WSSE10 + "}UsernameToken" ); outConfig.put(ConfigurationConstants.USER, "username"); outConfig.put(ConfigurationConstants.ENCRYPTION_USER, "myalias"); outConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback()); outConfig.put(ConfigurationConstants.ENC_PROP_FILE, "outsecurity.properties"); outConfig.put(ConfigurationConstants.ENC_SYM_ALGO, XMLSecurityConstants.NS_XENC_AES128); WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(outConfig); client.getOutInterceptors().add(ohandler); assertEquals("test", echo.echo("test")); }
Example 19
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 20
Source File: DOMToStaxRoundTripTest.java From cxf with Apache License 2.0 | 4 votes |
@Test public void testUsernameTokenDigest() throws Exception { // Create + configure service Service service = createService(); WSSSecurityProperties inProperties = new WSSSecurityProperties(); inProperties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_DIGEST); inProperties.setCallbackHandler(new TestPwdCallback()); WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties); service.getInInterceptors().add(inhandler); // Create + configure client Echo echo = createClientProxy(); Client client = ClientProxy.getClient(echo); client.getInInterceptors().add(new LoggingInInterceptor()); client.getOutInterceptors().add(new LoggingOutInterceptor()); Map<String, Object> properties = new HashMap<>(); properties.put(ConfigurationConstants.ACTION, ConfigurationConstants.USERNAME_TOKEN); properties.put(ConfigurationConstants.PASSWORD_TYPE, WSS4JConstants.PW_DIGEST); properties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback()); properties.put(ConfigurationConstants.USER, "username"); WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor(properties); client.getOutInterceptors().add(ohandler); assertEquals("test", echo.echo("test")); // Negative test for wrong password type service.getInInterceptors().remove(inhandler); inProperties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_TEXT); inhandler = new WSS4JStaxInInterceptor(inProperties); service.getInInterceptors().add(inhandler); service.put(SecurityConstants.RETURN_SECURITY_ERROR, true); try { echo.echo("test"); fail("Failure expected on the wrong password type"); } catch (javax.xml.ws.soap.SOAPFaultException ex) { // expected String error = "The security token could not be authenticated or authorized"; assertTrue(ex.getMessage().contains(error)); } }