Search in sources :

Example 31 with HttpResponse

use of org.apache.http.HttpResponse in project aws-iam-ldap-bridge by denismo.

the class IAMAccountPasswordValidator method verifyIAMPassword.

@Override
public boolean verifyIAMPassword(Entry user, String pw) throws LdapInvalidAttributeValueException, LdapAuthenticationException {
    try {
        LOG.debug("Verifying {} {} with accessKey <hidden> and secretKey <hidden>", "user", user.get("uid").getString());
        HttpClient client = new SystemDefaultHttpClient();
        HttpPost post = new HttpPost("https://signin.aws.amazon.com/oauth");
        post.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.65 Safari/537.36");
        post.setHeader("Referer", "https://signin.aws.amazon.com/oauth");
        List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
        urlParameters.add(new BasicNameValuePair("client_id", "arn:aws:iam::015428540659:user/homepage"));
        urlParameters.add(new BasicNameValuePair("isIAMUser", "1"));
        urlParameters.add(new BasicNameValuePair("account", user.get("accountNumber").getString()));
        urlParameters.add(new BasicNameValuePair("username", user.get("uid").getString()));
        urlParameters.add(new BasicNameValuePair("password", pw));
        urlParameters.add(new BasicNameValuePair("Action", "login"));
        urlParameters.add(new BasicNameValuePair("redirect_uri", "https://console.aws.amazon.com/console/home?state=hashArgs%23&isauthcode=true"));
        urlParameters.add(new BasicNameValuePair("forceMobileApp", ""));
        urlParameters.add(new BasicNameValuePair("forceMobileLayout", ""));
        urlParameters.add(new BasicNameValuePair("mfaLoginFailure", ""));
        urlParameters.add(new BasicNameValuePair("RemainingExpiryPeriod", ""));
        urlParameters.add(new BasicNameValuePair("mfacode", ""));
        urlParameters.add(new BasicNameValuePair("next_mfacode", ""));
        post.setEntity(new UrlEncodedFormEntity(urlParameters, Charset.forName("UTF-8")));
        HttpResponse response = client.execute(post);
        return containsHeaders(response, "aws-account-alias", "aws-creds");
    } catch (IOException e) {
        LOG.error("Exception validating password for " + user.get("uid").getString(), e);
        return false;
    } catch (RuntimeException t) {
        LOG.error("Exception validating password for " + user.get("uid").getString(), t);
        throw t;
    }
}
Also used : SystemDefaultHttpClient(org.apache.http.impl.client.SystemDefaultHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) SystemDefaultHttpClient(org.apache.http.impl.client.SystemDefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) IOException(java.io.IOException)

Example 32 with HttpResponse

use of org.apache.http.HttpResponse in project moco by dreamhead.

the class MocoJsonStandaloneTest method should_return_expected_json_response_based_on_specified_json_request_shortcut.

@Test
public void should_return_expected_json_response_based_on_specified_json_request_shortcut() throws IOException {
    runWithConfiguration("json.json");
    HttpResponse response = helper.getResponse(remoteUrl("/json_response_shortcut"));
    HttpEntity entity = response.getEntity();
    byte[] bytes = ByteStreams.toByteArray(entity.getContent());
    assertThat(new String(bytes), is("{\"foo\":\"bar\"}"));
    MediaType mediaType = MediaType.parse(entity.getContentType().getValue());
    assertThat(mediaType.type(), is("application"));
    assertThat(mediaType.subtype(), is("json"));
}
Also used : HttpEntity(org.apache.http.HttpEntity) HttpResponse(org.apache.http.HttpResponse) MediaType(com.google.common.net.MediaType) Test(org.junit.Test)

Example 33 with HttpResponse

use of org.apache.http.HttpResponse in project moco by dreamhead.

the class MocoStandaloneTest method should_run_as_proxy.

@Test
public void should_run_as_proxy() throws IOException {
    runWithConfiguration("foo.json");
    HttpResponse response = Request.Get(remoteUrl("/proxy")).execute().returnResponse();
    String value = response.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue();
    assertThat(value, startsWith("text/html"));
}
Also used : HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Example 34 with HttpResponse

use of org.apache.http.HttpResponse in project moco by dreamhead.

the class MocoStandaloneTest method should_expected_response_header.

@Test
public void should_expected_response_header() throws IOException {
    runWithConfiguration("foo.json");
    HttpResponse response = Request.Get(remoteUrl("/response_header")).execute().returnResponse();
    assertThat(response.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue(), is("application/json"));
    assertThat(response.getFirstHeader("foo").getValue(), is("bar"));
}
Also used : HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Example 35 with HttpResponse

use of org.apache.http.HttpResponse in project Trello-Android by chrisHoekstra.

the class TrelloService method getNotifications.

public ArrayList<NotificationVO> getNotifications() {
    ArrayList<NotificationVO> result = null;
    ArrayList<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("key", PUBLIC_KEY));
    params.add(new BasicNameValuePair("token", mToken));
    HttpGet httpGet = new HttpGet(TRELLO_API_URL + "members/" + "me/" + "notifications?" + URLEncodedUtils.format(params, "UTF-8"));
    HttpClient httpClient = getHttpClient();
    try {
        httpGet.setHeader("Accept", "application/json, text/javascript, */*; q=0.01");
        httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT_STRING);
        HttpResponse response = httpClient.execute(httpGet, mContext);
        if (response != null) {
            result = mObjectMapper.readValue(mJsonFactory.createJsonParser(new InputStreamReader(response.getEntity().getContent(), "UTF-8")), new TypeReference<ArrayList<NotificationVO>>() {
            });
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return result;
}
Also used : InputStreamReader(java.io.InputStreamReader) NotificationVO(com.chrishoekstra.trello.vo.NotificationVO) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) HttpGet(org.apache.http.client.methods.HttpGet) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) TypeReference(org.codehaus.jackson.type.TypeReference) IOException(java.io.IOException) ClientProtocolException(org.apache.http.client.ClientProtocolException)

Aggregations

HttpResponse (org.apache.http.HttpResponse)1502 HttpGet (org.apache.http.client.methods.HttpGet)717 Test (org.junit.Test)686 IOException (java.io.IOException)355 TestHttpClient (io.undertow.testutils.TestHttpClient)290 HttpPost (org.apache.http.client.methods.HttpPost)238 HttpClient (org.apache.http.client.HttpClient)237 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)219 HttpEntity (org.apache.http.HttpEntity)192 Header (org.apache.http.Header)178 StringEntity (org.apache.http.entity.StringEntity)138 ArrayList (java.util.ArrayList)104 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)104 InputStream (java.io.InputStream)97 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)81 URI (java.net.URI)77 StatusLine (org.apache.http.StatusLine)76 ClientProtocolException (org.apache.http.client.ClientProtocolException)76 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)71 NameValuePair (org.apache.http.NameValuePair)63