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")); }
/** * 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; } } }
/** * 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; }