Package org.apache.mina.proxy

Examples of org.apache.mina.proxy.ProxyAuthException


        if (authHandler != null) {
            authHandler.doHandshake(nextFilter);
        } else {
            if (requestSent) {
                // Safety check
                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("Error: unexpected response code "
                    + response.getStatusLine() + " received from proxy.");
        }
    }
View Full Code Here

        } catch (Exception ex) {
            if (ex instanceof ProxyAuthException) {
                throw ((ProxyAuthException) ex);
            }

            throw new ProxyAuthException("Handshake failed", ex);
        }
    }
View Full Code Here

    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 doHandshake(NextFilter nextFilter) throws ProxyAuthException {
        logger.debug(" doHandshake()");

        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
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 look 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

     */
    @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

        } catch (Exception ex) {
            if (ex instanceof ProxyAuthException) {
                throw ((ProxyAuthException) ex);
            }

            throw new ProxyAuthException("Handshake failed", ex);
        }
    }
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.