⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httpauthenticator.java

📁 Light in the box 抓取程序。 使用HttpClient
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     *   may be <tt>null</tt> if default credentials (not specific      *   to any particular host) are to be used     * @param state the HttpState object providing Credentials     *      * @return true if the <tt>Authenticate</tt> response header      *   was added     *      * @throws InvalidCredentialsException if authentication credentials     *         are not valid or not applicable for basic scheme     * @throws AuthenticationException when a parsing or other error occurs     *     * @see HttpState#setCredentials(String,String,Credentials)     *      * @deprecated use AuthScheme     */    public static boolean authenticateDefault(        HttpMethod method,         HttpConnection conn,        HttpState state)      throws AuthenticationException {        LOG.trace(            "enter HttpAuthenticator.authenticateDefault(HttpMethod, HttpConnection, HttpState)");        return doAuthenticateDefault(method, conn, state, false);    }    /**     * Attempt to provide default proxy authentication credentials      * to the given method in the given context using basic      * authentication scheme.     *      * @param method the HttpMethod which requires authentication     * @param conn the connection to a specific host. This parameter      *   may be <tt>null</tt> if default credentials (not specific      *   to any particular host) are to be used     * @param state the HttpState object providing Credentials     *      * @return true if the <tt>Proxy-Authenticate</tt> response header      *   was added     *      * @throws InvalidCredentialsException if authentication credentials     *         are not valid or not applicable for basic scheme     * @throws AuthenticationException when a parsing or other error occurs     * @see HttpState#setCredentials(String,String,Credentials)     *      * @deprecated use AuthScheme     */    public static boolean authenticateProxyDefault(        HttpMethod method,         HttpConnection conn,        HttpState state)      throws AuthenticationException {        LOG.trace("enter HttpAuthenticator.authenticateProxyDefault(HttpMethod, HttpState)");        return doAuthenticateDefault(method, conn, state, true);    }    private static boolean doAuthenticate(        AuthScheme authscheme,         HttpMethod method,         HttpConnection conn,        HttpState state,         boolean proxy)       throws AuthenticationException {        if (authscheme == null) {            throw new IllegalArgumentException("Authentication scheme may not be null");        }        if (method == null) {            throw new IllegalArgumentException("HTTP method may not be null");        }        if (state == null) {            throw new IllegalArgumentException("HTTP state may not be null");        }        String host = null;        if (conn != null) {            if (proxy) {                host = conn.getProxyHost();            } else {                host = method.getParams().getVirtualHost();                if (host == null) {                    host = conn.getHost();                }            }        }        String realm = authscheme.getRealm();        if (LOG.isDebugEnabled()) {            StringBuffer buffer = new StringBuffer();            buffer.append("Using credentials for ");            if (realm == null) {                buffer.append("default");            } else {                buffer.append('\'');                buffer.append(realm);                buffer.append('\'');            }            buffer.append(" authentication realm at ");             buffer.append(host);             LOG.debug(buffer.toString());        }        Credentials credentials = proxy             ? state.getProxyCredentials(realm, host)             : state.getCredentials(realm, host);        if (credentials == null) {            StringBuffer buffer = new StringBuffer();            buffer.append("No credentials available for the ");             if (realm == null) {                buffer.append("default");            } else {                buffer.append('\'');                buffer.append(realm);                buffer.append('\'');            }            buffer.append(" authentication realm at ");             buffer.append(host);             throw new CredentialsNotAvailableException(buffer.toString());        }        String auth = authscheme.authenticate(credentials, method);        if (auth != null) {            String s = proxy ? PROXY_AUTH_RESP : WWW_AUTH_RESP;            Header header = new Header(s, auth, true);            method.addRequestHeader(header);            return true;        } else {            return false;        }    }    /**     * Attempt to provide requisite authentication credentials to the      * given method in the given context using the given      * authentication scheme.     *      * @param authscheme The authentication scheme to be used     * @param method The HttpMethod which requires authentication     * @param conn the connection to a specific host. This parameter      *   may be <tt>null</tt> if default credentials (not specific      *   to any particular host) are to be used     * @param state The HttpState object providing Credentials     *      * @return true if the <tt>Authenticate</tt> response header was added     *      * @throws CredentialsNotAvailableException if authentication credentials     *         required to respond to the authentication challenge are not available     * @throws AuthenticationException when a parsing or other error occurs     * @see HttpState#setCredentials(String,String,Credentials)     *      * @deprecated use AuthScheme     */    public static boolean authenticate(        AuthScheme authscheme,         HttpMethod method,         HttpConnection conn,        HttpState state)         throws AuthenticationException {       LOG.trace(            "enter HttpAuthenticator.authenticate(AuthScheme, HttpMethod, HttpConnection, "            + "HttpState)");        return doAuthenticate(authscheme, method, conn, state, false);    }    /**     * Attempt to provide requisite proxy authentication credentials      * to the given method in the given context using      * the given authentication scheme.     *      * @param authscheme The authentication scheme to be used     * @param method the HttpMethod which requires authentication     * @param conn the connection to a specific host. This parameter      *   may be <tt>null</tt> if default credentials (not specific      *   to any particular host) are to be used     * @param state the HttpState object providing Credentials     *      * @return true if the <tt>Proxy-Authenticate</tt> response header      *  was added     *      * @throws CredentialsNotAvailableException if authentication credentials     *         required to respond to the authentication challenge are not available     * @throws AuthenticationException when a parsing or other error occurs     * @see HttpState#setCredentials(String,String,Credentials)     *      * @deprecated use AuthScheme     */    public static boolean authenticateProxy(        AuthScheme authscheme,         HttpMethod method,         HttpConnection conn,        HttpState state    ) throws AuthenticationException {       LOG.trace("enter HttpAuthenticator.authenticateProxy(AuthScheme, HttpMethod, HttpState)");       return doAuthenticate(authscheme, method, conn, state, true);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -