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

BasicScheme

public class BasicScheme extends RFC2617Scheme

Basic authentication scheme as defined in RFC 2617.

author
Remy Maucherat
author
Rodney Waldhoff
author
Jeff Dever
author
Ortwin Glueck
author
Sean C. Sullivan
author
Adrian Sutton
author
Mike Bowler
author
Oleg Kalnichevski
since
4.0

Fields Summary
private boolean
complete
Whether the basic authentication process is complete
Constructors Summary
public BasicScheme()
Default constructor for the basic authetication scheme.

        super();
        this.complete = false;
    
Methods Summary
public org.apache.http.Headerauthenticate(org.apache.http.auth.Credentials credentials, org.apache.http.HttpRequest request)
Produces basic authorization header for the given set of {@link Credentials}.

param
credentials The set of credentials to be used for athentication
param
request The request being authenticated
throws
org.apache.http.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


        if (credentials == null) {
            throw new IllegalArgumentException("Credentials may not be null");
        }
        if (request == null) {
            throw new IllegalArgumentException("HTTP request may not be null");
        }
        
        String charset = AuthParams.getCredentialCharset(request.getParams());
        return authenticate(credentials, charset, isProxy());
    
public static org.apache.http.Headerauthenticate(org.apache.http.auth.Credentials credentials, java.lang.String charset, boolean proxy)
Returns a basic Authorization header value for the given {@link Credentials} and charset.

param
credentials The credentials to encode.
param
charset The charset to use for encoding the credentials
return
a basic authorization header

        if (credentials == null) {
            throw new IllegalArgumentException("Credentials may not be null"); 
        }
        if (charset == null) {
            throw new IllegalArgumentException("charset may not be null");
        }

        StringBuilder tmp = new StringBuilder();
        tmp.append(credentials.getUserPrincipal().getName());
        tmp.append(":");
        tmp.append((credentials.getPassword() == null) ? "null" : credentials.getPassword());

        byte[] base64password = Base64.encodeBase64(
                EncodingUtils.getBytes(tmp.toString(), charset));
        
        CharArrayBuffer buffer = new CharArrayBuffer(32);
        if (proxy) {
            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);
    
public java.lang.StringgetSchemeName()
Returns textual designation of the basic authentication scheme.

return
basic

        return "basic";
    
public booleanisComplete()
Tests if the Basic authentication process has been completed.

return
true if Basic authorization has been processed, false otherwise.

        return this.complete;
    
public booleanisConnectionBased()
Returns false. Basic authentication scheme is request based.

return
false.

        return false;    
    
public voidprocessChallenge(org.apache.http.Header header)
Processes the Basic challenge.

param
header the challenge header
throws
MalformedChallengeException is thrown if the authentication challenge is malformed

        super.processChallenge(header);
        this.complete = true;