本文整理汇总了Java中org.apache.commons.httpclient.auth.AuthScope.ANY_PORT属性的典型用法代码示例。如果您正苦于以下问题:Java AuthScope.ANY_PORT属性的具体用法?Java AuthScope.ANY_PORT怎么用?Java AuthScope.ANY_PORT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.commons.httpclient.auth.AuthScope
的用法示例。
在下文中一共展示了AuthScope.ANY_PORT属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeHttpRequest
public static String makeHttpRequest(HttpMethod method, String username, String password)
{
try
{
HttpClient httpClient = new HttpClient();
AuthScope authScope = new AuthScope(method.getURI().getHost(), AuthScope.ANY_PORT, null,
AuthScope.ANY_SCHEME);
httpClient.getParams().setAuthenticationPreemptive(true);
httpClient.getState().setCredentials(authScope, new UsernamePasswordCredentials(username, password));
httpClient.executeMethod(method);
return method.getResponseBodyAsString();
} catch (IOException e)
{
throw new RuntimeException(e);
}
}
示例2: setNTLMCredentials
public static void setNTLMCredentials(HttpClient httpClient, UsernamePasswordCredentials credentials,
String domain) {
initNTLMv2();
String localHostName;
try {
localHostName = Inet4Address.getLocalHost().getHostName();
} catch (Exception e) {
localHostName = "";
}
AuthScope authscope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT);
httpClient.getState().setCredentials(
authscope,
new NTCredentials(
credentials.getUserName(),
credentials.getPassword(),
localHostName, domain));
}
示例3: getHost
public Host getHost() {
// e.g. 'https://reviewboard.eng.vmware.com/' -> 'reviewboard.eng.vmware.com'
String url = reviewboardURL;
int startIndex = 0;
int temp = url.indexOf("://");
if (temp >= 0) startIndex = temp + 3;
int endIndex = url.indexOf('/', startIndex);
if (endIndex < 0) endIndex = url.length();
String hostAndPort = url.substring(startIndex, endIndex);
int colon = hostAndPort.indexOf(':');
String host = colon >= 0 ? hostAndPort.substring(0, colon) : hostAndPort;
int port = colon >= 0 ?
Integer.parseInt(hostAndPort.substring(colon + 1)) :
url.startsWith("http:") ? 80 :
url.startsWith("https:") ? 443 :
AuthScope.ANY_PORT;
return new Host(host, port);
}
示例4: getCredentials
private Credentials getCredentials() {
Credentials credentials = null;
if (httpState != null) {
if (host != null) {
AuthScope authScope = new AuthScope(host, AuthScope.ANY_PORT, realm, AuthScope.ANY_SCHEME);
credentials = httpState.getCredentials(authScope);
}
}
return credentials;
}
示例5: testCredentialsMatching
public void testCredentialsMatching() {
Credentials creds1 = new UsernamePasswordCredentials("name1", "pass1");
Credentials creds2 = new UsernamePasswordCredentials("name2", "pass2");
Credentials creds3 = new UsernamePasswordCredentials("name3", "pass3");
AuthScope scope1 = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM);
AuthScope scope2 = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, "somerealm");
AuthScope scope3 = new AuthScope("somehost", AuthScope.ANY_PORT, AuthScope.ANY_REALM);
HttpState state = new HttpState();
state.setCredentials(scope1, creds1);
state.setCredentials(scope2, creds2);
state.setCredentials(scope3, creds3);
Credentials got = state.getCredentials(
new AuthScope("someotherhost", 80, "someotherrealm", "basic"));
Credentials expected = creds1;
assertEquals(expected, got);
got = state.getCredentials(
new AuthScope("someotherhost", 80, "somerealm", "basic"));
expected = creds2;
assertEquals(expected, got);
got = state.getCredentials(
new AuthScope("somehost", 80, "someotherrealm", "basic"));
expected = creds3;
assertEquals(expected, got);
}
示例6: initCredentials
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);
}
}
示例7: configureHttpClient
@Override
protected void configureHttpClient(HttpClient client) {
super.configureHttpClient(client);
if (isUseNTLM()) {
client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, Arrays.asList(AuthPolicy.NTLM));
AuthScope authScope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT);
Credentials credentials = new NTCredentials(getUsername(), getPassword(), getHost(), getDomain());
client.getState().setCredentials(authScope, credentials);
}
}
示例8: setProxyCredentials
public void setProxyCredentials(String username, String password) {
if (username == null || username.trim().length() == 0)
return;
Credentials cred = new UsernamePasswordCredentials(username, password);
AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT,
AuthScope.ANY_REALM);
client.getState().setProxyCredentials(scope, cred);
proxyAuthent = true;
}
示例9: setCredentials
public void setCredentials(String username, String password) {
Credentials cred = new UsernamePasswordCredentials(username, password);
AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT,
AuthScope.ANY_REALM);
client.getState().setCredentials(scope, cred);
client.getParams().setAuthenticationPreemptive(true);
serverAuthent = true;
}
示例10: getCommonsHttpSolrServer
public static CommonsHttpSolrServer getCommonsHttpSolrServer(JobConf job) throws MalformedURLException {
HttpClient client=new HttpClient();
// Check for username/password
if (job.getBoolean(SolrConstants.USE_AUTH, false)) {
String username = job.get(SolrConstants.USERNAME);
LOG.info("Authenticating as: " + username);
AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME);
client.getState().setCredentials(scope, new UsernamePasswordCredentials(username, job.get(SolrConstants.PASSWORD)));
HttpClientParams params = client.getParams();
params.setAuthenticationPreemptive(true);
client.setParams(params);
}
return new CommonsHttpSolrServer(job.get(SolrConstants.SERVER_URL), client);
}
示例11: setHttpProxyCredentials
@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);
}
示例12: login
@Override
public synchronized void login() {
// exclude the NTLM authentication scheme (requires NTCredentials we don't supply)
List<String> authPrefs = new ArrayList<String>(2);
authPrefs.add(AuthPolicy.DIGEST);
authPrefs.add(AuthPolicy.BASIC);
httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
// first try Apollo style login
String authPoint = pathJoin("/", location, "/authentication-point/alm-authenticate");
String authXml = createAuthXml();
PostMethod post = initPostMethod(authPoint, authXml);
ResultInfo resultInfo = ResultInfo.create(null);
executeAndWriteResponse(post, resultInfo, Collections.<Integer>emptySet());
if(resultInfo.getHttpStatus() == HttpStatus.SC_NOT_FOUND) {
// try Maya style login
Credentials cred = new UsernamePasswordCredentials(userName, password);
AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT);
httpClient.getParams().setParameter(HttpMethodParams.CREDENTIAL_CHARSET, "UTF-8");
httpClient.getState().setCredentials(scope, cred);
authPoint = pathJoin("/", location, "/authentication-point/authenticate");
GetMethod get = new GetMethod(authPoint);
resultInfo = ResultInfo.create(null);
executeAndWriteResponse(get, resultInfo, Collections.<Integer>emptySet());
}
HttpStatusBasedException.throwForError(resultInfo);
if(resultInfo.getHttpStatus() != 200) {
// during login we only accept 200 status (to avoid redirects and such as seemingly correct login)
throw new AuthenticationFailureException(resultInfo);
}
Cookie[] cookies = httpClient.getState().getCookies();
Cookie ssoCookie = getSessionCookieByName(cookies, COOKIE_SSO_NAME);
addTenantCookie(ssoCookie);
//Since ALM 12.00 it is required explicitly ask for QCSession calling "/rest/site-session"
//For all the rest of HP ALM / AGM versions it is optional
String siteSessionPoint = pathJoin("/", location, "/rest/site-session");
String sessionParamXml = createRestSessionXml();
post = initPostMethod(siteSessionPoint, sessionParamXml);
resultInfo = ResultInfo.create(null);
executeAndWriteResponse(post, resultInfo, Collections.<Integer>emptySet());
//AGM throws 403
if (resultInfo.getHttpStatus() != HttpStatus.SC_FORBIDDEN) {
HttpStatusBasedException.throwForError(resultInfo);
}
cookies = httpClient.getState().getCookies();
Cookie qcCookie = getSessionCookieByName(cookies, COOKIE_SESSION_NAME);
sessionContext = new SessionContext(location, ssoCookie, qcCookie);
}