本文整理了Java中org.apache.commons.httpclient.auth.AuthScope.<init>()
方法的一些代码示例,展示了AuthScope.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AuthScope.<init>()
方法的具体详情如下:
包路径:org.apache.commons.httpclient.auth.AuthScope
类名称:AuthScope
方法名:<init>
[英]Creates a new credentials scope for the given host, port, any realm name, and any authentication scheme.
[中]为给定主机、端口、任何领域名称和任何身份验证方案创建新的凭据范围。
代码示例来源:origin: commons-httpclient/commons-httpclient
/**
* Sets the {@link Credentials credentials} for the given authentication
* realm on the given host. The <code>null</code> realm signifies default
* credentials for the given host, which should be used when no
* {@link Credentials credentials} have been explictly supplied for the
* challenging realm. The <code>null</code> host signifies default
* credentials, which should be used when no {@link Credentials credentials}
* have been explictly supplied for the challenging host. Any previous
* credentials for the given realm on the given host will be overwritten.
*
* @param realm the authentication realm
* @param host the host the realm belongs to
* @param credentials the authentication {@link Credentials credentials}
* for the given realm.
*
* @see #getCredentials(String, String)
* @see #setProxyCredentials(String, String, Credentials)
*
* @deprecated use #setCredentials(AuthScope, Credentials)
*/
public synchronized void setCredentials(String realm, String host, Credentials credentials) {
LOG.trace("enter HttpState.setCredentials(String, String, Credentials)");
credMap.put(new AuthScope(host, AuthScope.ANY_PORT, realm, AuthScope.ANY_SCHEME), credentials);
}
代码示例来源:origin: commons-httpclient/commons-httpclient
/**
* Sets the {@link Credentials credentials} for the given proxy authentication
* realm on the given proxy host. The <code>null</code> proxy realm signifies
* default credentials for the given proxy host, which should be used when no
* {@link Credentials credentials} have been explictly supplied for the
* challenging proxy realm. The <code>null</code> proxy host signifies default
* credentials, which should be used when no {@link Credentials credentials}
* have been explictly supplied for the challenging proxy host. Any previous
* credentials for the given proxy realm on the given proxy host will be
* overwritten.
*
* @param realm the authentication realm
* @param proxyHost the proxy host
* @param credentials the authentication credentials for the given realm
*
* @see #getProxyCredentials(AuthScope)
* @see #setCredentials(AuthScope, Credentials)
*
* @deprecated use #setProxyCredentials(AuthScope, Credentials)
*/
public synchronized void setProxyCredentials(
String realm,
String proxyHost,
Credentials credentials
) {
LOG.trace("enter HttpState.setProxyCredentials(String, String, Credentials");
proxyCred.put(new AuthScope(proxyHost, AuthScope.ANY_PORT, realm, AuthScope.ANY_SCHEME), credentials);
}
代码示例来源:origin: commons-httpclient/commons-httpclient
/**
* Get the {@link Credentials credentials} for the proxy host with the given
* authentication scope.
*
* If the <i>realm</i> exists on <i>host</i>, return the coresponding credentials.
* If the <i>host</i> exists with a <tt>null</tt> <i>realm</i>, return the corresponding
* credentials.
* If the <i>realm</i> exists with a <tt>null</tt> <i>host</i>, return the
* corresponding credentials. If the <i>realm</i> does not exist, return
* the default Credentials. If there are no default credentials, return
* <code>null</code>.
*
* @param realm the authentication realm
* @param proxyHost the proxy host the realm is on
* @return the credentials
* @see #setProxyCredentials(String, String, Credentials)
*
* @deprecated use #getProxyCredentials(AuthScope)
*/
public synchronized Credentials getProxyCredentials(String realm, String proxyHost) {
LOG.trace("enter HttpState.getCredentials(String, String");
return matchCredentials(this.proxyCred,
new AuthScope(proxyHost, AuthScope.ANY_PORT, realm, AuthScope.ANY_SCHEME));
}
代码示例来源:origin: commons-httpclient/commons-httpclient
/**
* Get the {@link Credentials credentials} for the given authentication scope on the
* given host.
*
* If the <i>realm</i> exists on <i>host</i>, return the coresponding credentials.
* If the <i>host</i> exists with a <tt>null</tt> <i>realm</i>, return the corresponding
* credentials.
* If the <i>realm</i> exists with a <tt>null</tt> <i>host</i>, return the
* corresponding credentials. If the <i>realm</i> does not exist, return
* the default Credentials. If there are no default credentials, return
* <code>null</code>.
*
* @param realm the authentication realm
* @param host the host the realm is on
* @return the credentials
*
* @see #setCredentials(String, String, Credentials)
*
* @deprecated use #getCredentials(AuthScope)
*/
public synchronized Credentials getCredentials(String realm, String host) {
LOG.trace("enter HttpState.getCredentials(String, String");
return matchCredentials(this.credMap,
new AuthScope(host, AuthScope.ANY_PORT, realm, AuthScope.ANY_SCHEME));
}
代码示例来源:origin: jenkinsci/jenkins
client.getHostConfiguration().setProxy(name, port);
Credentials credentials = createCredentials(userName, password);
AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT);
client.getState().setProxyCredentials(scope, credentials);
代码示例来源:origin: commons-httpclient/commons-httpclient
return false;
AuthScope authscope = new AuthScope(
conn.getProxyHost(), conn.getProxyPort(),
authscheme.getRealm(),
代码示例来源:origin: commons-httpclient/commons-httpclient
AuthScope authscope = new AuthScope(
host, port,
authscheme.getRealm(),
代码示例来源:origin: commons-httpclient/commons-httpclient
AuthScope authscope = new AuthScope(
conn.getProxyHost(), conn.getProxyPort(),
authscheme.getRealm(),
代码示例来源:origin: commons-httpclient/commons-httpclient
AuthScope authscope = new AuthScope(
host, port,
authscheme.getRealm(),
代码示例来源:origin: KylinOLAP/Kylin
private void init(String host, int port, String userName, String password) {
this.host = host;
this.port = port;
this.userName = userName;
this.password = password;
this.baseUrl = "http://" + host + ":" + port + "/kylin/api";
client = new HttpClient();
if (userName != null && password != null) {
client.getParams().setAuthenticationPreemptive(true);
Credentials creds = new UsernamePasswordCredentials(userName, password);
client.getState().setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM), creds);
}
}
代码示例来源:origin: apache/cloudstack
public static InputStream getInputStreamFromUrl(String url, String user, String password) {
try {
Pair<String, Integer> hostAndPort = validateUrl(url);
HttpClient httpclient = new HttpClient(new MultiThreadedHttpConnectionManager());
if ((user != null) && (password != null)) {
httpclient.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds = new UsernamePasswordCredentials(user, password);
httpclient.getState().setCredentials(new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM), defaultcreds);
s_logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second());
}
// Execute the method.
GetMethod method = new GetMethod(url);
int statusCode = httpclient.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
s_logger.error("Failed to read from URL: " + url);
return null;
}
return method.getResponseBodyAsStream();
} catch (Exception ex) {
s_logger.error("Failed to read from URL: " + url);
return null;
}
}
代码示例来源:origin: apache/cloudstack
private void checkCredentials(String user, String password) {
try {
Pair<String, Integer> hostAndPort = UriUtils.validateUrl(downloadUrl);
if ((user != null) && (password != null)) {
client.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds = new UsernamePasswordCredentials(user, password);
client.getState().setCredentials(new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM), defaultcreds);
s_logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second());
} else {
s_logger.info("No credentials configured for host=" + hostAndPort.first() + ":" + hostAndPort.second());
}
} catch (IllegalArgumentException iae) {
errorString = iae.getMessage();
status = TemplateDownloader.Status.UNRECOVERABLE_ERROR;
inited = false;
}
}
代码示例来源:origin: apache/cloudstack
/**
* @param username
* @param password
* @param httpClient
*/
public static void setCredentials(String username, String password, HttpClient httpClient) {
if (username != null && password != null && httpClient != null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Setting credentials with username " + username + " for host " + httpClient.getHostConfiguration().getHost() + ":" + httpClient.getHostConfiguration().getPort());
}
httpClient.getParams().setAuthenticationPreemptive(true);
httpClient.getState().setCredentials(
new AuthScope(httpClient.getHostConfiguration().getHost(), httpClient.getHostConfiguration().getPort(), AuthScope.ANY_REALM), new UsernamePasswordCredentials(username, password));
}
}
代码示例来源:origin: org.jvnet.hudson/htmlunit
private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException {
final String host = (String) stream.readObject();
final int port = stream.readInt();
final String realm = (String) stream.readObject();
final String scheme = (String) stream.readObject();
authScope_ = new AuthScope(host, port, realm, scheme);
}
}
代码示例来源:origin: com.github.bingoohuang/diamond-client
private void setBasicAuth(String host, int port) {
String basicAuth = ClientProperties.getBasicAuth();
if (Strings.isNullOrEmpty(basicAuth)) return;
List<String> splits = Splitter.on(':').trimResults().splitToList(basicAuth);
if (splits.size() < 2) return;
String userName = splits.get(0);
String passWord = splits.get(1);
httpClient.getParams().setAuthenticationPreemptive(true);
Credentials credentials = new UsernamePasswordCredentials(userName, passWord);
AuthScope authScope = new AuthScope(host, port, AuthScope.ANY_REALM);
httpClient.getState().setCredentials(authScope, credentials);
}
代码示例来源:origin: org.apache.abdera/abdera-client
/**
* Specify the auth credentials for the proxy server
*/
public AbderaClient setProxyCredentials(String host, int port, String realm, String scheme, Credentials credentials) {
host = host != null ? host : AuthScope.ANY_HOST;
port = port > -1 ? port : AuthScope.ANY_PORT;
AuthScope scope =
new AuthScope(host, port, realm != null ? realm : AuthScope.ANY_REALM, scheme != null ? scheme
: AuthScope.ANY_SCHEME);
client.getState().setProxyCredentials(scope, credentials);
return this;
}
代码示例来源:origin: org.tinygroup/httpvisit
public void setAlternateAuth(String host, int port, String username,
String password, List<String> schemaList) {
httpState.setCredentials(new AuthScope("www.verisign.com", 443),
new UsernamePasswordCredentials("username", "password"));
authEnabled = true;
client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY,
schemaList);
}
代码示例来源:origin: org.alfresco/alfresco-repository
public void init()
{
ParameterCheck.mandatory("baseUrl", baseUrl);
StringBuilder sb = new StringBuilder();
sb.append(baseUrl + "/admin/cores");
this.adminUrl = sb.toString();
httpClient = httpClientFactory.getHttpClient();
HttpClientParams params = httpClient.getParams();
params.setBooleanParameter(HttpClientParams.PREEMPTIVE_AUTHENTICATION, true);
httpClient.getState().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials("admin", "admin"));
}
代码示例来源:origin: io.hawt/hawtio-system
public HttpClient createHttpClient(HttpMethod httpMethodProxyRequest) {
HttpClient client = new HttpClient();
if (userName != null) {
//client.getParams().setAuthenticationPreemptive(true);
httpMethodProxyRequest.setDoAuthentication(true);
Credentials defaultcreds = new UsernamePasswordCredentials(userName, password);
client.getState().setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM), defaultcreds);
}
return client;
}
代码示例来源:origin: com.payneteasy.superfly/superfly-client-opt
protected void initCredentials() {
if (username != null && password != null) {
AuthScope authscope = new AuthScope(
getAuthHost() == null ? AuthScope.ANY_HOST : getAuthHost(),
AuthScope.ANY_PORT);
Credentials credentials = new UsernamePasswordCredentials(getUsername(), getPassword());
httpClient.getState().setCredentials(authscope, credentials);
}
}
内容来源于网络,如有侵权,请联系作者删除!