Package org.apache.mina.proxy

Examples of org.apache.mina.proxy.ProxyAuthException


    public void doHandshake(final NextFilter nextFilter)
            throws ProxyAuthException {
        logger.debug(" doHandshake()");

        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
View Full Code Here


     */
    @Override
    public void handleResponse(final HttpProxyResponse response)
            throws ProxyAuthException {
        if (response.getStatusCode() != 407) {
            throw new ProxyAuthException("Received error response code ("
                    + response.getStatusLine() + ").");
        }
    }
View Full Code Here

     */
    @Override
    public void handleResponse(final HttpProxyResponse response)
            throws ProxyAuthException {
        // Should never get here !
        throw new ProxyAuthException("Received error response code ("
                + response.getStatusLine() + ").");
    }
View Full Code Here

    @Override
    public void doHandshake(NextFilter nextFilter) throws ProxyAuthException {
        logger.debug(" doHandshake()");

        if (step > 0 && directives == null) {
            throw new ProxyAuthException(
                    "Authentication challenge not received");
        } else {
            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");

                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;
                        } else {
                            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 ");
View Full Code Here

        this.response = response;

        if (step == 0) {
            if (response.getStatusCode() != 401
                    && response.getStatusCode() != 407) {
                throw new ProxyAuthException(
                        "Received unexpected response code ("
                                + response.getStatusLine() + ").");
            }

            // Header should be like this
            // Proxy-Authenticate: Digest still_some_more_stuff
            List<String> values = response.getHeaders().get(
                    "Proxy-Authenticate");
            String challengeResponse = null;

            for (String s : values) {
                if (s.startsWith("Digest")) {
                    challengeResponse = s;
                    break;
                }
            }

            if (challengeResponse == null) {
                throw new ProxyAuthException(
                        "Server doesn't support digest authentication method !");
            }

            try {
                directives = StringUtilities.parseDirectives(challengeResponse
                        .substring(7).getBytes(proxyIoSession.getCharsetName()));
            } catch (Exception e) {
                throw new ProxyAuthException(
                        "Parsing of server digest directives failed", e);
            }
            step = 1;
        } else {
            throw new ProxyAuthException("Received unexpected response code ("
                    + response.getStatusLine() + ").");
        }
    }
View Full Code Here

            sb.append(propertyName).append(' ');
          }
      }
        if (sb.length() > 0) {
          sb.append("property(ies) missing in request");
          throw new ProxyAuthException(sb.toString());
        }
    }
View Full Code Here

        if (authHandler != null) {
            authHandler.doHandshake(nextFilter);
        } else {
            if (requestSent) {
                throw new ProxyAuthException(
                        "Authentication request already sent");
            }

            logger.debug("  sending HTTP request");
View Full Code Here

            }

        }

        if (authHandler == null) {
            throw new ProxyAuthException(
                    "Unknown authentication mechanism(s): " + values);
        }
    }
View Full Code Here

            if (authHandler == null) {
                autoSelectAuthHandler(response);
            }
            authHandler.handleResponse(response);
        } else {
            throw new ProxyAuthException("Received error response code ("
                    + response.getStatusLine() + ").");
        }
    }
View Full Code Here

            // Header should look like :
            // Proxy-Authenticate: NTLM still_some_more_stuff
            String challengeResponse = getNTLMHeader(response);

            if (challengeResponse == null || challengeResponse.length() < 5) {
                throw new ProxyAuthException(
                        "Unexpected error while reading server challenge !");
            }

            try {
                challengePacket = Base64
                        .decodeBase64(challengeResponse.substring(5).getBytes(
                                proxyIoSession.getCharsetName()));
            } catch (IOException e) {
                throw new ProxyAuthException(
                        "Unable to decode the base64 encoded NTLM challenge", e);
            }
            step = 2;
        } else {
            throw new ProxyAuthException("Received unexpected response code ("
                    + response.getStatusLine() + ").");
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.mina.proxy.ProxyAuthException

Copyright © 2018 www.massapicom. 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.