use of org.apache.http.auth.UsernamePasswordCredentials in project testcases by coheigea.
the class SAMLSSOTest method login.
private static String login(String url, String user, String password, String idpPort) throws IOException {
final WebClient webClient = new WebClient();
webClient.getOptions().setUseInsecureSSL(true);
webClient.getCredentialsProvider().setCredentials(new AuthScope("localhost", Integer.parseInt(idpPort)), new UsernamePasswordCredentials(user, password));
webClient.getOptions().setJavaScriptEnabled(false);
final HtmlPage idpPage = webClient.getPage(url);
webClient.getOptions().setJavaScriptEnabled(true);
Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText());
final HtmlForm form = idpPage.getFormByName("samlsigninresponseform");
final HtmlSubmitInput button = form.getInputByName("_eventId_submit");
final XmlPage rpPage = button.click();
return rpPage.asXml();
}
use of org.apache.http.auth.UsernamePasswordCredentials in project webdrivermanager by bonigarcia.
the class ProxyTest method testProxyCredentials.
@Test
public void testProxyCredentials() throws Exception {
WebDriverManager.config().setProxy("myproxy:8081").setProxyUser("domain\\me").setProxyPass("pass");
HttpClient wdmClient = new HttpClient();
Field field = HttpClient.class.getDeclaredField("closeableHttpClient");
field.setAccessible(true);
CloseableHttpClient client = (CloseableHttpClient) field.get(wdmClient);
field = client.getClass().getDeclaredField("credentialsProvider");
field.setAccessible(true);
BasicCredentialsProvider provider = (BasicCredentialsProvider) field.get(client);
NTCredentials ntcreds = (NTCredentials) provider.getCredentials(new AuthScope(ANY_HOST, ANY_PORT, ANY_REALM, NTLM));
assertThat(ntcreds.getDomain(), equalTo("DOMAIN"));
assertThat(ntcreds.getUserName(), equalTo("me"));
assertThat(ntcreds.getPassword(), equalTo("pass"));
UsernamePasswordCredentials creds = (UsernamePasswordCredentials) provider.getCredentials(new AuthScope(ANY_HOST, ANY_PORT));
assertThat(creds.getUserName(), equalTo("domain\\me"));
assertThat(creds.getPassword(), equalTo("pass"));
}
use of org.apache.http.auth.UsernamePasswordCredentials in project apex-core by apache.
the class WebServicesClientTest method checkUserCredentials.
public static void checkUserCredentials(String username, String password, AuthScheme authScheme) throws NoSuchFieldException, IllegalAccessException {
CredentialsProvider provider = getCredentialsProvider();
String httpScheme = AuthScope.ANY_SCHEME;
if (authScheme == AuthScheme.BASIC) {
httpScheme = AuthSchemes.BASIC;
} else if (authScheme == AuthScheme.DIGEST) {
httpScheme = AuthSchemes.DIGEST;
}
AuthScope authScope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, httpScheme);
Credentials credentials = provider.getCredentials(authScope);
Assert.assertNotNull("Credentials", credentials);
Assert.assertTrue("Credentials type is user", UsernamePasswordCredentials.class.isAssignableFrom(credentials.getClass()));
UsernamePasswordCredentials pwdCredentials = (UsernamePasswordCredentials) credentials;
Assert.assertEquals("Username", username, pwdCredentials.getUserName());
Assert.assertEquals("Password", password, pwdCredentials.getPassword());
}
use of org.apache.http.auth.UsernamePasswordCredentials in project apex-core by apache.
the class WebServicesClient method setupUserPassAuthScheme.
private static void setupUserPassAuthScheme(AuthScheme scheme, String httpScheme, AuthSchemeProvider provider, ConfigProvider configuration) {
String username = configuration.getProperty(scheme, "username");
String password = configuration.getProperty(scheme, "password");
if ((username != null) && (password != null)) {
LOG.info("Setting up scheme {}", scheme);
AuthScope authScope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, httpScheme);
Credentials credentials = new UsernamePasswordCredentials(username, password);
setupHttpAuthScheme(httpScheme, provider, authScope, credentials);
} else if ((username != null) || (password != null)) {
LOG.warn("Not setting up scheme {}, missing credentials {}", scheme, (username == null) ? "username" : "password");
}
}
use of org.apache.http.auth.UsernamePasswordCredentials in project spring-boot-admin by codecentric.
the class AdminServerNotifierAutoConfiguration method createNotifierRestTemplate.
private static RestTemplate createNotifierRestTemplate(NotifierProxyProperties proxyProperties) {
RestTemplate restTemplate = new RestTemplate();
if (proxyProperties.getHost() != null) {
HttpClientBuilder builder = HttpClientBuilder.create();
builder.setProxy(new HttpHost(proxyProperties.getHost(), proxyProperties.getPort()));
if (proxyProperties.getUsername() != null && proxyProperties.getPassword() != null) {
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(proxyProperties.getHost(), proxyProperties.getPort()), new UsernamePasswordCredentials(proxyProperties.getUsername(), proxyProperties.getPassword()));
builder.setDefaultCredentialsProvider(credsProvider);
}
restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(builder.build()));
}
return restTemplate;
}
Aggregations