Package org.apache.http.auth

Examples of org.apache.http.auth.MalformedChallengeException


    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;
                    break; //that's our favourite, because auth-int is unsupported
                } 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");  
        }
       
        cnonce = createCnonce();  
        this.complete = true;
    }
View Full Code Here


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

        final HttpHost host = new HttpHost("somehost", 80);
        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");

        this.authState.setState(AuthProtocolState.CHALLENGED);

        Mockito.doThrow(new MalformedChallengeException()).when(this.authStrategy).getChallenges(
                Mockito.any(HttpHost.class),
                Mockito.any(HttpResponse.class),
                Mockito.any(HttpContext.class));

        Assert.assertFalse(this.httpAuthenticator.handleAuthChallenge(host,
View Full Code Here

  {
    BasicHeaderValueParser localBasicHeaderValueParser = BasicHeaderValueParser.DEFAULT;
    ParserCursor localParserCursor = new ParserCursor(paramInt1, paramCharArrayBuffer.length());
    HeaderElement[] arrayOfHeaderElement1 = localBasicHeaderValueParser.parseElements(paramCharArrayBuffer, localParserCursor);
    if (arrayOfHeaderElement1.length == 0)
      throw new MalformedChallengeException("Authentication challenge is empty");
    this.params.clear();
    for (HeaderElement localHeaderElement : arrayOfHeaderElement1)
      this.params.put(localHeaderElement.getName(), localHeaderElement.getValue());
  }
View Full Code Here

    if (str1.equalsIgnoreCase("WWW-Authenticate"))
      this.challengeState = ChallengeState.TARGET;
    else if (str1.equalsIgnoreCase("Proxy-Authenticate"))
      this.challengeState = ChallengeState.PROXY;
    else
      throw new MalformedChallengeException("Unexpected header name: " + str1);
    CharArrayBuffer localCharArrayBuffer;
    if ((paramHeader instanceof FormattedHeader))
    {
      localCharArrayBuffer = ((FormattedHeader)paramHeader).getBuffer();
      str2 = ((FormattedHeader)paramHeader).getValuePos();
    }
    else
    {
      str3 = paramHeader.getValue();
      if (str3 == null)
        throw new MalformedChallengeException("Header value is null");
      localCharArrayBuffer = new CharArrayBuffer(str3.length());
      localCharArrayBuffer.append(str3);
    }
    for (String str2 = 0; (str2 < localCharArrayBuffer.length()) && (HTTP.isWhitespace(localCharArrayBuffer.charAt(str2))); str2++);
    String str3 = str2;
    while ((str2 < localCharArrayBuffer.length()) && (!HTTP.isWhitespace(localCharArrayBuffer.charAt(str2))))
      str2++;
    int i = str2;
    String str4 = localCharArrayBuffer.substring(str3, i);
    if (!str4.equalsIgnoreCase(getSchemeName()))
      throw new MalformedChallengeException("Invalid scheme identifier: " + str4);
    parseChallenge(localCharArrayBuffer, str2, localCharArrayBuffer.length());
  }
View Full Code Here

      }
      else
      {
        str2 = localHeader.getValue();
        if (str2 == null)
          throw new MalformedChallengeException("Header value is null");
        localCharArrayBuffer = new CharArrayBuffer(str2.length());
        localCharArrayBuffer.append(str2);
      }
      for (String str1 = 0; (str1 < localCharArrayBuffer.length()) && (HTTP.isWhitespace(localCharArrayBuffer.charAt(str1))); str1++);
      String str2 = str1;
View Full Code Here

        if (authheader.equalsIgnoreCase(AUTH.WWW_AUTH)) {
            this.challengeState = ChallengeState.TARGET;
        } else if (authheader.equalsIgnoreCase(AUTH.PROXY_AUTH)) {
            this.challengeState = ChallengeState.PROXY;
        } 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 {
            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);
        if (!s.equalsIgnoreCase(getSchemeName())) {
            throw new MalformedChallengeException("Invalid scheme identifier: " + s);
        }

        parseChallenge(buffer, pos, buffer.length());
    }
View Full Code Here

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

            final CharArrayBuffer buffer, final int pos, final int len) throws MalformedChallengeException {
        final HeaderValueParser parser = BasicHeaderValueParser.INSTANCE;
        final ParserCursor cursor = new ParserCursor(pos, buffer.length());
        final HeaderElement[] elements = parser.parseElements(buffer, cursor);
        if (elements.length == 0) {
            throw new MalformedChallengeException("Authentication challenge is empty");
        }
        this.params.clear();
        for (final HeaderElement element : elements) {
            this.params.put(element.getName().toLowerCase(Locale.ENGLISH), element.getValue());
        }
View Full Code Here

TOP

Related Classes of org.apache.http.auth.MalformedChallengeException

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.