List of usage examples for org.apache.commons.httpclient.auth AuthScope ANY_PORT
int ANY_PORT
To view the source code for org.apache.commons.httpclient.auth AuthScope ANY_PORT.
Click Source Link
From source file:com.twinsoft.convertigo.engine.HttpStateEvent.java
private Credentials getCredentials() { Credentials credentials = null;/*w w w . j a v a2 s .c o m*/ if (httpState != null) { if (host != null) { AuthScope authScope = new AuthScope(host, AuthScope.ANY_PORT, realm, AuthScope.ANY_SCHEME); credentials = httpState.getCredentials(authScope); } } return credentials; }
From source file:fedora.client.Downloader.java
/** * Construct a downloader for a certain repository as a certain user. */// ww w .ja va 2 s . c om public Downloader(String host, int port, String context, String user, String pass) throws IOException { m_fedoraUrlStart = Administrator.getProtocol() + "://" + host + ":" + port + "/" + context + "/" + "get/"; m_authScope = new AuthScope(host, AuthScope.ANY_PORT, AuthScope.ANY_REALM); m_creds = new UsernamePasswordCredentials(user, pass); }
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 www. j a va 2s . com 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.twinsoft.convertigo.engine.enums.AuthenticationMode.java
public boolean setCredentials(HttpState httpState, String user, String password, String host, String domain) { if (httpState == null) return false; if (host == null) return false; AuthScope authScope = new AuthScope(host, AuthScope.ANY_PORT, AuthScope.ANY_REALM); Credentials credentials = null;/* w ww. j av a2 s. co m*/ int type = getType(); try { switch (type) { case 0: // Anonymous credentials = ac; break; case 1: // Basic credentials = new UsernamePasswordCredentials(user, password); break; case 2: // NTLM credentials = new NTCredentials(user, password, host, domain); break; default: // None case -1: break; } Credentials curCred = httpState.getCredentials(authScope); int needChange = compare(curCred, credentials); switch (needChange) { case -1: httpState.setCredentials(authScope, null); Engine.logEngine.debug("(AuthenticationMode) credentials cleared"); break; case 1: httpState.setCredentials(authScope, credentials); Engine.logEngine.debug("(AuthenticationMode) " + name() + " credentials: " + user + ": ******"); break; case 0: Engine.logEngine.debug("(AuthenticationMode) reusing credentials"); break; } return needChange != 0; } catch (Exception e) { Engine.logEngine.error("Unable to set " + name() + " credentials for user", e); return false; } }
From source file:com.mindquarry.common.index.SolrIndexClient.java
/** * Used to initialize the HTTP client./*from w ww. java2s. c o m*/ */ 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 and port is allowed. * //ww w . j a va2s . co m * @param host * @param username * @param password */ public Credential(String host, String username, String password) { this(host, AuthScope.ANY_PORT, username, password); }
From source file:com.antelink.sourcesquare.query.RestClient.java
protected RestTemplate getTemplate(String baseDomain) { HttpClient client = new HttpClient(); // Managing HTTP proxy - if any String proxyHost = System.getProperty("http.proxyHost"); String proxyPort = System.getProperty("http.proxyPort"); if (proxyHost != null && proxyPort != null) { client.getHostConfiguration().setProxy(proxyHost, Integer.parseInt(proxyPort)); }/* w w w .j ava 2 s . c o m*/ // Managing HTTP proxy authentication - if any String proxyUser = System.getProperty("http.proxyUser"); String proxyPassword = System.getProperty("http.proxyPassword"); AuthScope auth; if (proxyHost != null && proxyUser != null && proxyPassword != null) { auth = new AuthScope(proxyHost, Integer.parseInt(proxyPort)); client.getState().setProxyCredentials(auth, new UsernamePasswordCredentials(proxyUser, proxyPassword)); } else { auth = new AuthScope(baseDomain, AuthScope.ANY_PORT); client.getState().setCredentials(auth, null); } CommonsClientHttpRequestFactory commons = new CommonsClientHttpRequestFactory(client) { @Override public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException { ClientHttpRequest createRequest = super.createRequest(uri, httpMethod); createRequest.getHeaders().add("User-Agent", "SourceSquare"); return createRequest; } }; return new RestTemplate(commons); }
From source file:hr.fer.zemris.vhdllab.platform.remoting.HttpClientRequestExecutor.java
@SuppressWarnings("null") @Override//from w w w.jav a 2 s . c o m protected void executePostMethod(HttpInvokerClientConfiguration config, HttpClient httpClient, PostMethod postMethod) throws IOException { AuthScope scope = new AuthScope(config.getCodebaseUrl(), AuthScope.ANY_PORT); super.executePostMethod(config, httpClient, postMethod); switch (postMethod.getStatusCode()) { case HttpStatus.SC_UNAUTHORIZED: UsernamePasswordCredentials credentials; if (Environment.isDevelopment() && !showRetryMessage) { credentials = new UsernamePasswordCredentials("test", "test"); // credentials = new UsernamePasswordCredentials("admin", "admin"); showRetryMessage = true; } else { CommandManager manager = Application.instance().getActiveWindow().getCommandManager(); LoginCommand command = (LoginCommand) manager.getCommand("loginCommand"); command.execute(); credentials = command.getCredentials(); } if (credentials == null) { System.exit(1); } ApplicationContextHolder.getContext().setUserId(credentials.getUserName()); showRetryMessage = true; getHttpClient().getState().setCredentials(scope, credentials); executePostMethod(config, httpClient, postMethod); break; } }
From source file:edu.du.penrose.systems.fedora.client.Downloader.java
/** * @param administrator We use this instead of accessing fedora.client.Administator * (see class notes)/* ww w.j ava2s . com*/ * * @param host * @param port * @param user * @param pass * @throws IOException */ public Downloader(Administrator administrator, String host, int port, String user, String pass) throws IOException { myAdministrator = administrator; m_fedoraUrlStart = myAdministrator.getProtocol() + "://" + host + ":" + port + "/fedora/get/"; m_authScope = new AuthScope(host, AuthScope.ANY_PORT, AuthScope.ANY_REALM); m_creds = new UsernamePasswordCredentials(user, pass); }
From source file:fedora.common.http.WebClient.java
public HttpClient getHttpClient(String hostOrURL, UsernamePasswordCredentials creds) throws IOException { String host = null;//from ww w .j a va2 s .c om if (hostOrURL != null) { if (hostOrURL.indexOf("/") != -1) { URL url = new URL(hostOrURL); host = url.getHost(); } else { host = hostOrURL; } } HttpClient client = new HttpClient(m_cManager); if (host != null && creds != null) { client.getState().setCredentials(new AuthScope(host, AuthScope.ANY_PORT), creds); client.getParams().setAuthenticationPreemptive(true); } if (proxy.isHostProxyable(host)) { client.getHostConfiguration().setProxy(proxy.getProxyHost(), proxy.getProxyPort()); if (proxy.hasValidCredentials()) { client.getState().setProxyCredentials( new AuthScope(proxy.getProxyHost(), proxy.getProxyPort(), null), new UsernamePasswordCredentials(proxy.getProxyUser(), proxy.getProxyPassword())); } } return client; }