Dear all,

if followed the example on
http://hc.apache.org/httpcomponents-client-4.0.1/ntlm.html

But I am still not able to authenticate. (I have read that Domain and
Workstation are optional, so I have set them to the empty string (or
null)).
I have attached my code and the corresponding log file from a sample run.

Alternative:
If I connect to the website using java.net.url and java.net.authenticator
I am able to query the site. Is it possible to by-pass the authentication
by passing the Url, UrlConnection or the InputStream to the HttpClient
class?

Best regards,
  Daniel


public class TestCase
{
        private static final String SERVER = "my.server";
        private static final String BASE_URL = "https://"; + SERVER;
        private static final String USER = "user";
        private static final String PASS = "password";

        private static final Logger log = Logger.getLogger(TestCase.class);

        public static void main(String args[])
        {
                BasicConfigurator.configure();

                DefaultHttpClient httpclient = new DefaultHttpClient();
                httpclient.getAuthSchemes().register("ntlm", new 
NTLMSchemeFactory());

                httpclient.getCredentialsProvider().setCredentials(
                                new AuthScope(SERVER, -1),
                                new NTCredentials(USER, PASS, "", ""));

                HttpUriRequest request = new HttpGet(BASE_URL);
                HttpResponse response = null;
                HttpEntity entity = null;

                try
                {
                        response = httpclient.execute(request);
                        entity = response.getEntity();
                        entity.writeTo(System.err);
                }
                catch (ClientProtocolException e)
                {
                        e.printStackTrace();
                }
                catch (IOException e)
                {
                        e.printStackTrace();
                }
        }
}


public class JCIFSEngine implements NTLMEngine
{
        private Logger log = Logger.getLogger(JCIFSEngine.class);

        public String generateType1Msg(String domain, String workstation)
                        throws NTLMEngineException
        {
                log.info("##   TM1\tDOMAIN: '" + domain + "' WORKSTATION: '" +
workstation + "'");
                Type1Message t1m = new 
Type1Message(Type1Message.getDefaultFlags(),
                                domain, workstation);
                return Base64.encode(t1m.toByteArray());
        }

        public String generateType3Msg(String username, String password,
                        String domain, String workstation, String challenge)
                        throws NTLMEngineException
        {
                Type2Message t2m;

                try
                {
                        t2m = new Type2Message(Base64.decode(challenge));
                }
                catch (IOException ex)
                {
                        throw new NTLMEngineException("Invalid Type2 message", 
ex);
                }

                Type3Message t3m = new Type3Message(t2m, password, domain, 
username,
                                workstation, 0);

                return Base64.encode(t3m.toByteArray());
        }
}


public class NTLMSchemeFactory implements AuthSchemeFactory
{
        private Logger log = Logger.getLogger(NTLMSchemeFactory.class);

        public AuthScheme newInstance(final HttpParams params)
        {
                BasicConfigurator.configure();

                return new NTLMScheme(new JCIFSEngine());
        }
}




