Examples of HttpProxyRequest


Examples of org.apache.mina.proxy.handlers.http.HttpProxyRequest

        if (step > 0 && challengePacket == null) {
            throw new IllegalStateException("NTLM Challenge packet not received");
        }
       
        HttpProxyRequest req = (HttpProxyRequest) request;
        Map<String, List<String>> headers = req.getHeaders() != null ? req
                .getHeaders() : new HashMap<String, List<String>>();

        String domain = req.getProperties().get(
                HttpProxyConstants.DOMAIN_PROPERTY);
        String workstation = req.getProperties().get(
                HttpProxyConstants.WORKSTATION_PROPERTY);

        if (step > 0) {
            LOGGER.debug("  sending NTLM challenge response");

            byte[] challenge = NTLMUtilities
                    .extractChallengeFromType2Message(challengePacket);
            int serverFlags = NTLMUtilities
                    .extractFlagsFromType2Message(challengePacket);

            String username = req.getProperties().get(
                    HttpProxyConstants.USER_PROPERTY);
            String password = req.getProperties().get(
                    HttpProxyConstants.PWD_PROPERTY);

            byte[] authenticationPacket = NTLMUtilities.createType3Message(
                    username, password, challenge, domain, workstation,
                    serverFlags, null);

                StringUtilities.addValueToHeader(headers,
                        "Proxy-Authorization",
                        "NTLM "+ new String(Base64
                                        .encodeBase64(authenticationPacket)),
                        true);

            } else {
                LOGGER.debug("  sending NTLM negotiation packet");

                byte[] negotiationPacket = NTLMUtilities.createType1Message(
                        workstation, domain, null, null);
                StringUtilities
                        .addValueToHeader(
                                headers,
                                "Proxy-Authorization",
                                "NTLM "+ new String(Base64
                                          .encodeBase64(negotiationPacket)),
                                true);
            }

            addKeepAliveHeaders(headers);
            req.setHeaders(headers);

        writeRequest(nextFilter, req);
        step++;
    }
View Full Code Here

Examples of org.apache.mina.proxy.handlers.http.HttpProxyRequest

        if (step > 0) {
            throw new ProxyAuthException("Authentication request already sent");
        }

        // Send request
        HttpProxyRequest req = (HttpProxyRequest) request;
        Map<String, List<String>> headers = req.getHeaders() != null ? req
                .getHeaders() : new HashMap<String, List<String>>();

        String username = req.getProperties().get(
                HttpProxyConstants.USER_PROPERTY);
        String password = req.getProperties().get(
                HttpProxyConstants.PWD_PROPERTY);

        StringUtilities.addValueToHeader(headers, "Proxy-Authorization",
                "Basic " + createAuthorization(username, password), true);

        addKeepAliveHeaders(headers);
        req.setHeaders(headers);

        writeRequest(nextFilter, req);
        step++;
    }
View Full Code Here

