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


Java AuthState类代码示例

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


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

示例1: process

import ch.boye.httpclientandroidlib.auth.AuthState; //导入依赖的package包/类
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {
    Args.notNull(request, "HTTP request");
    Args.notNull(context, "HTTP context");

    final String method = request.getRequestLine().getMethod();
    if (method.equalsIgnoreCase("CONNECT")) {
        return;
    }

    if (request.containsHeader(AUTH.WWW_AUTH_RESP)) {
        return;
    }

    // Obtain authentication state
    final AuthState authState = (AuthState) context.getAttribute(
            ClientContext.TARGET_AUTH_STATE);
    if (authState == null) {
        this.log.debug("Target auth state not set in the context");
        return;
    }
    if (this.log.isDebugEnabled()) {
        this.log.debug("Target auth state: " + authState.getState());
    }
    process(authState, request, context);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:27,代码来源:RequestTargetAuthentication.java

示例2: doPreemptiveAuth

import ch.boye.httpclientandroidlib.auth.AuthState; //导入依赖的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

示例3: ProxyClient

import ch.boye.httpclientandroidlib.auth.AuthState; //导入依赖的package包/类
/**
 * @since 4.3
 */
public ProxyClient(
        final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory,
        final ConnectionConfig connectionConfig,
        final RequestConfig requestConfig) {
    super();
    this.connFactory = connFactory != null ? connFactory : ManagedHttpClientConnectionFactory.INSTANCE;
    this.connectionConfig = connectionConfig != null ? connectionConfig : ConnectionConfig.DEFAULT;
    this.requestConfig = requestConfig != null ? requestConfig : RequestConfig.DEFAULT;
    this.httpProcessor = new ImmutableHttpProcessor(
            new RequestTargetHost(), new RequestClientConnControl(), new RequestUserAgent());
    this.requestExec = new HttpRequestExecutor();
    this.proxyAuthStrategy = new ProxyAuthenticationStrategy();
    this.authenticator = new HttpAuthenticator();
    this.proxyAuthState = new AuthState();
    this.authSchemeRegistry = new AuthSchemeRegistry();
    this.authSchemeRegistry.register(AuthSchemes.BASIC, new BasicSchemeFactory());
    this.authSchemeRegistry.register(AuthSchemes.DIGEST, new DigestSchemeFactory());
    this.authSchemeRegistry.register(AuthSchemes.NTLM, new NTLMSchemeFactory());
    /* SPNegoSchemeFactory removed by HttpClient for Android script. */
    /* KerberosSchemeFactory removed by HttpClient for Android script. */
    this.reuseStrategy = new DefaultConnectionReuseStrategy();
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:26,代码来源:ProxyClient.java

示例4: setupContext

import ch.boye.httpclientandroidlib.auth.AuthState; //导入依赖的package包/类
private void setupContext(final HttpClientContext context) {
    if (context.getAttribute(HttpClientContext.TARGET_AUTH_STATE) == null) {
        context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, new AuthState());
    }
    if (context.getAttribute(HttpClientContext.PROXY_AUTH_STATE) == null) {
        context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, new AuthState());
    }
    if (context.getAttribute(HttpClientContext.AUTHSCHEME_REGISTRY) == null) {
        context.setAttribute(HttpClientContext.AUTHSCHEME_REGISTRY, this.authSchemeRegistry);
    }
    if (context.getAttribute(HttpClientContext.COOKIESPEC_REGISTRY) == null) {
        context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
    }
    if (context.getAttribute(HttpClientContext.COOKIE_STORE) == null) {
        context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
    }
    if (context.getAttribute(HttpClientContext.CREDS_PROVIDER) == null) {
        context.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credentialsProvider);
    }
    if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) {
        context.setAttribute(HttpClientContext.REQUEST_CONFIG, this.defaultConfig);
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:24,代码来源:InternalHttpClient.java

示例5: isCachable

import ch.boye.httpclientandroidlib.auth.AuthState; //导入依赖的package包/类
private boolean isCachable(final AuthState authState) {
    final AuthScheme authScheme = authState.getAuthScheme();
    if (authScheme == null || !authScheme.isComplete()) {
        return false;
    }
    final String schemeName = authScheme.getSchemeName();
    return schemeName.equalsIgnoreCase(AuthPolicy.BASIC) ||
            schemeName.equalsIgnoreCase(AuthPolicy.DIGEST);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:10,代码来源:ResponseAuthCache.java

示例6: process

import ch.boye.httpclientandroidlib.auth.AuthState; //导入依赖的package包/类
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {
    Args.notNull(request, "HTTP request");
    Args.notNull(context, "HTTP context");

    if (request.containsHeader(AUTH.PROXY_AUTH_RESP)) {
        return;
    }

    final HttpRoutedConnection conn = (HttpRoutedConnection) context.getAttribute(
            ExecutionContext.HTTP_CONNECTION);
    if (conn == null) {
        this.log.debug("HTTP connection not set in the context");
        return;
    }
    final HttpRoute route = conn.getRoute();
    if (route.isTunnelled()) {
        return;
    }

    // Obtain authentication state
    final AuthState authState = (AuthState) context.getAttribute(
            ClientContext.PROXY_AUTH_STATE);
    if (authState == null) {
        this.log.debug("Proxy auth state not set in the context");
        return;
    }
    if (this.log.isDebugEnabled()) {
        this.log.debug("Proxy auth state: " + authState.getState());
    }
    process(authState, request, context);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:33,代码来源:RequestProxyAuthentication.java

示例7: isAuthenticationRequested

import ch.boye.httpclientandroidlib.auth.AuthState; //导入依赖的package包/类
public boolean isAuthenticationRequested(
        final HttpHost host,
        final HttpResponse response,
        final AuthenticationStrategy authStrategy,
        final AuthState authState,
        final HttpContext context) {
    if (authStrategy.isAuthenticationRequested(host, response, context)) {
        this.log.debug("Authentication required");
        if (authState.getState() == AuthProtocolState.SUCCESS) {
            authStrategy.authFailed(host, authState.getAuthScheme(), context);
        }
        return true;
    } else {
        switch (authState.getState()) {
        case CHALLENGED:
        case HANDSHAKE:
            this.log.debug("Authentication succeeded");
            authState.setState(AuthProtocolState.SUCCESS);
            authStrategy.authSucceeded(host, authState.getAuthScheme(), context);
            break;
        case SUCCESS:
            break;
        default:
            authState.setState(AuthProtocolState.UNCHALLENGED);
        }
        return false;
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:29,代码来源:HttpAuthenticator.java

示例8: getUserToken

import ch.boye.httpclientandroidlib.auth.AuthState; //导入依赖的package包/类
public Object getUserToken(final HttpContext context) {

        final HttpClientContext clientContext = HttpClientContext.adapt(context);

        Principal userPrincipal = null;

        final AuthState targetAuthState = clientContext.getTargetAuthState();
        if (targetAuthState != null) {
            userPrincipal = getAuthPrincipal(targetAuthState);
            if (userPrincipal == null) {
                final AuthState proxyAuthState = clientContext.getProxyAuthState();
                userPrincipal = getAuthPrincipal(proxyAuthState);
            }
        }

        if (userPrincipal == null) {
            final HttpConnection conn = clientContext.getConnection();
            if (conn.isOpen() && conn instanceof ManagedHttpClientConnection) {
                final SSLSession sslsession = ((ManagedHttpClientConnection) conn).getSSLSession();
                if (sslsession != null) {
                    userPrincipal = sslsession.getLocalPrincipal();
                }
            }
        }

        return userPrincipal;
    }
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:28,代码来源:DefaultUserTokenHandler.java

示例9: getAuthPrincipal

import ch.boye.httpclientandroidlib.auth.AuthState; //导入依赖的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

示例10: authenticate

import ch.boye.httpclientandroidlib.auth.AuthState; //导入依赖的package包/类
public boolean authenticate (
        final HttpHost host,
        final HttpResponse response,
        final AuthenticationStrategy authStrategy,
        final AuthState authState,
        final HttpContext context) {
    return handleAuthChallenge(host, response, authStrategy, authState, context);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:9,代码来源:HttpAuthenticator.java

示例11: process

import ch.boye.httpclientandroidlib.auth.AuthState; //导入依赖的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

示例12: needAuthentication

import ch.boye.httpclientandroidlib.auth.AuthState; //导入依赖的package包/类
private boolean needAuthentication(
        final AuthState targetAuthState,
        final AuthState proxyAuthState,
        final HttpRoute route,
        final HttpResponse response,
        final HttpClientContext context) {
    final RequestConfig config = context.getRequestConfig();
    if (config.isAuthenticationEnabled()) {
        HttpHost target = context.getTargetHost();
        if (target == null) {
            target = route.getTargetHost();
        }
        if (target.getPort() < 0) {
            target = new HttpHost(
                    target.getHostName(),
                    route.getTargetHost().getPort(),
                    target.getSchemeName());
        }
        final boolean targetAuthRequested = this.authenticator.isAuthenticationRequested(
                target, response, this.targetAuthStrategy, targetAuthState, context);

        HttpHost proxy = route.getProxyHost();
        // if proxy is not set use target host instead
        if (proxy == null) {
            proxy = route.getTargetHost();
        }
        final boolean proxyAuthRequested = this.authenticator.isAuthenticationRequested(
                proxy, response, this.proxyAuthStrategy, proxyAuthState, context);

        if (targetAuthRequested) {
            return this.authenticator.handleAuthChallenge(target, response,
                    this.targetAuthStrategy, targetAuthState, context);
        }
        if (proxyAuthRequested) {
            return this.authenticator.handleAuthChallenge(proxy, response,
                    this.proxyAuthStrategy, proxyAuthState, context);
        }
    }
    return false;
}
 
开发者ID:jrconlin,项目名称:mc_backup,代码行数:41,代码来源:MainClientExec.java

示例13: getTargetAuthState

import ch.boye.httpclientandroidlib.auth.AuthState; //导入依赖的package包/类
public AuthState getTargetAuthState() {
    return getAttribute(TARGET_AUTH_STATE, AuthState.class);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:4,代码来源:HttpClientContext.java

示例14: getProxyAuthState

import ch.boye.httpclientandroidlib.auth.AuthState; //导入依赖的package包/类
public AuthState getProxyAuthState() {
    return getAttribute(PROXY_AUTH_STATE, AuthState.class);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:4,代码来源:HttpClientContext.java

示例15: handleAuthChallenge

import ch.boye.httpclientandroidlib.auth.AuthState; //导入依赖的package包/类
public boolean handleAuthChallenge(
        final HttpHost host,
        final HttpResponse response,
        final AuthenticationStrategy authStrategy,
        final AuthState authState,
        final HttpContext context) {
    try {
        if (this.log.isDebugEnabled()) {
            this.log.debug(host.toHostString() + " requested authentication");
        }
        final Map<String, Header> challenges = authStrategy.getChallenges(host, response, context);
        if (challenges.isEmpty()) {
            this.log.debug("Response contains no authentication challenges");
            return false;
        }

        final AuthScheme authScheme = authState.getAuthScheme();
        switch (authState.getState()) {
        case FAILURE:
            return false;
        case SUCCESS:
            authState.reset();
            break;
        case CHALLENGED:
        case HANDSHAKE:
            if (authScheme == null) {
                this.log.debug("Auth scheme is null");
                authStrategy.authFailed(host, null, context);
                authState.reset();
                authState.setState(AuthProtocolState.FAILURE);
                return false;
            }
        case UNCHALLENGED:
            if (authScheme != null) {
                final String id = authScheme.getSchemeName();
                final Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));
                if (challenge != null) {
                    this.log.debug("Authorization challenge processed");
                    authScheme.processChallenge(challenge);
                    if (authScheme.isComplete()) {
                        this.log.debug("Authentication failed");
                        authStrategy.authFailed(host, authState.getAuthScheme(), context);
                        authState.reset();
                        authState.setState(AuthProtocolState.FAILURE);
                        return false;
                    } else {
                        authState.setState(AuthProtocolState.HANDSHAKE);
                        return true;
                    }
                } else {
                    authState.reset();
                    // Retry authentication with a different scheme
                }
            }
        }
        final Queue<AuthOption> authOptions = authStrategy.select(challenges, host, response, context);
        if (authOptions != null && !authOptions.isEmpty()) {
            if (this.log.isDebugEnabled()) {
                this.log.debug("Selected authentication options: " + authOptions);
            }
            authState.setState(AuthProtocolState.CHALLENGED);
            authState.update(authOptions);
            return true;
        } else {
            return false;
        }
    } catch (final MalformedChallengeException ex) {
        if (this.log.isWarnEnabled()) {
            this.log.warn("Malformed challenge: " +  ex.getMessage());
        }
        authState.reset();
        return false;
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:75,代码来源:HttpAuthenticator.java


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