Example usage for org.apache.commons.httpclient.auth InvalidCredentialsException InvalidCredentialsException

List of usage examples for org.apache.commons.httpclient.auth InvalidCredentialsException InvalidCredentialsException

Introduction

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

Prototype

public InvalidCredentialsException(String paramString) 

Source Link

Usage

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

@Override
public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException {

    LOG.log(Level.FINEST, "Enter JCIFS_NTLMScheme.authenticate(Credentials, HttpMethod)");

    if (this.state == UNINITIATED) {
        throw new IllegalStateException("NTLM authentication process has not been initiated");
    }//from w w w  .  ja  va2s  . c o m

    NTCredentials ntcredentials = null;
    try {
        ntcredentials = (NTCredentials) credentials;
    } catch (ClassCastException e) {
        throw new InvalidCredentialsException(
                "Credentials cannot be used for NTLM authentication: " + credentials.getClass().getName());

    }

    NTLM ntlm = new NTLM();
    ntlm.setCredentialCharset(method.getParams().getCredentialCharset());
    String response = null;
    if (this.state == INITIATED || this.state == FAILED) {
        response = ntlm.generateType1Msg(ntcredentials.getHost(), ntcredentials.getDomain());
        this.state = TYPE1_MSG_GENERATED;
    } else {
        response = ntlm.generateType3Msg(ntcredentials.getUserName(), ntcredentials.getPassword(),
                ntcredentials.getHost(), ntcredentials.getDomain(), this.ntlmchallenge);
        this.state = TYPE3_MSG_GENERATED;
    }

    return "NTLM " + response;
}

From source file:it.greenvulcano.gvesb.http.ntlm.JCIFS_NTLMScheme.java

@Override
public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException {
    if (this.state == UNINITIATED) {
        throw new IllegalStateException("NTLM authentication process has not been initiated");
    }/*w  w  w  . j av a  2s.c  om*/

    NTCredentials ntcredentials = null;
    try {
        ntcredentials = (NTCredentials) credentials;
    } catch (ClassCastException e) {
        throw new InvalidCredentialsException(
                "Credentials cannot be used for NTLM authentication: " + credentials.getClass().getName());
    }

    NTLM ntlm = new NTLM();
    ntlm.setCredentialCharset(method.getParams().getCredentialCharset());

    String response = null;
    if ((this.state == INITIATED) || (this.state == FAILED)) {
        response = ntlm.generateType1Msg(ntcredentials.getHost(), ntcredentials.getDomain());
        this.state = TYPE1_MSG_GENERATED;
    } else {
        response = ntlm.generateType3Msg(ntcredentials.getUserName(), ntcredentials.getPassword(),
                ntcredentials.getHost(), ntcredentials.getDomain(), this.ntlmchallenge);
        this.state = TYPE3_MSG_GENERATED;
    }

    return "NTLM " + response;
}

From source file:com.owncloud.android.oc_framework.network.BearerAuthScheme.java

/**
 * Produces bearer authorization string for the given set of 
 * {@link Credentials}.//w ww.  j  a  v  a2 s.c  o m
 * 
 * @param   credentials                     The set of credentials to be used for authentication
 * @param   method                          Method name is ignored by the bearer authentication scheme
 * @param   uri                             URI is ignored by the bearer authentication scheme
 * @throws  InvalidCredentialsException     If authentication credentials are not valid or not applicable 
 *                                          for this authentication scheme
 * @throws  AuthenticationException         If authorization string cannot be generated due to an authentication failure
 * @return  A bearer authorization string
 * 
 * @deprecated Use {@link #authenticate(Credentials, HttpMethod)}
 */
public String authenticate(Credentials credentials, String method, String uri) throws AuthenticationException {
    Log.d(TAG, "enter BearerScheme.authenticate(Credentials, String, String)");

    BearerCredentials bearer = null;
    try {
        bearer = (BearerCredentials) credentials;
    } catch (ClassCastException e) {
        throw new InvalidCredentialsException(
                "Credentials cannot be used for bearer authentication: " + credentials.getClass().getName());
    }
    return BearerAuthScheme.authenticate(bearer);
}

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

/**
 * Produces bearer authorization string for the given set of 
 * {@link Credentials}.//from w  w  w  .  j av a  2  s. c  om
 * 
 * @param   credentials                     The set of credentials to be used for authentication
 * @param   method                          Method name is ignored by the bearer authentication scheme
 * @param   uri                             URI is ignored by the bearer authentication scheme
 * @throws  InvalidCredentialsException     If authentication credentials are not valid or not applicable 
 *                                          for this authentication scheme
 * @throws  AuthenticationException         If authorization string cannot be generated due to an authentication failure
 * @return  A bearer authorization string
 * 
 * @deprecated Use {@link #authenticate(Credentials, HttpMethod)}
 */
public String authenticate(Credentials credentials, String method, String uri) throws AuthenticationException {
    Log_OC.d(TAG, "enter BearerScheme.authenticate(Credentials, String, String)");

    BearerCredentials bearer = null;
    try {
        bearer = (BearerCredentials) credentials;
    } catch (ClassCastException e) {
        throw new InvalidCredentialsException(
                "Credentials cannot be used for bearer authentication: " + credentials.getClass().getName());
    }
    return BearerAuthScheme.authenticate(bearer);
}

