List of usage examples for org.apache.http.impl.auth BasicScheme BasicScheme
public BasicScheme()
From source file:com.liferay.portal.search.solr.interceptor.PreemptiveAuthInterceptor.java
@Override public void process(HttpRequest request, HttpContext httpContext) { AuthState authState = (AuthState) httpContext.getAttribute(ClientContext.TARGET_AUTH_STATE); if (authState.getAuthScheme() != null) { return;// w ww . j av a2s . c o m } CredentialsProvider credentialsProvider = (CredentialsProvider) httpContext .getAttribute(ClientContext.CREDS_PROVIDER); HttpHost targetHttpHost = (HttpHost) httpContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST); AuthScope authScope = new AuthScope(targetHttpHost.getHostName(), targetHttpHost.getPort()); Credentials credentials = credentialsProvider.getCredentials(authScope); if (credentials != null) { authState.update(new BasicScheme(), credentials); } }
From source file:org.dasein.security.joyent.BasicSchemeHttpAuth.java
public void addPreemptiveAuth(@Nonnull HttpRequest request) throws CloudException, InternalException { if (providerContext == null) { throw new CloudException("No context was defined for this request"); }/*from w w w. j a v a 2s . co m*/ try { String username = new String(providerContext.getAccessPublic(), "utf-8"); String password = new String(providerContext.getAccessPrivate(), "utf-8"); UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password); request.addHeader(new BasicScheme().authenticate(creds, request)); } catch (UnsupportedEncodingException e) { throw new InternalException(e); } catch (AuthenticationException e) { throw new InternalException(e); } }
From source file:cn.com.loopj.android.http.PreemptiveAuthorizationHttpRequestInterceptor.java
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); }/* www. jav a2 s . co m*/ } }
From source file:com.github.avarabyeu.restendpoint.http.PreemptiveAuthInterceptor.java
/** * Adds provided auth scheme to the client if there are no another provided * auth schemes/*from w w w. j a v a 2 s . c om*/ */ @Override public final void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE); if (authState.getAuthScheme() == null) { HttpHost targetHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST); AuthCache authCache = new BasicAuthCache(); authCache.put(targetHost, new BasicScheme()); context.setAttribute(HttpClientContext.AUTH_CACHE, authCache); } }
From source file:com.cisco.cta.taxii.adapter.httpclient.BasicAuthHttpRequestFactory.java
public BasicAuthHttpRequestFactory(HttpClient httpClient, TaxiiServiceSettings settings, ProxySettings proxySettings, CredentialsProvider credsProvider) { super(httpClient); this.credsProvider = credsProvider; URL url = settings.getPollEndpoint(); HttpHost targetHost = new HttpHost(url.getHost(), url.getPort(), url.getProtocol()); // Create auth cache with BASIC scheme authCache = new BasicAuthCache(); authCache.put(targetHost, new BasicScheme()); }
From source file:org.piraso.client.net.HttpBasicAuthentication.java
public void authenticate() { validate();// ww w .j a v a 2s. c o m UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(userName, password); httpClient.getCredentialsProvider() .setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), credentials); // 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(targetHost, basicAuth); context.setAttribute(ClientContext.AUTH_CACHE, authCache); }
From source file:bad.robot.http.apache.ApacheAuthenticationSchemeHttpContextBuilder.java
@Override public ApacheAuthenticationSchemeHttpContextBuilder withBasicAuthCredentials(String username, String password, URL url) {/* w w w .ja v a 2 s .c om*/ authenticationSchemes.put(asHttpHost(url), new BasicScheme()); return this; }
From source file:org.wso2.developerstudio.appfactory.core.client.RssClient.java
public static String getDBinfo(String operation, String dsBaseUrl) { String url = dsBaseUrl + "NDataSourceAdmin"; DefaultHttpClient client = new DefaultHttpClient(); client = (DefaultHttpClient) HttpsJaggeryClient.wrapClient(client, url); 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); client.addRequestInterceptor(new PreemptiveAuth(), 0); HttpPost post = new HttpPost(url); String sopactionValue = "urn:" + operation; post.addHeader("SOAPAction", sopactionValue); String body = createPayLoad(operation); try {/* w w w .j av a 2 s . co m*/ StringEntity entity = new StringEntity(body.toString(), "text/xml", HTTP.DEFAULT_CONTENT_CHARSET); post.setEntity(entity); HttpResponse response = client.execute(post); if (200 == response.getStatusLine().getStatusCode()) { HttpEntity entityGetAppsOfUser = response.getEntity(); BufferedReader rd = new BufferedReader(new InputStreamReader(entityGetAppsOfUser.getContent())); StringBuilder sb = new StringBuilder(); String line = ""; while ((line = rd.readLine()) != null) { sb.append(line); } String respond = sb.toString(); EntityUtils.consume(entityGetAppsOfUser); return respond; } } catch (Exception e) { // log.error("Jenkins Client err", e); } return null; }
From source file:jetbrains.buildServer.commitPublisher.github.api.impl.GitHubApiFactoryImpl.java
@NotNull public GitHubApi openGitHubForToken(@NotNull final String url, @NotNull final String token) { return new GitHubApiImpl(myWrapper, new GitHubApiPaths(url)) { @Override/*w w w . j a va 2 s .co m*/ protected void setAuthentication(@NotNull HttpRequest request) throws AuthenticationException { //NOTE: This auth could also be done via HTTP header request.addHeader(new BasicScheme() .authenticate(new UsernamePasswordCredentials(token, "x-oauth-basic"), request)); } }; }
From source file:com.github.restdriver.clientdriver.integration.BasicAuthTest.java
@Test public void basicAuthWorks() throws Exception { clientDriver.addExpectation(onRequestTo("/").withBasicAuth("Aladdin", "open sesame"), giveEmptyResponse().withStatus(418)).anyTimes(); DefaultHttpClient client = new DefaultHttpClient(); client.getCredentialsProvider().setCredentials(new AuthScope("localhost", AuthScope.ANY_PORT), new UsernamePasswordCredentials("Aladdin", "open sesame")); HttpHost host = new HttpHost("localhost", 12345); AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); authCache.put(host, basicAuth);/*from w w w . j av a 2 s.com*/ BasicHttpContext context = new BasicHttpContext(); context.setAttribute(ClientContext.AUTH_CACHE, authCache); List<String> authPrefs = new ArrayList<String>(); authPrefs.add(AuthPolicy.BASIC); client.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authPrefs); HttpGet get = new HttpGet(clientDriver.getBaseUrl() + "/"); HttpResponse response = client.execute(host, get, context); assertThat(response.getStatusLine().getStatusCode(), is(418)); }