List of usage examples for org.apache.commons.httpclient.auth AuthScope ANY_HOST
String ANY_HOST
To view the source code for org.apache.commons.httpclient.auth AuthScope ANY_HOST.
Click Source Link
From source file:it.drwolf.ridire.utility.test.SSLConnectionTest.java
public SSLConnectionTest() { Protocol.registerProtocol("https", new Protocol("https", new EasySSLProtocolSocketFactory(), 8443)); this.httpClient = new HttpClient(); // this.httpClient.getParams().setAuthenticationPreemptive(true); Credentials defaultcreds = new UsernamePasswordCredentials("admin", "admin"); this.httpClient.getState().setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM), defaultcreds); PostMethod method = new PostMethod("https://localhost:8443/engine"); method.addParameter(new NameValuePair("action", "rescan")); try {/*from w w w . jav a2 s .co m*/ int status = this.httpClient.executeMethod(method); Header redirectLocation = method.getResponseHeader("location"); String loc = redirectLocation.getValue(); GetMethod getmethod = new GetMethod("https://localhost:8443/engine"); status = this.httpClient.executeMethod(getmethod); System.out.println(status); } catch (HttpException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { method.releaseConnection(); } }
From source file:com.mindquarry.common.index.SolrIndexClient.java
/** * Used to initialize the HTTP client.//from w w w . j av a 2 s.c om */ public void initialize() throws Exception { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); httpClient = new HttpClient(connectionManager); // enable Preemptive authentication to save one round trip httpClient.getParams().setAuthenticationPreemptive(true); Credentials solrCreds = new UsernamePasswordCredentials(solrLogin, solrPassword); AuthScope anyAuthScope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM); httpClient.getState().setCredentials(anyAuthScope, solrCreds); // register events by calling base class initialization super.initialize(); }
From source file:be.fedict.trust.Credential.java
/** * Any scheme, realm, port and host is allowed. * //from w ww. j a v a 2s . c o m * @param username * @param password */ public Credential(String username, String password) { this(AuthScope.ANY_HOST, username, password); }
From source file:com.lp.client.frame.component.phone.HttpPhoneDialerAuth.java
@Override protected void prepareClient(HttpClient client, GetMethod method) { super.prepareClient(client, method); if (authUser != null && authPassword != null) { client.getState().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), // new UsernamePasswordCredentials("admin", "0000")) ; new UsernamePasswordCredentials(authUser, authPassword)); method.setDoAuthentication(true); }/* w w w. ja va 2 s . co m*/ }
From source file:com.gargoylesoftware.htmlunit.DefaultCredentialsProvider.java
/** * Adds credentials for the specified username/password for any host/port/realm combination. * The credentials may be for any authentication scheme, including NTLM, digest and basic * HTTP authentication. If you are using sensitive username/password information, please do * NOT use this method. If you add credentials using this method, any server that requires * authentication may receive the specified username and password. * @param username the username for the new credentials * @param password the password for the new credentials *//*from w ww. j a v a2 s . c o m*/ public void addCredentials(final String username, final String password) { addCredentials(username, password, AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM); }
From source file:com.gargoylesoftware.htmlunit.DefaultCredentialsProvider.java
/** * Adds proxy credentials for the specified username/password for any host/port/realm combination. * @param username the username for the new credentials * @param password the password for the new credentials *//*from ww w . ja va2 s. com*/ public void addProxyCredentials(final String username, final String password) { addProxyCredentials(username, password, AuthScope.ANY_HOST, AuthScope.ANY_PORT); }
From source file:com.marvelution.hudson.plugins.apiv2.client.connectors.HttpClient3Connector.java
/** * Get the {@link AuthScope} for the {@link #server} * //from ww w . j a v a 2 s .c o m * @return the {@link AuthScope} */ private AuthScope getAuthScope() { String host = AuthScope.ANY_HOST; int port = AuthScope.ANY_PORT; try { final URI hostUri = new URI(server.getHost()); host = hostUri.getHost(); if (hostUri.getPort() > -1) { port = hostUri.getPort(); } else if ("http".equalsIgnoreCase(hostUri.getScheme())) { port = 80; } else if ("https".equalsIgnoreCase(hostUri.getScheme())) { port = 443; } } catch (URISyntaxException e) { // Failed to parse the server host URI // Fall-back on preset defaults log.error("Failed to parse the host URI", e); } return new AuthScope(host, port, "realm"); }
From source file:com.mirth.connect.connectors.http.HttpMessageDispatcher.java
private void submitHttpRequest(String address, MessageObject mo) throws Exception { HttpMethod httpMethod = null;/* w ww .j av a2 s. c om*/ try { httpMethod = buildHttpRequest(replacer.replaceValues(address, mo), mo); // authentication if (connector.isDispatcherUseAuthentication()) { List<String> authenticationPreferences = new ArrayList<String>(); if ("Digest".equalsIgnoreCase(connector.getDispatcherAuthenticationType())) { authenticationPreferences.add(AuthPolicy.DIGEST); logger.debug("using Digest authentication"); } else { authenticationPreferences.add(AuthPolicy.BASIC); logger.debug("using Basic authentication"); } client.getParams().setAuthenticationPreemptive(true); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authenticationPreferences); Credentials credentials = new UsernamePasswordCredentials( replacer.replaceValues(connector.getDispatcherUsername(), mo), replacer.replaceValues(connector.getDispatcherPassword(), mo)); client.getState().setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM), credentials); logger.debug("using authentication with credentials: " + credentials); } client.getParams().setSoTimeout( NumberUtils.toInt(replacer.replaceValues(connector.getDispatcherSocketTimeout()), 30000)); // execute the method logger.debug( "executing method: type=" + httpMethod.getName() + ", uri=" + httpMethod.getURI().toString()); int statusCode = client.executeMethod(httpMethod); logger.debug("received status code: " + statusCode); String response = null; if (connector.isDispatcherIncludeHeadersInResponse()) { HttpMessageConverter converter = new HttpMessageConverter(); response = converter.httpResponseToXml(httpMethod.getStatusLine().toString(), httpMethod.getResponseHeaders(), httpMethod.getResponseBodyAsString()); } else { response = httpMethod.getResponseBodyAsString(); } if (statusCode < HttpStatus.SC_BAD_REQUEST) { messageObjectController.setSuccess(mo, response, null); // send to reply channel if ((connector.getDispatcherReplyChannelId() != null) && !connector.getDispatcherReplyChannelId().equals("sink")) { new VMRouter().routeMessageByChannelId(connector.getDispatcherReplyChannelId(), response, true); } } else { alertController.sendAlerts(connector.getChannelId(), Constants.ERROR_404, "Received error response from HTTP server.", null); messageObjectController.setError(mo, Constants.ERROR_404, response, null, null); } } catch (Exception e) { throw e; } finally { if (httpMethod != null) { httpMethod.releaseConnection(); } } }
From source file:com.hp.alm.ali.rest.client.AliRestClient.java
@Override public void setHttpProxyCredentials(String username, String password) { Credentials cred = new UsernamePasswordCredentials(username, password); AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT); httpClient.getState().setProxyCredentials(scope, cred); }
From source file:com.intuit.tank.httpclient3.TankHttpClient3.java
@Override public void addAuth(AuthCredentials creds) { String host = (StringUtils.isBlank(creds.getHost()) || "*".equals(creds.getHost())) ? AuthScope.ANY_HOST : creds.getHost();//from w ww.ja v a2 s .c o m String realm = (StringUtils.isBlank(creds.getRealm()) || "*".equals(creds.getRealm())) ? AuthScope.ANY_REALM : creds.getRealm(); int port = NumberUtils.toInt(creds.getPortString(), AuthScope.ANY_PORT); String scheme = creds.getScheme() != null ? creds.getScheme().getRepresentation() : AuthScope.ANY_SCHEME; Credentials defaultcreds = new UsernamePasswordCredentials(creds.getUserName(), creds.getPassword()); httpclient.getState().setCredentials(new AuthScope(host, port, realm, scheme), defaultcreds); }