Example usage for org.apache.commons.httpclient.auth AuthChallengeParser extractScheme

List of usage examples for org.apache.commons.httpclient.auth AuthChallengeParser extractScheme

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.auth AuthChallengeParser extractScheme.

Prototype

public static String extractScheme(String paramString) throws MalformedChallengeException 

Source Link

Usage

From source file:davmail.http.SpNegoScheme.java

/**
 * Processes the Negotiate challenge.//from   w ww .  ja va 2s . co m
 *
 * @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;
        }
    }
}

From source file:davmail.http.NTLMv2Scheme.java

/**
 * Processes the NTLM challenge.//from   w w w . j av  a 2  s. co  m
 *
 * @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;
        }
    }
}

From source file:com.cerema.cloud2.lib.common.network.BearerAuthScheme.java

/**
 * Processes the Bearer challenge.//  w ww .j a  v  a  2 s.com
 *  
 * @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;
}

From source file:edu.cmu.cs.diamond.pathfind.DjangoAnnotationStore.java

private int maybeAuthenticate(HttpMethodBase method, int code)
        throws MalformedChallengeException, IOException, HttpException {
    while (code == 401) {
        // let's authenticate
        Header header = method.getResponseHeader("WWW-Authenticate");
        System.out.println(header);
        String scheme = AuthChallengeParser.extractScheme(header.getValue());
        Map<?, ?> params = AuthChallengeParser.extractParams(header.getValue());

        if (!scheme.equals("login")) {
            throw new IOException("Authentication requested but of unknown scheme: " + scheme);
        }//from w  ww  . j a v a2 s .  c o  m

        // get the login form
        String loginuri = (String) params.get("realm");
        login(loginuri);

        // try again
        code = httpClient.executeMethod(method);
    }
    return code;
}

From source file:com.mobilehelix.appserver.auth.JCIFS_NTLMScheme.java

/**
 *
 * Processes the NTLM challenge./*from  w  w w. j av  a2s .co  m*/
 *
 * @param challenge the challenge string
 *
 * @throws MalformedChallengeException is thrown if the authentication challenge is malformed
 * @since 3.0
 */
@Override
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:microsoft.exchange.webservices.data.EwsJCIFSNTLMScheme.java

/**
 * Processes the NTLM challenge./*w w w .  j a  va  2s . co 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:it.greenvulcano.gvesb.http.ntlm.JCIFS_NTLMScheme.java

/**
 * Processes the NTLM challenge./*from   w  w w. j a  v a  2s  . co  m*/
 * 
 * @param challenge
 *        the challenge string
 * @throws MalformedChallengeException
 *         is thrown if the authentication challenge is malformed
 * @since 3.0
 */
@Override
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.jetbrains.tfsIntegration.webservice.auth.NTLM2Scheme.java

/**
 * Processes the NTLM challenge.//from  ww w.  j a  v  a 2s. 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.mule.transport.http.ntlm.NTLMScheme.java

/**
 * Processes the NTLM challenge./*from   www  .j a  v a 2s  .c  o m*/
 *
 * @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;
    }
}

From source file:org.wso2.carbon.mediator.ntlm.CustomNTLMAuthScheme.java

/**
 * Processes the NTLM challenge./*from ww  w  .  j  ava  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;
        }
    }
}