org.apache.cxf.common.classloader.ClassLoaderUtils Java Examples
The following examples show how to use
org.apache.cxf.common.classloader.ClassLoaderUtils.
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: UndertowHTTPDestination.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Override public void service(ServletContext context, HttpServletRequest req, HttpServletResponse resp) throws IOException { ClassLoaderHolder origLoader = null; Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus); try { if (loader != null) { origLoader = ClassLoaderUtils.setThreadContextClassloader(loader); } invoke(null, context, req, resp); } finally { if (origBus != bus) { BusFactory.setThreadDefaultBus(origBus); } if (origLoader != null) { origLoader.reset(); } } }
Example #2
Source File: JAXRSHTTPSignatureTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testMissingDigestHeader() throws Exception { URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml"); CreateSignatureInterceptor signatureFilter = new CreateSignatureInterceptor(); signatureFilter.setAddDigest(false); KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(ClassLoaderUtils.getResourceAsStream("keys/alice.jks", this.getClass()), "password".toCharArray()); PrivateKey privateKey = (PrivateKey)keyStore.getKey("alice", "password".toCharArray()); assertNotNull(privateKey); List<String> headerList = Arrays.asList("accept", "(request-target)"); MessageSigner messageSigner = new MessageSigner(keyId -> privateKey, "alice-key-id", headerList); signatureFilter.setMessageSigner(messageSigner); String address = "http://localhost:" + PORT + "/httpsigprops/bookstore/books"; WebClient client = WebClient.create(address, Collections.singletonList(signatureFilter), busFile.toString()); client.type("application/xml").accept("application/xml"); Response response = client.post(new Book("CXF", 126L)); assertEquals(400, response.getStatus()); }
Example #3
Source File: JAXRSHTTPSignatureTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testHttpSignature() throws Exception { URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml"); CreateSignatureInterceptor signatureFilter = new CreateSignatureInterceptor(); KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(ClassLoaderUtils.getResourceAsStream("keys/alice.jks", this.getClass()), "password".toCharArray()); PrivateKey privateKey = (PrivateKey)keyStore.getKey("alice", "password".toCharArray()); assertNotNull(privateKey); MessageSigner messageSigner = new MessageSigner(keyId -> privateKey, "alice-key-id"); signatureFilter.setMessageSigner(messageSigner); String address = "http://localhost:" + PORT + "/httpsig/bookstore/books"; WebClient client = WebClient.create(address, Collections.singletonList(signatureFilter), busFile.toString()); client.type("application/xml").accept("application/xml"); Response response = client.post(new Book("CXF", 126L)); assertEquals(200, response.getStatus()); Book returnedBook = response.readEntity(Book.class); assertEquals(126L, returnedBook.getId()); }
Example #4
Source File: JAXRSHTTPSignatureTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testUnknownKeyId() throws Exception { URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml"); CreateSignatureInterceptor signatureFilter = new CreateSignatureInterceptor(); KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(ClassLoaderUtils.getResourceAsStream("keys/alice.jks", this.getClass()), "password".toCharArray()); PrivateKey privateKey = (PrivateKey)keyStore.getKey("alice", "password".toCharArray()); assertNotNull(privateKey); MessageSigner messageSigner = new MessageSigner(keyId -> privateKey, "unknown-key-id"); signatureFilter.setMessageSigner(messageSigner); String address = "http://localhost:" + PORT + "/httpsig/bookstore/books"; WebClient client = WebClient.create(address, Collections.singletonList(signatureFilter), busFile.toString()); client.type("application/xml").accept("application/xml"); Response response = client.post(new Book("CXF", 126L)); assertEquals(400, response.getStatus()); }
Example #5
Source File: BusFactory.java From cxf with Apache License 2.0 | 6 votes |
/** * Create a new BusFactory * * @param className The class of the BusFactory to create. If null, uses the default search algorithm. * @return a new BusFactory to be used to create Bus objects */ public static BusFactory newInstance(String className) { if (className == null) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); className = getBusFactoryClass(loader); if (className == null && loader != BusFactory.class.getClassLoader()) { className = getBusFactoryClass(BusFactory.class.getClassLoader()); } } if (className == null) { className = BusFactory.DEFAULT_BUS_FACTORY; } try { Class<? extends BusFactory> busFactoryClass = ClassLoaderUtils.loadClass(className, BusFactory.class) .asSubclass(BusFactory.class); return busFactoryClass.getConstructor().newInstance(); } catch (Exception ex) { LogUtils.log(LOG, Level.SEVERE, "BUS_FACTORY_INSTANTIATION_EXC", ex); throw new RuntimeException(ex); } }
Example #6
Source File: JAXRSHTTPSignatureTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testHttpSignatureRsaSha512() throws Exception { URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml"); CreateSignatureInterceptor signatureFilter = new CreateSignatureInterceptor(); KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(ClassLoaderUtils.getResourceAsStream("keys/alice.jks", this.getClass()), "password".toCharArray()); PrivateKey privateKey = (PrivateKey)keyStore.getKey("alice", "password".toCharArray()); assertNotNull(privateKey); MessageSigner messageSigner = new MessageSigner("rsa-sha512", keyId -> privateKey, "alice-key-id"); signatureFilter.setMessageSigner(messageSigner); String address = "http://localhost:" + PORT + "/httpsigrsasha512/bookstore/books"; WebClient client = WebClient.create(address, Collections.singletonList(signatureFilter), busFile.toString()); client.type("application/xml").accept("application/xml"); Response response = client.post(new Book("CXF", 126L)); assertEquals(200, response.getStatus()); Book returnedBook = response.readEntity(Book.class); assertEquals(126L, returnedBook.getId()); }
Example #7
Source File: JAXRSHTTPSignatureTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testHttpSignatureRsaSha512ServiceProperties() throws Exception { URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml"); CreateSignatureInterceptor signatureFilter = new CreateSignatureInterceptor(); KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(ClassLoaderUtils.getResourceAsStream("keys/alice.jks", this.getClass()), "password".toCharArray()); PrivateKey privateKey = (PrivateKey)keyStore.getKey("alice", "password".toCharArray()); assertNotNull(privateKey); MessageSigner messageSigner = new MessageSigner("rsa-sha512", keyId -> privateKey, "alice-key-id"); signatureFilter.setMessageSigner(messageSigner); String address = "http://localhost:" + PORT + "/httpsigrsasha512props/bookstore/books"; WebClient client = WebClient.create(address, Collections.singletonList(signatureFilter), busFile.toString()); client.type("application/xml").accept("application/xml"); Response response = client.post(new Book("CXF", 126L)); assertEquals(200, response.getStatus()); Book returnedBook = response.readEntity(Book.class); assertEquals(126L, returnedBook.getId()); }
Example #8
Source File: AbstractColocTest.java From cxf with Apache License 2.0 | 6 votes |
/** * Setup this test case */ @Before public void setUp() throws Exception { // initialize Mule Manager URL cxfConfig = null; if (getCxfConfig() != null) { cxfConfig = ClassLoaderUtils.getResource(getCxfConfig(), AbstractColocTest.class); if (cxfConfig == null) { throw new Exception("Make sure " + getCxfConfig() + " is in the CLASSPATH"); } assertNotNull(cxfConfig.toExternalForm()); } //Bus is shared by client, router and server. SpringBusFactory bf = new SpringBusFactory(); bus = bf.createBus(cxfConfig); BusFactory.setDefaultBus(bus); //Start the Remote Server // the endpoint of the "real" cxf server endpoint = Endpoint.publish(getTransportURI(), getServiceImpl()); }
Example #9
Source File: JAXRS20HttpsBookTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testGetBook() throws Exception { ClientBuilder builder = ClientBuilder.newBuilder(); try (InputStream keystore = ClassLoaderUtils.getResourceAsStream("keys/Truststore.jks", this.getClass())) { KeyStore trustStore = loadStore(keystore, "password"); builder.trustStore(trustStore); } builder.hostnameVerifier(new AllowAllHostnameVerifier()); try (InputStream keystore = ClassLoaderUtils.getResourceAsStream("keys/Morpit.jks", this.getClass())) { KeyStore keyStore = loadStore(keystore, "password"); builder.keyStore(keyStore, "password"); } Client client = builder.build(); client.register(new LoggingFeature()); WebTarget target = client.target("https://localhost:" + PORT + "/bookstore/securebooks/123"); Book b = target.request().accept(MediaType.APPLICATION_XML_TYPE).get(Book.class); assertEquals(123, b.getId()); }
Example #10
Source File: OAuth2Test.java From openwebbeans-meecrowave with Apache License 2.0 | 6 votes |
private void createRedirectedClient(final int httpPort) throws URISyntaxException { final CachingProvider provider = Caching.getCachingProvider(); final CacheManager cacheManager = provider.getCacheManager( ClassLoaderUtils.getResource("default-oauth2.jcs", OAuth2Test.class).toURI(), Thread.currentThread().getContextClassLoader()); Cache<String, org.apache.cxf.rs.security.oauth2.common.Client> cache; try { cache = cacheManager .createCache(JCacheCodeDataProvider.CLIENT_CACHE_KEY, new MutableConfiguration<String, org.apache.cxf.rs.security.oauth2.common.Client>() .setTypes(String.class, org.apache.cxf.rs.security.oauth2.common.Client.class) .setStoreByValue(true)); } catch (final RuntimeException re) { cache = cacheManager.getCache(JCacheCodeDataProvider.CLIENT_CACHE_KEY, String.class, org.apache.cxf.rs.security.oauth2.common.Client.class); } final org.apache.cxf.rs.security.oauth2.common.Client value = new org.apache.cxf.rs.security.oauth2.common.Client("c1", "cpwd", true); value.setRedirectUris(singletonList("http://localhost:" + httpPort + "/redirected")); cache.put("c1", value); }
Example #11
Source File: JAXRSHTTPSignatureTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testEmptySignatureValue() throws Exception { URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml"); ClientTestFilter signatureFilter = new ClientTestFilter(); signatureFilter.setEmptySignatureValue(true); KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(ClassLoaderUtils.getResourceAsStream("keys/alice.jks", this.getClass()), "password".toCharArray()); PrivateKey privateKey = (PrivateKey)keyStore.getKey("alice", "password".toCharArray()); assertNotNull(privateKey); MessageSigner messageSigner = new MessageSigner(keyId -> privateKey, "alice-key-id"); signatureFilter.setMessageSigner(messageSigner); String address = "http://localhost:" + PORT + "/httpsig/bookstore/books"; WebClient client = WebClient.create(address, Collections.singletonList(signatureFilter), busFile.toString()); client.type("application/xml").accept("application/xml"); Response response = client.post(new Book("CXF", 126L)); assertEquals(400, response.getStatus()); }
Example #12
Source File: JAXRSHTTPSignatureTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testChangedSignatureMethod() throws Exception { URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml"); ClientTestFilter signatureFilter = new ClientTestFilter(); signatureFilter.setChangeSignatureAlgorithm(true); KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(ClassLoaderUtils.getResourceAsStream("keys/alice.jks", this.getClass()), "password".toCharArray()); PrivateKey privateKey = (PrivateKey)keyStore.getKey("alice", "password".toCharArray()); assertNotNull(privateKey); MessageSigner messageSigner = new MessageSigner(keyId -> privateKey, "alice-key-id"); signatureFilter.setMessageSigner(messageSigner); String address = "http://localhost:" + PORT + "/httpsig/bookstore/books"; WebClient client = WebClient.create(address, Collections.singletonList(signatureFilter), busFile.toString()); client.type("application/xml").accept("application/xml"); Response response = client.post(new Book("CXF", 126L)); assertEquals(400, response.getStatus()); }
Example #13
Source File: RestClientBean.java From cxf with Apache License 2.0 | 6 votes |
List<Class<?>> getConfiguredProviders() { String providersList = ConfigFacade.getOptionalValue(REST_PROVIDERS_FORMAT, clientInterface, String.class) .orElse(null); List<Class<?>> providers = new ArrayList<>(); if (providersList != null) { String[] providerClassNames = providersList.split(","); for (int i = 0; i < providerClassNames.length; i++) { try { providers.add(ClassLoaderUtils.loadClass(providerClassNames[i], RestClientBean.class)); } catch (ClassNotFoundException e) { LOG.log(Level.WARNING, "Could not load provider, {0}, configured for Rest Client interface, {1} ", new Object[]{providerClassNames[i], clientInterface.getName()}); } } } return providers; }
Example #14
Source File: ProviderFactory.java From cxf with Apache License 2.0 | 6 votes |
protected static Object createProvider(String className, Bus bus) { try { Class<?> cls = ClassLoaderUtils.loadClass(className, ProviderFactory.class); for (Constructor<?> c : cls.getConstructors()) { if (c.getParameterTypes().length == 1 && c.getParameterTypes()[0] == Bus.class) { return c.newInstance(bus); } } return cls.newInstance(); } catch (Throwable ex) { String message = "Problem with creating the default provider " + className; if (ex.getMessage() != null) { message += ": " + ex.getMessage(); } else { message += ", exception class : " + ex.getClass().getName(); } LOG.fine(message); } return null; }
Example #15
Source File: JaxWsServerFactoryBean.java From cxf with Apache License 2.0 | 6 votes |
public Server create() { ClassLoaderHolder orig = null; try { if (bus != null) { ClassLoader loader = bus.getExtension(ClassLoader.class); if (loader != null) { orig = ClassLoaderUtils.setThreadContextClassloader(loader); } } Server server = super.create(); initializeResourcesAndHandlerChain(server); checkPrivateEndpoint(server.getEndpoint()); return server; } finally { if (orig != null) { orig.reset(); } } }
Example #16
Source File: JAXRSHTTPSignatureTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testNonMatchingSignatureAlgorithm() throws Exception { URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml"); CreateSignatureInterceptor signatureFilter = new CreateSignatureInterceptor(); KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(ClassLoaderUtils.getResourceAsStream("keys/alice.jks", this.getClass()), "password".toCharArray()); PrivateKey privateKey = (PrivateKey)keyStore.getKey("alice", "password".toCharArray()); assertNotNull(privateKey); MessageSigner messageSigner = new MessageSigner("rsa-sha512", keyId -> privateKey, "alice-key-id"); signatureFilter.setMessageSigner(messageSigner); String address = "http://localhost:" + PORT + "/httpsig/bookstore/books"; WebClient client = WebClient.create(address, Collections.singletonList(signatureFilter), busFile.toString()); client.type("application/xml").accept("application/xml"); Response response = client.post(new Book("CXF", 126L)); assertEquals(400, response.getStatus()); }
Example #17
Source File: PluginLoader.java From cxf with Apache License 2.0 | 6 votes |
private Class<? extends ToolContainer> loadContainerClass(String fullClzName) { Class<?> clz = null; try { clz = ClassLoaderUtils.loadClass(fullClzName, getClass()); } catch (Exception e) { Message msg = new Message("LOAD_CONTAINER_CLASS_FAILED", LOG, fullClzName); LOG.log(Level.SEVERE, msg.toString()); throw new ToolException(msg, e); } if (!ToolContainer.class.isAssignableFrom(clz)) { Message message = new Message("CLZ_SHOULD_IMPLEMENT_INTERFACE", LOG, clz.getName()); LOG.log(Level.SEVERE, message.toString()); throw new ToolException(message); } return clz.asSubclass(ToolContainer.class); }
Example #18
Source File: PluginLoader.java From cxf with Apache License 2.0 | 5 votes |
private DataBindingProfile loadDataBindingProfile(String fullClzName) { DataBindingProfile profile = null; try { profile = (DataBindingProfile)ClassLoaderUtils.loadClass(fullClzName, getClass()).newInstance(); } catch (Exception e) { Message msg = new Message("DATABINDING_PROFILE_LOAD_FAIL", LOG, fullClzName); LOG.log(Level.SEVERE, msg.toString()); throw new ToolException(msg); } return profile; }
Example #19
Source File: PluginLoader.java From cxf with Apache License 2.0 | 5 votes |
private AbstractWSDLBuilder loadBuilder(String fullClzName) { AbstractWSDLBuilder builder = null; try { builder = (AbstractWSDLBuilder) ClassLoaderUtils .loadClass(fullClzName, getClass()).newInstance(); } catch (Exception e) { Message msg = new Message("LOAD_PROCESSOR_FAILED", LOG, fullClzName); LOG.log(Level.SEVERE, msg.toString()); throw new ToolException(msg, e); } return builder; }
Example #20
Source File: XMLTypeCreator.java From cxf with Apache License 2.0 | 5 votes |
protected void setType(TypeClassInfo info, Element parameter) { String type = DOMUtils.getAttributeValueEmptyNull(parameter, "type"); if (type != null) { try { Class<?> aegisTypeClass = ClassLoaderUtils.loadClass(type, getClass()); info.setAegisTypeClass(Java5TypeCreator.castToAegisTypeClass(aegisTypeClass)); } catch (ClassNotFoundException e) { throw new DatabindingException("Unable to load type class " + type, e); } } }
Example #21
Source File: XKMSClientCacheTest.java From cxf with Apache License 2.0 | 5 votes |
public XKMSClientCacheTest() throws Exception { cache = new EHCacheXKMSClientCache(); KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); keystore.load(ClassLoaderUtils.getResourceAsStream("keys/alice.jks", XKMSClientCacheTest.class), "password".toCharArray()); alice = (X509Certificate)keystore.getCertificate("alice"); keystore = KeyStore.getInstance(KeyStore.getDefaultType()); keystore.load(ClassLoaderUtils.getResourceAsStream("keys/bob.jks", XKMSClientCacheTest.class), "password".toCharArray()); bob = (X509Certificate)keystore.getCertificate("bob"); }
Example #22
Source File: JexlClaimsMapper.java From cxf with Apache License 2.0 | 5 votes |
public final void setScript(String scriptLocation) throws IOException { URL resource = ClassLoaderUtils.getResource(scriptLocation, this.getClass()); if (resource != null) { scriptLocation = resource.getPath(); if (LOG.isLoggable(Level.FINE)) { LOG.fine("Script found within Classpath: " + scriptLocation); } } File scriptFile = new File(scriptLocation); if (scriptFile.exists()) { this.script = jexlEngine.createScript(scriptFile); } else { throw new IllegalArgumentException("Script resource not found!"); } }
Example #23
Source File: WebClient.java From cxf with Apache License 2.0 | 5 votes |
protected Response doChainedInvocation(String httpMethod, //NOPMD MultivaluedMap<String, String> headers, Object body, Class<?> requestClass, Type inType, Annotation[] inAnns, Class<?> respClass, Type outType, Exchange exchange, Map<String, Object> invContext) { //CHECKSTYLE:ON Bus configuredBus = getConfiguration().getBus(); Bus origBus = BusFactory.getAndSetThreadDefaultBus(configuredBus); ClassLoaderHolder origLoader = null; try { ClassLoader loader = configuredBus.getExtension(ClassLoader.class); if (loader != null) { origLoader = ClassLoaderUtils.setThreadContextClassloader(loader); } Message m = finalizeMessage(httpMethod, headers, body, requestClass, inType, inAnns, respClass, outType, exchange, invContext); doRunInterceptorChain(m); return doResponse(m, respClass, outType); } finally { if (origLoader != null) { origLoader.reset(); } if (origBus != configuredBus) { BusFactory.setThreadDefaultBus(origBus); } } }
Example #24
Source File: SSLUtils.java From cxf with Apache License 2.0 | 5 votes |
private static InputStream getResourceAsStream(String resource) { InputStream is = ClassLoaderUtils.getResourceAsStream(resource, SSLUtils.class); if (is == null) { Bus bus = BusFactory.getThreadDefaultBus(true); ResourceManager rm = bus.getExtension(ResourceManager.class); if (rm != null) { is = rm.getResourceAsStream(resource); } } return is; }
Example #25
Source File: JAXRSHTTPSignatureTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testHttpSignatureEmptyResponse() throws Exception { URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml"); CreateSignatureInterceptor signatureFilter = new CreateSignatureInterceptor(); KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(ClassLoaderUtils.getResourceAsStream("keys/alice.jks", this.getClass()), "password".toCharArray()); PrivateKey privateKey = (PrivateKey)keyStore.getKey("alice", "password".toCharArray()); assertNotNull(privateKey); MessageSigner messageSigner = new MessageSigner(keyId -> privateKey, "alice-key-id"); signatureFilter.setMessageSigner(messageSigner); VerifySignatureClientFilter signatureResponseFilter = new VerifySignatureClientFilter(); MessageVerifier messageVerifier = new MessageVerifier(new CustomPublicKeyProvider()); signatureResponseFilter.setMessageVerifier(messageVerifier); String address = "http://localhost:" + PORT + "/httpsigresponse/bookstore/booksnoresp"; WebClient client = WebClient.create(address, Arrays.asList(signatureFilter, signatureResponseFilter), busFile.toString()); client.type("application/xml").accept("application/xml"); Response response = client.post(new Book("CXF", 126L)); assertEquals(204, response.getStatus()); }
Example #26
Source File: AbstractWSS4JInterceptor.java From steady with Apache License 2.0 | 5 votes |
@Override protected Crypto loadCryptoFromPropertiesFile( String propFilename, RequestData reqData ) throws WSSecurityException { ClassLoaderHolder orig = null; try { try { URL url = ClassLoaderUtils.getResource(propFilename, this.getClass()); if (url == null) { ResourceManager manager = ((Message)reqData.getMsgContext()).getExchange() .getBus().getExtension(ResourceManager.class); ClassLoader loader = manager.resolveResource("", ClassLoader.class); if (loader != null) { orig = ClassLoaderUtils.setThreadContextClassloader(loader); } url = manager.resolveResource(propFilename, URL.class); } if (url != null) { Properties props = new Properties(); InputStream in = url.openStream(); props.load(in); in.close(); return CryptoFactory.getInstance(props, this.getClassLoader(reqData.getMsgContext())); } } catch (Exception e) { //ignore } return CryptoFactory.getInstance(propFilename, this.getClassLoader(reqData.getMsgContext())); } finally { if (orig != null) { orig.reset(); } } }
Example #27
Source File: JAXRSHTTPSignatureTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testHttpSignatureEmptyResponseProps() throws Exception { URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml"); CreateSignatureInterceptor signatureFilter = new CreateSignatureInterceptor(); KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(ClassLoaderUtils.getResourceAsStream("keys/alice.jks", this.getClass()), "password".toCharArray()); PrivateKey privateKey = (PrivateKey)keyStore.getKey("alice", "password".toCharArray()); assertNotNull(privateKey); MessageSigner messageSigner = new MessageSigner(keyId -> privateKey, "alice-key-id"); signatureFilter.setMessageSigner(messageSigner); VerifySignatureClientFilter signatureResponseFilter = new VerifySignatureClientFilter(); String address = "http://localhost:" + PORT + "/httpsigresponse/bookstore/booksnoresp"; WebClient client = WebClient.create(address, Arrays.asList(signatureFilter, signatureResponseFilter), busFile.toString()); client.type("application/xml").accept("application/xml"); Map<String, Object> properties = new HashMap<>(); properties.put("rs.security.signature.in.properties", "org/apache/cxf/systest/jaxrs/security/httpsignature/bob.httpsig.properties"); WebClient.getConfig(client).getRequestContext().putAll(properties); Response response = client.post(new Book("CXF", 126L)); assertEquals(204, response.getStatus()); }
Example #28
Source File: OpenApiParseUtils.java From cxf with Apache License 2.0 | 5 votes |
private static void setJavaType(Parameter userParam, String typeName) { Class<?> javaType = OPENAPI_TYPE_MAP.get(typeName); if (javaType == null) { try { // May work if the model has already been compiled // TODO: need to know the package name javaType = ClassLoaderUtils.loadClass(typeName, OpenApiParseUtils.class); } catch (Throwable t) { // ignore } } userParam.setJavaType(javaType); }
Example #29
Source File: CXFNonSpringServlet.java From cxf with Apache License 2.0 | 5 votes |
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { ClassLoaderHolder origLoader = null; Bus origBus = null; if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) { try { if (loader != null) { origLoader = ClassLoaderUtils.setThreadContextClassloader(loader); } if (bus != null) { origBus = BusFactory.getAndSetThreadDefaultBus(bus); } HttpServletRequest httpRequest = (HttpServletRequest)request; if (controller.filter(new HttpServletRequestFilter(httpRequest, super.getServletName()), (HttpServletResponse)response)) { return; } } finally { if (origBus != bus) { BusFactory.setThreadDefaultBus(origBus); } if (origLoader != null) { origLoader.reset(); } } } chain.doFilter(request, response); }
Example #30
Source File: CXFNonSpringJaxrsServlet.java From cxf with Apache License 2.0 | 5 votes |
protected Class<?> loadClass(String cName, String classType) throws ServletException { try { Class<?> cls = null; if (classLoader == null) { cls = ClassLoaderUtils.loadClass(cName, CXFNonSpringJaxrsServlet.class); } else { cls = classLoader.loadClass(cName); } return cls; } catch (ClassNotFoundException ex) { throw new ServletException("No " + classType + " class " + cName.trim() + " can be found", ex); } }