You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@wink.apache.org by Paulo Borges <ab...@hotmail.com> on 2010/06/07 00:18:14 UTC

Adding Authorization to http header using RestClient

Hello:

Our wink rest application is using container security (in Websphere). Basically any attempt to access a resource is required to have an id and password. Normally in using java native URL api, I use the following code to authenticate a user [say id mack and pwd wink4you] to container:

String authorization = "mack:wink4you";
BASE64Encoder encoder = new sun.misc.BASE64Encoder();
URL url = new URL("http://localhost:9080/....");
HttpURLConnection urlc = (HttpURLConnection) url.openConnection();            
urlc.setRequestProperty("Authorization", "Basic "+ encoder.encode(authorization));

is there a way to achieve the above result using wink client api.
 		 	   		  
_________________________________________________________________
MSN Dating: Find someone special. Start now.
http://go.microsoft.com/?linkid=9734384

Re: Adding Authorization to http header using RestClient

Posted by Bryant Luk <br...@gmail.com>.
Hi,

Can you try using:
org.apache.wink.client.handlers.BasicAuthSecurityHandler and add it to
your client config?

ClientConfig config = new ClientConfig();
BasicAuthSecurityHandler basicAuth = new BasicAuthSecurityHandler();
basicAuth.setUserName("mack");
basicAuth.setPassword("wink4you");
config.handlers(basicAuth);
// create the rest client instance
RestClient client = new RestClient(config);
// create the resource instance to interact with Resource
resource = client.resource("https://localhost:9080/path/to/resource");

You can also directly set any header via the client API:

client.resource("https://localhost:9080/path/to/resource").header("customHeader",
"customValue);

On Sun, Jun 6, 2010 at 5:18 PM, Paulo Borges <ab...@hotmail.com> wrote:
>
> Hello:
>
> Our wink rest application is using container security (in Websphere). Basically any attempt to access a resource is required to have an id and password. Normally in using java native URL api, I use the following code to authenticate a user [say id mack and pwd wink4you] to container:
>
> String authorization = "mack:wink4you";
> BASE64Encoder encoder = new sun.misc.BASE64Encoder();
> URL url = new URL("http://localhost:9080/....");
> HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
> urlc.setRequestProperty("Authorization", "Basic "+ encoder.encode(authorization));
>
> is there a way to achieve the above result using wink client api.
>
> _________________________________________________________________
> MSN Dating: Find someone special. Start now.
> http://go.microsoft.com/?linkid=9734384