Search in sources :

Example 1 with MalformedChallengeException

use of org.apache.http.auth.MalformedChallengeException in project platform_external_apache-http by android.

the class DigestScheme method processChallenge.

/**
     * Processes the Digest challenge.
     *  
     * @param header the challenge header
     * 
     * @throws MalformedChallengeException is thrown if the authentication challenge
     * is malformed
     */
@Override
public void processChallenge(final Header header) throws MalformedChallengeException {
    super.processChallenge(header);
    if (getParameter("realm") == null) {
        throw new MalformedChallengeException("missing realm in challange");
    }
    if (getParameter("nonce") == null) {
        throw new MalformedChallengeException("missing nonce in challange");
    }
    boolean unsupportedQop = false;
    // qop parsing
    String qop = getParameter("qop");
    if (qop != null) {
        StringTokenizer tok = new StringTokenizer(qop, ",");
        while (tok.hasMoreTokens()) {
            String variant = tok.nextToken().trim();
            if (variant.equals("auth")) {
                qopVariant = QOP_AUTH;
                //that's our favourite, because auth-int is unsupported
                break;
            } else if (variant.equals("auth-int")) {
                qopVariant = QOP_AUTH_INT;
            } else {
                unsupportedQop = true;
            }
        }
    }
    if (unsupportedQop && (qopVariant == QOP_MISSING)) {
        throw new MalformedChallengeException("None of the qop methods is supported");
    }
    // Reset cnonce
    this.cnonce = null;
    this.complete = true;
}
Also used : StringTokenizer(java.util.StringTokenizer) MalformedChallengeException(org.apache.http.auth.MalformedChallengeException)

Example 2 with MalformedChallengeException

use of org.apache.http.auth.MalformedChallengeException in project platform_external_apache-http by android.

the class RFC2617Scheme method parseChallenge.

@Override
protected void parseChallenge(final CharArrayBuffer buffer, int pos, int len) throws MalformedChallengeException {
    HeaderValueParser parser = BasicHeaderValueParser.DEFAULT;
    ParserCursor cursor = new ParserCursor(pos, buffer.length());
    HeaderElement[] elements = parser.parseElements(buffer, cursor);
    if (elements.length == 0) {
        throw new MalformedChallengeException("Authentication challenge is empty");
    }
    this.params = new HashMap<String, String>(elements.length);
    for (HeaderElement element : elements) {
        this.params.put(element.getName(), element.getValue());
    }
}
Also used : ParserCursor(org.apache.http.message.ParserCursor) HeaderElement(org.apache.http.HeaderElement) HeaderValueParser(org.apache.http.message.HeaderValueParser) BasicHeaderValueParser(org.apache.http.message.BasicHeaderValueParser) MalformedChallengeException(org.apache.http.auth.MalformedChallengeException)

Example 3 with MalformedChallengeException

use of org.apache.http.auth.MalformedChallengeException in project platform_external_apache-http by android.

the class AbstractAuthenticationHandler method parseChallenges.

protected Map<String, Header> parseChallenges(final Header[] headers) throws MalformedChallengeException {
    Map<String, Header> map = new HashMap<String, Header>(headers.length);
    for (Header header : headers) {
        CharArrayBuffer buffer;
        int pos;
        if (header instanceof FormattedHeader) {
            buffer = ((FormattedHeader) header).getBuffer();
            pos = ((FormattedHeader) header).getValuePos();
        } else {
            String s = header.getValue();
            if (s == null) {
                throw new MalformedChallengeException("Header value is null");
            }
            buffer = new CharArrayBuffer(s.length());
            buffer.append(s);
            pos = 0;
        }
        while (pos < buffer.length() && HTTP.isWhitespace(buffer.charAt(pos))) {
            pos++;
        }
        int beginIndex = pos;
        while (pos < buffer.length() && !HTTP.isWhitespace(buffer.charAt(pos))) {
            pos++;
        }
        int endIndex = pos;
        String s = buffer.substring(beginIndex, endIndex);
        map.put(s.toLowerCase(Locale.ENGLISH), header);
    }
    return map;
}
Also used : Header(org.apache.http.Header) FormattedHeader(org.apache.http.FormattedHeader) HashMap(java.util.HashMap) CharArrayBuffer(org.apache.http.util.CharArrayBuffer) MalformedChallengeException(org.apache.http.auth.MalformedChallengeException) FormattedHeader(org.apache.http.FormattedHeader)

Example 4 with MalformedChallengeException

use of org.apache.http.auth.MalformedChallengeException in project platform_external_apache-http by android.

the class AuthSchemeBase method processChallenge.

