use of com.sun.jersey.api.client.config.DefaultClientConfig in project ranger by apache.
the class LdapPolicyMgrUserGroupBuilder method getClient.
private synchronized Client getClient() {
Client ret = null;
if (policyMgrBaseUrl.startsWith("https://")) {
ClientConfig config = new DefaultClientConfig();
if (sslContext == null) {
try {
KeyManager[] kmList = null;
TrustManager[] tmList = null;
if (keyStoreFile != null && keyStoreFilepwd != null) {
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
InputStream in = null;
try {
in = getFileInputStream(keyStoreFile);
if (in == null) {
LOG.error("Unable to obtain keystore from file [" + keyStoreFile + "]");
return ret;
}
keyStore.load(in, keyStoreFilepwd.toCharArray());
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, keyStoreFilepwd.toCharArray());
kmList = keyManagerFactory.getKeyManagers();
} finally {
if (in != null) {
in.close();
}
}
}
if (trustStoreFile != null && trustStoreFilepwd != null) {
KeyStore trustStore = KeyStore.getInstance(trustStoreType);
InputStream in = null;
try {
in = getFileInputStream(trustStoreFile);
if (in == null) {
LOG.error("Unable to obtain keystore from file [" + trustStoreFile + "]");
return ret;
}
trustStore.load(in, trustStoreFilepwd.toCharArray());
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trustStore);
tmList = trustManagerFactory.getTrustManagers();
} finally {
if (in != null) {
in.close();
}
}
}
sslContext = SSLContext.getInstance("SSL");
sslContext.init(kmList, tmList, new SecureRandom());
hv = new HostnameVerifier() {
public boolean verify(String urlHostName, SSLSession session) {
return session.getPeerHost().equals(urlHostName);
}
};
} catch (Throwable t) {
throw new RuntimeException("Unable to create SSLConext for communication to policy manager", t);
}
}
config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(hv, sslContext));
ret = Client.create(config);
} else {
ClientConfig cc = new DefaultClientConfig();
cc.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true);
ret = Client.create(cc);
}
if (!(authenticationType != null && AUTH_KERBEROS.equalsIgnoreCase(authenticationType) && SecureClientLogin.isKerberosCredentialExists(principal, keytab))) {
if (ret != null) {
String username = config.getPolicyMgrUserName();
String password = config.getPolicyMgrPassword();
if (username == null || password == null || username.trim().isEmpty() || password.trim().isEmpty()) {
username = config.getDefaultPolicyMgrUserName();
password = config.getDefaultPolicyMgrPassword();
}
if (username != null && password != null) {
ret.addFilter(new HTTPBasicAuthFilter(username, password));
}
}
}
return ret;
}
use of com.sun.jersey.api.client.config.DefaultClientConfig in project ranger by apache.
the class PolicyMgrUserGroupBuilder method getClient.
private synchronized Client getClient() {
Client ret = null;
if (policyMgrBaseUrl.startsWith("https://")) {
ClientConfig config = new DefaultClientConfig();
if (sslContext == null) {
try {
KeyManager[] kmList = null;
TrustManager[] tmList = null;
if (keyStoreFile != null && keyStoreFilepwd != null) {
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
InputStream in = null;
try {
in = getFileInputStream(keyStoreFile);
if (in == null) {
LOG.error("Unable to obtain keystore from file [" + keyStoreFile + "]");
return ret;
}
keyStore.load(in, keyStoreFilepwd.toCharArray());
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, keyStoreFilepwd.toCharArray());
kmList = keyManagerFactory.getKeyManagers();
} finally {
if (in != null) {
in.close();
}
}
}
if (trustStoreFile != null && trustStoreFilepwd != null) {
KeyStore trustStore = KeyStore.getInstance(trustStoreType);
InputStream in = null;
try {
in = getFileInputStream(trustStoreFile);
if (in == null) {
LOG.error("Unable to obtain keystore from file [" + trustStoreFile + "]");
return ret;
}
trustStore.load(in, trustStoreFilepwd.toCharArray());
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trustStore);
tmList = trustManagerFactory.getTrustManagers();
} finally {
if (in != null) {
in.close();
}
}
}
sslContext = SSLContext.getInstance("SSL");
sslContext.init(kmList, tmList, new SecureRandom());
hv = new HostnameVerifier() {
public boolean verify(String urlHostName, SSLSession session) {
return session.getPeerHost().equals(urlHostName);
}
};
} catch (Throwable t) {
throw new RuntimeException("Unable to create SSLConext for communication to policy manager", t);
}
}
config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(hv, sslContext));
ret = Client.create(config);
} else {
ClientConfig cc = new DefaultClientConfig();
cc.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true);
ret = Client.create(cc);
}
if (!(authenticationType != null && AUTH_KERBEROS.equalsIgnoreCase(authenticationType) && SecureClientLogin.isKerberosCredentialExists(principal, keytab))) {
if (ret != null) {
String username = config.getPolicyMgrUserName();
String password = config.getPolicyMgrPassword();
if (username == null || password == null || username.trim().isEmpty() || password.trim().isEmpty()) {
username = config.getDefaultPolicyMgrUserName();
password = config.getDefaultPolicyMgrPassword();
}
if (username != null && password != null) {
ret.addFilter(new HTTPBasicAuthFilter(username, password));
}
}
}
return ret;
}
use of com.sun.jersey.api.client.config.DefaultClientConfig in project nutch by apache.
the class NutchClientImpl method createClient.
public void createClient() {
ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, true);
this.client = Client.create(clientConfig);
this.nutchResource = client.resource(instance.getUrl());
}
use of com.sun.jersey.api.client.config.DefaultClientConfig in project pentaho-kettle by pentaho.
the class Carte method callStopCarteRestService.
/**
* Checks that Carte is running and if so, shuts down the Carte server
*
* @param hostname
* @param port
* @param username
* @param password
* @throws ParseException
* @throws CarteCommandException
*/
@VisibleForTesting
static void callStopCarteRestService(String hostname, String port, String username, String password) throws ParseException, CarteCommandException {
// get information about the remote connection
try {
KettleClientEnvironment.init();
ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
Client client = Client.create(clientConfig);
client.addFilter(new HTTPBasicAuthFilter(username, Encr.decryptPasswordOptionallyEncrypted(password)));
// check if the user can access the carte server. Don't really need this call but may want to check it's output at
// some point
String contextURL = "http://" + hostname + ":" + port + "/kettle";
WebResource resource = client.resource(contextURL + "/status/?xml=Y");
String response = resource.get(String.class);
if (response == null || !response.contains("<serverstatus>")) {
throw new Carte.CarteCommandException(BaseMessages.getString(PKG, "Carte.Error.NoServerFound", hostname, "" + port));
}
// This is the call that matters
resource = client.resource(contextURL + "/stopCarte");
response = resource.get(String.class);
if (response == null || !response.contains("Shutting Down")) {
throw new Carte.CarteCommandException(BaseMessages.getString(PKG, "Carte.Error.NoShutdown", hostname, "" + port));
}
} catch (Exception e) {
throw new Carte.CarteCommandException(BaseMessages.getString(PKG, "Carte.Error.NoServerFound", hostname, "" + port), e);
}
}
use of com.sun.jersey.api.client.config.DefaultClientConfig in project pentaho-kettle by pentaho.
the class PentahoDiPlugin method createClient.
/**
* Create a new Client instance
*/
public static com.sun.jersey.api.client.Client createClient() {
ClientConfig cc = new DefaultClientConfig();
customizeClientConfiguration(cc);
return createClientInstance(cc);
}
Aggregations