Java 类org.apache.commons.httpclient.auth.MalformedChallengeException 实例源码

项目:lib-commons-httpclient    文件:TestChallengeParser.java   
public void testParsingChallenge() {
    String challenge = 
      "Basic realm=\"realm1\", test, test1 =  stuff, test2 =  \"stuff, stuff\", test3=\"crap";
    String scheme = null;
    Map elements = null;
    try {
        scheme = AuthChallengeParser.extractScheme(challenge);
        elements = AuthChallengeParser.extractParams(challenge);
    } catch (MalformedChallengeException e) {
        fail("Unexpected exception: " + e.toString());
    }
    assertEquals("basic", scheme);
    assertEquals("realm1", elements.get("realm"));
    assertEquals(null, elements.get("test"));
    assertEquals("stuff", elements.get("test1"));
    assertEquals("stuff, stuff", elements.get("test2"));
    assertEquals("\"crap", elements.get("test3"));
}
项目:todopl    文件:EwsJCIFSNTLMScheme.java   
/**
 * Processes the NTLM challenge.
 * 
 * @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;
        }
    }
}
项目:httpclientAuthHelper    文件:CustomNTLM2Scheme.java   
protected void parseChallenge(
        final CharArrayBuffer buffer,
        int beginIndex, int endIndex) throws MalformedChallengeException {
    String challenge = buffer.substringTrimmed(beginIndex, endIndex);
    if (challenge.length() == 0) {
        if (this.state == State.UNINITIATED) {
            this.state = State.CHALLENGE_RECEIVED;
        } else {
            this.state = State.FAILED;
        }
        this.challenge = null;
    } else {
        this.state = State.MSG_TYPE2_RECEVIED;
        this.challenge = challenge;
    }
}
项目:httpclient3-ntml    文件:NTLMScheme.java   
/**
 * Processes the NTLM challenge.
 *
 * @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;
        }
    }

}
项目:httpclient3-ntml    文件:TestChallengeParser.java   
public void testParsingChallenge() {
    String challenge = 
      "Basic realm=\"realm1\", test, test1 =  stuff, test2 =  \"stuff, stuff\", test3=\"crap";
    String scheme = null;
    Map elements = null;
    try {
        scheme = AuthChallengeParser.extractScheme(challenge);
        elements = AuthChallengeParser.extractParams(challenge);
    } catch (MalformedChallengeException e) {
        fail("Unexpected exception: " + e.toString());
    }
    assertEquals("basic", scheme);
    assertEquals("realm1", elements.get("realm"));
    assertEquals(null, elements.get("test"));
    assertEquals("stuff", elements.get("test1"));
    assertEquals("stuff, stuff", elements.get("test2"));
    assertEquals("\"crap", elements.get("test3"));
}
项目:picframe    文件:BearerAuthScheme.java   
/**
 * Processes the Bearer challenge.
 *  
 * @param   challenge                   The challenge string
 * 
 * @throws MalformedChallengeException  Thrown if the authentication challenge is malformed
 */
public void processChallenge(String challenge) throws MalformedChallengeException {
    String s = AuthChallengeParser.extractScheme(challenge);
    if (!s.equalsIgnoreCase(getSchemeName())) {
        throw new MalformedChallengeException(
          "Invalid " + getSchemeName() + " challenge: " + challenge); 
    }
    mParams = AuthChallengeParser.extractParams(challenge);
    mComplete = true;
}
项目:lib-commons-httpclient    文件:CustomAuthenticationExample.java   
public void processChallenge(String challenge)
        throws MalformedChallengeException {
    // Nothing to do here, this is not a challenge based
    // auth scheme.  See NTLMScheme for a good example.
}
项目:httpclientAuthHelper    文件:CustomNTLM2SchemeBase.java   
/**
 * 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 authheader the challenge header
 *
 * @throws MalformedChallengeException is thrown if the authentication challenge
 * is malformed
 */
public void processChallenge(final String authheader) throws MalformedChallengeException {
    if (authheader == null) {
        throw new IllegalArgumentException("Header may not be null");
    }
    //String authheader = header.getName();
    /* TEST
    if (authheader.equalsIgnoreCase(WWW_AUTH)) {
        this.challengeState = ChallengeState.TARGET;
    } else if (authheader.equalsIgnoreCase(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 {
        String s = header.getValue();  */
    String s = authheader;
    if (s == null) {
        throw new MalformedChallengeException("Header value is null");
    }
    buffer = new CharArrayBuffer(s.length());
    buffer.append(s);
    pos = 0;
    //}
    while (pos < buffer.length() && EncodingUtils.isWhitespace(buffer.charAt(pos))) {
        pos++;
    }
    int beginIndex = pos;
    while (pos < buffer.length() && !EncodingUtils.isWhitespace(buffer.charAt(pos))) {
        pos++;
    }
    int endIndex = pos;
    String s2 = buffer.substring(beginIndex, endIndex);
    if (!s2.equalsIgnoreCase(getSchemeName())) {
        throw new MalformedChallengeException("Invalid scheme identifier: " + s2);
    }

    parseChallenge(buffer, pos, buffer.length());
}
项目:httpclientAuthHelper    文件:CustomNTLM2SchemeBase.java   
protected abstract void parseChallenge(
CharArrayBuffer buffer, int beginIndex, int endIndex) throws MalformedChallengeException;
项目:httpclient3-ntml    文件:NTLMScheme.java   
public NTLMScheme(final String challenge) throws MalformedChallengeException {
    super();
    processChallenge(challenge);
}
项目:httpclient3-ntml    文件:CustomAuthenticationExample.java   
public void processChallenge(String challenge)
        throws MalformedChallengeException {
    // Nothing to do here, this is not a challenge based
    // auth scheme.  See NTLMScheme for a good example.
}
项目:httpsig-java    文件:Http3SignatureAuthScheme.java   
@Override
public void processChallenge(String challenge) throws MalformedChallengeException {
    super.processChallenge(challenge);
    this.rotate = true;
}
项目:picframe    文件:BearerAuthScheme.java   
/**
 * Constructor for the basic authentication scheme.
 * 
 * @param   challenge                       Authentication challenge
 * 
 * @throws  MalformedChallengeException     Thrown if the authentication challenge is malformed
 * 
 * @deprecated Use parameterless constructor and {@link AuthScheme#processChallenge(String)} method
 */
public BearerAuthScheme(final String challenge) throws MalformedChallengeException {
    processChallenge(challenge);
    mComplete = true;
}
项目:RestServices    文件:JCIFS_NTLMScheme.java   
/**

        * Processes the NTLM challenge.

        *

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

                     }

              }

       }