• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java CredentialsProvider类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.commons.httpclient.auth.CredentialsProvider的典型用法代码示例。如果您正苦于以下问题:Java CredentialsProvider类的具体用法?Java CredentialsProvider怎么用?Java CredentialsProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CredentialsProvider类属于org.apache.commons.httpclient.auth包,在下文中一共展示了CredentialsProvider类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
        }
    }
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:19,代码来源:InteractiveAuthenticationExample.java


示例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();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:26,代码来源:TestProxy.java


示例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();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:26,代码来源:TestProxy.java


示例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();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:28,代码来源:TestProxy.java


示例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();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:28,代码来源:TestProxy.java


示例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();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:27,代码来源:TestProxy.java


示例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();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:27,代码来源:TestProxy.java


示例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();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:29,代码来源:TestProxy.java


示例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();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:29,代码来源:TestProxy.java


示例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();
    }
}
 
开发者ID:magneticmoon,项目名称:httpclient3-ntml,代码行数:27,代码来源:TestProxy.java


示例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();
    }
}
 
开发者ID:magneticmoon,项目名称:httpclient3-ntml,代码行数:27,代码来源:TestProxy.java


示例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();
    }
}
 
开发者ID:magneticmoon,项目名称:httpclient3-ntml,代码行数:29,代码来源:TestProxy.java


示例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();
    }
}
 
开发者ID:magneticmoon,项目名称:httpclient3-ntml,代码行数:29,代码来源:TestProxy.java


示例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);
}
 
开发者ID:adamcin,项目名称:httpsig-java,代码行数:26,代码来源:Http3Util.java


示例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;
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:28,代码来源:HttpMethodDirector.java


示例16: promptForProxyCredentials

import org.apache.commons.httpclient.auth.CredentialsProvider; //导入依赖的package包/类
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;
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:28,代码来源:HttpMethodDirector.java


示例17: SignerCredentialsProvider

import org.apache.commons.httpclient.auth.CredentialsProvider; //导入依赖的package包/类
public SignerCredentialsProvider(Signer signer, CredentialsProvider delegatee) {
    this.signer = signer;
    this.delegatee = delegatee;
}
 
开发者ID:adamcin,项目名称:httpsig-java,代码行数:5,代码来源:SignerCredentialsProvider.java


示例18: getDelegatee

import org.apache.commons.httpclient.auth.CredentialsProvider; //导入依赖的package包/类
public CredentialsProvider getDelegatee() {
    return delegatee;
}
 
开发者ID:adamcin,项目名称:httpsig-java,代码行数:4,代码来源:SignerCredentialsProvider.java


示例19: RestS3Service

import org.apache.commons.httpclient.auth.CredentialsProvider; //导入依赖的package包/类
/**
 * Constructs the service and initialises the properties.
 * 
 * @param awsCredentials
 * the S3 user credentials to use when communicating with S3, may be null in which case the
 * communication is done as an anonymous user.
 * @param invokingApplicationDescription
 * a short description of the application using the service, suitable for inclusion in a
 * user agent string for REST/HTTP requests. Ideally this would include the application's
 * version number, for example: <code>Cockpit/0.6.1</code> or <code>My App Name/1.0</code>
 * @param credentialsProvider
 * an implementation of the HttpClient CredentialsProvider interface, to provide a means for
 * prompting for credentials when necessary.
 *   
 * @throws S3ServiceException
 */
public RestS3Service(AWSCredentials awsCredentials, String invokingApplicationDescription, 
    CredentialsProvider credentialsProvider) throws S3ServiceException 
{
    this(awsCredentials, invokingApplicationDescription, credentialsProvider, 
        Jets3tProperties.getInstance(Constants.JETS3T_PROPERTIES_FILENAME));
}
 
开发者ID:fajoy,项目名称:jets3t,代码行数:23,代码来源:RestS3Service.java



注:本文中的org.apache.commons.httpclient.auth.CredentialsProvider类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Instance类代码示例发布时间:2022-05-23
下一篇:
Java LoginBehavior类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap