Search in sources :

Example 1 with SystemDefaultHttpClient

use of org.apache.http.impl.client.SystemDefaultHttpClient 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 SystemDefaultHttpClient

use of org.apache.http.impl.client.SystemDefaultHttpClient in project tdi-studio-se by Talend.

the class WsdlTokenManager method getSOAPResponse.

private static String getSOAPResponse(URI issuerUri, String soapEnvelope) {
    HttpResponse response = null;
    // Create the request that will submit the request to the server
    try {
        HttpParams params = new BasicHttpParams();
        params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 180000);
        HttpClient client = new SystemDefaultHttpClient(params);
        HttpPost post = new HttpPost(issuerUri);
        StringEntity entity = new StringEntity(soapEnvelope);
        post.setHeader("Content-Type", "application/soap+xml; charset=UTF-8");
        post.setEntity(entity);
        response = client.execute(post);
        return EntityUtils.toString(response.getEntity());
    } catch (ClientProtocolException e) {
        logger.error(e.getMessage());
    } catch (IOException e) {
        logger.error(e.getMessage());
    }
    return null;
}
Also used : SystemDefaultHttpClient(org.apache.http.impl.client.SystemDefaultHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) HttpClient(org.apache.http.client.HttpClient) SystemDefaultHttpClient(org.apache.http.impl.client.SystemDefaultHttpClient) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) BasicHttpParams(org.apache.http.params.BasicHttpParams) ClientProtocolException(org.apache.http.client.ClientProtocolException)

Example 3 with SystemDefaultHttpClient

use of org.apache.http.impl.client.SystemDefaultHttpClient in project tdi-studio-se by Talend.

the class DeviceIdManager method executeRegistrationRequest.

/**
     * This method demonstrate execution of device registration request.
     * 
     * @param url Registration uri
     * @param soapEnvelope Registration xml envelope
     * @return device registration puid
     */
private static String executeRegistrationRequest(String url, String soapEnvelope) throws IllegalStateException, SAXException, ParserConfigurationException, DeviceRegistrationFailedException, IOException {
    HttpResponse response = null;
    // Create the request that will submit the request to the server
    try {
        HttpParams params = new BasicHttpParams();
        params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 180000);
        HttpClient client = new SystemDefaultHttpClient(params);
        // Uncomment following lines to view the traffic in fiddler.
        // HttpHost proxy = new HttpHost("localhost", 8888);
        // client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        HttpPost post = new HttpPost(url);
        StringEntity entity = new StringEntity(soapEnvelope);
        post.setHeader("Content-Type", "application/soap+xml; charset=UTF-8");
        post.setEntity(entity);
        response = client.execute(post);
        return parseRegistrationResponse(response, false);
    } catch (ClientProtocolException e) {
        Log.error(e.getMessage());
        parseRegistrationResponse(response, true);
        throw e;
    } catch (IOException e) {
        Log.error(e.getMessage());
        parseRegistrationResponse(response, true);
        throw e;
    }
}
Also used : SystemDefaultHttpClient(org.apache.http.impl.client.SystemDefaultHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) HttpClient(org.apache.http.client.HttpClient) SystemDefaultHttpClient(org.apache.http.impl.client.SystemDefaultHttpClient) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) BasicHttpParams(org.apache.http.params.BasicHttpParams) ClientProtocolException(org.apache.http.client.ClientProtocolException)

Aggregations

IOException (java.io.IOException)3 HttpResponse (org.apache.http.HttpResponse)3 HttpClient (org.apache.http.client.HttpClient)3 HttpPost (org.apache.http.client.methods.HttpPost)3 SystemDefaultHttpClient (org.apache.http.impl.client.SystemDefaultHttpClient)3 ClientProtocolException (org.apache.http.client.ClientProtocolException)2 StringEntity (org.apache.http.entity.StringEntity)2 BasicHttpParams (org.apache.http.params.BasicHttpParams)2 HttpParams (org.apache.http.params.HttpParams)2 NameValuePair (org.apache.http.NameValuePair)1 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)1 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)1