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;
}
}
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;
}
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;
}
}
Aggregations