Re: Issue 6 in android-xmlrpc: HTTP Basic authentication & Pre-emptive Authentication

34 views
Skip to first unread message

android...@googlecode.com

unread,
Sep 14, 2010, 9:45:32 AM9/14/10
to android-x...@googlegroups.com

Comment #25 on issue 6 by JonTheNiceGuy: HTTP Basic authentication &
Pre-emptive Authentication
http://code.google.com/p/android-xmlrpc/issues/detail?id=6

bszabolcs: If you've got a code snippet which works, would you be willing
to paste it in this ticket, so we can add it to the Wiki, and amend the
code to incorporate the calls that you made?

android...@googlecode.com

unread,
Sep 14, 2010, 10:23:22 AM9/14/10
to android-x...@googlegroups.com

Comment #26 on issue 6 by erickok: HTTP Basic authentication & Pre-emptive
Authentication
http://code.google.com/p/android-xmlrpc/issues/detail?id=6

It's really simple. Do something like this:

this.rpcclient = new XMLRPCClient(buildWebUIUrl(),
settings.getSslTrustAll());
if (settings.shouldUseAuthentication()) {
this.rpcclient.setBasicAuthentication(settings.getUsername(),
settings.getPassword());
}
this.rpcclient.call("load_start", new String[] { url });

This is taken from my project. Full source code:
http://code.google.com/p/transdroid/source/browse/trunk/src/org/transdroid/daemon/Rtorrent/RtorrentAdapter.java

To do pre-emptive authorization, look for the line 'HttpResponse response =
client.execute(postMethod);' in the XMLRPCClient.java file and add this
just before the execute():

// Force preemptive authentication
// This makes sure there is an 'Authentication: ' header being send before
trying and failing and retrying
// by the basic authentication mechanism of DefaultHttpClient
postMethod.addHeader("Authorization", "Basic " +
Base64.encodeBytes((username + ":" + password).getBytes()));

This manually adds the authorization header. Hope this helps.

android...@googlecode.com

unread,
Sep 15, 2010, 8:24:11 AM9/15/10
to android-x...@googlegroups.com

Comment #27 on issue 6 by bszabolcs: HTTP Basic authentication &
Pre-emptive Authentication
http://code.google.com/p/android-xmlrpc/issues/detail?id=6

I have defined this innerclass in XMLRPCClient.java:

HttpRequestInterceptor preemptiveAuth = new HttpRequestInterceptor() {
public void process(final HttpRequest request, final HttpContext
context) throws HttpException, IOException {
AuthState authState = (AuthState)
context.getAttribute(ClientContext.TARGET_AUTH_STATE);
CredentialsProvider credsProvider = (CredentialsProvider)
context.getAttribute(ClientContext.CREDS_PROVIDER);
HttpHost targetHost = (HttpHost)
context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);

if (authState.getAuthScheme() == null) {
AuthScope authScope = new AuthScope(targetHost.getHostName(),
targetHost.getPort());
Credentials creds = credsProvider.getCredentials(authScope);
if (creds != null) {
authState.setAuthScheme(new BasicScheme());
authState.setCredentials(creds);
}
}
}
};

and I have added the first line to activate preemptive authentication:

((DefaultHttpClient) client).addRequestInterceptor(preemptiveAuth, 0);
((DefaultHttpClient) client).getCredentialsProvider().setCredentials(
new AuthScope(postMethod.getURI().getHost(),
postMethod.getURI().getPort(),AuthScope.ANY_REALM),
new UsernamePasswordCredentials(username, password));


android...@googlecode.com

unread,
Nov 19, 2010, 11:17:23 AM11/19/10
to android-x...@googlegroups.com
Updates:
Owner: j...@sprig.gs
Labels: Usability

Comment #28 on issue 6 by j...@sprig.gs: HTTP Basic authentication &
Pre-emptive Authentication
http://code.google.com/p/android-xmlrpc/issues/detail?id=6

Thanks for these code snippets erickok and bszabolcs. I'll try and
implement something around this over the next week or so.

android...@googlecode.com

unread,
Nov 23, 2010, 10:10:36 AM11/23/10
to android-x...@googlegroups.com

Comment #29 on issue 6 by j.rehborn: HTTP Basic authentication &
Pre-emptive Authentication
http://code.google.com/p/android-xmlrpc/issues/detail?id=6

The Code snippets are working very well. I implement them because i need
them for my project. If you tell me how I can push them, I will do that
tomorrow ;)

Attachments:
XMLRPCClient.java 17.3 KB

android...@googlecode.com

