Comments (11)
you can use https with it now:
load key stores from files and
static SSLSocketFactory getSSLSocketFactory() {
SSLSocketFactory sf = new SSLSocketFactory("SSL", keyStore, "changeit", trustStore,
SecureRandom.getInstance("SHA1PRNG"), new AllowAllHostnameVerifier())
return sf
}
private initJestClient(Set servers) {
// Configuration
ClientConfig clientConfig = new ClientConfig()
clientConfig.getServerProperties().put(ClientConstants.SERVER_LIST, servers)
// Construct a new Jest client according to configuration via factory
JestClientFactory factory = new JestClientFactory()
factory.setClientConfig(clientConfig)
client = factory.getObject()
// ssl
SSLSocketFactory sf = securityUtils.getSSLSocketFactory()
client.httpClient.connectionManager.schemeRegistry.register(new Scheme("https", sf, 8443))
}
hope this helps!
Peter Hawkins
Sr Software Engineer
From: Javier Antoniucci [email protected]
To: searchbox-io/Jest [email protected]
Sent: Monday, April 1, 2013 10:15 AM
Subject: [Jest] HTTPS Support ? (#34)
Are there plans to include HTTPS support ?
—
Reply to this email directly or view it on GitHub.
from jest.
Works! Thanks!
from jest.
Sorry for not being involved, was fighting with production issues.
@peterhawkins thanks for suggestion, really made me smile how you helped here. Spirit of open source.
We may add this internally and construct according to given end points.
from jest.
Hi All
I try with @peterhawkins way but not work. Do you have any more advice to make it work?
Thank you
from jest.
Any error messages which it can guide us?
from jest.
Hi Ferhat
Thanks for your reply.
I am trying to connect to elastic search with jetty plugin and enable ssl. I use the sample project on : https://github.com/searchbox-io/java-jest-sample.
No error messages, because the code already marked a error on line
client.httpClient.connectionManager.schemeRegistry.register(new Scheme("https", sf, 8443));
This is the full code
@configuration
public class SpringConfiguration {
@bean
public JestClient jestClient() throws Exception {
String connectionUrl = "https://localhost:9443";
// Configuration
ClientConfig clientConfig = new ClientConfig.Builder(connectionUrl).multiThreaded(true).build();
// Construct a new Jest client according to configuration via factory
JestClientFactory factory = new JestClientFactory();
factory.setClientConfig(clientConfig);
//ssl
SSLSocketFactory sf = getSSLSocketFactory();
JestClient client = factory.getObject();
// SSLSocketFactory sf = getSSLSocketFactory();
client.httpClient.connectionManager.schemeRegistry.register(new Scheme("https", sf, 8443));
return client;
}
private SSLSocketFactory getSSLSocketFactory() throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException {
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("jettykeystore");
KeyStore keyStore = KeyStore.getInstance("pkcs12");
keyStore.load(stream, "tomi12".toCharArray());
SSLSocketFactory sf = new SSLSocketFactory("SSL", keyStore, "changeit", keyStore, SecureRandom.getInstance("RSA"), new AllowAllHostnameVerifier());
return sf;
}
}
Thank you
from jest.
Try this;
client.getHttpClient().getConnectionManager().getSchemeRegistry().register(new Scheme("https", sf, 8443));
from jest.
Hi @ferhatsb
Thank you very much for your reply. Now i have no issue on the code. My code can compile without any error.
But still i can't connect to the elastic-search with jetty plugin, with my generated keystore.
This is my code now
@Bean
public JestClient jestClient() {
String connectionUrl = "https://localhost:9443";
// Configuration
ClientConfig clientConfig = new ClientConfig.Builder(connectionUrl).multiThreaded(true).build();
// Construct a new Jest client according to configuration via factory
JestClientFactory factory = new JestClientFactory();
factory.setClientConfig(clientConfig);
//ssl
SSLSocketFactory sf = getSSLSocketFactory();
JestHttpClient client = (JestHttpClient) factory.getObject();
client.getHttpClient().getConnectionManager().getSchemeRegistry().register(new Scheme("https", 9443, sf));
return client;
}
private SSLSocketFactory getSSLSocketFactory() {
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("jettykeystore");
KeyStore keyStore;
try {
keyStore = KeyStore.getInstance("JKS");
keyStore.load(stream, "tomi12".toCharArray());
SSLSocketFactory sf = new SSLSocketFactory(SSLSocketFactory.SSL, keyStore, "tomi12", keyStore, SecureRandom.getInstance("SHA1PRNG"), new AllowAllHostnameVerifier());
return sf;
} catch (KeyStoreException e) {
log.info("Keystore Exception : {} \n {}",e.getMessage(), e.getClass());
} catch (NoSuchAlgorithmException e) {
log.info("NSA Exception : {} \n {}",e.getMessage(), e.getClass());
} catch (CertificateException e) {
log.info("Certificate Exception : {} \n {}",e.getMessage(), e.getClass());
} catch (IOException e) {
log.info("IO Exception : {} \n {}",e.getMessage(), e.getClass());
} catch (KeyManagementException e) {
log.info("KeyManagement Exception : {} \n {}",e.getMessage(), e.getClass());
} catch (UnrecoverableKeyException e) {
log.info("Uncoverable Key Exception : {} \n {}",e.getMessage(), e.getClass());
}
return null;
}
Right now when i am trying to connect to elastic search, i will get authorization issue.
ERROR AbstractJestClient - An exception occurred while converting json string to map object
INFO SearchService - RESULT : 401 Unauthorized
I am still trying to find the way to make it work.
Thank you
from jest.
Hi @ferhatsb
Thanks for your help, now my code working as i expected. Beside register scheme, I need to add auth to my code.
List<String> authpref = new ArrayList<String>();
authpref.add(AuthPolicy.BASIC);
client.getHttpClient().getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref);
DefaultHttpClient httpClient = (DefaultHttpClient) client.getHttpClient();
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("user", "password");
httpClient.getCredentialsProvider().setCredentials(new AuthScope("localhost", 9443), creds);
from jest.
Hi @tomidp
I was going to advise you to check credentials due to error 401.
Anyway it is sorted now. Also you should be able to;
String connectionUrl = "https://user:password@localhost:9443";
Instead of setting credentials explicitly.
from jest.
Looks like the apis have changed, the above implementations to connect ES via Jest does not work as a lot of http client functions are deprecated.
Update on how you would do it now:
SSLContext sslContext = SSLContexts.custom()
.loadTrustMaterial(keyStore, new TrustSelfSignedStrategy())
.useSSL()
.build();
SSLConnectionSocketFactory sf = new SSLConnectionSocketFactory(sslContext, new AllowAllHostnameVerifier());
client.setHttpClient(HttpClientBuilder.create().setSSLSocketFactory(sf).build());
from jest.
Related Issues (20)
- Invalid type conversion Integer -> Double
- Why do not working the index pattern in search request
- Path to hits/total needs to be updated for ESV7 HOT 2
- update by query
- Documentation for Kerberos Authentication
- Geo distance which api can support
- Delete child documents without parent
- Node Discovery Frequency Only send to one node.
- Search query logging
- Support for alias is_write_index
- release of version 6.8.10
- How to exit main thread when executeAsync method execute completed? HOT 1
- Refactor Search to be Generic
- update gson version to latest 2.8.6?
- 在处理jejstId注解时, 注解属性存在父类无法识别
- How to add parameters on '/_search' method like this '/_search?preference=zxcvzxd123'
- io.searchbox.client.http.JestHttpClient#deserializeResponse cause oom exception
- CatResult.parseResultArray throws java.lang.UnsupportedOperationException: JsonNull
- a problem wen upgrading to ES 7
- Is this project dead? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jest.