Examples of org.apache.mina.proxy.handlers.http.HttpProxyRequest

        if (step > 0 && directives == null) {
            throw new ProxyAuthException(
                    "Authentication challenge not received");
        }
       
        HttpProxyRequest req = (HttpProxyRequest) request;
        Map<String, List<String>> headers = req.getHeaders() != null ? req
                .getHeaders() : new HashMap<String, List<String>>();

        if (step > 0) {
            logger.debug("  sending DIGEST challenge response");

            // Build a challenge response
            HashMap<String, String> map = new HashMap<String, String>();
            map.put("username", req.getProperties().get(
                    HttpProxyConstants.USER_PROPERTY));
            StringUtilities.copyDirective(directives, map, "realm");
            StringUtilities.copyDirective(directives, map, "uri");
            StringUtilities.copyDirective(directives, map, "opaque");
            StringUtilities.copyDirective(directives, map, "nonce");
            String algorithm = StringUtilities.copyDirective(directives,
                    map, "algorithm");

            // Check for a supported algorithm
            if (algorithm != null && !"md5".equalsIgnoreCase(algorithm)
                    && !"md5-sess".equalsIgnoreCase(algorithm)) {
                throw new ProxyAuthException(
                        "Unknown algorithm required by server");
            }

            // Check for a supported qop
            String qop = directives.get("qop");
            if (qop != null) {
                StringTokenizer st = new StringTokenizer(qop, ",");
                String token = null;

                while (st.hasMoreTokens()) {
                    String tk = st.nextToken();
                    if ("auth".equalsIgnoreCase(token)) {
                        break;
                    }

                    int pos = Arrays.binarySearch(
                            DigestUtilities.SUPPORTED_QOPS, tk);
                    if (pos > -1) {
                        token = tk;
                    }
                }

                if (token != null) {
                    map.put("qop", token);

                    byte[] nonce = new byte[8];
                    rnd.nextBytes(nonce);

                    try {
                        String cnonce = new String(Base64
                                .encodeBase64(nonce), proxyIoSession
                                .getCharsetName());
                        map.put("cnonce", cnonce);
                    } catch (UnsupportedEncodingException e) {
                        throw new ProxyAuthException(
                                "Unable to encode cnonce", e);
                    }
                } else {
                    throw new ProxyAuthException(
                            "No supported qop option available");
                }
            }

            map.put("nc", "00000001");
            map.put("uri", req.getHttpURI());

            // Compute the response
            try {
                map.put("response", DigestUtilities
                        .computeResponseValue(proxyIoSession.getSession(),
                                map, req.getHttpVerb().toUpperCase(),
                                req.getProperties().get(
                                        HttpProxyConstants.PWD_PROPERTY),
                                proxyIoSession.getCharsetName(), response
                                        .getBody()));

            } catch (Exception e) {
                throw new ProxyAuthException(
                        "Digest response computing failed", e);
            }

            // Prepare the challenge response header and add it to the
            // request we will send
            StringBuilder sb = new StringBuilder("Digest ");
            boolean addSeparator = false;

            for (String key : map.keySet()) {

                if (addSeparator) {
                    sb.append(", ");
                } else {
                    addSeparator = true;
                }

                boolean quotedValue = !"qop".equals(key)
                        && !"nc".equals(key);
                sb.append(key);
                if (quotedValue) {
                    sb.append("=\"").append(map.get(key)).append('\"');
                } else {
                    sb.append('=').append(map.get(key));
                }
            }

            StringUtilities.addValueToHeader(headers,
                    "Proxy-Authorization", sb.toString(), true);
        }

        addKeepAliveHeaders(headers);
        req.setHeaders(headers);

        writeRequest(nextFilter, req);
        step++;
    }
View Full Code Here

Examples of org.apache.mina.proxy.handlers.http.HttpProxyRequest

                SocksProxyConstants.SOCKS_VERSION_5,
                SocksProxyConstants.ESTABLISH_TCPIP_STREAM, serverAddress, USER);
        req.setPassword(PWD);
        */

        HttpProxyRequest req = new HttpProxyRequest(serverAddress);
        HashMap<String, String> props = new HashMap<String, String>();
        props.put(HttpProxyConstants.USER_PROPERTY, USER);
        props.put(HttpProxyConstants.PWD_PROPERTY, PWD);
        req.setProperties(props);       

        ProxyIoSession proxyIoSession = new ProxyIoSession(proxyAddress, req);
        connector.setProxyIoSession(proxyIoSession);

        LineDelimiter delim = new LineDelimiter("\r\n");
View Full Code Here

Examples of org.apache.mina.proxy.handlers.http.HttpProxyRequest

     *
     * @param uri the requested uri to connect to through the HTTP proxy
     * @return the fully initialized {@link HttpProxyRequest} object
     */
    private HttpProxyRequest createHttpProxyRequest(String uri) {
        HttpProxyRequest req = new HttpProxyRequest(uri);
        HashMap<String, String> props = new HashMap<String, String>();
        props.put(HttpProxyConstants.USER_PROPERTY, USER);
        props.put(HttpProxyConstants.PWD_PROPERTY, PWD);
        props.put(HttpProxyConstants.DOMAIN_PROPERTY, DOMAIN);
        props.put(HttpProxyConstants.WORKSTATION_PROPERTY, WORKSTATION);

        req.setProperties(props);
        if (USE_HTTP_1_1) {
            req.setHttpVersion(HttpProxyConstants.HTTP_1_1);
        }

        return req;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.