187 [main] DEBUG org.apache.http.impl.conn.SingleClientConnManager  - Get
connection for route HttpRoute[{s}->https://my.server]
655 [main] DEBUG org.apache.http.client.protocol.RequestAddCookies  -
CookieSpec selected: best-match
670 [main] DEBUG org.apache.http.impl.client.DefaultHttpClient  - Attempt
1 to execute request
670 [main] DEBUG org.apache.http.impl.conn.DefaultClientConnection  -
Sending request: GET / HTTP/1.1
670 [main] DEBUG org.apache.http.wire  - >> "GET / HTTP/1.1[EOL]"
670 [main] DEBUG org.apache.http.wire  - >> "Host: my.server[EOL]" 670
[main] DEBUG org.apache.http.wire  - >> "Connection: Keep-Alive[EOL]" 670
[main] DEBUG org.apache.http.wire  - >> "User-Agent:
Apache-HttpClient/4.0.1 (java 1.5)[EOL]"
670 [main] DEBUG org.apache.http.wire  - >> "[EOL]"
670 [main] DEBUG org.apache.http.headers  - >> GET / HTTP/1.1
670 [main] DEBUG org.apache.http.headers  - >> Host: my.server
670 [main] DEBUG org.apache.http.headers  - >> Connection: Keep-Alive 670
[main] DEBUG org.apache.http.headers  - >> User-Agent:
Apache-HttpClient/4.0.1 (java 1.5)
670 [main] DEBUG org.apache.http.wire  - << "HTTP/1.1 401
Unauthorized[EOL]"
686 [main] DEBUG org.apache.http.wire  - << "Content-Length: 1656[EOL]"
686 [main] DEBUG org.apache.http.wire  - << "Content-Type: text/html[EOL]"
686 [main] DEBUG org.apache.http.wire  - << "Server:
Microsoft-IIS/6.0[EOL]"
686 [main] DEBUG org.apache.http.wire  - << "WWW-Authenticate:
Negotiate[EOL]"
686 [main] DEBUG org.apache.http.wire  - << "WWW-Authenticate: NTLM[EOL]"
686 [main] DEBUG org.apache.http.wire  - << "Date: Thu, 08 Apr 2010
12:59:47 GMT[EOL]"
686 [main] DEBUG org.apache.http.wire  - << "[EOL]"
686 [main] DEBUG org.apache.http.impl.conn.DefaultClientConnection  -
Receiving response: HTTP/1.1 401 Unauthorized
686 [main] DEBUG org.apache.http.headers  - << HTTP/1.1 401 Unauthorized
686 [main] DEBUG org.apache.http.headers  - << Content-Length: 1656 686
[main] DEBUG org.apache.http.headers  - << Content-Type: text/html 686
[main] DEBUG org.apache.http.headers  - << Server: Microsoft-IIS/6.0 686
[main] DEBUG org.apache.http.headers  - << WWW-Authenticate: Negotiate 686
[main] DEBUG org.apache.http.headers  - << WWW-Authenticate: NTLM 686
[main] DEBUG org.apache.http.headers  - << Date: Thu, 08 Apr 2010 12:59:47
GMT
686 [main] DEBUG org.apache.http.impl.client.DefaultHttpClient  -
Connection can be kept alive indefinitely
686 [main] DEBUG org.apache.http.impl.client.DefaultHttpClient  - Target
requested authentication
686 [main] DEBUG
org.apache.http.impl.client.DefaultTargetAuthenticationHandler  -
Authentication schemes in the order of preference: [ntlm, digest, basic]
686 [main] DEBUG
org.apache.http.impl.client.DefaultTargetAuthenticationHandler  - ntlm
authentication scheme selected
686 [main] INFO de.balkonien.webtest.NTLMSchemeFactory  - ##
newInstance()
686 [main] INFO de.balkonien.webtest.NTLMSchemeFactory  - ##
newInstance()
686 [main] INFO de.balkonien.webtest.JCIFSEngine  - ##   JCIFSEngine() 686
[main] INFO de.balkonien.webtest.JCIFSEngine  - ##   JCIFSEngine() 686
[main] DEBUG org.apache.http.impl.client.DefaultHttpClient  -
Authorization challenge processed
686 [main] DEBUG org.apache.http.impl.client.DefaultHttpClient  -
Authorization challenge processed
686 [main] DEBUG org.apache.http.impl.client.DefaultHttpClient  -
Authentication scope: NTLM <any realm>@my.server:443
686 [main] DEBUG org.apache.http.impl.client.DefaultHttpClient  -
Authentication scope: NTLM <any realm>@my.server:443
686 [main] DEBUG org.apache.http.impl.client.DefaultHttpClient  - Found
credentials
686 [main] DEBUG org.apache.http.impl.client.DefaultHttpClient  - Found
credentials
686 [main] DEBUG org.apache.http.wire  - << "<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd";>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd";>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<HTML><HEAD><TITLE>You are
not authorized to view this page</TITLE>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<HTML><HEAD><TITLE>You are
not authorized to view this page</TITLE>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<META
HTTP-EQUIV="Content-Type" Content="text/html;
charset=Windows-1252">[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<META
HTTP-EQUIV="Content-Type" Content="text/html;
charset=Windows-1252">[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<STYLE
type="text/css">[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<STYLE
type="text/css">[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "  BODY { font: 8pt/12pt
verdana }[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "  BODY { font: 8pt/12pt
verdana }[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "  H1 { font: 13pt/15pt
verdana }[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "  H1 { font: 13pt/15pt
verdana }[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "  H2 { font: 8pt/12pt verdana
}[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "  H2 { font: 8pt/12pt verdana
}[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "  A:link { color: red }[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "  A:link { color: red }[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "  A:visited { color: maroon
}[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "  A:visited { color: maroon
}[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "</STYLE>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "</STYLE>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "</HEAD><BODY><TABLE width=500
border=0 cellspacing=10><TR><TD>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "</HEAD><BODY><TABLE width=500
border=0 cellspacing=10><TR><TD>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<h1>You are not authorized to
view this page</h1>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<h1>You are not authorized to
view this page</h1>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "You do not have permission to
view this directory or page using the credentials that you supplied
because your Web browser is sending a WWW-Authenticate header field that
the Web server is not configured to accept.[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "You do not have permission to
view this directory or page using the credentials that you supplied
because your Web browser is sending a WWW-Authenticate header field that
the Web server is not configured to accept.[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<hr>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<hr>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<p>Please try the
following:</p>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<p>Please try the
following:</p>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<ul>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<ul>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<li>Contact the Web site
administrator if you believe you should be able to view this directory or
page.</li>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<li>Contact the Web site
administrator if you believe you should be able to view this directory or
page.</li>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<li>Click the <a
href="javascript:location.reload()">Refresh</a> button to try again with
different credentials.</li>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<li>Click the <a
href="javascript:location.reload()">Refresh</a> button to try again with
different credentials.</li>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "</ul>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "</ul>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<h2>HTTP Error 401.2 -
Unauthorized: Access is denied due to server configuration.<br>Internet
Information Services (IIS)</h2>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<h2>HTTP Error 401.2 -
Unauthorized: Access is denied due to server configuration.<br>Internet
Information Services (IIS)</h2>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<hr>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<hr>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<p>Technical Information (for
support personnel)</p>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<p>Technical Information (for
support personnel)</p>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<ul>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<ul>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<li>Go to <a
href="http://go.microsoft.com/fwlink/?linkid=8180";>Microsoft Product
Support Services</a> and perform a title search for the words <b>HTTP</b>
and <b>401</b>.</li>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<li>Go to <a
href="http://go.microsoft.com/fwlink/?linkid=8180";>Microsoft Product
Support Services</a> and perform a title search for the words <b>HTTP</b>
and <b>401</b>.</li>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<li>Open <b>IIS Help</b>,
which is accessible in IIS Manager (inetmgr),[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "<li>Open <b>IIS Help</b>,
which is accessible in IIS Manager (inetmgr),[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << " and search for topics titled
<b>About Security</b>, <b>Authentication</b>, and <b>About Custom Error
Messages</b>.</li>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << " and search for topics titled
<b>About Security</b>, <b>Authentication</b>, and <b>About Custom Error
Messages</b>.</li>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "</ul>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "</ul>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - << "[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - <<
"</TD></TR></TABLE></BODY></HTML>[\r][\n]"
686 [main] DEBUG org.apache.http.wire  - <<
"</TD></TR></TABLE></BODY></HTML>[\r][\n]"
686 [main] DEBUG org.apache.http.client.protocol.RequestAddCookies  -
CookieSpec selected: best-match
686 [main] DEBUG org.apache.http.client.protocol.RequestAddCookies  -
CookieSpec selected: best-match
686 [main] INFO de.balkonien.webtest.JCIFSEngine  - ## generateType1Msg()
686 [main] INFO de.balkonien.webtest.JCIFSEngine  - ## generateType1Msg()
686 [main] INFO de.balkonien.webtest.JCIFSEngine  - ##   TM1    DOMAIN: ''
WORKSTATION: ''
686 [main] INFO de.balkonien.webtest.JCIFSEngine  - ##   TM1    DOMAIN: ''
WORKSTATION: ''
702 [main] DEBUG org.apache.http.impl.client.DefaultHttpClient  - Attempt
2 to execute request
702 [main] DEBUG org.apache.http.impl.client.DefaultHttpClient  - Attempt
2 to execute request
702 [main] DEBUG org.apache.http.impl.conn.DefaultClientConnection  -
Sending request: GET / HTTP/1.1
702 [main] DEBUG org.apache.http.impl.conn.DefaultClientConnection  -
Sending request: GET / HTTP/1.1
702 [main] DEBUG org.apache.http.wire  - >> "GET / HTTP/1.1[EOL]"
702 [main] DEBUG org.apache.http.wire  - >> "GET / HTTP/1.1[EOL]"
702 [main] DEBUG org.apache.http.wire  - >> "Host: my.server[EOL]" 702
[main] DEBUG org.apache.http.wire  - >> "Host: my.server[EOL]" 702 [main]
DEBUG org.apache.http.wire  - >> "Connection: Keep-Alive[EOL]" 702 [main]
DEBUG org.apache.http.wire  - >> "Connection: Keep-Alive[EOL]" 702 [main]
DEBUG org.apache.http.wire  - >> "User-Agent:
Apache-HttpClient/4.0.1 (java 1.5)[EOL]"
702 [main] DEBUG org.apache.http.wire  - >> "User-Agent:
Apache-HttpClient/4.0.1 (java 1.5)[EOL]"
702 [main] DEBUG org.apache.http.wire  - >> "Authorization: NTLM
TlRMTVNTUAABAAAAAQIAAA==[EOL]"
702 [main] DEBUG org.apache.http.wire  - >> "Authorization: NTLM
TlRMTVNTUAABAAAAAQIAAA==[EOL]"
702 [main] DEBUG org.apache.http.wire  - >> "[EOL]"
702 [main] DEBUG org.apache.http.wire  - >> "[EOL]"
702 [main] DEBUG org.apache.http.headers  - >> GET / HTTP/1.1
702 [main] DEBUG org.apache.http.headers  - >> GET / HTTP/1.1
702 [main] DEBUG org.apache.http.headers  - >> Host: my.server
702 [main] DEBUG org.apache.http.headers  - >> Host: my.server
702 [main] DEBUG org.apache.http.headers  - >> Connection: Keep-Alive 702
[main] DEBUG org.apache.http.headers  - >> Connection: Keep-Alive 702
[main] DEBUG org.apache.http.headers  - >> User-Agent:
Apache-HttpClient/4.0.1 (java 1.5)
702 [main] DEBUG org.apache.http.headers  - >> User-Agent:
Apache-HttpClient/4.0.1 (java 1.5)
702 [main] DEBUG org.apache.http.headers  - >> Authorization: NTLM
TlRMTVNTUAABAAAAAQIAAA==
702 [main] DEBUG org.apache.http.headers  - >> Authorization: NTLM
TlRMTVNTUAABAAAAAQIAAA==
702 [main] DEBUG org.apache.http.wire  - << "HTTP/1.1 500 Internal Server
Error[EOL]"
702 [main] DEBUG org.apache.http.wire  - << "HTTP/1.1 500 Internal Server
Error[EOL]"
702 [main] DEBUG org.apache.http.wire  - << "Content-Length: 100[EOL]" 702
[main] DEBUG org.apache.http.wire  - << "Content-Length: 100[EOL]" 702
[main] DEBUG org.apache.http.wire  - << "Content-Type: text/html[EOL]" 702
[main] DEBUG org.apache.http.wire  - << "Content-Type: text/html[EOL]" 702
[main] DEBUG org.apache.http.wire  - << "Server:
Microsoft-IIS/6.0[EOL]"
702 [main] DEBUG org.apache.http.wire  - << "Server:
Microsoft-IIS/6.0[EOL]"
702 [main] DEBUG org.apache.http.wire  - << "Date: Thu, 08 Apr 2010
12:59:47 GMT[EOL]"
702 [main] DEBUG org.apache.http.wire  - << "Date: Thu, 08 Apr 2010
12:59:47 GMT[EOL]"
702 [main] DEBUG org.apache.http.wire  - << "Connection: close[EOL]" 702
[main] DEBUG org.apache.http.wire  - << "Connection: close[EOL]" 702
[main] DEBUG org.apache.http.wire  - << "[EOL]"
702 [main] DEBUG org.apache.http.wire  - << "[EOL]"
702 [main] DEBUG org.apache.http.impl.conn.DefaultClientConnection  -
Receiving response: HTTP/1.1 500 Internal Server Error
702 [main] DEBUG org.apache.http.impl.conn.DefaultClientConnection  -
Receiving response: HTTP/1.1 500 Internal Server Error
702 [main] DEBUG org.apache.http.headers  - << HTTP/1.1 500 Internal
Server Error
702 [main] DEBUG org.apache.http.headers  - << HTTP/1.1 500 Internal
Server Error
702 [main] DEBUG org.apache.http.headers  - << Content-Length: 100 702
[main] DEBUG org.apache.http.headers  - << Content-Length: 100 702 [main]
DEBUG org.apache.http.headers  - << Content-Type: text/html 702 [main]
DEBUG org.apache.http.headers  - << Content-Type: text/html 702 [main]
DEBUG org.apache.http.headers  - << Server: Microsoft-IIS/6.0 702 [main]
DEBUG org.apache.http.headers  - << Server: Microsoft-IIS/6.0 702 [main]
DEBUG org.apache.http.headers  - << Date: Thu, 08 Apr 2010 12:59:47 GMT
702 [main] DEBUG org.apache.http.headers  - << Date: Thu, 08 Apr 2010
12:59:47 GMT
702 [main] DEBUG org.apache.http.headers  - << Connection: close
702 [main] DEBUG org.apache.http.headers  - << Connection: close
<html><head><title>Error</title></head><body>The function requested is not
supported
</body></html>717 [main] DEBUG org.apache.http.wire  - <<
"<html><head><title>Error</title></head><body>The function requested is
not supported[\r][\n]"
717 [main] DEBUG org.apache.http.wire  - <<
"<html><head><title>Error</title></head><body>The function requested is
not supported[\r][\n]"
717 [main] DEBUG org.apache.http.wire  - << "</body></html>"
717 [main] DEBUG org.apache.http.wire  - << "</body></html>"
717 [main] DEBUG org.apache.http.impl.conn.SingleClientConnManager  -
Releasing connection
org.apache.http.impl.conn.singleclientconnmanager$connadap...@1a33d48 717
[main] DEBUG org.apache.http.impl.conn.SingleClientConnManager  -
Releasing connection
org.apache.http.impl.conn.singleclientconnmanager$connadap...@1a33d48 717
[main] DEBUG org.apache.http.impl.conn.SingleClientConnManager  - Released
connection open but not reusable.
717 [main] DEBUG org.apache.http.impl.conn.SingleClientConnManager  -
Released connection open but not reusable.
717 [main] DEBUG org.apache.http.impl.conn.DefaultClientConnection  -
Connection shut down
717 [main] DEBUG org.apache.http.impl.conn.DefaultClientConnection  -
Connection shut down






---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to