JavierSolis / resting

Automatically exported from code.google.com/p/resting
0 stars 0 forks source link

Allow HTTP authentication for secure REST clients #20

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Connect to a REST web service that requires HTTP authentication

What is the expected output? What do you see instead?
Instead of a successful REST connection, I received:

Error 401 An Authentication object was not found in the SecurityContext

What version of the product are you using? On what operating system?
resting 0.6 binary as well as source TRUNK as of 18Oct2011 on Windows 7.

Please provide any additional information below.

I'm trying to connect to a REST web service that requires HTTP authentication 
over HTTPS. 

I've pulled down the trunk resting source from SVN and made the following 
change locally in RESTClient.secureInvoke():

  String userName = serviceContext.getUserName();
  String password = serviceContext.getPassword();
  if (userName != null && userName.isEmpty() == false && password != null) {
    httpclient.getCredentialsProvider().setCredentials(
        new AuthScope(targetHost.getHostName(), targetHost.getPort()),
        new UsernamePasswordCredentials(userName, password));
  }

That was added immediately after the DefaultHttpClient was declared.

For my local code, I overloaded the Resting methods to take the username and 
password.  I updated URLContext to hold those values so it can be passed to the 
ServiceContext object (like it does for isSecureInvocation).  I updated 
ServiceContext to house the username and password (like it does for 
isSecureInvocation). RESTClient caccesses the username and password from the 
ServiceContext passed to secureInvoke().  If username or password are set, then 
I execute the code above.

I can contribute this code change if you like.  I wasn't sure how you were 
going to deal with the proxy authentication, so I didn't want to incorrectly 
complicate your API.

Original issue reported on code.google.com by sno...@gmail.com on 18 Oct 2011 at 7:39

GoogleCodeExporter commented 9 years ago
Assigned to Priya

Original comment by sujata...@gmail.com on 16 Apr 2012 at 8:29

GoogleCodeExporter commented 9 years ago
The change for this is checked in

Original comment by sujata...@gmail.com on 21 Mar 2013 at 3:03