本文整理了Java中org.apache.commons.httpclient.auth.AuthScope
类的一些代码示例,展示了AuthScope
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AuthScope
类的具体详情如下:
包路径:org.apache.commons.httpclient.auth.AuthScope
类名称:AuthScope
[英]The class represents an authentication scope consisting of a host name, a port number, a realm name and an authentication scheme name which org.apache.commons.httpclient.Credentials apply to.
[中]该类表示一个身份验证作用域,该作用域由一个主机名、一个端口号、一个领域名和一个验证方案名组成,该组织使用该名称。阿帕奇。平民httpclient。凭据适用于。
代码示例来源: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: commons-httpclient/commons-httpclient
private Credentials promptForCredentials(
final AuthScheme authScheme,
final HttpParams params,
final AuthScope authscope)
{
LOG.debug("Credentials required");
Credentials creds = null;
CredentialsProvider credProvider =
(CredentialsProvider)params.getParameter(CredentialsProvider.PROVIDER);
if (credProvider != null) {
try {
creds = credProvider.getCredentials(
authScheme, authscope.getHost(), authscope.getPort(), false);
} catch (CredentialsNotAvailableException e) {
LOG.warn(e.getMessage());
}
if (creds != null) {
this.state.setCredentials(authscope, creds);
if (LOG.isDebugEnabled()) {
LOG.debug(authscope + " new credentials given");
}
}
} else {
LOG.debug("Credentials provider not available");
}
return creds;
}
代码示例来源:origin: commons-httpclient/commons-httpclient
/**
* Creates a copy of the given credentials scope.
*
* @since 3.0
*/
public AuthScope(final AuthScope authscope) {
super();
if (authscope == null) {
throw new IllegalArgumentException("Scope may not be null");
}
this.host = authscope.getHost();
this.port = authscope.getPort();
this.realm = authscope.getRealm();
this.scheme = authscope.getScheme();
}
代码示例来源:origin: commons-httpclient/commons-httpclient
private Credentials promptForProxyCredentials(
final AuthScheme authScheme,
final HttpParams params,
final AuthScope authscope)
{
LOG.debug("Proxy credentials required");
Credentials creds = null;
CredentialsProvider credProvider =
(CredentialsProvider)params.getParameter(CredentialsProvider.PROVIDER);
if (credProvider != null) {
try {
creds = credProvider.getCredentials(
authScheme, authscope.getHost(), authscope.getPort(), true);
} catch (CredentialsNotAvailableException e) {
LOG.warn(e.getMessage());
}
if (creds != null) {
this.state.setProxyCredentials(authscope, creds);
if (LOG.isDebugEnabled()) {
LOG.debug(authscope + " new credentials given");
}
}
} else {
LOG.debug("Proxy credentials provider not available");
}
return creds;
}
代码示例来源:origin: org.dspace/dspace-sword-api
/**
* Set the basic credentials. You must have previously set the server and
* port using setServer.
*
* @param username
* @param password
*/
private void setBasicCredentials(String username, String password) {
log.debug("server: " + server + " port: " + port + " u: '" + username
+ "' p '" + password + "'");
client.getState().setCredentials(new AuthScope(server, port),
new UsernamePasswordCredentials(username, password));
}
代码示例来源: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: jenkinsci/jenkins
method.getParams().setParameter("http.socket.timeout", DEFAULT_CONNECT_TIMEOUT_MILLIS > 0 ? DEFAULT_CONNECT_TIMEOUT_MILLIS : new Integer(30 * 1000));
HttpClient client = new HttpClient();
if (Util.fixEmptyAndTrim(name) != null && !isNoProxyHost(host, noProxyHost)) {
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: org.tinygroup/org.tinygroup.httpvisit
public void init() {
client = new HttpClient(new MultiThreadedHttpConnectionManager());
client.getHttpConnectionManager().getParams().setConnectionTimeout(timeout);
client.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
client.setState(httpState);
if (authPrefs != null) {
client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
}
if (proxyHost != null) {
client.getHostConfiguration().setProxy(proxyHost, proxyPort);
if (proxyUserPassword != null) {
httpState.setProxyCredentials(new AuthScope(proxyHost, proxyPort), proxyUserPassword);
}
}
}
代码示例来源:origin: jbarrez/Activiti-KickStart
private int executeDelete(String url) {
LOGGER.info("Executed module delete: " + url);
GetMethod method = new GetMethod(url);
try {
HttpState httpState = new HttpState();
httpState.setCredentials(new AuthScope(null, AuthScope.ANY_PORT), new UsernamePasswordCredentials("admin", "admin"));
HttpClient httpClient = new HttpClient();
int statusCode = httpClient.executeMethod(null, method, httpState);
LOGGER.info("Status code result for delete: " + statusCode);
return statusCode;
} catch (Throwable t) {
LOGGER.log(Level.SEVERE, "Error: " + t.getMessage());
t.printStackTrace();
} finally {
method.releaseConnection();
}
throw new RuntimeException("Programmatic error. You shouldn't be here.");
}
代码示例来源:origin: org.opensaml/openws
HttpClientParams clientParams = new HttpClientParams();
clientParams.setAuthenticationPreemptive(isPreemptiveAuthentication());
clientParams.setContentCharset(getContentCharSet());
clientParams.setParameter(HttpClientParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(
connectionRetryAttempts, false));
connMgr.setParams(connMgrParams);
HttpClient httpClient = new HttpClient(clientParams, connMgr);
httpClient.setHostConfiguration(hostConfig);
AuthScope proxyAuthScope = new AuthScope(proxyHost, proxyPort);
UsernamePasswordCredentials proxyCredentials = new UsernamePasswordCredentials(proxyUsername,
proxyPassword);
httpClient.getState().setProxyCredentials(proxyAuthScope, proxyCredentials);
代码示例来源:origin: org.apache.ivy/ivy
private HttpClient getClient() {
if (httpClient == null) {
final MultiThreadedHttpConnectionManager connManager = new MultiThreadedHttpConnectionManager();
httpClient = new HttpClient(connManager);
authPrefs.add(AuthPolicy.BASIC);
httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort);
if (useProxyAuthentication()) {
httpClient.getState().setProxyCredentials(
new AuthScope(proxyHost, proxyPort, AuthScope.ANY_REALM),
createCredentials(proxyUserName, proxyPasswd));
httpClient.getParams().setParameter(HttpMethodParams.USER_AGENT,
getUserAgent());
httpClient.getParams().setParameter(CredentialsProvider.PROVIDER,
new IvyCredentialsProvider());
代码示例来源:origin: uk.org.mygrid.taverna/taverna-contrib
protected void setProxy(HttpClient client) {
String host = System.getProperty("http.proxyHost");
String port = System.getProperty("http.proxyPort");
String user = System.getProperty("http.proxyUser");
String password = System.getProperty("http.proxyPassword");
if (host != null && port != null) {
try {
int portInteger = Integer.parseInt(port);
client.getHostConfiguration().setProxy(host, portInteger);
if (user != null && password != null) {
client.getState().setProxyCredentials(
new AuthScope(host, portInteger),
new UsernamePasswordCredentials(user, password));
}
} catch (NumberFormatException e) {
logger.error("Proxy port not an integer", e);
}
}
}
代码示例来源: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: gooddata/GoodData-CL
List authPrefs = new ArrayList();
authPrefs.add(AuthPolicy.NTLM);
client.getState().setProxyCredentials(new AuthScope(null, proxyPort, null), new NTCredentials(user,
password, "", domain));
client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
if(user != null && password !=null) {
authPrefs.add(AuthPolicy.BASIC);
client.getState().setProxyCredentials(new AuthScope(null, proxyPort, null), new UsernamePasswordCredentials(user,
password));
client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
代码示例来源:origin: org.mule.transports/mule-transport-http
protected HttpClient doClientConnect() throws Exception
{
HttpState state = new HttpState();
if (getProxyUsername() != null)
{
Credentials credentials;
if (isProxyNtlmAuthentication())
{
credentials = new NTCredentials(getProxyUsername(), getProxyPassword(), getProxyHostname(), "");
}
else
{
credentials = new UsernamePasswordCredentials(getProxyUsername(), getProxyPassword());
}
AuthScope authscope = new AuthScope(getProxyHostname(), getProxyPort());
state.setProxyCredentials(authscope, credentials);
}
HttpClient client = new HttpClient();
client.setState(state);
client.setHttpConnectionManager(getClientConnectionManager());
return client;
}
代码示例来源:origin: org.opensaml/opensaml
/**
* Constructor.
*
* @param metadataURL the URL to fetch the metadata
* @param requestTimeout the time, in milliseconds, to wait for the metadata server to respond
*
* @throws MetadataProviderException thrown if the URL is not a valid URL or the metadata can not be retrieved from
* the URL
*/
@Deprecated
public HTTPMetadataProvider(String metadataURL, int requestTimeout) throws MetadataProviderException {
super();
try {
metadataURI = new URI(metadataURL);
} catch (URISyntaxException e) {
throw new MetadataProviderException("Illegal URL syntax", e);
}
HttpClientParams clientParams = new HttpClientParams();
clientParams.setSoTimeout(requestTimeout);
httpClient = new HttpClient(clientParams);
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(requestTimeout);
authScope = new AuthScope(metadataURI.getHost(), metadataURI.getPort());
}
代码示例来源:origin: org.tinygroup/org.tinygroup.httpvisit
/**
* @param host
* @param port
* @param realm
* @param schema
* @param username
* @param password
*/
public void setBasicAuth(String host, int port, String realm, String schema, String username, String password) {
httpState.setCredentials(new AuthScope("www.verisign.com", 443, realm, schema), new UsernamePasswordCredentials("username", "password"));
authEnabled = true;
}
代码示例来源:origin: mguessan/davmail
/**
* Enable NTLM authentication on http client
*
* @param httpClient HttpClient instance
*/
public static void addNTLM(HttpClient httpClient) {
// disable preemptive authentication
httpClient.getParams().setParameter(HttpClientParams.PREEMPTIVE_AUTHENTICATION, false);
// register the jcifs based NTLMv2 implementation
AuthPolicy.registerAuthScheme(AuthPolicy.NTLM, NTLMv2Scheme.class);
ArrayList<String> authPrefs = new ArrayList<String>();
authPrefs.add(AuthPolicy.NTLM);
authPrefs.add(AuthPolicy.DIGEST);
authPrefs.add(AuthPolicy.BASIC);
httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
// make sure NTLM is always active
needNTLM = true;
// separate domain from username in credentials
AuthScope authScope = new AuthScope(null, -1);
NTCredentials credentials = (NTCredentials) httpClient.getState().getCredentials(authScope);
if (credentials != null && credentials.getDomain() == null) {
setCredentials(httpClient, credentials.getUserName(), credentials.getPassword());
}
}
代码示例来源: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: 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);
}
内容来源于网络,如有侵权,请联系作者删除!