FileDocCategorySizeDatePackage
NTLMScheme.javaAPI DocAndroid 1.5 API5329Wed May 06 22:41:10 BST 2009org.apache.http.impl.auth

NTLMScheme

public class NTLMScheme extends AuthSchemeBase

Fields Summary
private final NTLMEngine
engine
private State
state
private String
challenge
Constructors Summary
public NTLMScheme(NTLMEngine engine)

        super();
        if (engine == null) {
            throw new IllegalArgumentException("NTLM engine may not be null");
        }
        this.engine = engine;
        this.state = State.UNINITIATED;
        this.challenge = null;
    
Methods Summary
public org.apache.http.Headerauthenticate(org.apache.http.auth.Credentials credentials, org.apache.http.HttpRequest request)

        NTCredentials ntcredentials = null;
        try {
            ntcredentials = (NTCredentials) credentials;
        } catch (ClassCastException e) {
            throw new InvalidCredentialsException(
             "Credentials cannot be used for NTLM authentication: " 
              + credentials.getClass().getName());
        }
        String response = null;
        if (this.state == State.CHALLENGE_RECEIVED || this.state == State.FAILED) {
            response = this.engine.generateType1Msg(
                    ntcredentials.getDomain(), 
                    ntcredentials.getWorkstation());
            this.state = State.MSG_TYPE1_GENERATED;
        } else if (this.state == State.MSG_TYPE2_RECEVIED) {
            response = this.engine.generateType3Msg(
                    ntcredentials.getUserName(), 
                    ntcredentials.getPassword(), 
                    ntcredentials.getDomain(), 
                    ntcredentials.getWorkstation(),
                    this.challenge);
            this.state = State.MSG_TYPE3_GENERATED;
        } else {
            throw new AuthenticationException("Unexpected state: " + this.state);
        }
        CharArrayBuffer buffer = new CharArrayBuffer(32);
        if (isProxy()) {
            buffer.append(AUTH.PROXY_AUTH_RESP);
        } else {
            buffer.append(AUTH.WWW_AUTH_RESP);
        }
        buffer.append(": NTLM ");
        buffer.append(response);
        return new BufferedHeader(buffer);
    
public java.lang.StringgetParameter(java.lang.String name)

        // String parameters not supported
        return null;
    
public java.lang.StringgetRealm()

        // NTLM does not support the concept of an authentication realm
        return null;
    
public java.lang.StringgetSchemeName()

        return "ntlm";
    
public booleanisComplete()

        return this.state == State.MSG_TYPE3_GENERATED || this.state == State.FAILED;
    
public booleanisConnectionBased()

        return true;
    
protected voidparseChallenge(org.apache.http.util.CharArrayBuffer buffer, int pos, int len)

        String challenge = buffer.substringTrimmed(pos, len);
        if (challenge.length() == 0) {
            if (this.state == State.UNINITIATED) {
                this.state = State.CHALLENGE_RECEIVED;
            } else {
                this.state = State.FAILED;
            }
            this.challenge = null;
        } else {
            this.state = State.MSG_TYPE2_RECEVIED;
            this.challenge = challenge;
        }