Search in sources :

Example 41 with HTTPBasicAuthFilter

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());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Client(com.sun.jersey.api.client.Client) UserAccount(org.activityinfo.test.sut.UserAccount) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter) Then(cucumber.api.java.en.Then)

Example 42 with HTTPBasicAuthFilter

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);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WebResource(com.sun.jersey.api.client.WebResource) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)

Example 43 with HTTPBasicAuthFilter

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;
}
Also used : ApacheHttpClient(com.sun.jersey.client.apache.ApacheHttpClient) RestClientItf(com.emc.storageos.services.restutil.RestClientItf) ApacheHttpClient(com.sun.jersey.client.apache.ApacheHttpClient) Client(com.sun.jersey.api.client.Client) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)

Example 44 with HTTPBasicAuthFilter

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"));
}
Also used : DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)

Example 45 with HTTPBasicAuthFilter

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;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) LoggingFilter(com.sun.jersey.api.client.filter.LoggingFilter) WebResource(com.sun.jersey.api.client.WebResource) Client(com.sun.jersey.api.client.Client) WebServiceClient(code.satyagraha.gfm.support.api.WebServiceClient) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)

Aggregations

HTTPBasicAuthFilter (com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)45 Client (com.sun.jersey.api.client.Client)31 WebResource (com.sun.jersey.api.client.WebResource)19 ClientResponse (com.sun.jersey.api.client.ClientResponse)15 ClientConfig (com.sun.jersey.api.client.config.ClientConfig)14 DefaultClientConfig (com.sun.jersey.api.client.config.DefaultClientConfig)14 LoggingFilter (com.sun.jersey.api.client.filter.LoggingFilter)7 ArrayList (java.util.ArrayList)7 ClientFilter (com.sun.jersey.api.client.filter.ClientFilter)6 HTTPSProperties (com.sun.jersey.client.urlconnection.HTTPSProperties)5 ApacheHttpClient (com.sun.jersey.client.apache.ApacheHttpClient)4 HostnameVerifier (javax.net.ssl.HostnameVerifier)4 SSLSession (javax.net.ssl.SSLSession)4 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)3 ClientRequest (com.sun.jersey.api.client.ClientRequest)3 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)3 FormDataMultiPart (com.sun.jersey.multipart.FormDataMultiPart)3 FileInputStream (java.io.FileInputStream)3 URI (java.net.URI)3 KeyStore (java.security.KeyStore)3