byte[] response = authenticator.buildChallengeReponse((byte[]) items[1]);
    public void authenticate(SVNRepositoryImpl repository) throws SVNException {        SVNErrorMessage failureReason = null;        Object[] items = read("[((*W)?S)]", null);        List mechs = SVNReader.getList(items, 0);        myRealm = SVNReader.getString(items, 1);        if (mechs == null || mechs.size() == 0) {            return;        }        ISVNAuthenticationManager authManager = myRepository.getAuthenticationManager();        if (authManager != null && authManager.isAuthenticationForced() && mechs.contains("ANONYMOUS") && mechs.contains("CRAM-MD5")) {            mechs.remove("ANONYMOUS");        }        SVNURL location = myRepository.getLocation();                SVNPasswordAuthentication auth = null;        if (repository.getExternalUserName() != null && mechs.contains("EXTERNAL")) {            write("(w(s))", new Object[] { "EXTERNAL", "" });            failureReason = readAuthResponse(repository);        } else if (mechs.contains("ANONYMOUS")) {            write("(w())", new Object[] { "ANONYMOUS" });            failureReason = readAuthResponse(repository);        } else if (mechs.contains("CRAM-MD5")) {            while (true) {                CramMD5 authenticator = new CramMD5();                String realm = getRealm();                if (location != null) {                    realm = "<" + location.getProtocol() + "://"                            + location.getHost() + ":"                            + location.getPort() + "> " + realm;                }                if (auth == null && authManager != null) {                    auth = (SVNPasswordAuthentication) authManager.getFirstAuthentication(ISVNAuthenticationManager.PASSWORD, realm, location);                } else if (authManager != null) {                    authManager.acknowledgeAuthentication(false, ISVNAuthenticationManager.PASSWORD, realm, failureReason, auth);                    auth = (SVNPasswordAuthentication) authManager.getNextAuthentication(ISVNAuthenticationManager.PASSWORD, realm, location);                }                if (auth == null || auth.getUserName() == null || auth.getPassword() == null) {                    failureReason = SVNErrorMessage.create(SVNErrorCode.RA_NOT_AUTHORIZED, "Authentication is required for ''{0}''", realm);                    break;                }                write("(w())", new Object[] { "CRAM-MD5" });                while (true) {                    authenticator.setUserCredentials(auth);                    items = read("(W(?B))", null);                    if (SUCCESS.equals(items[0])) {                        if (!myIsCredentialsReceived) {                            Object[] creds = read("[(S?S)]", null);                            if (creds != null && creds.length == 2                                    && creds[0] != null && creds[1] != null) {                                SVNURL rootURL = SVNURL.parseURIEncoded((String) creds[1]);                                 repository.updateCredentials((String) creds[0], rootURL);                                if (myRealm == null) {                                    myRealm = (String) creds[0];                                }                            }                            myIsCredentialsReceived = true;                        }                        authManager.acknowledgeAuthentication(true, ISVNAuthenticationManager.PASSWORD, realm, null, auth);                        return;                    } else if (FAILURE.equals(items[0])) {                        failureReason = SVNErrorMessage.create(SVNErrorCode.RA_NOT_AUTHORIZED, new String((byte[]) items[1]));                        break;                    } else if (STEP.equals(items[0])) {                        byte[] response = authenticator.buildChallengeReponse((byte[]) items[1]);                        try {                            getOutputStream().write(response);                            getOutputStream().flush();                        } catch (IOException e) {                            SVNErrorManager.error(SVNErrorMessage.create(SVNErrorCode.RA_SVN_IO_ERROR, e.getMessage()), e);                        }                     }                }            }        } else {            SVNErrorManager.error(SVNErrorMessage.create(SVNErrorCode.RA_UNKNOWN_AUTH));        }        if (failureReason == null) {            return;        }        SVNErrorManager.error(failureReason);    }