use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter in project pentaho-kettle by pentaho.
the class Wadl2JavaRestConnectivetyCheck method initRestService1.
/**
* Test stand alone generated code web service connectivity
*/
private void initRestService1() throws InitializationException {
// get information about the remote connection
String username = "admin";
String password = "password";
ClientConfig clientConfig = new DefaultClientConfig();
client = Client.create(clientConfig);
client.addFilter(new HTTPBasicAuthFilter(username, password));
URI baseUri = null;
try {
baseUri = new URI(uri + "/plugin/");
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
PentahoDiPlugin.PurRepositoryPluginApiRevision revisionService = PentahoDiPlugin.purRepositoryPluginApiRevision(client, baseUri);
PentahoDiPlugin.PurRepositoryPluginApiRevision.PathIdVersioningConfiguration versioningConfigurationMethod = revisionService.pathIdVersioningConfiguration("foo.ktr");
FileVersioningConfiguration fileVersioningConfiguration = versioningConfigurationMethod.getAsXml(FileVersioningConfiguration.class);
System.out.println("Test1: " + fileVersioningConfiguration.isVersioningEnabled());
}
use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter in project pentaho-kettle by pentaho.
the class RepositoryCleanupUtil method authenticateLoginCredentials.
/**
* Use REST API to authenticate provided credentials
*
* @throws Exception
*/
private void authenticateLoginCredentials() throws Exception {
if (client == null) {
ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
client = Client.create(clientConfig);
client.addFilter(new HTTPBasicAuthFilter(username, password));
}
WebResource resource = client.resource(url + AUTHENTICATION + AdministerSecurityAction.NAME);
String response = resource.get(String.class);
if (!response.equals("true")) {
throw new Exception(Messages.getInstance().getString("REPOSITORY_CLEANUP_UTIL.ERROR_0012.ACCESS_DENIED"));
}
}
use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter 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
*/
private static void callStopCarteRestService(String hostname, String port, String username, String password) throws ParseException, CarteCommandException {
// get information about the remote connection
try {
ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
Client client = Client.create(clientConfig);
client.addFilter(new HTTPBasicAuthFilter(username, 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.filter.HTTPBasicAuthFilter in project pentaho-kettle by pentaho.
the class Rest method setConfig.
private void setConfig() throws KettleException {
if (data.config == null) {
// Use ApacheHttpClient for supporting proxy authentication.
data.config = new DefaultApacheHttpClient4Config();
if (!Utils.isEmpty(data.realProxyHost)) {
// PROXY CONFIGURATION
data.config.getProperties().put(ApacheHttpClient4Config.PROPERTY_PROXY_URI, "http://" + data.realProxyHost + ":" + data.realProxyPort);
if (!Utils.isEmpty(data.realHttpLogin) && !Utils.isEmpty(data.realHttpPassword)) {
AuthScope authScope = new AuthScope(data.realProxyHost, data.realProxyPort);
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(data.realHttpLogin, data.realHttpPassword);
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(authScope, credentials);
data.config.getProperties().put(ApacheHttpClient4Config.PROPERTY_CREDENTIALS_PROVIDER, credentialsProvider);
}
} else {
if (!Utils.isEmpty(data.realHttpLogin)) {
// Basic authentication
data.basicAuthentication = new HTTPBasicAuthFilter(data.realHttpLogin, data.realHttpPassword);
}
}
if (meta.isPreemptive()) {
data.config.getProperties().put(ApacheHttpClient4Config.PROPERTY_PREEMPTIVE_BASIC_AUTHENTICATION, true);
}
// SSL TRUST STORE CONFIGURATION
if (!Utils.isEmpty(data.trustStoreFile)) {
try (FileInputStream trustFileStream = new FileInputStream(data.trustStoreFile)) {
KeyStore trustStore = KeyStore.getInstance("JKS");
trustStore.load(trustFileStream, data.trustStorePassword.toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
tmf.init(trustStore);
SSLContext ctx = SSLContext.getInstance("SSL");
ctx.init(null, tmf.getTrustManagers(), null);
HostnameVerifier hv = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
if (isDebug()) {
logDebug("Warning: URL Host: " + hostname + " vs. " + session.getPeerHost());
}
return true;
}
};
data.config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(hv, ctx));
} catch (NoSuchAlgorithmException e) {
throw new KettleException(BaseMessages.getString(PKG, "Rest.Error.NoSuchAlgorithm"), e);
} catch (KeyStoreException e) {
throw new KettleException(BaseMessages.getString(PKG, "Rest.Error.KeyStoreException"), e);
} catch (CertificateException e) {
throw new KettleException(BaseMessages.getString(PKG, "Rest.Error.CertificateException"), e);
} catch (FileNotFoundException e) {
throw new KettleException(BaseMessages.getString(PKG, "Rest.Error.FileNotFound", data.trustStoreFile), e);
} catch (IOException e) {
throw new KettleException(BaseMessages.getString(PKG, "Rest.Error.IOException"), e);
} catch (KeyManagementException e) {
throw new KettleException(BaseMessages.getString(PKG, "Rest.Error.KeyManagementException"), e);
}
}
}
}
use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter in project coprhd-controller by CoprHD.
the class AuthSvcTests method createHttpsClient.
/**
* Conveninence method to create a Client, and add authentication info
* if desired. If addAuthFilter is set to true, credentials will be added
* to a Basic Auth filter, and 302 will be followed manually, adding the auth token
* on the final redirect to the service location. If addAuthFilter is set to
* false, a regular 302 follow up will be done, no headers or basic auth will be
* added.
*
* @throws NoSuchAlgorithmException
*/
protected Client createHttpsClient(final String username, final String password, boolean addAuthFilters) throws NoSuchAlgorithmException {
// Disable server certificate validation as we are using
// self-signed certificate
disableCertificateValidation();
final ClientConfig config = new DefaultClientConfig();
final Client c = Client.create(config);
c.addFilter(new LoggingFilter());
if (addAuthFilters) {
// do a "modified 302" below with copying the header
c.setFollowRedirects(false);
c.addFilter(new HTTPBasicAuthFilter(username, password));
c.addFilter(new ClientFilter() {
@Override
public ClientResponse handle(ClientRequest request) throws ClientHandlerException {
if (_savedTokens.containsKey(username)) {
ArrayList<Object> token = new ArrayList<Object>();
token.add(_savedTokens.get(username));
request.getHeaders().put(AUTH_TOKEN_HEADER, token);
}
ClientResponse response = getNext().handle(request);
if (response.getHeaders() != null && response.getHeaders().get(AUTH_TOKEN_HEADER) != null) {
_savedTokens.put(username, response.getHeaders().getFirst(AUTH_TOKEN_HEADER));
}
if (response.getHeaders() != null && response.getHeaders().get(AUTH_PROXY_TOKEN_HEADER) != null) {
_savedProxyTokens.put(username, response.getHeaders().getFirst(AUTH_PROXY_TOKEN_HEADER));
}
if (response.getStatus() == 302) {
WebResource wb = c.resource(response.getLocation());
response = wb.header(AUTH_TOKEN_HEADER, _savedTokens.get(username)).get(ClientResponse.class);
}
return response;
}
});
} else {
// no auth filter, and do a regular 302 follow up, don't copy any auth token.
c.setFollowRedirects(true);
}
return c;
}
Aggregations