Domain d = prov.get(DomainBy.virtualHostname, hostHeader.toLowerCase()); if (d != null) user += "@" + d.getName();
    protected Account basicAuthRequest(HttpServletRequest req, HttpServletResponse resp, boolean sendChallenge)    throws IOException, ServiceException {        String auth = req.getHeader("Authorization");        // TODO: more liberal parsing of Authorization value...        if (auth == null || !auth.startsWith("Basic ")) {            if (sendChallenge) {                resp.addHeader(WWW_AUTHENTICATE_HEADER, getRealmHeader());                            resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, "must authenticate");            }            return null;        }        // 6 comes from "Basic ".length();        String userPass = new String(Base64.decodeBase64(auth.substring(6).getBytes()));        int loc = userPass.indexOf(":");         if (loc == -1) {            resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "invalid basic auth credentials");            return null;        }                String user = userPass.substring(0, loc);        String pass = userPass.substring(loc + 1);        Provisioning prov = Provisioning.getInstance();                if (user.indexOf('@') == -1) {            String hostHeader = req.getHeader("Host");            if (hostHeader != null && hostHeader.length() > 1) {                int i = hostHeader.indexOf(':');                if (i != -1) hostHeader = hostHeader.substring(0, i);            }            Domain d = prov.get(DomainBy.virtualHostname, hostHeader.toLowerCase());            if (d != null) user += "@" + d.getName();        }        Account acct = prov.get(AccountBy.name, user);        if (acct == null) {            if (sendChallenge) {                resp.addHeader(WWW_AUTHENTICATE_HEADER, getRealmHeader());                resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, "invalid username/password");            }            return new ACL.GuestAccount(user, pass);        }        try {            prov.authAccount(acct, pass, "http/basic");        } catch (ServiceException se) {            if (sendChallenge) {                resp.addHeader(WWW_AUTHENTICATE_HEADER, getRealmHeader());                resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, "invalid username/password");            }            return null;        }        return acct;    }