use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter in project activityinfo by bedatadriven.
the class DataEntrySteps method field_s_downloadable_link_is_forbidden_for.
@Then("^\"([^\"]*)\" field's downloadable link is forbidden for \"([^\"]*)\"$")
public void field_s_downloadable_link_is_forbidden_for(String attachmentFieldName, String userEmail) throws Throwable {
UserAccount account = accounts.ensureAccountExists(userEmail);
String blobLink = firstDownloadableLinkOfFirstSubmission(attachmentFieldName);
Client client = new Client();
client.addFilter(new HTTPBasicAuthFilter(account.getEmail(), account.getPassword()));
client.setFollowRedirects(false);
ClientResponse clientResponse = client.resource(blobLink).get(ClientResponse.class);
assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), clientResponse.getStatus());
}
use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter in project ecs-dashboard by carone1.
the class ManagementClient method login.
/**
* Login using admin username and secretKey
* returned authentication token is stored internally
* @throws RuntimeException - run time exception
*/
protected void login() {
WebResource mgmtResource = this.mgmtClient.resource(this.uri);
// login
WebResource loginResource = mgmtResource.path(REST_LOGIN);
loginResource.addFilter(new HTTPBasicAuthFilter(this.mgmtConfig.getMgmtUsername(), this.mgmtConfig.getMgmtSecretKey()));
ClientResponse loginResponse = loginResource.get(ClientResponse.class);
// Check for sucsess
int statusCode = loginResponse.getStatusInfo().getStatusCode();
if (statusCode != Status.OK.getStatusCode()) {
String errorMessage = "Login to " + this.uri + REST_LOGIN + " failed" + " Server returned: " + statusCode;
throw new RuntimeException(errorMessage);
}
String authToken = loginResponse.getHeaders().getFirst(X_SDS_AUTH_TOKEN);
if (authToken != null) {
this.mgmtAuthToken = authToken;
} else {
String errorMessage = "Login to " + this.uri + " ok but Server did not return " + X_SDS_AUTH_TOKEN + "in response header";
throw new RuntimeException(errorMessage);
}
}
use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter in project coprhd-controller by CoprHD.
the class XtremIOClientFactory method getRESTClient.
public RestClientItf getRESTClient(URI endpoint, String username, String password, String version, boolean authFilter) {
// removed caching RestClient session as it is not actually a session, just a java RestClient object
// RestClientItf clientApi = _clientMap.get(endpoint.toString() + ":" + username + ":" + password + ":" + model);
Client jerseyClient = new ApacheHttpClient(_clientHandler);
if (authFilter) {
jerseyClient.addFilter(new HTTPBasicAuthFilter(username, password));
}
RestClientItf clientApi = createNewRestClient(endpoint, username, password, version, jerseyClient);
return clientApi;
}
use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter in project data-access by pentaho.
the class TestDataSourceResource method init.
private static void init() {
ClientConfig clientConfig = new DefaultClientConfig();
client = Client.create(clientConfig);
client.addFilter(new HTTPBasicAuthFilter("joe", "password"));
}
use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter in project gfm_viewer by satyagraha.
the class WebServiceClientDefault method transform.
@Override
public String transform(String mdText) {
if (StringUtils.isBlank(config.getApiUrl())) {
String responseText = String.format("<pre>\n%s\n</pre>", StringEscapeUtils.escapeHtml4(mdText));
return responseText;
}
Client client = getClient(config.getApiUrl());
LOGGER.fine("client: " + client);
String username = config.getUsername();
if (username != null && username.length() > 0) {
String password = config.getPassword();
client.removeFilter(null);
client.addFilter(new HTTPBasicAuthFilter(username, password));
}
client.addFilter(new LoggingFilter(LOGGER));
WebResource webResource = client.resource(config.getApiUrl());
Markdown markdown = new Markdown(mdText);
ClientResponse response = webResource.path("markdown").type(MediaType.APPLICATION_JSON).entity(markdown).accept(MediaType.TEXT_HTML).post(ClientResponse.class);
String responseText = response.getEntity(String.class);
return responseText;
}
Aggregations