From source file:davmail.http.NTLMv2Scheme.java

/**
 * Produces NTLM authorization string for the given set of
 * {@link Credentials}./*from w  ww.j  a  v  a  2s.c om*/
 *
 * @param credentials The set of credentials to be used for authentication
 * @param httpMethod  The method being authenticated
 * @return an NTLM authorization string
 * @throws InvalidCredentialsException if authentication credentials
 *                                     are not valid or not applicable for this authentication scheme
 * @throws AuthenticationException     if authorization string cannot
 *                                     be generated due to an authentication failure
 */
public String authenticate(Credentials credentials, HttpMethod httpMethod) throws AuthenticationException {
    if (this.state == UNINITIATED) {
        throw new IllegalStateException("NTLM authentication process has not been initiated");
    }

    NTCredentials ntcredentials;
    try {
        ntcredentials = (NTCredentials) credentials;
    } catch (ClassCastException e) {
        throw new InvalidCredentialsException(
                "Credentials cannot be used for NTLM authentication: " + credentials.getClass().getName());
    }
    String response;
    if (this.state == INITIATED || this.state == FAILED) {
        int flags = NtlmFlags.NTLMSSP_NEGOTIATE_NTLM2 | NtlmFlags.NTLMSSP_NEGOTIATE_ALWAYS_SIGN
                | NtlmFlags.NTLMSSP_NEGOTIATE_OEM_WORKSTATION_SUPPLIED
                | NtlmFlags.NTLMSSP_NEGOTIATE_OEM_DOMAIN_SUPPLIED | NtlmFlags.NTLMSSP_NEGOTIATE_NTLM
                | NtlmFlags.NTLMSSP_REQUEST_TARGET | NtlmFlags.NTLMSSP_NEGOTIATE_OEM
                | NtlmFlags.NTLMSSP_NEGOTIATE_UNICODE | NtlmFlags.NTLMSSP_NEGOTIATE_56
                | NtlmFlags.NTLMSSP_NEGOTIATE_128;
        Type1Message type1Message = new Type1Message(flags, ntcredentials.getDomain(), ntcredentials.getHost());
        response = EncodingUtil.getAsciiString(Base64.encodeBase64(type1Message.toByteArray()));
        this.state = TYPE1_MSG_GENERATED;
    } else {
        int flags = NtlmFlags.NTLMSSP_NEGOTIATE_NTLM2 | NtlmFlags.NTLMSSP_NEGOTIATE_ALWAYS_SIGN
                | NtlmFlags.NTLMSSP_NEGOTIATE_NTLM | NtlmFlags.NTLMSSP_NEGOTIATE_UNICODE;
        Type3Message type3Message = new Type3Message(type2Message, ntcredentials.getPassword(),
                ntcredentials.getDomain(), ntcredentials.getUserName(), ntcredentials.getHost(), flags);
        response = EncodingUtil.getAsciiString(Base64.encodeBase64(type3Message.toByteArray()));
        this.state = TYPE3_MSG_GENERATED;
    }
    return "NTLM " + response;
}

From source file:com.owncloud.android.oc_framework.network.BearerAuthScheme.java

/**
 * Produces bearer authorization string for the given set of {@link Credentials}.
 * /* w  w  w. jav  a2  s .c o  m*/
 * @param   credentials                     The set of credentials to be used for authentication
 * @param   method                          The method being authenticated
 * @throws  InvalidCredentialsException     If authentication credentials are not valid or not applicable for this authentication 
 *                                          scheme.
 * @throws AuthenticationException         If authorization string cannot be generated due to an authentication failure.
 * 
 * @return a basic authorization string
 */
public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException {
    Log.d(TAG, "enter BearerScheme.authenticate(Credentials, HttpMethod)");

    if (method == null) {
        throw new IllegalArgumentException("Method may not be null");
    }
    BearerCredentials bearer = null;
    try {
        bearer = (BearerCredentials) credentials;
    } catch (ClassCastException e) {
        throw new InvalidCredentialsException(
                "Credentials cannot be used for bearer authentication: " + credentials.getClass().getName());
    }
    return BearerAuthScheme.authenticate(bearer, method.getParams().getCredentialCharset());
}

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

/**
 * Produces bearer authorization string for the given set of {@link Credentials}.
 * /*from  w  w  w.java2s  . c  o  m*/
 * @param   credentials                     The set of credentials to be used for authentication
 * @param   method                          The method being authenticated
 * @throws  InvalidCredentialsException     If authentication credentials are not valid or not applicable for this authentication 
 *                                          scheme.
 * @throws AuthenticationException         If authorization string cannot be generated due to an authentication failure.
 * 
 * @return a basic authorization string
 */
