本文整理汇总了Java中org.apache.commons.httpclient.auth.AuthScope.ANY_HOST属性的典型用法代码示例。如果您正苦于以下问题:Java AuthScope.ANY_HOST属性的具体用法?Java AuthScope.ANY_HOST怎么用?Java AuthScope.ANY_HOST使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.commons.httpclient.auth.AuthScope
的用法示例。
在下文中一共展示了AuthScope.ANY_HOST属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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));
}
示例2: 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);
}
示例3: addAuth
@Override
public void addAuth(AuthCredentials creds) {
String host = (StringUtils.isBlank(creds.getHost()) || "*".equals(creds.getHost())) ? AuthScope.ANY_HOST : creds.getHost();
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);
}
示例4: 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);
}
}
示例5: 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);
}
}
示例6: 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;
}
示例7: 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;
}
示例8: 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);
}
示例9: 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);
}
示例10: 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);
}