unread,
Nov 23, 2010, 4:22:29 PM11/23/10
to android-x...@googlegroups.com

Comment #30 on issue 6 by j...@sprig.gs: HTTP Basic authentication &
Pre-emptive Authentication
http://code.google.com/p/android-xmlrpc/issues/detail?id=6

j.rehborn thanks for your code - it's best to attach patches rather than
complete files, as it helps us to work out what the differences are that
you've introduced.

I copied your code into the tree, and it introduced an error (around the
Base64 library), so to be honest, as I'd already started on this, I've not
looked too deeply into fixing the issue in your code, or looking at whether
it's a clearer and cleaner piece of code. I'll be pushing the patch
inspired by erickok's code snippet, shortly (as part of a few patches), but
in the meantime, here's the patch I'll be pushing.

(Note, I've just spotted that I've not credited erickok as inspiration,
this will be fixed in the push.)

Attachments:
issue6.patch 2.8 KB

android...@googlecode.com

unread,
Nov 24, 2010, 4:52:55 AM11/24/10
to android-x...@googlegroups.com
Updates:
Status: Started

Comment #31 on issue 6 by j...@sprig.gs: HTTP Basic authentication &
Pre-emptive Authentication
http://code.google.com/p/android-xmlrpc/issues/detail?id=6

This code has been committed, and requires testing.

android...@googlecode.com

unread,
Dec 27, 2010, 3:09:52 PM12/27/10
to android-x...@googlegroups.com

Comment #32 on issue 6 by canyumusak: HTTP Basic authentication &
Pre-emptive Authentication
http://code.google.com/p/android-xmlrpc/issues/detail?id=6

Hey Guys,

i'm pretty new to android-developing but i'm having this íssue as well -
even after using the patch and trying both - with false and true option at
BasicAuth Setting, here my code snippet:


try {
serverURL = new URL(server+":"+port);
} catch (MalformedURLException e) {
System.out.println("Invalid URL - could not connect!");
}
myServer = new XMLRPCClient(serverURL);
myServer.setBasicAuthentication("myuser", "mypw", true);
state =
(HashMap<String,Integer>)
myServer.call("Tester.getStatement", params );

I don't really know how to solve this problem. I attached my webserver
(Apache XML-RPC java) code. The Serverside see's both username and password
as null.



Attachments:
Server.txt 3.3 KB

android...@googlecode.com

unread,
Dec 27, 2010, 5:19:08 PM12/27/10
to android-x...@googlegroups.com

Comment #33 on issue 6 by j...@sprig.gs: HTTP Basic authentication &
Pre-emptive Authentication
http://code.google.com/p/android-xmlrpc/issues/detail?id=6

Hi canyumusak,

I'm not certain whether the issue you've mentioned is linked to this issue
- can you advise what happens when you try and run your script? Can you
provide any log output? Do you see the access attempt occur on your web
server? Are you able to provide any packet capture of what happens when you
try to make your connection?

Also, are you able to try the following:

try {
serverURL = new URL(server+":"+port);
} catch (MalformedURLException e) {
System.out.println("Invalid URL - could not connect!");
}

myServer = new XMLRPCClient(serverURL, "myuser", "mypw");


state = (HashMap<String,Integer>) myServer.call("Tester.getStatement",
params );

The current version of the code, while it's not covered in the
documentation, does support client creation method.

android...@googlecode.com

unread,
Dec 27, 2010, 6:41:44 PM12/27/10
to android-x...@googlegroups.com

Comment #34 on issue 6 by canyumusak: HTTP Basic authentication &
Pre-emptive Authentication
http://code.google.com/p/android-xmlrpc/issues/detail?id=6

Hey jon,