/**
     * Processes the given challenge token. Some authentication schemes
     * may involve multiple challenge-response exchanges. Such schemes must be able 
     * to maintain the state information when dealing with sequential challenges 
     * 
     * @param header the challenge header
     * 
     * @throws MalformedChallengeException is thrown if the authentication challenge
     * is malformed
     */
public void processChallenge(final Header header) throws MalformedChallengeException {
    if (header == null) {
        throw new IllegalArgumentException("Header may not be null");
    }
    String authheader = header.getName();
    if (authheader.equalsIgnoreCase(AUTH.WWW_AUTH)) {
        this.proxy = false;
    } else if (authheader.equalsIgnoreCase(AUTH.PROXY_AUTH)) {
        this.proxy = true;
    } else {
        throw new MalformedChallengeException("Unexpected header name: " + authheader);
    }
    CharArrayBuffer buffer;
    int pos;
    if (header instanceof FormattedHeader) {
        buffer = ((FormattedHeader) header).getBuffer();
        pos = ((FormattedHeader) header).getValuePos();
    } else {
        String s = header.getValue();
        if (s == null) {
            throw new MalformedChallengeException("Header value is null");
        }
        buffer = new CharArrayBuffer(s.length());
        buffer.append(s);
        pos = 0;
    }
    while (pos < buffer.length() && HTTP.isWhitespace(buffer.charAt(pos))) {
        pos++;
    }
    int beginIndex = pos;
    while (pos < buffer.length() && !HTTP.isWhitespace(buffer.charAt(pos))) {
        pos++;
    }
    int endIndex = pos;
    String s = buffer.substring(beginIndex, endIndex);
    if (!s.equalsIgnoreCase(getSchemeName())) {
        throw new MalformedChallengeException("Invalid scheme identifier: " + s);
    }
    parseChallenge(buffer, pos, buffer.length());
}
Also used : CharArrayBuffer(org.apache.http.util.CharArrayBuffer) MalformedChallengeException(org.apache.http.auth.MalformedChallengeException) FormattedHeader(org.apache.http.FormattedHeader)

Example 5 with MalformedChallengeException

use of org.apache.http.auth.MalformedChallengeException in project robovm by robovm.

the class AbstractAuthenticationHandler method parseChallenges.

protected Map<String, Header> parseChallenges(final Header[] headers) throws MalformedChallengeException {
    Map<String, Header> map = new HashMap<String, Header>(headers.length);
    for (Header header : headers) {
        CharArrayBuffer buffer;
        int pos;
        if (header instanceof FormattedHeader) {
            buffer = ((FormattedHeader) header).getBuffer();
            pos = ((FormattedHeader) header).getValuePos();
        } else {
            String s = header.getValue();
            if (s == null) {
                throw new MalformedChallengeException("Header value is null");
            }
            buffer = new CharArrayBuffer(s.length());
            buffer.append(s);
            pos = 0;
        }
        while (pos < buffer.length() && HTTP.isWhitespace(buffer.charAt(pos))) {
            pos++;
        }
        int beginIndex = pos;
        while (pos < buffer.length() && !HTTP.isWhitespace(buffer.charAt(pos))) {
            pos++;
        }
        int endIndex = pos;
        String s = buffer.substring(beginIndex, endIndex);
        map.put(s.toLowerCase(Locale.ENGLISH), header);
    }
    return map;
}
Also used : Header(org.apache.http.Header) FormattedHeader(org.apache.http.FormattedHeader) HashMap(java.util.HashMap) CharArrayBuffer(org.apache.http.util.CharArrayBuffer) MalformedChallengeException(org.apache.http.auth.MalformedChallengeException) FormattedHeader(org.apache.http.FormattedHeader)

Aggregations

MalformedChallengeException (org.apache.http.auth.MalformedChallengeException)13 FormattedHeader (org.apache.http.FormattedHeader)6 CharArrayBuffer (org.apache.http.util.CharArrayBuffer)6 Header (org.apache.http.Header)4 HashMap (java.util.HashMap)3 StringTokenizer (java.util.StringTokenizer)3 HeaderElement (org.apache.http.HeaderElement)3 BasicHeaderValueParser (org.apache.http.message.BasicHeaderValueParser)3 HeaderValueParser (org.apache.http.message.HeaderValueParser)3 ParserCursor (org.apache.http.message.ParserCursor)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 CreateRepositoryDTO (io.fabric8.gerrit.CreateRepositoryDTO)1 IOException (java.io.IOException)1 ConnectException (java.net.ConnectException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 HttpEntity (org.apache.http.HttpEntity)1 HttpResponse (org.apache.http.HttpResponse)1 AuthenticationException (org.apache.http.auth.AuthenticationException)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1