Search in sources :

Example 1 with BasicNameValuePair

use of org.apache.http.message.BasicNameValuePair 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 2 with BasicNameValuePair

use of org.apache.http.message.BasicNameValuePair 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)

Example 3 with BasicNameValuePair

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

the class TrelloService method addCard.

public Boolean addCard(String boardListId, String name) {
    Boolean result = false;
    ArrayList<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("key", PUBLIC_KEY));
    params.add(new BasicNameValuePair("token", mToken));
    params.add(new BasicNameValuePair("name", name));
    params.add(new BasicNameValuePair("idList", boardListId));
    HttpPost httpPost = new HttpPost(TRELLO_API_URL + "cards?" + URLEncodedUtils.format(params, "UTF-8"));
    HttpClient httpClient = getHttpClient();
    try {
        httpPost.setHeader("Accept", "application/json, text/javascript, */*; q=0.01");
        httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT_STRING);
        HttpResponse response = httpClient.execute(httpPost, mContext);
        if (response != null) {
            result = true;
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return result;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) ClientProtocolException(org.apache.http.client.ClientProtocolException)

Example 4 with BasicNameValuePair

use of org.apache.http.message.BasicNameValuePair in project moco by dreamhead.

the class MocoWebTest method should_match_form_value.

@Test
public void should_match_form_value() throws Exception {
    server.post(eq(form("name"), "dreamhead")).response("foobar");
    running(server, new Runnable() {

        @Override
        public void run() throws Exception {
            String content = Post(root()).bodyForm(new BasicNameValuePair("name", "dreamhead")).execute().returnContent().asString();
            assertThat(content, is("foobar"));
        }
    });
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) IOException(java.io.IOException) Test(org.junit.Test)

Example 5 with BasicNameValuePair

use of org.apache.http.message.BasicNameValuePair in project android-app by eoecn.

the class MainActivity method onClick.

// [end]
// [start]继承方法
@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch(v.getId()) {
        case R.id.Linear_above_toHome:
            showMenu();
            break;
        case R.id.login_login:
            SharedPreferences share = this.getSharedPreferences(UserLoginUidActivity.SharedName, Context.MODE_PRIVATE);
            // [start] 修复上一个bug
            String Key = share.getString(UserLoginUidActivity.KEY, "");
            if (Key != "" && !Key.contains(":")) {
                Editor edit = share.edit();
                edit.putString(UserLoginUidActivity.KEY, "");
                edit.commit();
            }
            // [end] 下一版本删除掉
            if (share.contains(UserLoginUidActivity.KEY) && !share.getString(UserLoginUidActivity.KEY, "").equals("")) {
                IntentUtil.start_activity(this, UserCenterActivity.class);
            } else {
                IntentUtil.start_activity(this, UserLoginActivity.class);
            }
            break;
        case R.id.imageview_above_more:
            if (isShowPopupWindows) {
                new PopupWindowUtil(mViewPager).showActionWindow(v, this, mBasePageAdapter.tabs);
            }
            break;
        case R.id.imageview_above_query:
            if (NetWorkHelper.isNetworkAvailable(MainActivity.this)) {
                IntentUtil.start_activity(this, SearchActivity.class, new BasicNameValuePair("tag", current_page));
            } else {
                Toast.makeText(getApplicationContext(), "网络连接失败,请检查网络", Toast.LENGTH_LONG).show();
            }
            break;
        case R.id.cbFeedback:
            FeedbackAgent agent = new FeedbackAgent(this);
            agent.startFeedbackActivity();
            break;
        case R.id.cbAbove:
            IntentUtil.start_activity(this, AboutActivity.class);
            break;
        case R.id.bn_refresh:
            switch(mTag) {
                case 0:
                    imgQuery.setVisibility(View.GONE);
                    new MyTask().execute(topDao);
                    break;
                case 1:
                    new MyTask().execute(newsDao);
                    break;
                case 2:
                    new MyTask().execute(wikiDao);
                    break;
                case 3:
                    new MyTask().execute(blogsDao);
                    break;
                default:
                    break;
            }
            break;
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) Editor(android.content.SharedPreferences.Editor) PopupWindowUtil(cn.eoe.app.utils.PopupWindowUtil) FeedbackAgent(com.umeng.fb.FeedbackAgent)

Aggregations

BasicNameValuePair (org.apache.http.message.BasicNameValuePair)279 NameValuePair (org.apache.http.NameValuePair)191 ArrayList (java.util.ArrayList)178 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)96 HttpPost (org.apache.http.client.methods.HttpPost)81 HttpResponse (org.apache.http.HttpResponse)75 HttpEntity (org.apache.http.HttpEntity)57 IOException (java.io.IOException)51 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)33 Test (org.junit.Test)31 HttpGet (org.apache.http.client.methods.HttpGet)29 ClientProtocolException (org.apache.http.client.ClientProtocolException)28 CSVReader (com.talend.csv.CSVReader)27 HttpClient (org.apache.http.client.HttpClient)24 JSONObject (org.json.JSONObject)20 UnsupportedEncodingException (java.io.UnsupportedEncodingException)19 HashMap (java.util.HashMap)19 Map (java.util.Map)17 URI (java.net.URI)16 WebserviceInvocation (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation)15