1
votes

I have a working xmpp web client using strophe,my current approach is to login user from strophe on java script,but security point of view it is not secure and in my application ihave to switch pages vary rapidly, while searching on internet on SO i found that Jake Moffitt has given a solution of implementing session which overcome both limitation ,as mention in his book "professional xmpp using java script",one can easy implement session and get SID and RID on server[have to create xmpp bosh connection from server]and pass it to java script(jid,sid and rid) which will than used in attach() method to connect with xmpp bosh manager,

I am using java as server side language,while some one try to implement boshclient in java it seem java smack and jbosh is only available solution (i mean working solution), But i couldn't find any method by which i can get RID and SID using java script, i went through another approach

why not run strophe client on top of jvm,(why to run strophe on jvm? i am able to get rid and sid using strophe on java script as mention on this link ,why one should try this solution on java) i have included rihno in my dynamic web project js.jar to my lib folder in WebContent/WEBINF/lib and gave a qualified path to run env.rihno.js which create an browser run time on java and included strophe.js and jquey.js file and try to connect to bosh clint as i did on javascript for my web app,

code::

Context cx = ContextFactory.getGlobal().enterContext();
            cx.setOptimizationLevel(-1);
            cx.setLanguageVersion(Context.VERSION_1_5);
            Global global = Main.getGlobal();
            global.init(cx);
            Main.processSource(cx, "/home/devwrat/workspace/Test/env.rhino.1.2.js");
            Main.processSource(cx, "/home/devwrat/workspace/Test/jquery-1.11.1.js");
            Main.processSource(cx, "/home/devwrat/workspace/Test/strophe.js");
            Main.processSource(cx, "/home/devwrat/workspace/Test/boshconnection.js");

It seem everything is working fine on java until cinnection.connect() using strophe execute in my java script,i observers that it is not connection to bosh manager.

My question is as below is it possible to establish bosh connection using strophe in java? and yes how?

thanks in advance!!!!

Edit (21-8-2014):: I observed that after executing conn.connect(Arthur.jid, Arthur.password, function (status){print(status);}),status is 1 which in turn means connection status is connecting,it always say connecting never get connected ??May be xmpp bosh manager is not authenticating connection!!!

1

1 Answers

0
votes

Strophe.js is usually used with the client side javascript. I think you're adding unnecessary complexity by trying to run Strophe.js on the server side.

You've mentioned two separate problems, moving authentication to the server side, and also maintaining session between page changes.

Problem #1 Moving authentication to server-side (Prebinding)

If you want to move the login process to the server side, then you can do so by utilizing a java based XMPP library or by manually creating and sending the stanza's (isn't that hard, it's basically just XML being sent over HTTP) which are needed for the authentication process. Once the BOSH session has been established server side, the JID+RID+SID attributes of the session can be passed to the client side javascript and used by Strophe's attach().

In order to write your own BOSH pre-binder, you should start by inspecting the stanza's which are exchanged between Strophe and ejabberd, and you should also read XEP-206. In summary, you will need to create a HTTPClient of some sort, point it towards ejabberd's /http-bind/ address, and begin sending it the same messages that strophe sends during login. You can always inspect the messages (stanzas) with your browser's network debugger, or Fiddler2 (I recommend this). Once you understand how Strophe establishes a session, you can begin writing your own server side mechanism to establish a session. Once the session has been established server side, you can extract the SID+RID+JID, and send them to your page and use them with attach().

Problem #2 Maintaining session between page changes

The second problem you state is that your application changes pages frequently. If you want to implement a mechanism to maintain your XMPP session between page changes, this can be done by utilizing strophes attach() in combination with a mechanism to store the JID+RID+SID. I use a combination of LocalStorage with fallback to AJAX to accomplish this.

BOSH and XMPP

The reason you cannot extract the RID and SID values from many XMPP libraries is because they don't use these attributes. SID and RID are used with BOSH, which is what enables us to communicate with an XMPP server using HTTP. With a web application using BOSH to communicate to an XMPP server, we have 3 levels: the XMPP server itself, a BOSH connection manager, and the web application. Since HTTP is stateless, and XMPP is not (it's designed to maintain a persistent connection), we need to use a BOSH connection manager to maintain that persistent connection to the XMPP server. This connection manager is what's managing our session with the server and handling the intermittent requests from the web application, it's able to push messages to the client with Comet.

In order for the BOSH connection manager to validate the intermittent requests coming from the web application, we include a SID and a RID attribute with each stanza. The SID will remain the same during the lifetime of the session, and the RID will increment by 1 with each outgoing request. It is important that the RID is incremented properly, if a request with an unexpected RID is sent to the connection manager, the session is usually ended and the connection manager will return an error.

Hope that helps.