Example usage for org.apache.http.auth MalformedChallengeException MalformedChallengeException

List of usage examples for org.apache.http.auth MalformedChallengeException MalformedChallengeException

Introduction

In this page you can find the example usage for org.apache.http.auth MalformedChallengeException MalformedChallengeException.

Prototype

public MalformedChallengeException(final String message) 

Source Link

Document

Creates a new MalformedChallengeException with the specified message.

Usage

From source file:com.soundcloud.playerapi.OAuth2Scheme.java

@Override
public void processChallenge(Header header) throws MalformedChallengeException {
    if (header == null) {
        throw new IllegalArgumentException("Header may not be null");
    }/*from  www  .  ja  v a2s.com*/
    String authHeader = header.getName();
    if (!authHeader.equalsIgnoreCase(AUTH.WWW_AUTH)) {
        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);
    }
    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");
    }
    for (HeaderElement element : elements) {
        this.mParams.put(element.getName(), element.getValue());
    }
}

From source file:org.odk.collect.android.utilities.EnhancedDigestScheme.java

/**
 * Processes the Digest challenge./*from  www  .  java2  s . c o  m*/
 * 
 * @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 challenge");
    }
    if (getParameter("nonce") == null) {
        throw new MalformedChallengeException("missing nonce in challenge");
    }
    this.complete = true;
}

From source file:microsoft.exchange.webservices.data.EwsJCIFSNTLMScheme.java

/**
 * Processes the NTLM challenge./*from  w w  w . ja v  a  2 s .  c o  m*/
 * 
 * @param challenge
 *            the challenge string
 * 
 * @throws MalformedChallengeException
 *             is thrown if the authentication challenge is malformed
 *
 * @since 3.0
 */
public void processChallenge(final String challenge) throws MalformedChallengeException {

    String s = AuthChallengeParser.extractScheme(challenge);
    if (!s.equalsIgnoreCase(getSchemeName())) {
        throw new MalformedChallengeException("Invalid NTLM challenge: " + challenge);
    }
    int i = challenge.indexOf(' ');
    if (i != -1) {
        s = challenge.substring(i, challenge.length());
        this.ntlmchallenge = s.trim();
        this.state = TYPE2_MSG_RECEIVED;
    } else {
        this.ntlmchallenge = "";
        if (this.state == UNINITIATED) {
            this.state = INITIATED;
        } else {
            this.state = FAILED;
        }
    }
}

From source file:org.apache.http.impl.client.AbstractAuthenticationHandler.java

protected Map<String, Header> parseChallenges(final Header[] headers) throws MalformedChallengeException {

    final Map<String, Header> map = new HashMap<String, Header>(headers.length);
    for (final Header header : headers) {
        final CharArrayBuffer buffer;
        int pos;/*from w  w w.  ja v a  2 s . c o m*/
        if (header instanceof FormattedHeader) {
            buffer = ((FormattedHeader) header).getBuffer();
            pos = ((FormattedHeader) header).getValuePos();
        } else {
            final 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++;
        }
        final int beginIndex = pos;
        while (pos < buffer.length() && !HTTP.isWhitespace(buffer.charAt(pos))) {
            pos++;
        }
        final int endIndex = pos;
        final String s = buffer.substring(beginIndex, endIndex);
        map.put(s.toLowerCase(Locale.US), header);
    }
    return map;
}

From source file:org.apache.http.impl.client.AuthenticationStrategyImpl.java

public Map<String, Header> getChallenges(final HttpHost authhost, final HttpResponse response,
        final HttpContext context) throws MalformedChallengeException {
    Args.notNull(response, "HTTP response");
    final Header[] headers = response.getHeaders(this.headerName);
    final Map<String, Header> map = new HashMap<String, Header>(headers.length);
    for (final Header header : headers) {
        final CharArrayBuffer buffer;
        int pos;//  w  ww  .j av  a 2  s .c o m
        if (header instanceof FormattedHeader) {
            buffer = ((FormattedHeader) header).getBuffer();
            pos = ((FormattedHeader) header).getValuePos();
        } else {
            final 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++;
        }
        final int beginIndex = pos;
        while (pos < buffer.length() && !HTTP.isWhitespace(buffer.charAt(pos))) {
            pos++;
        }
        final int endIndex = pos;
        final String s = buffer.substring(beginIndex, endIndex);
        map.put(s.toLowerCase(Locale.US), header);
    }
    return map;
}