powered by Jive Software

Disconnecting/Kicking session

I’‘m building a plugin with special features, which uses Wf’'s routing to communicate with other participants. It works very well so far.

Now I want to be able to disconnect all sessions for a certain user. Which is the correct way of doing that?

I have found SessionManager, and located getSessions(), which gives me an array of ClientSessions. How do I now “kick” this session?

Thanks for any help!

//Peter

Hi Peter,

The following code will close the session for a given user with a given resource:

SessionManager sessionManager = SessionManager.getInstance();
ClientSession clientSession = sessionManager.getSession("bob", "example.com", "work");
clientSession.getConnection().close();

If a user is signed in with multiple resources (i.e. work and home) you’'d have to execute the above code twice.

Hope that helps,

Ryan

Thanks!

I was on the right path, but wasn’'t sure how the protocol worked. Anyway, this is the result:

public void closeSessionsFor(JID account) {
     SessionManager sm = SessionManager.getInstance();
     Collection<ClientSession> cs = sm.getSessions(account.getNode());
     for (ClientSession c : cs) {
          c.getConnection().close();
     }
}

Haven’‘t tested it yet, but I’‘m sure it’'s working!

Haven’‘t tested it yet, but I’‘m sure it’'s working!

Glad to hear it.

Hi Mr. Graham,

I’m trying the code you have provided for disconnecting session.

But it is giving me an error on line

clientSession.getConnection().close();

The method getConnection() is undefined for the type ClientSession

I am using openfire 3.6.4

Can you help me how to disconnect session on

openfire 3.6.4

Thx!