use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter 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.filter.HTTPBasicAuthFilter 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.filter.HTTPBasicAuthFilter in project coprhd-controller by CoprHD.
the class IsilonApiFactory method getRESTClient.
/**
* Create Isilon API client
*
* @param endpoint isilon endpoint
* @return
*/
public IsilonApi getRESTClient(URI endpoint, String username, String password) {
IsilonApi isilonApi = _clientMap.get(endpoint.toString() + ":" + username + ":" + password);
if (isilonApi == null) {
Client jerseyClient = new ApacheHttpClient(_clientHandler);
jerseyClient.addFilter(new HTTPBasicAuthFilter(username, password));
RESTClient restClient = new RESTClient(jerseyClient);
isilonApi = new IsilonApi(endpoint, restClient);
_clientMap.putIfAbsent(endpoint.toString() + ":" + username + ":" + password, isilonApi);
}
return isilonApi;
}
use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter in project ORCID-Source by ORCID.
the class OrcidClientHelper method addBasicAuth.
public void addBasicAuth(String username, String password) {
basicAuthFilter = new HTTPBasicAuthFilter(username, password);
jerseyClient.addFilter(basicAuthFilter);
}
use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter in project microservices by pwillhan.
the class ComponentFinder method main.
public static void main(String[] args) {
Scanner scanner = null;
try {
scanner = new Scanner(System.in);
System.out.println("Enter component type in plural form (e.g. queues, exchanges) ");
String type = scanner.nextLine();
System.out.println("Enter vhost (leave empty for default vhost) ");
String vhost = scanner.nextLine();
System.out.println("Enter name pattern (leave empty for match-all pattern)");
String pattern = scanner.nextLine();
Client client = Client.create();
String path;
if (vhost.trim().isEmpty()) {
path = API_ROOT + "/" + type + "?columns=name";
} else {
path = API_ROOT + "/" + type + "/" + vhost + "?columns=name";
}
WebResource resource = client.resource(path);
resource.header("Content-Type", "application/json;charset=UTF-8");
resource.addFilter(new HTTPBasicAuthFilter("guest", "guest".getBytes()));
String result = resource.get(String.class);
JSONArray jsonResult = new JSONArray(result);
LOGGER.debug("Result: \n" + jsonResult.toString(4));
filterResult(jsonResult, pattern);
} finally {
if (scanner != null) {
scanner.close();
}
}
}
Aggregations