List of usage examples for org.apache.http.impl.auth BasicScheme BasicScheme
public BasicScheme()
From source file:jetbrains.buildServer.commitPublisher.github.api.impl.GitHubApiFactoryImpl.java
@NotNull public GitHubApi openGitHubForUser(@NotNull final String url, @NotNull final String username, @NotNull final String password) { return new GitHubApiImpl(myWrapper, new GitHubApiPaths(url)) { @Override//from www .j av a 2 s . com protected void setAuthentication(@NotNull HttpRequest request) throws AuthenticationException { request.addHeader(new BasicScheme() .authenticate(new UsernamePasswordCredentials(username, password), request)); } }; }
From source file:dtu.ds.warnme.app.ws.client.https.ssl.PreemptiveAuthenticationRequestInterceptor.java
@Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE); CredentialsProvider credsProvider = (CredentialsProvider) context .getAttribute(ClientContext.CREDS_PROVIDER); HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST); if (authState.getAuthScheme() == null) { AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort()); Credentials creds = credsProvider.getCredentials(authScope); if (creds != null) { authState.setAuthScheme(new BasicScheme()); authState.setCredentials(creds); }/*from w ww.ja va 2 s.co m*/ } }
From source file:com.mycompany.projecta.JenkinsScraper.java
public String scrape(String urlString, String username, String password) throws ClientProtocolException, IOException { URI uri = URI.create(urlString); HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(username, password)); // Create AuthCache instance AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local auth cache BasicScheme basicAuth = new BasicScheme(); authCache.put(host, basicAuth);// w w w . ja v a2 s .c o m CloseableHttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); HttpGet httpGet = new HttpGet(uri); // Add AuthCache to the execution context HttpClientContext localContext = HttpClientContext.create(); localContext.setAuthCache(authCache); HttpResponse response = httpClient.execute(host, httpGet, localContext); String resp = response.toString(); return EntityUtils.toString(response.getEntity()); }
From source file:org.wso2.developerstudio.appfactory.core.client.HttpsJenkinsClient.java
public static HttpResponse getBulildinfo(String applicationId, String version, String builderBaseUrl, int lastBuildNo) { DefaultHttpClient client = new DefaultHttpClient(); client = (DefaultHttpClient) HttpsJaggeryClient.wrapClient(client, builderBaseUrl); client.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(Authenticator.getInstance().getCredentials().getUser(), Authenticator.getInstance().getCredentials().getPassword())); // Generate BASIC scheme object and stick it to the execution context BasicScheme basicAuth = new BasicScheme(); BasicHttpContext context = new BasicHttpContext(); context.setAttribute("preemptive-auth", basicAuth); // Add as the first (because of the zero) request interceptor // It will first intercept the request and preemptively initialize the authentication scheme if there is not client.addRequestInterceptor(new PreemptiveAuth(), 0); String getUrl = builderBaseUrl + "/job/" + applicationId + "-" + version + "-default/" + lastBuildNo + "/consoleText"; HttpGet get = new HttpGet(getUrl); try {/* www.j a v a2 s .c om*/ // Execute your request with the given context HttpResponse response = client.execute(get, context); return response; } catch (Exception e) { log.error("Jenkins Client err", e); } return null; }
From source file:org.springframework.cloud.dataflow.shell.command.support.PreemptiveBasicAuthHttpComponentsClientHttpRequestFactory.java
private HttpContext createHttpContext() { final AuthCache authCache = new BasicAuthCache(); final BasicScheme basicAuth = new BasicScheme(); authCache.put(host, basicAuth);//w ww .j a va 2s. co m final BasicHttpContext localcontext = new BasicHttpContext(); localcontext.setAttribute(HttpClientContext.AUTH_CACHE, authCache); return localcontext; }
From source file:se.vgregion.pubsub.twitter.impl.PreemptiveBasicAuth.java
public void process(HttpRequest request, HttpContext context) { AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE); // If not auth scheme has been initialized yet if (authState.getAuthScheme() == null) { Credentials creds = new UsernamePasswordCredentials(username, password); authState.setAuthScheme(new BasicScheme()); authState.setCredentials(creds); }//from w w w . j a v a 2 s.co m }
From source file:at.bitfire.davdroid.webdav.PreemptiveAuthInterceptor.java
@Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE); CredentialsProvider credsProvider = (CredentialsProvider) context .getAttribute(ClientContext.CREDS_PROVIDER); HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST); if (authState.getAuthScheme() == null) { AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort()); Credentials creds = credsProvider.getCredentials(authScope); if (creds != null) { authState.setAuthScheme(new BasicScheme()); authState.setCredentials(creds); }/*from w w w . ja v a 2 s .co m*/ } }
From source file:org.springframework.cloud.dataflow.rest.util.PreemptiveBasicAuthHttpComponentsClientHttpRequestFactory.java
@Override protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) { final AuthCache authCache = new BasicAuthCache(); final BasicScheme basicAuth = new BasicScheme(); authCache.put(host, basicAuth);/*from www . j a v a 2 s .c o m*/ final BasicHttpContext localcontext = new BasicHttpContext(); localcontext.setAttribute(HttpClientContext.AUTH_CACHE, authCache); return localcontext; }
From source file:org.deegree.maven.utils.HttpUtils.java
public static HttpClient getAuthenticatedHttpClient(ServiceIntegrationTestHelper helper) { DefaultHttpClient client = new DefaultHttpClient(); HttpConnectionParams.setConnectionTimeout(client.getParams(), 30000); HttpConnectionParams.setSoTimeout(client.getParams(), 1200000); client.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("deegree", "deegree")); // preemptive authentication used to be easier in pre-4.x httpclient AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); HttpHost host = new HttpHost("localhost", Integer.parseInt(helper.getPort())); authCache.put(host, basicAuth);//from w w w.jav a 2s . c om BasicHttpContext localcontext = new BasicHttpContext(); localcontext.setAttribute(AUTH_CACHE, authCache); return client; }
From source file:se.vgregion.util.HTTPUtils.java
public static HttpResponse basicAuthRequest(String url, String username, String password, DefaultHttpClient client) throws HttpUtilsException { HttpGet get = new HttpGet(url); client.getCredentialsProvider().setCredentials(new AuthScope(null, 443), new UsernamePasswordCredentials(username, password)); BasicHttpContext localcontext = new BasicHttpContext(); // Generate BASIC scheme object and stick it to the local // execution context BasicScheme basicAuth = new BasicScheme(); localcontext.setAttribute("preemptive-auth", basicAuth); // Add as the first request interceptor client.addRequestInterceptor(new PreemptiveAuth(), 0); HttpResponse response;/*from ww w .j ava 2 s .c o m*/ try { response = client.execute(get, localcontext); } catch (ClientProtocolException e) { throw new HttpUtilsException("Invalid http protocol", e); } catch (IOException e) { throw new HttpUtilsException(e.getMessage(), e); } return response; }