You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by "Park, Sung-Gu" <je...@thinkfree.com> on 2000/12/05 23:35:16 UTC

Authenticator.java

It's my digest scheme patch for  Authorization.


============================================

public class Authenticator {


    protected static Base64 base64 = new Base64();


    public static String challengeResponse(String challenge,
                                           Credentials credentials)
        throws WebdavException {

        if (challenge.startsWith("Basic")) {
            return basic(credentials);
        } else if (challenge.startsWith("Digest")) {
            throw new WebdavException("Unable to authenticate for Digest");
        }
        return null;

    }

    public static String challengeResponse(String challenge,
                                           Credentials credentials,
                                           String path)
        throws WebdavException {

        if (challenge.startsWith("Basic")) {
            return basic(credentials);
        } else if (challenge.startsWith("Digest")) {
            int indx = challenge.indexOf("realm");
// FIX ME: in the secure communication, it's possbile to have a problem.
            String realm = challenge.substring(indx);
            return digest(credentials, realm, path);
        }
        return null;
    }


    public static String digest(Credentials credentials, String realm,
                                String path) {

        String authString =
            "Digest username=\"" + credentials.getUserName() + "\", " +
            "realm=\"" + realm + "\", nonce=\"...\", " +
            "uri=\"" + path + "\", " +
            "response=\"...\", opaque=\"...\"";

        return authString;
    }

<snip>