Search in sources :

Example 1 with NTCredentials

use of org.apache.commons.httpclient.NTCredentials in project java-apns by notnoop.

the class TlsTunnelBuilder method AuthenticateProxy.

private Socket AuthenticateProxy(ConnectMethod method, ProxyClient client, String proxyHost, int proxyPort, String proxyUsername, String proxyPassword) throws IOException {
    if ("ntlm".equalsIgnoreCase(method.getProxyAuthState().getAuthScheme().getSchemeName())) {
        // If Auth scheme is NTLM, set NT credentials with blank host and domain name
        client.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort), new NTCredentials(proxyUsername, proxyPassword, "", ""));
    } else {
        // If Auth scheme is Basic/Digest, set regular Credentials
        client.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort), new UsernamePasswordCredentials(proxyUsername, proxyPassword));
    }
    ProxyClient.ConnectResponse response = client.connect();
    Socket socket = response.getSocket();
    if (socket == null) {
        method = response.getConnectMethod();
        throw new ProtocolException("Proxy Authentication failed. Socket not created: " + method.getStatusLine());
    }
    return socket;
}
Also used : ProtocolException(java.net.ProtocolException) ProxyClient(org.apache.commons.httpclient.ProxyClient) AuthScope(org.apache.commons.httpclient.auth.AuthScope) Socket(java.net.Socket) NTCredentials(org.apache.commons.httpclient.NTCredentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 2 with NTCredentials

use of org.apache.commons.httpclient.NTCredentials in project zaproxy by zaproxy.

the class ZapNTLMScheme method authenticate.

@Override
public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException {
    NTCredentials ntcredentials = null;
    try {
        ntcredentials = (NTCredentials) credentials;
    } catch (final ClassCastException e) {
        throw new AuthenticationException("Credentials cannot be used for NTLM authentication: " + credentials.getClass().getName());
    }
    String response = null;
    if (this.state == State.FAILED) {
        throw new AuthenticationException("NTLM authentication failed");
    } else if (this.state == State.CHALLENGE_RECEIVED) {
        response = this.engine.generateType1Msg(ntcredentials.getDomain(), ntcredentials.getHost());
        this.state = State.MSG_TYPE1_GENERATED;
    } else if (this.state == State.MSG_TYPE2_RECEVIED) {
        response = this.engine.generateType3Msg(ntcredentials.getUserName(), ntcredentials.getPassword(), ntcredentials.getDomain(), ntcredentials.getHost(), this.challenge);
        this.state = State.MSG_TYPE3_GENERATED;
    } else {
        throw new AuthenticationException("Unexpected state: " + this.state);
    }
    return "NTLM " + response;
}
Also used : AuthenticationException(org.apache.commons.httpclient.auth.AuthenticationException) NTCredentials(org.apache.commons.httpclient.NTCredentials)

Example 3 with NTCredentials

use of org.apache.commons.httpclient.NTCredentials in project tdi-studio-se by Talend.

the class JCIFS_NTLMScheme method authenticate.

public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException {
    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());
    }
    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;
}
Also used : InvalidCredentialsException(org.apache.commons.httpclient.auth.InvalidCredentialsException) NTCredentials(org.apache.commons.httpclient.NTCredentials)

Aggregations

NTCredentials (org.apache.commons.httpclient.NTCredentials)3 ProtocolException (java.net.ProtocolException)1 Socket (java.net.Socket)1 ProxyClient (org.apache.commons.httpclient.ProxyClient)1 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)1 AuthScope (org.apache.commons.httpclient.auth.AuthScope)1 AuthenticationException (org.apache.commons.httpclient.auth.AuthenticationException)1 InvalidCredentialsException (org.apache.commons.httpclient.auth.InvalidCredentialsException)1