I looking for a way to programmatically set the credential of an HTTP adapter?
Is somebody has an example?
Is it possible to modify the adapter implementation js to overwrite the credentials?
with something like:
function getMyAdapters(path) {
var tok = "myuser:mypw";
var hash = Base64Encoder.encode(tok);
var headers="{'User-Agent':'Mozilla'"+"Authentication: Basic }"+hash;
var input = {
method : 'get',
returnedContentType : 'json',
headers: headers,
path : path
};
return WL.Server.invokeHttp(input);
}
But it failed as it doesn't find the Base64Encoder.
Any idea?
Firstly, you should use "Authorization" and not "Authentication" as described here: http://en.wikipedia.org/wiki/Basic_access_authentication
In addition, you should do the following:
Create a Java class, something like this (you'll need to clean and adjust it of course):
public class Idan {
public String basicHash(String user, String password) {
BASE64Encoder base64Encoder = new BASE64Encoder();
String authorization = user + ":" + password;
return base64Encoder.encode(authorization.getBytes());
}
// to test:
public static void main(String[] args) {
Idan i = new Idan();
System.out.println(i.basicHash("idan", "somepassword"));
}
}
In the adapter's .js file, declare globally:
var idan = new org.Idan();
And the procedure:
function test(){
WL.Logger.debug(idan.basicHash("username_test", "secret_password"));
}