List of usage examples for org.apache.http.auth AuthScope ANY
AuthScope ANY
To view the source code for org.apache.http.auth AuthScope ANY.
Click Source Link
From source file:com.sonymobile.tools.gerrit.gerritevents.workers.rest.AbstractRestCommandJob2.java
@Override public String call() throws IOException { String response = ""; ReviewInput reviewInput = createReview(); String reviewEndpoint = resolveEndpointURL(); HttpPost httpPost = createHttpPostEntity(reviewInput, reviewEndpoint); if (httpPost == null) { return response; }/*w w w . ja v a 2 s. c o m*/ CredentialsProvider credProvider = new BasicCredentialsProvider(); credProvider.setCredentials(AuthScope.ANY, credentials); HttpHost proxy = null; if (httpProxy != null && !httpProxy.isEmpty()) { try { URL url = new URL(httpProxy); proxy = new HttpHost(url.getHost(), url.getPort(), url.getProtocol()); } catch (MalformedURLException e) { logger.error("Could not parse proxy URL, attempting without proxy.", e); if (altLogger != null) { altLogger.print("ERROR Could not parse proxy URL, attempting without proxy. " + e.getMessage()); } } } HttpClientBuilder builder = HttpClients.custom(); builder.setDefaultCredentialsProvider(credProvider); if (proxy != null) { builder.setProxy(proxy); } CloseableHttpClient httpClient = builder.build(); try { CloseableHttpResponse httpResponse = httpClient.execute(httpPost); response = IOUtils.toString(httpResponse.getEntity().getContent(), "UTF-8"); if (httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { logger.error("Gerrit response: {}", httpResponse.getStatusLine().getReasonPhrase()); if (altLogger != null) { altLogger.print("ERROR Gerrit response: " + httpResponse.getStatusLine().getReasonPhrase()); } } } catch (Exception e) { logger.error("Failed to submit result to Gerrit", e); if (altLogger != null) { altLogger.print("ERROR Failed to submit result to Gerrit" + e.toString()); } } return response; }
From source file:com.granita.icloudcalsync.webdav.WebDavResource.java
public WebDavResource(CloseableHttpClient httpClient, URI baseURI, String username, String password, boolean preemptive) { this(httpClient, baseURI); context.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); if (preemptive) { HttpHost host = new HttpHost(baseURI.getHost(), baseURI.getPort(), baseURI.getScheme()); Log.d(TAG, "Using preemptive authentication (not compatible with Digest auth)"); AuthCache authCache = context.getAuthCache(); if (authCache == null) authCache = new BasicAuthCache(); authCache.put(host, new BasicSchemeHC4()); context.setAuthCache(authCache); }/*from w w w . j ava 2s.c o m*/ }
From source file:org.muhia.app.psi.integ.config.ke.crba.CreditReferenceBureauAuthorityClientConfiguration.java
@Bean(name = "transunionHttpClient") public CloseableHttpClient httpClient() { RequestConfig config = RequestConfig.custom() .setConnectTimeout(properties.getCrbaTransportConnectionTimeout()) .setConnectionRequestTimeout(properties.getCrbaTransportConnectionRequestTimeout()) .setSocketTimeout(properties.getCrbaTransportReadTimeout()).build(); CredentialsProvider provider = new BasicCredentialsProvider(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials( properties.getCrbaTransunionTransportUsername(), properties.getCrbaTransunionTransportPassword()); provider.setCredentials(AuthScope.ANY, credentials); PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(); connManager.setMaxTotal(properties.getCrbaPoolMaxHost()); connManager.setDefaultMaxPerRoute(properties.getCrbaPoolDefaultmaxPerhost()); connManager.setValidateAfterInactivity(properties.getCrbaPoolValidateAfterInactivity()); return HttpClientBuilder.create().setDefaultRequestConfig(config).setDefaultCredentialsProvider(provider) .setConnectionManager(connManager).evictExpiredConnections() .addInterceptorFirst(new RemoveHttpHeadersInterceptor()).build(); }
From source file:es.ujaen.dae.restClient.controllers.SessionBackingBean.java
public String login() { DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user.getName(), user.getPassword())); ClientHttpRequestFactory rf = new HttpComponentsClientHttpRequestFactory(httpClient); template = new RestTemplate(rf); try {// w w w .j a v a 2 s . c om template.getForObject(URL + "users/loginTest", String.class); loggedIn = true; return "userMenu?faces-redirect=true"; } catch (HttpClientErrorException e) { loggedIn = false; user.setPassword(""); return "loginError?faces-redirect=true"; } }
From source file:org.tinymediamanager.scraper.util.TmmHttpClient.java
private static void setProxy(HttpClientBuilder httpClientBuilder) { HttpHost proxyHost = null;//from w ww . ja v a 2 s .com if (StringUtils.isNotEmpty(Globals.settings.getProxyPort())) { proxyHost = new HttpHost(Globals.settings.getProxyHost(), Integer.parseInt(Globals.settings.getProxyPort())); } else { proxyHost = new HttpHost(Globals.settings.getProxyHost()); } // authenticate if (!StringUtils.isEmpty(Globals.settings.getProxyUsername()) && !StringUtils.isEmpty(Globals.settings.getProxyPassword())) { CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); if (Globals.settings.getProxyUsername().contains("\\")) { // use NTLM int offset = Globals.settings.getProxyUsername().indexOf("\\"); String domain = Globals.settings.getProxyUsername().substring(0, offset); String username = Globals.settings.getProxyUsername().substring(offset + 1, Globals.settings.getProxyUsername().length()); credentialsProvider.setCredentials(AuthScope.ANY, new NTCredentials(username, Globals.settings.getProxyPassword(), "", domain)); } else { credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials( Globals.settings.getProxyUsername(), Globals.settings.getProxyPassword())); } httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); } // set proxy DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxyHost); httpClientBuilder.setRoutePlanner(routePlanner); // try to get proxy settings from JRE - is probably added in HttpClient 4.3; fixed with 4.3.3 // (https://issues.apache.org/jira/browse/HTTPCLIENT-1457) // SystemDefaultCredentialsProvider credentialsProvider = new SystemDefaultCredentialsProvider(); // httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); // SystemDefaultRoutePlanner routePlanner = new SystemDefaultRoutePlanner(ProxySelector.getDefault()); // httpClientBuilder.setRoutePlanner(routePlanner); }
From source file:com.codebutler.rsp.Playlist.java
public void fetchItems(final FetchItemsProgressListener progressListener) throws Exception { if (mItems != null) throw new Exception("fetchItems() already called!"); mItems = new SortedArrayList<Item>(new Comparator<Item>() { public int compare(Item first, Item second) { return first.getTitle().compareToIgnoreCase(second.getTitle()); }//from w w w . jav a2 s .c om }); mOrderedArtists = new SortedArrayList<Artist>(new Comparator<Artist>() { public int compare(Artist first, Artist second) { return first.getName().compareToIgnoreCase(second.getName()); } }); mArtists = new HashMap<String, Artist>(); mAlbums = new SortedArrayList<Album>(new Comparator<Album>() { public int compare(Album first, Album second) { return first.getName().compareToIgnoreCase(second.getName()); } }); URL url = mServer.buildUrl("db/" + Integer.toString(mId)); Log.d("FetchItems", url.toString()); DefaultHttpClient client = new DefaultHttpClient(); String password = mServer.getPassword(); if (password != null && password.length() > 0) { UsernamePasswordCredentials creds; creds = new UsernamePasswordCredentials("user", password); client.getCredentialsProvider().setCredentials(AuthScope.ANY, creds); } HttpGet method = new HttpGet(url.toURI()); InputStream stream = client.execute(method).getEntity().getContent(); try { /* <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <response> <status> <errorcode>0</errorcode> <errorstring></errorstring> <records>0</records> <totalrecords>1</totalrecords> </status> <items> <item> <id>1</id> <title>Rock Robotic (Osx Mix)</title> <artist>Oscillator X</artist> <album>Techno * Techyes</album> <genre>Dance & DJ</genre> <type>mp3</type> <bitrate>192</bitrate> <samplerate>44100</samplerate> <song_length>61440</song_length> <file_size>1474560</file_size> <year>0</year> <track>15</track> <total_tracks>0</total_tracks> <disc>0</disc> <total_discs>0</total_discs> <bpm>0</bpm> <compilation>0</compilation> <rating>0</rating> <play_count>4</play_count> <description>MPEG audio file</description> <time_added>1270096204</time_added> <time_modified>1270078936</time_modified> <time_played>1270156178</time_played> <disabled>0</disabled> <codectype>mpeg</codectype> </item> </items> </response> */ RootElement rootElement = new RootElement("response"); Element itemsElement = rootElement.getChild("items"); Element itemElement = itemsElement.getChild("item"); Element idElement = itemElement.getChild("id"); Element titleElement = itemElement.getChild("title"); Element artistElement = itemElement.getChild("artist"); Element albumElement = itemElement.getChild("album"); Element lengthElement = itemElement.getChild("song_length"); itemElement.setElementListener(new ElementListener() { public void start(Attributes arg0) { mCurrentItem = new Item(Playlist.this); } public void end() { mItems.add(mCurrentItem); // Artist cache String artistName = mCurrentItem.getArtist(); if (artistName != null && artistName.trim().length() > 0) { Artist artist = mArtists.get(artistName); if (artist == null) { artist = new Artist(artistName); mArtists.put(artistName, artist); mOrderedArtists.add(artist); } // Album cache // FIXME: This should support compilation albums! String albumName = mCurrentItem.getAlbum(); if (albumName != null && albumName.trim().length() > 0) { Album album = artist.getAlbum(albumName); if (album == null) { album = new Album(artist, albumName); artist.addAlbum(album); mAlbums.add(album); } album.addItem(mCurrentItem); } } mCurrentItem = null; if (progressListener != null) { if ((mItems.size() % 100) == 0) progressListener.onProgressChange(mItems.size()); } } }); idElement.setEndTextElementListener(new EndTextElementListener() { public void end(String body) { mCurrentItem.setId(Integer.parseInt(body)); } }); titleElement.setEndTextElementListener(new EndTextElementListener() { public void end(String body) { mCurrentItem.setTitle(body); } }); artistElement.setEndTextElementListener(new EndTextElementListener() { public void end(String body) { mCurrentItem.setArtist(body); } }); albumElement.setEndTextElementListener(new EndTextElementListener() { public void end(String body) { mCurrentItem.setAlbum(body); } }); lengthElement.setEndTextElementListener(new EndTextElementListener() { public void end(String body) { mCurrentItem.setDuration(Long.parseLong(body) / 1000); } }); android.util.Xml.parse(stream, Xml.Encoding.UTF_8, rootElement.getContentHandler()); } finally { stream.close(); } }
From source file:org.springframework.xd.shell.command.ConfigCommands.java
@CliCommand(value = { "admin config server" }, help = "Configure the XD admin server to use") public String target(@CliOption(mandatory = false, key = { "", "uri" }, help = "the location of the XD Admin REST endpoint", unspecifiedDefaultValue = Target.DEFAULT_TARGET) String targetUriString, @CliOption(mandatory = false, key = { "username" }, help = "the username for authenticated access to the Admin REST endpoint", unspecifiedDefaultValue = Target.DEFAULT_USERNAME) String targetUsername, @CliOption(mandatory = false, key = { "password" }, help = "the password for authenticated access to the Admin REST endpoint (valid only with a username)", specifiedDefaultValue = Target.DEFAULT_SPECIFIED_PASSWORD, unspecifiedDefaultValue = Target.DEFAULT_UNSPECIFIED_PASSWORD) String targetPassword) { try {// www. jav a 2 s.com if (!StringUtils.isEmpty(targetPassword) && StringUtils.isEmpty(targetUsername)) { return "A password may be specified only together with a username"; } if (Target.DEFAULT_SPECIFIED_PASSWORD.equalsIgnoreCase(targetPassword) && !StringUtils.isEmpty(targetUsername)) { // read password from the command line targetPassword = userInput.prompt("Password", "", false); } configuration.setTarget(new Target(targetUriString, targetUsername, targetPassword)); if (configuration.getTarget().getTargetCredentials() != null) { BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials( configuration.getTarget().getTargetCredentials().getUsername(), configuration.getTarget().getTargetCredentials().getPassword())); CloseableHttpClient httpClient = HttpClientBuilder.create() .setDefaultCredentialsProvider(credentialsProvider).build(); HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory( httpClient); this.xdShell.setSpringXDOperations( new SpringXDTemplate(requestFactory, configuration.getTarget().getTargetUri())); } else { this.xdShell.setSpringXDOperations(new SpringXDTemplate(configuration.getTarget().getTargetUri())); } configuration.getTarget().setTargetResultMessage( String.format("Successfully targeted %s", configuration.getTarget().getTargetUri())); } catch (Exception e) { configuration.getTarget().setTargetException(e); this.xdShell.setSpringXDOperations(null); configuration.getTarget().setTargetResultMessage( String.format("Unable to contact XD Admin Server at '%s'.", targetUriString)); if (logger.isTraceEnabled()) { logger.trace(configuration.getTarget().getTargetResultMessage(), e); } } return configuration.getTarget().getTargetResultMessage(); }
From source file:com.example.dailyphoto.oath.EasyHttpClient.java
public EasyHttpClient(String username, String password) { if (username != null && password != null) { UsernamePasswordCredentials c = new UsernamePasswordCredentials(username, password); BasicCredentialsProvider cP = new BasicCredentialsProvider(); cP.setCredentials(AuthScope.ANY, c); setCredentialsProvider(cP);//from w w w. j a v a2s . co m } }
From source file:neembuu.vfs.test.FileNameAndSizeFinderService.java
private DefaultHttpClient newClient() { DefaultHttpClient client = new DefaultHttpClient(); GlobalTestSettings.ProxySettings proxySettings = GlobalTestSettings.getGlobalProxySettings(); HttpContext context = new BasicHttpContext(); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", new PlainSocketFactory(), 80)); try {//from w w w. j av a 2 s . c o m KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); schemeRegistry.register(new Scheme("https", new SSLSocketFactory(keyStore), 8080)); } catch (Exception a) { a.printStackTrace(System.err); } context.setAttribute(ClientContext.SCHEME_REGISTRY, schemeRegistry); context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, new BasicScheme()/*file.httpClient.getAuthSchemes()*/); context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, client.getCookieSpecs()/*file.httpClient.getCookieSpecs()*/ ); BasicCookieStore basicCookieStore = new BasicCookieStore(); context.setAttribute(ClientContext.COOKIE_STORE, basicCookieStore/*file.httpClient.getCookieStore()*/); context.setAttribute(ClientContext.CREDS_PROVIDER, new BasicCredentialsProvider()/*file.httpClient.getCredentialsProvider()*/); HttpConnection hc = new DefaultHttpClientConnection(); context.setAttribute(ExecutionContext.HTTP_CONNECTION, hc); //System.out.println(file.httpClient.getParams().getParameter("http.useragent")); HttpParams httpParams = new BasicHttpParams(); if (proxySettings != null) { AuthState as = new AuthState(); as.setCredentials(new UsernamePasswordCredentials(proxySettings.userName, proxySettings.password)); as.setAuthScope(AuthScope.ANY); as.setAuthScheme(new BasicScheme()); httpParams.setParameter(ClientContext.PROXY_AUTH_STATE, as); httpParams.setParameter("http.proxy_host", new HttpHost(proxySettings.host, proxySettings.port)); } client = new DefaultHttpClient( new SingleClientConnManager(httpParams/*file.httpClient.getParams()*/, schemeRegistry), httpParams/*file.httpClient.getParams()*/); if (proxySettings != null) { client.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(proxySettings.userName, proxySettings.password)); } return client; }
From source file:com.cloud.network.brocade.BrocadeVcsApi.java
public BrocadeVcsApi(String address, String username, String password) { _host = address;// w w w . j a v a 2s.co m _adminuser = username; _adminpass = password; _client = new DefaultHttpClient(); _client.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(_adminuser, _adminpass)); }