当前位置: 首页>>代码示例>>Java>>正文


Java Credentials类代码示例

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


Credentials类属于ch.boye.httpclientandroidlib.auth包,在下文中一共展示了Credentials类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doPreemptiveAuth

import ch.boye.httpclientandroidlib.auth.Credentials; //导入依赖的package包/类
private void doPreemptiveAuth(
        final HttpHost host,
        final AuthScheme authScheme,
        final AuthState authState,
        final CredentialsProvider credsProvider) {
    final String schemeName = authScheme.getSchemeName();
    if (this.log.isDebugEnabled()) {
        this.log.debug("Re-using cached '" + schemeName + "' auth scheme for " + host);
    }

    final AuthScope authScope = new AuthScope(host, AuthScope.ANY_REALM, schemeName);
    final Credentials creds = credsProvider.getCredentials(authScope);

    if (creds != null) {
        if ("BASIC".equalsIgnoreCase(authScheme.getSchemeName())) {
            authState.setState(AuthProtocolState.CHALLENGED);
        } else {
            authState.setState(AuthProtocolState.SUCCESS);
        }
        authState.update(authScheme, creds);
    } else {
        this.log.debug("No credentials for preemptive authentication");
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:25,代码来源:RequestAuthCache.java

示例2: authenticate

import ch.boye.httpclientandroidlib.auth.Credentials; //导入依赖的package包/类
/**
 * Produces a digest authorization string for the given set of
 * {@link Credentials}, method name and URI.
 *
 * @param credentials A set of credentials to be used for athentication
 * @param request    The request being authenticated
 *
 * @throws ch.boye.httpclientandroidlib.auth.InvalidCredentialsException if authentication credentials
 *         are not valid or not applicable for this authentication scheme
 * @throws AuthenticationException if authorization string cannot
 *   be generated due to an authentication failure
 *
 * @return a digest authorization string
 */
@Override
public Header authenticate(
        final Credentials credentials,
        final HttpRequest request,
        final HttpContext context) throws AuthenticationException {

    Args.notNull(credentials, "Credentials");
    Args.notNull(request, "HTTP request");
    if (getParameter("realm") == null) {
        throw new AuthenticationException("missing realm in challenge");
    }
    if (getParameter("nonce") == null) {
        throw new AuthenticationException("missing nonce in challenge");
    }
    // Add method name and request-URI to the parameter map
    getParameters().put("methodname", request.getRequestLine().getMethod());
    getParameters().put("uri", request.getRequestLine().getUri());
    final String charset = getParameter("charset");
    if (charset == null) {
        getParameters().put("charset", getCredentialsCharset(request));
    }
    return createDigestHeader(credentials, request);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:38,代码来源:DigestScheme.java

示例3: matchCredentials

import ch.boye.httpclientandroidlib.auth.Credentials; //导入依赖的package包/类
/**
 * Find matching {@link Credentials credentials} for the given authentication scope.
 *
 * @param map the credentials hash map
 * @param authscope the {@link AuthScope authentication scope}
 * @return the credentials
 *
 */
private static Credentials matchCredentials(
        final Map<AuthScope, Credentials> map,
        final AuthScope authscope) {
    // see if we get a direct hit
    Credentials creds = map.get(authscope);
    if (creds == null) {
        // Nope.
        // Do a full scan
        int bestMatchFactor  = -1;
        AuthScope bestMatch  = null;
        for (final AuthScope current: map.keySet()) {
            final int factor = authscope.match(current);
            if (factor > bestMatchFactor) {
                bestMatchFactor = factor;
                bestMatch = current;
            }
        }
        if (bestMatch != null) {
            creds = map.get(bestMatch);
        }
    }
    return creds;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:32,代码来源:BasicCredentialsProvider.java

示例4: authenticate

import ch.boye.httpclientandroidlib.auth.Credentials; //导入依赖的package包/类
private Header authenticate(
        final AuthScheme authScheme,
        final Credentials creds,
        final HttpRequest request,
        final HttpContext context) throws AuthenticationException {
    Asserts.notNull(authScheme, "Auth scheme");
    if (authScheme instanceof ContextAwareAuthScheme) {
        return ((ContextAwareAuthScheme) authScheme).authenticate(creds, request, context);
    } else {
        return authScheme.authenticate(creds, request);
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:13,代码来源:RequestAuthenticationBase.java

示例5: authenticate

import ch.boye.httpclientandroidlib.auth.Credentials; //导入依赖的package包/类
/**
 * Produces basic authorization header for the given set of {@link Credentials}.
 *
 * @param credentials The set of credentials to be used for authentication
 * @param request The request being authenticated
 * @throws ch.boye.httpclientandroidlib.auth.InvalidCredentialsException if authentication
 *   credentials are not valid or not applicable for this authentication scheme
 * @throws AuthenticationException if authorization string cannot
 *   be generated due to an authentication failure
 *
 * @return a basic authorization string
 */
@Override
public Header authenticate(
        final Credentials credentials,
        final HttpRequest request,
        final HttpContext context) throws AuthenticationException {

    Args.notNull(credentials, "Credentials");
    Args.notNull(request, "HTTP request");
    final StringBuilder tmp = new StringBuilder();
    tmp.append(credentials.getUserPrincipal().getName());
    tmp.append(":");
    tmp.append((credentials.getPassword() == null) ? "null" : credentials.getPassword());

    final byte[] base64password = Base64.encodeBase64(
            EncodingUtils.getBytes(tmp.toString(), getCredentialsCharset(request)));

    final CharArrayBuffer buffer = new CharArrayBuffer(32);
    if (isProxy()) {
        buffer.append(AUTH.PROXY_AUTH_RESP);
    } else {
        buffer.append(AUTH.WWW_AUTH_RESP);
    }
    buffer.append(": Basic ");
    buffer.append(base64password, 0, base64password.length);

    return new BufferedHeader(buffer);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:40,代码来源:BasicScheme.java

示例6: authenticate

import ch.boye.httpclientandroidlib.auth.Credentials; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public Header authenticate(
        final Credentials credentials,
        final HttpRequest request,
        final HttpContext context) throws AuthenticationException {
    return authenticate(credentials, request);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:8,代码来源:AuthSchemeBase.java

示例7: doAuth

import ch.boye.httpclientandroidlib.auth.Credentials; //导入依赖的package包/类
@SuppressWarnings("deprecation")
private Header doAuth(
        final AuthScheme authScheme,
        final Credentials creds,
        final HttpRequest request,
        final HttpContext context) throws AuthenticationException {
    if (authScheme instanceof ContextAwareAuthScheme) {
        return ((ContextAwareAuthScheme) authScheme).authenticate(creds, request, context);
    } else {
        return authScheme.authenticate(creds, request);
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:13,代码来源:HttpAuthenticator.java

示例8: getAuthPrincipal

import ch.boye.httpclientandroidlib.auth.Credentials; //导入依赖的package包/类
private static Principal getAuthPrincipal(final AuthState authState) {
    final AuthScheme scheme = authState.getAuthScheme();
    if (scheme != null && scheme.isComplete() && scheme.isConnectionBased()) {
        final Credentials creds = authState.getCredentials();
        if (creds != null) {
            return creds.getUserPrincipal();
        }
    }
    return null;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:11,代码来源:DefaultUserTokenHandler.java

示例9: getCredentials

import ch.boye.httpclientandroidlib.auth.Credentials; //导入依赖的package包/类
public Credentials getCredentials(final AuthScope authscope) {
    Args.notNull(authscope, "Auth scope");
    final Credentials localcreds = internal.getCredentials(authscope);
    if (localcreds != null) {
        return localcreds;
    }
    if (authscope.getHost() != null) {
        PasswordAuthentication systemcreds = getSystemCreds(
                authscope, Authenticator.RequestorType.SERVER);
        if (systemcreds == null) {
            systemcreds = getSystemCreds(
                    authscope, Authenticator.RequestorType.PROXY);
        }
        if (systemcreds != null) {
            final String domain = System.getProperty("http.auth.ntlm.domain");
            if (domain != null) {
                return new NTCredentials(
                        systemcreds.getUserName(),
                        new String(systemcreds.getPassword()),
                        null, domain);
            } else {
                if (AuthSchemes.NTLM.equalsIgnoreCase(authscope.getScheme())) {
                    // Domian may be specified in a fully qualified user name
                    return new NTCredentials(
                            systemcreds.getUserName(),
                            new String(systemcreds.getPassword()),
                            null, null);
                } else {
                    return new UsernamePasswordCredentials(
                            systemcreds.getUserName(),
                            new String(systemcreds.getPassword()));
                }
            }
        }
    }
    return null;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:38,代码来源:SystemDefaultCredentialsProvider.java

示例10: process

import ch.boye.httpclientandroidlib.auth.Credentials; //导入依赖的package包/类
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
    CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(
            ClientContext.CREDS_PROVIDER);
    HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
    
    if (authState.getAuthScheme() == null) {
        AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
        Credentials creds = credsProvider.getCredentials(authScope);
        if (creds != null) {
            authState.setAuthScheme(new BasicScheme());
            authState.setCredentials(creds);
        }
    }
}
 
开发者ID:starn,项目名称:encdroidMC,代码行数:16,代码来源:SardineImpl.java

示例11: getAuthHeader

import ch.boye.httpclientandroidlib.auth.Credentials; //导入依赖的package包/类
/**
 * Return a Header object representing an Authentication header for HTTP
 * Basic.
 */
@Override
public Header getAuthHeader(HttpRequestBase request, BasicHttpContext context, DefaultHttpClient client) {
  Credentials creds = new UsernamePasswordCredentials(credentials);

  // This must be UTF-8 to generate the same Basic Auth headers as desktop for non-ASCII passwords.
  return BasicScheme.authenticate(creds, "UTF-8", false);
}
 
开发者ID:jrconlin,项目名称:mc_backup,代码行数:12,代码来源:BasicAuthHeaderProvider.java

示例12: select

import ch.boye.httpclientandroidlib.auth.Credentials; //导入依赖的package包/类
public Queue<AuthOption> select(
        final Map<String, Header> challenges,
        final HttpHost authhost,
        final HttpResponse response,
        final HttpContext context) throws MalformedChallengeException {
    Args.notNull(challenges, "Map of auth challenges");
    Args.notNull(authhost, "Host");
    Args.notNull(response, "HTTP response");
    Args.notNull(context, "HTTP context");

    final Queue<AuthOption> options = new LinkedList<AuthOption>();
    final CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(
            ClientContext.CREDS_PROVIDER);
    if (credsProvider == null) {
        this.log.debug("Credentials provider not set in the context");
        return options;
    }

    final AuthScheme authScheme;
    try {
        authScheme = this.handler.selectScheme(challenges, response, context);
    } catch (final AuthenticationException ex) {
        if (this.log.isWarnEnabled()) {
            this.log.warn(ex.getMessage(), ex);
        }
        return options;
    }
    final String id = authScheme.getSchemeName();
    final Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));
    authScheme.processChallenge(challenge);

    final AuthScope authScope = new AuthScope(
            authhost.getHostName(),
            authhost.getPort(),
            authScheme.getRealm(),
            authScheme.getSchemeName());

    final Credentials credentials = credsProvider.getCredentials(authScope);
    if (credentials != null) {
        options.add(new AuthOption(authScheme, credentials));
    }
    return options;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:44,代码来源:AuthenticationStrategyAdaptor.java

示例13: select

import ch.boye.httpclientandroidlib.auth.Credentials; //导入依赖的package包/类
public Queue<AuthOption> select(
        final Map<String, Header> challenges,
        final HttpHost authhost,
        final HttpResponse response,
        final HttpContext context) throws MalformedChallengeException {
    Args.notNull(challenges, "Map of auth challenges");
    Args.notNull(authhost, "Host");
    Args.notNull(response, "HTTP response");
    Args.notNull(context, "HTTP context");
    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    final Queue<AuthOption> options = new LinkedList<AuthOption>();
    final Lookup<AuthSchemeProvider> registry = clientContext.getAuthSchemeRegistry();
    if (registry == null) {
        this.log.debug("Auth scheme registry not set in the context");
        return options;
    }
    final CredentialsProvider credsProvider = clientContext.getCredentialsProvider();
    if (credsProvider == null) {
        this.log.debug("Credentials provider not set in the context");
        return options;
    }
    final RequestConfig config = clientContext.getRequestConfig();
    Collection<String> authPrefs = getPreferredAuthSchemes(config);
    if (authPrefs == null) {
        authPrefs = DEFAULT_SCHEME_PRIORITY;
    }
    if (this.log.isDebugEnabled()) {
        this.log.debug("Authentication schemes in the order of preference: " + authPrefs);
    }

    for (final String id: authPrefs) {
        final Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));
        if (challenge != null) {
            final AuthSchemeProvider authSchemeProvider = registry.lookup(id);
            if (authSchemeProvider == null) {
                if (this.log.isWarnEnabled()) {
                    this.log.warn("Authentication scheme " + id + " not supported");
                    // Try again
                }
                continue;
            }
            final AuthScheme authScheme = authSchemeProvider.create(context);
            authScheme.processChallenge(challenge);

            final AuthScope authScope = new AuthScope(
                    authhost.getHostName(),
                    authhost.getPort(),
                    authScheme.getRealm(),
                    authScheme.getSchemeName());

            final Credentials credentials = credsProvider.getCredentials(authScope);
            if (credentials != null) {
                options.add(new AuthOption(authScheme, credentials));
            }
        } else {
            if (this.log.isDebugEnabled()) {
                this.log.debug("Challenge for " + id + " authentication scheme not available");
                // Try again
            }
        }
    }
    return options;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:65,代码来源:AuthenticationStrategyImpl.java

示例14: BasicCredentialsProvider

import ch.boye.httpclientandroidlib.auth.Credentials; //导入依赖的package包/类
/**
 * Default constructor.
 */
public BasicCredentialsProvider() {
    super();
    this.credMap = new ConcurrentHashMap<AuthScope, Credentials>();
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:8,代码来源:BasicCredentialsProvider.java

示例15: setCredentials

import ch.boye.httpclientandroidlib.auth.Credentials; //导入依赖的package包/类
public void setCredentials(
        final AuthScope authscope,
        final Credentials credentials) {
    Args.notNull(authscope, "Authentication scope");
    credMap.put(authscope, credentials);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:7,代码来源:BasicCredentialsProvider.java


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