Search in sources :

Example 91 with UsernamePasswordCredentials

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();
}
Also used : HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlSubmitInput(com.gargoylesoftware.htmlunit.html.HtmlSubmitInput) AuthScope(org.apache.http.auth.AuthScope) XmlPage(com.gargoylesoftware.htmlunit.xml.XmlPage) WebClient(com.gargoylesoftware.htmlunit.WebClient) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 92 with UsernamePasswordCredentials

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"));
}
Also used : Field(java.lang.reflect.Field) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpClient(io.github.bonigarcia.wdm.HttpClient) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) AuthScope(org.apache.http.auth.AuthScope) NTCredentials(org.apache.http.auth.NTCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Test(org.junit.Test)

Example 93 with UsernamePasswordCredentials

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());
}
Also used : AuthScope(org.apache.http.auth.AuthScope) CredentialsProvider(org.apache.http.client.CredentialsProvider) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 94 with UsernamePasswordCredentials

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");
    }
}
Also used : AuthScope(org.apache.http.auth.AuthScope) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 95 with UsernamePasswordCredentials

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;
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpHost(org.apache.http.HttpHost) RestTemplate(org.springframework.web.client.RestTemplate) AuthScope(org.apache.http.auth.AuthScope) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Aggregations

UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)337 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)212 CredentialsProvider (org.apache.http.client.CredentialsProvider)189 AuthScope (org.apache.http.auth.AuthScope)163 HttpHost (org.apache.http.HttpHost)95 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)78 HttpGet (org.apache.http.client.methods.HttpGet)73 IOException (java.io.IOException)54 BasicScheme (org.apache.http.impl.auth.BasicScheme)53 Test (org.junit.Test)53 HttpResponse (org.apache.http.HttpResponse)52 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)46 Credentials (org.apache.http.auth.Credentials)44 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)43 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)37 URI (java.net.URI)34 AuthCache (org.apache.http.client.AuthCache)32 HttpClient (org.apache.http.client.HttpClient)31 BasicAuthCache (org.apache.http.impl.client.BasicAuthCache)31 HttpPost (org.apache.http.client.methods.HttpPost)29