本文整理汇总了Java中org.apache.commons.httpclient.auth.CredentialsProvider类的典型用法代码示例。如果您正苦于以下问题:Java CredentialsProvider类的具体用法?Java CredentialsProvider怎么用?Java CredentialsProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CredentialsProvider类属于org.apache.commons.httpclient.auth包,在下文中一共展示了CredentialsProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doDemo
import org.apache.commons.httpclient.auth.CredentialsProvider; //导入依赖的package包/类
private void doDemo() throws IOException {
HttpClient client = new HttpClient();
client.getParams().setParameter(
CredentialsProvider.PROVIDER, new ConsoleAuthPrompter());
GetMethod httpget = new GetMethod("http://target-host/requires-auth.html");
httpget.setDoAuthentication(true);
try {
// execute the GET
int status = client.executeMethod(httpget);
// print the status and response
System.out.println(httpget.getStatusLine().toString());
System.out.println(httpget.getResponseBodyAsString());
} finally {
// release any connection resources used by the method
httpget.releaseConnection();
}
}
示例2: testGetInteractiveHostAuthConnKeepAlive
import org.apache.commons.httpclient.auth.CredentialsProvider; //导入依赖的package包/类
/**
* Tests GET via non-authenticating proxy + interactive host auth + connection keep-alive
*/
public void testGetInteractiveHostAuthConnKeepAlive() throws Exception {
UsernamePasswordCredentials creds =
new UsernamePasswordCredentials("testuser", "testpass");
this.client.getParams().setParameter(CredentialsProvider.PROVIDER,
new GetItWrongThenGetItRight());
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds, "test", true));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
this.server.setRequestHandler(handlerchain);
GetMethod get = new GetMethod("/");
try {
this.client.executeMethod(get);
assertEquals(HttpStatus.SC_OK, get.getStatusCode());
} finally {
get.releaseConnection();
}
}
示例3: testGetInteractiveHostAuthConnClose
import org.apache.commons.httpclient.auth.CredentialsProvider; //导入依赖的package包/类
/**
* Tests GET via non-authenticating proxy + interactive host auth + connection close
*/
public void testGetInteractiveHostAuthConnClose() throws Exception {
UsernamePasswordCredentials creds =
new UsernamePasswordCredentials("testuser", "testpass");
this.client.getParams().setParameter(CredentialsProvider.PROVIDER,
new GetItWrongThenGetItRight());
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds, "test", false));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
this.server.setRequestHandler(handlerchain);
GetMethod get = new GetMethod("/");
try {
this.client.executeMethod(get);
assertEquals(HttpStatus.SC_OK, get.getStatusCode());
} finally {
get.releaseConnection();
}
}
示例4: testGetInteractiveProxyAuthHostAuthConnKeepAlive
import org.apache.commons.httpclient.auth.CredentialsProvider; //导入依赖的package包/类
/**
* Tests GET via authenticating proxy + interactive host and proxy auth + connection keep-alive
*/
public void testGetInteractiveProxyAuthHostAuthConnKeepAlive() throws Exception {
UsernamePasswordCredentials creds =
new UsernamePasswordCredentials("testuser", "testpass");
this.client.getParams().setParameter(CredentialsProvider.PROVIDER,
new GetItWrongThenGetItRight());
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds, "test", true));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
this.server.setRequestHandler(handlerchain);
this.proxy.requireAuthentication(creds, "test", true);
GetMethod get = new GetMethod("/");
try {
this.client.executeMethod(get);
assertEquals(HttpStatus.SC_OK, get.getStatusCode());
} finally {
get.releaseConnection();
}
}
示例5: testGetInteractiveProxyAuthHostAuthConnClose
import org.apache.commons.httpclient.auth.CredentialsProvider; //导入依赖的package包/类
/**
* Tests GET via authenticating proxy + interactive host and proxy auth + connection close
*/
public void testGetInteractiveProxyAuthHostAuthConnClose() throws Exception {
UsernamePasswordCredentials creds =
new UsernamePasswordCredentials("testuser", "testpass");
this.client.getParams().setParameter(CredentialsProvider.PROVIDER,
new GetItWrongThenGetItRight());
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds, "test", false));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
this.server.setRequestHandler(handlerchain);
this.proxy.requireAuthentication(creds, "test", true);
GetMethod get = new GetMethod("/");
try {
this.client.executeMethod(get);
assertEquals(HttpStatus.SC_OK, get.getStatusCode());
} finally {
get.releaseConnection();
}
}
示例6: testPostInteractiveHostAuthConnKeepAlive
import org.apache.commons.httpclient.auth.CredentialsProvider; //导入依赖的package包/类
/**
* Tests POST via non-authenticating proxy + interactive host auth + connection keep-alive
*/
public void testPostInteractiveHostAuthConnKeepAlive() throws Exception {
UsernamePasswordCredentials creds =
new UsernamePasswordCredentials("testuser", "testpass");
this.client.getParams().setParameter(CredentialsProvider.PROVIDER,
new GetItWrongThenGetItRight());
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds, "test", true));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
this.server.setRequestHandler(handlerchain);
PostMethod post = new PostMethod("/");
post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null));
try {
this.client.executeMethod(post);
assertEquals(HttpStatus.SC_OK, post.getStatusCode());
assertNotNull(post.getResponseBodyAsString());
} finally {
post.releaseConnection();
}
}
示例7: testPostInteractiveHostAuthConnClose
import org.apache.commons.httpclient.auth.CredentialsProvider; //导入依赖的package包/类
/**
* Tests POST via non-authenticating proxy + interactive host auth + connection close
*/
public void testPostInteractiveHostAuthConnClose() throws Exception {
UsernamePasswordCredentials creds =
new UsernamePasswordCredentials("testuser", "testpass");
this.client.getParams().setParameter(CredentialsProvider.PROVIDER,
new GetItWrongThenGetItRight());
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds, "test", false));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
this.server.setRequestHandler(handlerchain);
PostMethod post = new PostMethod("/");
post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null));
try {
this.client.executeMethod(post);
assertEquals(HttpStatus.SC_OK, post.getStatusCode());
assertNotNull(post.getResponseBodyAsString());
} finally {
post.releaseConnection();
}
}
示例8: testPostInteractiveProxyAuthHostAuthConnKeepAlive
import org.apache.commons.httpclient.auth.CredentialsProvider; //导入依赖的package包/类
/**
* Tests POST via non-authenticating proxy + interactive host auth + connection keep-alive
*/
public void testPostInteractiveProxyAuthHostAuthConnKeepAlive() throws Exception {
UsernamePasswordCredentials creds =
new UsernamePasswordCredentials("testuser", "testpass");
this.client.getParams().setParameter(CredentialsProvider.PROVIDER,
new GetItWrongThenGetItRight());
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds, "test", true));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
this.server.setRequestHandler(handlerchain);
this.proxy.requireAuthentication(creds, "test", true);
PostMethod post = new PostMethod("/");
post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null));
try {
this.client.executeMethod(post);
assertEquals(HttpStatus.SC_OK, post.getStatusCode());
assertNotNull(post.getResponseBodyAsString());
} finally {
post.releaseConnection();
}
}
示例9: testPostInteractiveProxyAuthHostAuthConnClose
import org.apache.commons.httpclient.auth.CredentialsProvider; //导入依赖的package包/类
/**
* Tests POST via non-authenticating proxy + interactive host auth + connection close
*/
public void testPostInteractiveProxyAuthHostAuthConnClose() throws Exception {
UsernamePasswordCredentials creds =
new UsernamePasswordCredentials("testuser", "testpass");
this.client.getParams().setParameter(CredentialsProvider.PROVIDER,
new GetItWrongThenGetItRight());
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds, "test", false));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
this.server.setRequestHandler(handlerchain);
this.proxy.requireAuthentication(creds, "test", true);
PostMethod post = new PostMethod("/");
post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null));
try {
this.client.executeMethod(post);
assertEquals(HttpStatus.SC_OK, post.getStatusCode());
assertNotNull(post.getResponseBodyAsString());
} finally {
post.releaseConnection();
}
}
示例10: testPostInteractiveHostAuthConnKeepAlive
import org.apache.commons.httpclient.auth.CredentialsProvider; //导入依赖的package包/类
/**
* Tests POST via non-authenticating proxy + interactive host auth + connection keep-alive
*/
public void testPostInteractiveHostAuthConnKeepAlive() throws Exception {
UsernamePasswordCredentials creds =
new UsernamePasswordCredentials("testuser", "testpass");
this.client.getParams().setParameter(CredentialsProvider.PROVIDER,
new GetItWrongThenGetItRight());
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds, "test", true));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
this.server.setRequestHandler(handlerchain);
PostMethod post = new PostMethod("/");
post.setRequestEntity(new StringRequestEntity("Like tons of stuff"));
try {
this.client.executeMethod(post);
assertEquals(HttpStatus.SC_OK, post.getStatusCode());
assertNotNull(post.getResponseBodyAsString());
} finally {
post.releaseConnection();
}
}
示例11: testPostInteractiveHostAuthConnClose
import org.apache.commons.httpclient.auth.CredentialsProvider; //导入依赖的package包/类
/**
* Tests POST via non-authenticating proxy + interactive host auth + connection close
*/
public void testPostInteractiveHostAuthConnClose() throws Exception {
UsernamePasswordCredentials creds =
new UsernamePasswordCredentials("testuser", "testpass");
this.client.getParams().setParameter(CredentialsProvider.PROVIDER,
new GetItWrongThenGetItRight());
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds, "test", false));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
this.server.setRequestHandler(handlerchain);
PostMethod post = new PostMethod("/");
post.setRequestEntity(new StringRequestEntity("Like tons of stuff"));
try {
this.client.executeMethod(post);
assertEquals(HttpStatus.SC_OK, post.getStatusCode());
assertNotNull(post.getResponseBodyAsString());
} finally {
post.releaseConnection();
}
}
示例12: testPostInteractiveProxyAuthHostAuthConnKeepAlive
import org.apache.commons.httpclient.auth.CredentialsProvider; //导入依赖的package包/类
/**
* Tests POST via non-authenticating proxy + interactive host auth + connection keep-alive
*/
public void testPostInteractiveProxyAuthHostAuthConnKeepAlive() throws Exception {
UsernamePasswordCredentials creds =
new UsernamePasswordCredentials("testuser", "testpass");
this.client.getParams().setParameter(CredentialsProvider.PROVIDER,
new GetItWrongThenGetItRight());
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds, "test", true));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
this.server.setRequestHandler(handlerchain);
this.proxy.requireAuthentication(creds, "test", true);
PostMethod post = new PostMethod("/");
post.setRequestEntity(new StringRequestEntity("Like tons of stuff"));
try {
this.client.executeMethod(post);
assertEquals(HttpStatus.SC_OK, post.getStatusCode());
assertNotNull(post.getResponseBodyAsString());
} finally {
post.releaseConnection();
}
}
示例13: testPostInteractiveProxyAuthHostAuthConnClose
import org.apache.commons.httpclient.auth.CredentialsProvider; //导入依赖的package包/类
/**
* Tests POST via non-authenticating proxy + interactive host auth + connection close
*/
public void testPostInteractiveProxyAuthHostAuthConnClose() throws Exception {
UsernamePasswordCredentials creds =
new UsernamePasswordCredentials("testuser", "testpass");
this.client.getParams().setParameter(CredentialsProvider.PROVIDER,
new GetItWrongThenGetItRight());
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds, "test", false));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
this.server.setRequestHandler(handlerchain);
this.proxy.requireAuthentication(creds, "test", true);
PostMethod post = new PostMethod("/");
post.setRequestEntity(new StringRequestEntity("Like tons of stuff"));
try {
this.client.executeMethod(post);
assertEquals(HttpStatus.SC_OK, post.getStatusCode());
assertNotNull(post.getResponseBodyAsString());
} finally {
post.releaseConnection();
}
}
示例14: enableAuth
import org.apache.commons.httpclient.auth.CredentialsProvider; //导入依赖的package包/类
public static void enableAuth(HttpClient client, Keychain keychain, KeyId keyId) {
Signer signer = new Signer(keychain, keyId);
CredentialsProvider credProvider =
(CredentialsProvider) client.getParams()
.getParameter(CredentialsProvider.PROVIDER);
CredentialsProvider newProvider;
if (credProvider instanceof SignerCredentialsProvider) {
newProvider = new SignerCredentialsProvider(signer,
((SignerCredentialsProvider) credProvider).getDelegatee());
} else {
newProvider = new SignerCredentialsProvider(signer, credProvider);
}
client.getParams().setParameter(CredentialsProvider.PROVIDER, newProvider);
AuthPolicy.registerAuthScheme(Constants.SCHEME, Http3SignatureAuthScheme.class);
List<String> schemes = new ArrayList<String>();
schemes.add(Constants.SCHEME);
Collection authSchemePriority = (Collection) DefaultHttpParams.getDefaultParams().getParameter(AuthPolicy.AUTH_SCHEME_PRIORITY);
if (authSchemePriority != null) {
schemes.addAll(authSchemePriority);
}
client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, schemes);
}
示例15: promptForCredentials
import org.apache.commons.httpclient.auth.CredentialsProvider; //导入依赖的package包/类
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;
}