/** * Extracts authentication scheme from the given authentication * challenge. * * @param challengeStr the authentication challenge string * @return authentication scheme * * @throws MalformedChallengeException when the authentication challenge string * is malformed * * @since 2.0beta1 */ public static String extractScheme(final String challengeStr) throws MalformedChallengeException { if (challengeStr == null) { throw new IllegalArgumentException("Challenge may not be null"); } int idx = challengeStr.indexOf(' '); String s = null; if (idx == -1) { s = challengeStr; } else { s = challengeStr.substring(0, idx); } if (s.equals("")) { throw new MalformedChallengeException("Invalid challenge: " + challengeStr); } return s.toLowerCase(); }
/** * 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; } } }
throw new MalformedChallengeException("missing realm in challange"); throw new MalformedChallengeException("missing nonce in challange"); throw new MalformedChallengeException("None of the qop methods is supported");
/** * Extracts a map of challenge parameters from an authentication challenge. * Keys in the map are lower-cased * * @param challengeStr the authentication challenge string * @return a map of authentication challenge parameters * @throws MalformedChallengeException when the authentication challenge string * is malformed * * @since 2.0beta1 */ public static Map extractParams(final String challengeStr) throws MalformedChallengeException { if (challengeStr == null) { throw new IllegalArgumentException("Challenge may not be null"); } int idx = challengeStr.indexOf(' '); if (idx == -1) { throw new MalformedChallengeException("Invalid challenge: " + challengeStr); } Map map = new HashMap(); ParameterParser parser = new ParameterParser(); List params = parser.parse( challengeStr.substring(idx + 1, challengeStr.length()), ','); for (int i = 0; i < params.size(); i++) { NameValuePair param = (NameValuePair) params.get(i); map.put(param.getName().toLowerCase(), param.getValue()); } return map; }
/** * 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 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 " + getSchemeName() + " challenge: " + challenge); } this.params = AuthChallengeParser.extractParams(challenge); }
/** * Extracts authentication scheme from the given authentication * challenge. * * @param challengeStr the authentication challenge string * @return authentication scheme * * @throws MalformedChallengeException when the authentication challenge string * is malformed * * @since 2.0beta1 */ public static String extractScheme(final String challengeStr) throws MalformedChallengeException { if (challengeStr == null) { throw new IllegalArgumentException("Challenge may not be null"); } int idx = challengeStr.indexOf(' '); String s = null; if (idx == -1) { s = challengeStr; } else { s = challengeStr.substring(0, idx); } if (s.equals("")) { throw new MalformedChallengeException("Invalid challenge: " + challengeStr); } return s.toLowerCase(); }
/** * Extracts authentication scheme from the given authentication * challenge. * * @param challengeStr the authentication challenge string * @return authentication scheme * * @throws MalformedChallengeException when the authentication challenge string * is malformed * * @since 2.0beta1 */ public static String extractScheme(final String challengeStr) throws MalformedChallengeException { if (challengeStr == null) { throw new IllegalArgumentException("Challenge may not be null"); } int idx = challengeStr.indexOf(' '); String s = null; if (idx == -1) { s = challengeStr; } else { s = challengeStr.substring(0, idx); } if (s.equals("")) { throw new MalformedChallengeException("Invalid challenge: " + challengeStr); } return s.toLowerCase(); }
/** * Extracts authentication scheme from the given authentication * challenge. * * @param challengeStr the authentication challenge string * @return authentication scheme * * @throws MalformedChallengeException when the authentication challenge string * is malformed * * @since 2.0beta1 */ public static String extractScheme(final String challengeStr) throws MalformedChallengeException { if (challengeStr == null) { throw new IllegalArgumentException("Challenge may not be null"); } int idx = challengeStr.indexOf(' '); String s = null; if (idx == -1) { s = challengeStr; } else { s = challengeStr.substring(0, idx); } if (s.equals("")) { throw new MalformedChallengeException("Invalid challenge: " + challengeStr); } return s.toLowerCase(); }
@Override public void processChallenge(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) { if (this.state == State.UNINITIATED) { this.state = State.CHALLENGE_RECEIVED; } else { this.state = State.FAILED; } } else { if (this.state.compareTo(State.MSG_TYPE1_GENERATED) < 0) { this.state = State.FAILED; throw new MalformedChallengeException("Out of sequence NTLM response message"); } else if (this.state == State.MSG_TYPE1_GENERATED) { this.state = State.MSG_TYPE2_RECEVIED; this.challenge = challenge.substring(i, challenge.length()).trim(); } } }
/** * Processes the NTLM challenge. * * @param challenge the challenge string * @throws MalformedChallengeException is thrown if the authentication challenge is malformed */ 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()); receivedNtlmChallenge = s.trim(); authenticationState = AUTHENTICATION_STATE.TYPE2_MSG_RECEIVED; } else { receivedNtlmChallenge = null; authenticationState = authenticationState == AUTHENTICATION_STATE.UNINITIATED ? AUTHENTICATION_STATE.INITIATED : AUTHENTICATION_STATE.FAILED; } }
/** * Processes the Negotiate challenge. * * @param challenge the challenge string * @throws MalformedChallengeException is thrown if the authentication challenge is malformed */ public void processChallenge(final String challenge) throws MalformedChallengeException { String authScheme = AuthChallengeParser.extractScheme(challenge); if (!authScheme.equalsIgnoreCase(getSchemeName())) { throw new MalformedChallengeException("Invalid Negotiate challenge: " + challenge); } int spaceIndex = challenge.indexOf(' '); if (spaceIndex != -1) { // step 2: received server challenge serverToken = Base64.decodeBase64(EncodingUtil.getBytes( challenge.substring(spaceIndex, challenge.length()).trim(), "ASCII")); this.state = TYPE2_MSG_RECEIVED; } else { this.serverToken = null; if (this.state == UNINITIATED) { this.state = INITIATED; } else { this.state = FAILED; } } }
/** * Processes the NTLM challenge. * * @param challenge the challenge string * @throws MalformedChallengeException is thrown if the authentication challenge * is malformed */ public void processChallenge(final String challenge) throws MalformedChallengeException { String authScheme = AuthChallengeParser.extractScheme(challenge); if (!authScheme.equalsIgnoreCase(getSchemeName())) { throw new MalformedChallengeException("Invalid NTLM challenge: " + challenge); } int spaceIndex = challenge.indexOf(' '); if (spaceIndex != -1) { try { type2Message = new Type2Message(Base64.decodeBase64(EncodingUtil.getBytes( challenge.substring(spaceIndex, challenge.length()).trim(), "ASCII"))); } catch (IOException e) { throw new MalformedChallengeException("Invalid NTLM challenge: " + challenge, e); } this.state = TYPE2_MSG_RECEIVED; } else { this.type2Message = null; if (this.state == UNINITIATED) { this.state = INITIATED; } else { this.state = FAILED; } } }
/** * Extracts a map of challenge parameters from an authentication challenge. * Keys in the map are lower-cased * * @param challengeStr the authentication challenge string * @return a map of authentication challenge parameters * @throws MalformedChallengeException when the authentication challenge string * is malformed * * @since 2.0beta1 */ public static Map extractParams(final String challengeStr) throws MalformedChallengeException { if (challengeStr == null) { throw new IllegalArgumentException("Challenge may not be null"); } int idx = challengeStr.indexOf(' '); if (idx == -1) { throw new MalformedChallengeException("Invalid challenge: " + challengeStr); } Map map = new HashMap(); ParameterParser parser = new ParameterParser(); List params = parser.parse( challengeStr.substring(idx + 1, challengeStr.length()), ','); for (int i = 0; i < params.size(); i++) { NameValuePair param = (NameValuePair) params.get(i); map.put(param.getName().toLowerCase(), param.getValue()); } return map; }
/** * Extracts a map of challenge parameters from an authentication challenge. * Keys in the map are lower-cased * * @param challengeStr the authentication challenge string * @return a map of authentication challenge parameters * @throws MalformedChallengeException when the authentication challenge string * is malformed * * @since 2.0beta1 */ public static Map extractParams(final String challengeStr) throws MalformedChallengeException { if (challengeStr == null) { throw new IllegalArgumentException("Challenge may not be null"); } int idx = challengeStr.indexOf(' '); if (idx == -1) { throw new MalformedChallengeException("Invalid challenge: " + challengeStr); } Map map = new HashMap(); ParameterParser parser = new ParameterParser(); List params = parser.parse( challengeStr.substring(idx + 1, challengeStr.length()), ','); for (int i = 0; i < params.size(); i++) { NameValuePair param = (NameValuePair) params.get(i); map.put(param.getName().toLowerCase(), param.getValue()); } return map; }
/** * Extracts a map of challenge parameters from an authentication challenge. * Keys in the map are lower-cased * * @param challengeStr the authentication challenge string * @return a map of authentication challenge parameters * @throws MalformedChallengeException when the authentication challenge string * is malformed * * @since 2.0beta1 */ public static Map extractParams(final String challengeStr) throws MalformedChallengeException { if (challengeStr == null) { throw new IllegalArgumentException("Challenge may not be null"); } int idx = challengeStr.indexOf(' '); if (idx == -1) { throw new MalformedChallengeException("Invalid challenge: " + challengeStr); } Map map = new HashMap(); ParameterParser parser = new ParameterParser(); List params = parser.parse( challengeStr.substring(idx + 1, challengeStr.length()), ','); for (int i = 0; i < params.size(); i++) { NameValuePair param = (NameValuePair) params.get(i); map.put(param.getName().toLowerCase(), param.getValue()); } return map; }
/** * 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; }
/** * 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 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 " + getSchemeName() + " challenge: " + challenge); } this.params = AuthChallengeParser.extractParams(challenge); }
/** * 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 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 " + getSchemeName() + " challenge: " + challenge); } this.params = AuthChallengeParser.extractParams(challenge); }
/** * 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 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 " + getSchemeName() + " challenge: " + challenge); } this.params = AuthChallengeParser.extractParams(challenge); }
/** * 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 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 " + getSchemeName() + " challenge: " + challenge); } this.params = AuthChallengeParser.extractParams(challenge); }