You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Leo Wraith <ha...@yahoo.com> on 2008/10/04 15:57:15 UTC

ntlm authentication

 
I have a Web application online running on a Linux server. I need to access files located on a private network running Windows server. The client has given me a public IP which uses port 8080 that I can use to access the reources that I need. 
 
If I type the IP plus the port in IE like so: http://[my ip addres]:8080 I get the prompt to enter the appropriate user and password. When I enter the user and password that were given to me by the client, I’m able to access the directories that I need. 
 
Now, I want to this from my application without user intervention. In other words, I want to be able to pass the IP, port, userid and password from within my routine and then access the necessary resources. 
 
I’ve been working with several samples but the result is always the same. When I run the JSP page, I get prompted for the userid and password. 
 
Could you please take a look at the code snippet and give me a heads-up. 
 
    HttpClient client = new HttpClient(); 
    // Set credentials on the client 
    Credentials credentials = new NTCredentials("userid", "password", 
                                                                         "http://0.0.0.0:8080", null); 
    //HttpState state = client.getState(); 
    //state().setCredentials(null, null, credentials); 
    client.getState().setCredentials(null, null, credentials); 
    String url = "http://0.0.0.0/PathToFiles"; 
    HttpMethod method = new GetMethod(url); 
    client.executeMethod(method); 
   
    // String responseStr = method.getResponseBodyAsString(); 
    // System.out.println(responseStr); 
    // method.releaseConnection(); 
 
    String redirectURL = "http://0.0.0.0:8080/PathToFiles" ; 
    response.sendRedirect(response.encodeRedirectURL(redirectURL)); 
 
Thanks so much for the help
 
 


      

Re: ntlm authentication

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Sat, 2008-10-04 at 07:26 -0700, Leo Wraith wrote:
> Hi sebb, 
>  
> Sorry, i should have mentioned it. 
>  
> I'm using httpclient-4.0-beta1 and yes, 0.0.0.0 is just for show. 

Leo

Judging by the code snippet you posted in your first message, you are
still using HttpClient 3.1. So, you need to make sure the target server
is configured to allow older version of the NTLM protocol (NTLMv1). 

Oleg


>  
> thanks,
> 
> --- On Sat, 10/4/08, sebb <se...@gmail.com> wrote:
> 
> From: sebb <se...@gmail.com>
> Subject: Re: ntlm authentication
> To: "HttpClient User Discussion" <ht...@hc.apache.org>
> Date: Saturday, October 4, 2008, 9:16 AM
> 
> On 04/10/2008, Leo Wraith <ha...@yahoo.com> wrote:
> >
> >
> >  I have a Web application online running on a Linux server. I need to
> access files located on a private network running Windows server. The client has
> given me a public IP which uses port 8080 that I can use to access the reources
> that I need.
> >
> >  If I type the IP plus the port in IE like so: http://[my ip addres]:8080
> I get the prompt to enter the appropriate user and password. When I enter the
> user and password that were given to me by the client, I'm able to access
> the directories that I need.
> >
> >  Now, I want to this from my application without user intervention. In
> other words, I want to be able to pass the IP, port, userid and password from
> within my routine and then access the necessary resources.
> >
> >  I've been working with several samples but the result is always the
> same. When I run the JSP page, I get prompted for the userid and password.
> >
> >  Could you please take a look at the code snippet and give me a heads-up.
> >
> >      HttpClient client = new HttpClient();
> >      // Set credentials on the client
> >      Credentials credentials = new NTCredentials("userid",
> "password",
> >                                                                          
> "http://0.0.0.0:8080", null);
> >      //HttpState state = client.getState();
> >      //state().setCredentials(null, null, credentials);
> >      client.getState().setCredentials(null, null, credentials);
> >      String url = "http://0.0.0.0/PathToFiles";
> >      HttpMethod method = new GetMethod(url);
> >      client.executeMethod(method);
> >
> >      // String responseStr = method.getResponseBodyAsString();
> >      // System.out.println(responseStr);
> >      // method.releaseConnection();
> >
> >      String redirectURL = "http://0.0.0.0:8080/PathToFiles" ;
> >      response.sendRedirect(response.encodeRedirectURL(redirectURL));
> 
> I assume that 0.0.0.0 is not the real IP address...
> 
> >  Thanks so much for the help
> 
> Which version of HTTPClient are you using?
> 
> BTW, HTTPClient 3.x only ever supported NTLMv1, it does not support NTLMv2.
> 
> See also:
> 
> http://hc.apache.org/httpclient-3.x/authentication.html#NTLM
> 
> http://hc.apache.org/httpcomponents-client/ntlm.html
> 
> >
> >
> >
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 
> 
> 
> 
>       


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: ntlm authentication