i am currently running the same client in a normal JRE, using the XML-RPC
Client creation of apache.
I tried several combinations (myServer = new
XMLRPCClient(serverURL, "myuser", "mypw"), myServer = new XMLRPCClient(new
URL(http://myuser:my...@192.168.2.24/));, etc..).
My Server can't seem to recognize the username and password.

I tried to look at the logcat log now. It returns me the attached error (i
think it's the fatal one). Should i continue posting here?

greetings,
Geki

Attachments:
Logcat.txt 4.4 KB

android...@googlecode.com

unread,
Dec 27, 2010, 7:18:58 PM12/27/10
to android-x...@googlegroups.com

Comment #35 on issue 6 by canyumusak: HTTP Basic authentication &
Pre-emptive Authentication
http://code.google.com/p/android-xmlrpc/issues/detail?id=6

I tried several combinations.
I attached my Logcat results. I suppose, that this XML-RPC Client is not
compatible with the apache XML-RPC Server.

What XML-RPC java alternative should I use?

greetings,

Geki

Attachments:
Logcat.txt 7.9 KB

android...@googlecode.com

unread,
Dec 27, 2010, 7:29:02 PM12/27/10
to android-x...@googlegroups.com

Comment #36 on issue 6 by canyumusak: HTTP Basic authentication &
Pre-emptive Authentication
http://code.google.com/p/android-xmlrpc/issues/detail?id=6

What i forgot to write: The Server gives me this error:

28.12.2010 01:15:25 org.apache.xmlrpc.server.XmlRpcErrorLogger log
SCHWERWIEGEND: Not authorized
org.apache.xmlrpc.common.XmlRpcNotAuthorizedException: Not authorized
at
org.apache.xmlrpc.server.ReflectiveXmlRpcHandler.execute(ReflectiveXmlRpcHandler.java:84)
at
org.apache.xmlrpc.server.XmlRpcServerWorker.execute(XmlRpcServerWorker.java:46)
at org.apache.xmlrpc.server.XmlRpcServer.execute(XmlRpcServer.java:86)
at
org.apache.xmlrpc.server.XmlRpcStreamServer.execute(XmlRpcStreamServer.java:200)
at org.apache.xmlrpc.webserver.Connection.run(Connection.java:208)
at org.apache.xmlrpc.util.ThreadPool$Poolable$1.run(ThreadPool.java:68)
28.12.2010 01:22:21 org.apache.xmlrpc.server.XmlRpcErrorLogger log

android...@googlecode.com

unread,
Dec 27, 2010, 7:33:03 PM12/27/10
to android-x...@googlegroups.com

Comment #37 on issue 6 by j...@sprig.gs: HTTP Basic authentication &
Pre-emptive Authentication
http://code.google.com/p/android-xmlrpc/issues/detail?id=6

Certainly this library can't handle URLs in the format

http://username:password@hostname/path/to/xmlrpc.svc

but it should be able to cope with

http://hostname/path/to/xmlrpc.svc

although I also noticed in your URL creation above (in comment 32), you've
used

serverURL = new URL(server+":"+port);

Is there any reason you're quoting port numbers? Given our inflexibility in
the authentication portion, it would probably be worth trying (if you're
using a different port) running the service on straight port 80, and trying
just using the straight URL (no ports or auth details)?

Thus your code would be:

myServer = new XMLRPCClient(server_url, "user", "passwd");

I'm not saying this will fix it, but it's something else to try?

android...@googlecode.com

unread,
Dec 27, 2010, 9:00:29 PM12/27/10
to android-x...@googlegroups.com

Comment #38 on issue 6 by canyumusak: HTTP Basic authentication &
Pre-emptive Authentication
http://code.google.com/p/android-xmlrpc/issues/detail?id=6

I get absolutely the same error.
Trying to get it to work "anyhow" - i set the auth-method to always return
true. It works this way.
My port was 8080, changing it to 80 didn't change the error or the way it
behaves.
Unfortunately i am programming this with access to critical data, hence i
can't leave it without any authentication.

I am thinking about migrating away from apache xml-rpc in java, if this
solves the error. Are there good alternatives?

android...@googlecode.com

unread,
Dec 27, 2010, 9:31:48 PM12/27/10
to android-x...@googlegroups.com

Comment #39 on issue 6 by canyumusak: HTTP Basic authentication &
Pre-emptive Authentication
http://code.google.com/p/android-xmlrpc/issues/detail?id=6

News:
Using myServer = new XMLRPCClient(server_url, "user", "passwd"); ends in
the error i wrote above.

myServer = new XMLRPCClient(server_url); connects succesfully (with no Auth
requested)

android...@googlecode.com

unread,
Mar 25, 2011, 1:48:09 PM3/25/11
to android-x...@googlegroups.com

Comment #40 on issue 6 by giaco.me...@gmail.com: HTTP Basic authentication

first of all thanks for the code, then:
still bad user name and password issue for wordpress?


android...@googlecode.com

unread,
Sep 14, 2011, 8:18:23 AM9/14/11
to android-x...@googlegroups.com
Updates:
Owner: ---

Comment #41 on issue 6 by j...@sprig.gs: HTTP Basic authentication &
Pre-emptive Authentication
http://code.google.com/p/android-xmlrpc/issues/detail?id=6

I'm no longer able to commit time to this project, and as such, I am
removing myself from any tickets I've previously been involved in.

Reply all
Reply to author
Forward
0 new messages