FileDocCategorySizeDatePackage
DefaultUserTokenHandler.javaAPI DocAndroid 1.5 API3489Wed May 06 22:41:10 BST 2009org.apache.http.impl.client

DefaultUserTokenHandler

public class DefaultUserTokenHandler extends Object implements UserTokenHandler

Fields Summary
Constructors Summary
Methods Summary
private static java.security.PrincipalgetAuthPrincipal(org.apache.http.auth.AuthState authState)

        AuthScheme scheme = authState.getAuthScheme();
        if (scheme != null && scheme.isComplete() && scheme.isConnectionBased()) {
            Credentials creds = authState.getCredentials();
            if (creds != null) {
                return creds.getUserPrincipal(); 
            }
        }
        return null;
    
public java.lang.ObjectgetUserToken(org.apache.http.protocol.HttpContext context)

        
        Principal userPrincipal = null;
        
        AuthState targetAuthState = (AuthState) context.getAttribute(
                ClientContext.TARGET_AUTH_STATE);
        if (targetAuthState != null) {
            userPrincipal = getAuthPrincipal(targetAuthState);
            if (userPrincipal == null) {
                AuthState proxyAuthState = (AuthState) context.getAttribute(
                        ClientContext.PROXY_AUTH_STATE);
                userPrincipal = getAuthPrincipal(proxyAuthState);
            }
        }
        
        if (userPrincipal == null) {
            ManagedClientConnection conn = (ManagedClientConnection) context.getAttribute(
                    ExecutionContext.HTTP_CONNECTION);
            if (conn.isOpen()) {
                SSLSession sslsession = conn.getSSLSession();
                if (sslsession != null) {
                    userPrincipal = sslsession.getLocalPrincipal();
                }
            }
        }
        
        return userPrincipal;