Posted by Leo Wraith <ha...@yahoo.com>.
Hi sebb, 
 
Sorry, i should have mentioned it. 
 
I'm using httpclient-4.0-beta1 and yes, 0.0.0.0 is just for show. 
 
thanks,

--- On Sat, 10/4/08, sebb <se...@gmail.com> wrote:

From: sebb <se...@gmail.com>
Subject: Re: ntlm authentication
To: "HttpClient User Discussion" <ht...@hc.apache.org>
Date: Saturday, October 4, 2008, 9:16 AM

On 04/10/2008, Leo Wraith <ha...@yahoo.com> wrote:
>
>
>  I have a Web application online running on a Linux server. I need to
access files located on a private network running Windows server. The client has
given me a public IP which uses port 8080 that I can use to access the reources
that I need.
>
>  If I type the IP plus the port in IE like so: http://[my ip addres]:8080
I get the prompt to enter the appropriate user and password. When I enter the
user and password that were given to me by the client, I'm able to access
the directories that I need.
>
>  Now, I want to this from my application without user intervention. In
other words, I want to be able to pass the IP, port, userid and password from
within my routine and then access the necessary resources.
>
>  I've been working with several samples but the result is always the
same. When I run the JSP page, I get prompted for the userid and password.
>
>  Could you please take a look at the code snippet and give me a heads-up.
>
>      HttpClient client = new HttpClient();
>      // Set credentials on the client
>      Credentials credentials = new NTCredentials("userid",
"password",
>                                                                          
"http://0.0.0.0:8080", null);
>      //HttpState state = client.getState();
>      //state().setCredentials(null, null, credentials);
>      client.getState().setCredentials(null, null, credentials);
>      String url = "http://0.0.0.0/PathToFiles";
>      HttpMethod method = new GetMethod(url);
>      client.executeMethod(method);
>
>      // String responseStr = method.getResponseBodyAsString();
>      // System.out.println(responseStr);
>      // method.releaseConnection();
>
>      String redirectURL = "http://0.0.0.0:8080/PathToFiles" ;
>      response.sendRedirect(response.encodeRedirectURL(redirectURL));

I assume that 0.0.0.0 is not the real IP address...

>  Thanks so much for the help

Which version of HTTPClient are you using?

BTW, HTTPClient 3.x only ever supported NTLMv1, it does not support NTLMv2.

See also:

http://hc.apache.org/httpclient-3.x/authentication.html#NTLM

http://hc.apache.org/httpcomponents-client/ntlm.html

>
>
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org




      

Re: ntlm authentication

Posted by sebb <se...@gmail.com>.
On 04/10/2008, Leo Wraith <ha...@yahoo.com> wrote:
>
>
>  I have a Web application online running on a Linux server. I need to access files located on a private network running Windows server. The client has given me a public IP which uses port 8080 that I can use to access the reources that I need.
>
>  If I type the IP plus the port in IE like so: http://[my ip addres]:8080 I get the prompt to enter the appropriate user and password. When I enter the user and password that were given to me by the client, I'm able to access the directories that I need.
>
>  Now, I want to this from my application without user intervention. In other words, I want to be able to pass the IP, port, userid and password from within my routine and then access the necessary resources.
>
>  I've been working with several samples but the result is always the same. When I run the JSP page, I get prompted for the userid and password.
>
>  Could you please take a look at the code snippet and give me a heads-up.
>
>      HttpClient client = new HttpClient();
>      // Set credentials on the client
>      Credentials credentials = new NTCredentials("userid", "password",
>                                                                           "http://0.0.0.0:8080", null);
>      //HttpState state = client.getState();
>      //state().setCredentials(null, null, credentials);
>      client.getState().setCredentials(null, null, credentials);
>      String url = "http://0.0.0.0/PathToFiles";
>      HttpMethod method = new GetMethod(url);
>      client.executeMethod(method);
>
>      // String responseStr = method.getResponseBodyAsString();
>      // System.out.println(responseStr);
>      // method.releaseConnection();
>
>      String redirectURL = "http://0.0.0.0:8080/PathToFiles" ;
>      response.sendRedirect(response.encodeRedirectURL(redirectURL));

I assume that 0.0.0.0 is not the real IP address...

>  Thanks so much for the help

Which version of HTTPClient are you using?

BTW, HTTPClient 3.x only ever supported NTLMv1, it does not support NTLMv2.

See also:

http://hc.apache.org/httpclient-3.x/authentication.html#NTLM

http://hc.apache.org/httpcomponents-client/ntlm.html

>
>
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org