WebClient createWebClient(String baseAddress, Bus bus) { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setBus(bus); bean.setAddress(baseAddress); return bean.createWebClient(); }
static JAXRSClientFactoryBean getBean(String baseAddress, String configLocation) { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); if (configLocation != null) { SpringBusFactory bf = new SpringBusFactory(); Bus bus = bf.createBus(configLocation); bean.setBus(bus); } bean.setAddress(baseAddress); return bean; }
static JAXRSClientFactoryBean getBean(String baseAddress, String configLocation) { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); if (configLocation != null) { SpringBusFactory bf = new SpringBusFactory(); Bus bus = bf.createBus(configLocation); bean.setBus(bus); } bean.setAddress(baseAddress); return bean; }
static JAXRSClientFactoryBean getBean(String baseAddress, String configLocation) { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); if (configLocation != null) { SpringBusFactory bf = new SpringBusFactory(); Bus bus = bf.createBus(configLocation); bean.setBus(bus); } bean.setAddress(baseAddress); return bean; }
protected Client createClient() { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setBus(bus); bean.setAddress(address); bean.setThreadSafe(threadSafe); setJaxrsResources(bean); for (String beanName : context.getBeanDefinitionNames()) { if (context.findAnnotationOnBean(beanName, Provider.class) != null) { bean.setProvider(context.getBean(beanName)); } else if (context.findAnnotationOnBean(beanName, org.apache.cxf.annotations.Provider.class) != null) { addCxfProvider(bean, context.getBean(beanName)); } } Map<String, String> extraHeaders = new HashMap<>(); if (!StringUtils.isEmpty(accept)) { extraHeaders.put("Accept", accept); } if (!StringUtils.isEmpty(contentType)) { extraHeaders.put("Content-Type", contentType); } if (!extraHeaders.isEmpty()) { bean.setHeaders(extraHeaders); } return bean.create(); } protected void addCxfProvider(JAXRSClientFactoryBean factory, Object provider) {
private WebClient createWebClient(String address, Map<String, Object> extraProperties) { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(address); SpringBusFactory bf = new SpringBusFactory(); URL busFile = JAXRSSamlAuthorizationTest.class.getResource("client.xml"); Bus springBus = bf.createBus(busFile.toString()); bean.setBus(springBus); Map<String, Object> properties = new HashMap<>(); properties.put(SecurityConstants.SAML_CALLBACK_HANDLER, "org.apache.cxf.systest.jaxrs.security.saml.SamlCallbackHandler"); if (extraProperties != null) { properties.putAll(extraProperties); } bean.setProperties(properties); bean.getOutInterceptors().add(new SamlEnvelopedOutInterceptor()); return bean.createWebClient(); } }
private BookStore createBookStoreTwoRecipients(String address) throws Exception { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); SpringBusFactory bf = new SpringBusFactory(); URL busFile = JAXRSJweJsonTest.class.getResource("client.xml"); Bus springBus = bf.createBus(busFile.toString()); bean.setBus(springBus); bean.setServiceClass(BookStore.class); bean.setAddress(address); bean.setProvider(new JweJsonWriterInterceptor()); List<String> properties = new ArrayList<>(); properties.add("org/apache/cxf/systest/jaxrs/security/jwejson1.properties"); properties.add("org/apache/cxf/systest/jaxrs/security/jwejson2.properties"); bean.getProperties(true).put(JoseConstants.RSSEC_ENCRYPTION_PROPS, properties); return bean.create(BookStore.class); }
private WebClient createRsWebClient(String address, ClientAccessToken at, String clientContext) { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(address); SpringBusFactory bf = new SpringBusFactory(); URL busFile = JAXRSOAuth2TlsTest.class.getResource(clientContext); Bus springBus = bf.createBus(busFile.toString()); bean.setBus(springBus); WebClient wc = bean.createWebClient(); wc.accept(MediaType.APPLICATION_XML); wc.authorization(at); return wc; }
private BookStore createBookStore(String address, String propLoc) throws Exception { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); SpringBusFactory bf = new SpringBusFactory(); URL busFile = JAXRSJweJsonTest.class.getResource("client.xml"); Bus springBus = bf.createBus(busFile.toString()); bean.setBus(springBus); bean.setServiceClass(BookStore.class); bean.setAddress(address); List<Object> providers = new LinkedList<>(); JweJsonWriterInterceptor writer = new JweJsonWriterInterceptor(); providers.add(writer); providers.add(new JweJsonClientResponseFilter()); bean.setProviders(providers); bean.getProperties(true).put(JoseConstants.RSSEC_ENCRYPTION_PROPS, propLoc); return bean.create(BookStore.class); }
private WebClient createWebClient(String address) { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(address); SpringBusFactory bf = new SpringBusFactory(); URL busFile = JAXRSOAuth2Test.class.getResource("client.xml"); Bus springBus = bf.createBus(busFile.toString()); bean.setBus(springBus); WebClient wc = bean.createWebClient(); wc.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_JSON); return wc; }
private WebClient createOAuth2WebClient(String address) { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(address); SpringBusFactory bf = new SpringBusFactory(); URL busFile = JAXRSOAuth2TlsTest.class.getResource("client.xml"); Bus springBus = bf.createBus(busFile.toString()); bean.setBus(springBus); WebClient wc = bean.createWebClient(); wc.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_JSON); return wc; } private WebClient createDynRegWebClient(String address) {
private WebClient createWebClient(String address, Interceptor<Message> outInterceptor, Object provider, CallbackHandler samlCallbackHandler) { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(address); SpringBusFactory bf = new SpringBusFactory(); URL busFile = JAXRSSamlTest.class.getResource("client.xml"); Bus springBus = bf.createBus(busFile.toString()); bean.setBus(springBus); Map<String, Object> properties = new HashMap<>(); properties.put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.jaxrs.security.saml.KeystorePasswordCallback"); properties.put(SecurityConstants.SAML_CALLBACK_HANDLER, samlCallbackHandler); properties.put(SecurityConstants.SIGNATURE_USERNAME, "alice"); properties.put(SecurityConstants.SIGNATURE_PROPERTIES, "org/apache/cxf/systest/jaxrs/security/alice.properties"); bean.setProperties(properties); bean.getOutInterceptors().add(outInterceptor); if (provider != null) { bean.setProvider(provider); } return bean.createWebClient(); }
private WebClient createWebClientForExistingToken(String address, Interceptor<Message> outInterceptor, Object provider) { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(address); SpringBusFactory bf = new SpringBusFactory(); URL busFile = JAXRSSamlTest.class.getResource("client.xml"); Bus springBus = bf.createBus(busFile.toString()); bean.setBus(springBus); bean.getOutInterceptors().add(outInterceptor); bean.getOutInterceptors().add(new SamlRetrievalInterceptor()); if (provider != null) { bean.setProvider(provider); } return bean.createWebClient(); }
private BookStore createJweBookStore(String address, List<?> mbProviders) throws Exception { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); SpringBusFactory bf = new SpringBusFactory(); URL busFile = JAXRSJweJwsTest.class.getResource("client.xml"); Bus springBus = bf.createBus(busFile.toString()); bean.setBus(springBus); bean.setServiceClass(BookStore.class); bean.setAddress(address); List<Object> providers = new LinkedList<>(); JweWriterInterceptor jweWriter = new JweWriterInterceptor(); jweWriter.setUseJweOutputStream(true); providers.add(jweWriter); providers.add(new JweClientResponseFilter()); if (mbProviders != null) { providers.addAll(mbProviders); } bean.setProviders(providers); bean.getProperties(true).put("rs.security.encryption.out.properties", "org/apache/cxf/systest/jaxrs/security/bob.jwk.properties"); bean.getProperties(true).put("rs.security.encryption.in.properties", "org/apache/cxf/systest/jaxrs/security/alice.jwk.properties"); return bean.create(BookStore.class); }
private BookStore createBookStore(String address, Map<String, Object> mapProperties, List<?> extraProviders, boolean encodePayload) throws Exception { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); SpringBusFactory bf = new SpringBusFactory(); URL busFile = JAXRSJwsJsonTest.class.getResource("client.xml"); Bus springBus = bf.createBus(busFile.toString()); bean.setBus(springBus); bean.setServiceClass(BookStore.class); bean.setAddress(address); List<Object> providers = new LinkedList<>(); JwsJsonWriterInterceptor writer = new JwsJsonWriterInterceptor(); writer.setUseJwsJsonOutputStream(true); writer.setEncodePayload(encodePayload); providers.add(writer); providers.add(new JwsJsonClientResponseFilter()); if (extraProviders != null) { providers.addAll(extraProviders); } bean.setProviders(providers); bean.getProperties(true).putAll(mapProperties); return bean.create(BookStore.class); }
@Test public void testInvalidSAMLTokenAsHeader() throws Exception { String address = "https://localhost:" + PORT + "/samlheader/bookstore/books/123"; JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(address); SpringBusFactory bf = new SpringBusFactory(); URL busFile = JAXRSSamlTest.class.getResource("client.xml"); Bus springBus = bf.createBus(busFile.toString()); bean.setBus(springBus); WebClient wc = bean.createWebClient(); wc.header("Authorization", "SAML invalid_grant"); Response r = wc.get(); assertEquals(401, r.getStatus()); }
private WebClient createWebClientWithProps(String address) { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(address); SpringBusFactory bf = new SpringBusFactory(); URL busFile = JAXRSOAuth2Test.class.getResource("client.xml"); Bus springBus = bf.createBus(busFile.toString()); bean.setBus(springBus); Map<String, Object> properties = new HashMap<>(); properties.put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.jaxrs.security.saml.KeystorePasswordCallback"); SamlCallbackHandler samlCallbackHandler = new SamlCallbackHandler(true); samlCallbackHandler.setIssuer("alice"); String audienceURI = "https://localhost:" + port + "/oauth2-auth/token"; samlCallbackHandler.setAudience(audienceURI); properties.put(SecurityConstants.SAML_CALLBACK_HANDLER, samlCallbackHandler); properties.put(SecurityConstants.SIGNATURE_USERNAME, "alice"); properties.put(SecurityConstants.SIGNATURE_PROPERTIES, CRYPTO_RESOURCE_PROPERTIES); bean.setProperties(properties); bean.getOutInterceptors().add(new Saml2BearerAuthOutInterceptor()); WebClient wc = bean.createWebClient(); wc.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_JSON); return wc; }
private JAXRSClientFactoryBean createJAXRSClientFactoryBean(String address, boolean bufferPayload, boolean useJwsJsonSignatureFormat) throws Exception { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); SpringBusFactory bf = new SpringBusFactory(); URL busFile = JAXRSJwsMultipartTest.class.getResource("client.xml"); Bus springBus = bf.createBus(busFile.toString()); bean.setBus(springBus); bean.setServiceClass(BookStore.class); bean.setAddress(address); List<Object> providers = new LinkedList<>(); JwsMultipartClientRequestFilter outFilter = new JwsMultipartClientRequestFilter(); outFilter.setUseJwsJsonSignatureFormat(useJwsJsonSignatureFormat); providers.add(outFilter); JwsMultipartClientResponseFilter inFilter = new JwsMultipartClientResponseFilter(); inFilter.setBufferPayload(bufferPayload); providers.add(inFilter); providers.add(new JwsDetachedSignatureProvider()); bean.setProviders(providers); return bean; } }
private WebClient createDynRegWebClient(String address) { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(address); bean.setProvider(new JsonMapObjectProvider()); SpringBusFactory bf = new SpringBusFactory(); URL busFile = JAXRSOAuth2TlsTest.class.getResource("client.xml"); Bus springBus = bf.createBus(busFile.toString()); bean.setBus(springBus); WebClient wc = bean.createWebClient(); wc.type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON); return wc; } private WebClient createRsWebClient(String address, ClientAccessToken at, String clientContext) {
@Test public void testPostBookWithNoSig() throws Exception { if (test.streaming) { // Only testing the endpoints, not the clients here return; } String address = "https://localhost:" + test.port + "/xmlsig"; JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(address); SpringBusFactory bf = new SpringBusFactory(); URL busFile = JAXRSXmlSecTest.class.getResource("client.xml"); Bus springBus = bf.createBus(busFile.toString()); bean.setBus(springBus); bean.setServiceClass(BookStore.class); BookStore store = bean.create(BookStore.class); try { store.addBook(new Book("CXF", 126L)); fail("Failure expected on no Signature"); } catch (WebApplicationException ex) { // expected } }