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

BasicCredentialsProvider

public class BasicCredentialsProvider extends Object implements CredentialsProvider
Default implementation of {@link CredentialsProvider}
author
Remy Maucherat
author
Rodney Waldhoff
author
Jeff Dever
author
Sean C. Sullivan
author
Michael Becke
author
Oleg Kalnichevski
author
Mike Bowler
author
Adrian Sutton
since
4.0

Fields Summary
private final HashMap
credMap
Constructors Summary
public BasicCredentialsProvider()
Default constructor.

        super();
        this.credMap = new HashMap<AuthScope, Credentials>();
    
Methods Summary
public synchronized voidclear()
Clears all credentials.

        this.credMap.clear();
    
public synchronized org.apache.http.auth.CredentialsgetCredentials(org.apache.http.auth.AuthScope authscope)
Get the {@link Credentials credentials} for the given authentication scope.

param
authscope the {@link AuthScope authentication scope}
return
the credentials
see
#setCredentials(AuthScope, Credentials)

        if (authscope == null) {
            throw new IllegalArgumentException("Authentication scope may not be null");
        }
        return matchCredentials(this.credMap, authscope);
    
private static org.apache.http.auth.CredentialsmatchCredentials(java.util.HashMap map, org.apache.http.auth.AuthScope authscope)
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

        // 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 (AuthScope current: map.keySet()) {
                int factor = authscope.match(current);
                if (factor > bestMatchFactor) {
                    bestMatchFactor = factor;
                    bestMatch = current;
                }
            }
            if (bestMatch != null) {
                creds = map.get(bestMatch);
            }
        }
        return creds;
    
public synchronized voidsetCredentials(org.apache.http.auth.AuthScope authscope, org.apache.http.auth.Credentials credentials)
Sets the {@link Credentials credentials} for the given authentication scope. Any previous credentials for the given scope will be overwritten.

param
authscope the {@link AuthScope authentication scope}
param
credentials the authentication {@link Credentials credentials} for the given scope.
see
#getCredentials(AuthScope)

        if (authscope == null) {
            throw new IllegalArgumentException("Authentication scope may not be null");
        }
        credMap.put(authscope, credentials);
    
public java.lang.StringtoString()

        return credMap.toString();