public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException {
    Log_OC.d(TAG, "enter BearerScheme.authenticate(Credentials, HttpMethod)");

    if (method == null) {
        throw new IllegalArgumentException("Method may not be null");
    }
    BearerCredentials bearer = null;
    try {
        bearer = (BearerCredentials) credentials;
    } catch (ClassCastException e) {
        throw new InvalidCredentialsException(
                "Credentials cannot be used for bearer authentication: " + credentials.getClass().getName());
    }
    return BearerAuthScheme.authenticate(bearer, method.getParams().getCredentialCharset());
}

From source file:org.jetbrains.tfsIntegration.webservice.auth.NTLM2Scheme.java

/**
 * Produces NTLM authorization string for the given set of
 * {@link Credentials}./* w w  w.  ja v a2s  . c o m*/
 *
 * @param credentials The set of credentials to be used for athentication
 * @param method The method being authenticated
 *
 * @throws InvalidCredentialsException if authentication credentials
 *         are not valid or not applicable for this authentication scheme
 * @throws AuthenticationException if authorization string cannot
 *   be generated due to an authentication failure
 *
 * @return an NTLM authorization string
 *
 * @since 3.0
 */
public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException {
    if (state == UNINITIATED) {
        throw new IllegalStateException("NTLM authentication process was not initiated");
    }

    NTCredentials ntcredentials = null;
    try {
        ntcredentials = (NTCredentials) credentials;
    } catch (ClassCastException e) {
        throw new InvalidCredentialsException(
                "Credentials cannot be used for NTLM authentication: " + credentials.getClass().getName());
    }

    String response;
    if (state == INITIATED || state == FAILED) {
        response = getType1MessageResponse(ntcredentials, method.getParams());
        state = TYPE1_MSG_GENERATED;
    } else {
        response = getType3MessageResponse(ntlmchallenge, ntcredentials, method.getParams());
        state = TYPE3_MSG_GENERATED;
    }
    return "NTLM " + response;
}

From source file:org.mule.transport.http.ntlm.NTLMScheme.java

private NTCredentials getNTCredentials(Credentials credentials) throws InvalidCredentialsException {
    try {//from  w w  w  .ja v  a2 s  . c  o m
        return (NTCredentials) credentials;
    } catch (ClassCastException e) {
        throw new InvalidCredentialsException(
                "Credentials cannot be used for NTLM authentication: " + credentials.getClass().getName());
    }
}

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

/**
 * Produces NTLM authorization string for the given set of
 * {@link Credentials}./*from   w  ww .  j  av a  2 s .c  o m*/
 *
 * @param credentials
 *            The set of credentials to be used for athentication
 * @param method
 *            The method being authenticated
 *
 * @throws InvalidCredentialsException
 *             if authentication credentials are not valid or not applicable
 *             for this authentication scheme
 * @throws AuthenticationException
 *             if authorization string cannot be generated due to an
 *             authentication failure
 *
 * @return an NTLM authorization string
 *
 * @since 3.0
 */
public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException {
    LOG.trace("enter NTLMScheme.authenticate (Credentials, HttpMethod)");

    if (this.state == UNINITIATED) {
        throw new IllegalStateException("NTLM authentication process has not been initiated");
    }

    NTCredentials ntcredentials = null;
    try {
        ntcredentials = (NTCredentials) credentials;
    } catch (ClassCastException e) {
        throw new InvalidCredentialsException(
                "Credentials cannot be used for NTLM authentication: " + credentials.getClass().getName());
    }
    byte[] msgBytes = null;
    String response = null;
    if (this.state == INITIATED) {
        Type1Message msg = new Type1Message();
        // @see http://davenport.sourceforge.net/ntlm.html#theType1Message
        // dont' support Unicode
        // negotiate OEM
        // request authentication realm in Type2 response
        // not signed
        // not encrypted
        // not authenticated
        // no lan manager key
        // negotiate NTLM
        msg.setFlags(0x5206);
        msg.setSuppliedWorkstation(ntcredentials.getHost());
        msg.setSuppliedDomain(ntcredentials.getDomain());
        msgBytes = msg.toByteArray();
        this.state = TYPE1_MSG_GENERATED;
    } else if (this.state == TYPE2_MSG_RECEIVED) {
        byte[] msg2Bytes = Base64.decodeBase64(
                EncodingUtil.getBytes(this.ntlmChallenge, method.getParams().getCredentialCharset()));
        try {
            Type2Message msg2 = new Type2Message(msg2Bytes);
            int flags = Type3Message.NTLMSSP_NEGOTIATE_OEM | Type3Message.NTLMSSP_NEGOTIATE_LM_KEY;

            Type3Message msg3 = new Type3Message(msg2, ntcredentials.getPassword(), ntcredentials.getDomain(),
                    ntcredentials.getUserName(), ntcredentials.getHost(), flags);

            msgBytes = msg3.toByteArray();
        } catch (IOException ex) {
            throw new AuthenticationException("unable to parse Type2Message", ex);
        }
        this.state = TYPE3_MSG_GENERATED;
    } else {
        throw new RuntimeException("failed to authenticate");
    }
    response = EncodingUtil.getAsciiString(Base64.encodeBase64(msgBytes));
    return "NTLM " + response;
}