Subscription requests
Submitted by Anonymous on Tue, 2006-10-31 15:08
::
Hi,
first of all, thanks for the great job.
I want to automatically accept subscription requests. For this purpose all subscription requests, regardless of which server the user account resides on, need to be intercepted and accepted. I know it can make Tigase vulnerable to spIM*.
I don't know how to start implementing this feature, can you help me please ?
Bruno
- 2165 reads
Printer-friendly version- Send to friend






Hello all. Has anyone one
Hello all. Has anyone one had success implementing the ability for the server to auto-accept add requests from the user? Am I missing a step in this workflow? The previous code snippet is in the in_subscribe processing codepath. Thanks much in advance!
I've been trying to implement
I've been trying to implement the auto-add feature myself. So far I have something close to the following. This is from Presence.java in_subscribe processing. The logic that I am trying to implement takes a user from one of the following states and adds them as subscribed.
none, from or to. If they are already subscribed "from" then there is logic prior to this which sends the subscribed packet. Am I missing something here? It doesn't seem to work as expected. I am using Tigase 4.x. Thanks much in advance!
SubscriptionType curr_sub =
roster_util.getBuddySubscription(session, packet.getElemFrom());
if (curr_sub == null) {
curr_sub = SubscriptionType.both;
roster_util.addBuddy(session, packet.getElemFrom(), null, "");
} // end of if (curr_sub == null)
roster_util.updateBuddySubscription(session, PresenceType.in_subscribe, packet.getElemFrom());
roster_util.addBuddy(session, packet.getElemFrom(), null, null);
sendPresence(StanzaType.subscribed,
JIDUtils.getNodeID(packet.getElemFrom()),
session.getUserId(), results, null);
Element presence = (Element) session.getSessionData(PRESENCE_KEY);
sendPresence(StanzaType.available, packet.getElemFrom(), session.getUserId(), results, presence);
Yes, you are very close.
Yes, you are very close. process() method is the one to modify. You have to look at in_subscribe and out_subscribe events to modify subscription on your end.
To set subscription to whatever value you need just use helper class: tigase.xmpp.impl.Roster and method:
updateBuddySubscription.
Let me know if you have any problems...
Let's go
1. yes
2. user B is connected to an unknown xmpp server. so I don't manage the roster of UserA. But if I reply a "suscribed" message, the unknown server will add UserB to the roster of UserA.
I have take a look at Presence class. I think I need to modify process() method; in case "in_subscribe" just call sendPresence(StanzaType.subscribed, packet.getElemFrom(), session.getJID(), results, null); and add userA to the roster of UserB with subscription 'both' (I don't know how to do that for now). Am I in the right way ?
Thanks very much for all your replies.
Ok, let's go one step
Ok, let's go one step further with details.
All these subscriptions and presence stuff is quite complex so to make things simple do I correctly understand that is UserA want to subscribe to UserB it actually means that server should:
If this is a case and you want it to work for all users than indeed you should rewrite Presence class (which would be much simpler in your case) and load it instead of standard Presence class provided in Tigase server.
Scenario
Hi,
what I want is when a jabber user (user A) subscribes to one of my tigase user (user B), my tigase server auto reply "subscribed" to user A. I don't want to bother user B with subscription stuff. Moreover I want this feature on server side in order to be client independent.
Am I clear ?
Thanks for your attention and advices.
Give us more info please
Hi again,
I was hoping that you give us more info about your problem. Presence class is one of the most complex classes as presence design is quite complex in XMPP. So I would rather avoid modifying it.
The better option would be probably to implement another processor which could catch selected presence stanzas and do what you want.
My worry is however, that it still might not be the most efficient solution for your case. If you could tell us what exactly you need and why you need it we could give you better advice/solution or we could even help you implement extension for your needs.
on server
First thanks for your fast answer.
Yes, I want to implement it on server level. I will have a look at tigase.xmpp.impl.Presence class and I hope to success. I keep you inform.
Not sure if I understand...
Hm, not sure if I understand you correctly.
You want to implement it on server level right? Why? I just found similar feature in the last Psi version. So Psi can automatically accept and authorize all subscription requests. Isn't it enough?
I am asking because I just need to understand your requirements correctly. There are quite a few possible ways to implement it in Tigase but selecting proper way depends on you use case.
The most strightforward way would be to reimplement tigase.xmpp.impl.Presence class to change behaviour on subscription request. The downside of such solution is that then you change behavior for ALL subscription requests. The more flexible approach would be to create another Presence which could coexists with existing one and for selected subscription requests it could execute desired action.
I was about to write a developers guide how to create new extensions for Tigase server. Well, it could be a good starting point...
Post new comment