Hi everybody,
I've added the support for XWIki authentication to the chat prototype.
Now, XMPP connections are authenticated using the XWiki authentication service.
To make the integration seamless, BOSH connections are authenticated
using XWiki cookies. So if you connect from an XWiki page where you
are already logged in, you will be automatically authenticated.
Otherwise you must provide actual XWiki usernames and passwords
(e.g., if you login from Pidgin)
Everything works quite well, though I think that some code review is
needed because accessing the AuthService from outside a real HTTP
request is quite tricky and I don't know if what I did has potential
issues.
There are 2 places where I can perform authentication:
1) In the XWikiUserAuthorization class. This code is called by the
Vysper server when it needs to authenticate a request. Here we are
outside the HTTP/Servlet realm because calls to the verifyCredentials
method could come also from the TCP/IP endpoint (the one used by
Pidgin, for example). What I did here is to create fake HTTP/Servlet
request/response to build an XWiki context and access to the
AuthService. I've adapted the code from
XWikiContextInitializationFilter and it looks like this:
https://github.com/xwiki-contrib/xwiki-platform-chat/blob/master/xwiki-plat…
(called from here:
https://github.com/xwiki-contrib/xwiki-platform-chat/blob/master/xwiki-plat…)
2) In the XWikiBoshHandler class. Here I have basically overridden
Vysper's Bosh process method that processes XMPP Stanzas. I intercept
AUTH stanzas and I try to authenticate the request from where these
stanzas come from using cookies. Here we are in the HTTP/Servlet realm
and I use the Execution object to retrieve the XWiki context which is
available because I associated a XWikiContextInitializationFilter to
the Bosh servlet. The code is here:
https://github.com/xwiki-contrib/xwiki-platform-chat/blob/master/xwiki-plat…
(pretty standard)
Comments are welcome.
Thanks,
-Fabio