Search in sources :

Example 1 with DefaultAttribute

use of org.dom4j.tree.DefaultAttribute in project Openfire by igniterealtime.

the class DiscoIQRegisteredProcessor method process.

@Override
public void process(Packet packet, final String subdomain, String to, String from) throws PacketRejectedException {
    Log.debug("Processing packet in DiscoIQRegisteredProcessor for " + subdomain);
    // Check if the jabber:iq:register is enabled in admin panel
    boolean isFeatureEnabled = JiveGlobals.getBooleanProperty("plugin.remoteroster.sparkDiscoInfo", false);
    if (!isFeatureEnabled) {
        Log.debug("Spark extension is deactivated. Won't change the disco#info");
        return;
    }
    final InterceptorManager interceptorManager = InterceptorManager.getInstance();
    final PacketInterceptor interceptor = new PacketInterceptor() {

        public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) throws PacketRejectedException {
            if (!processed && incoming) {
                if (packet instanceof IQ) {
                    IQ iqPacket = (IQ) packet;
                    Element packetElement = iqPacket.getChildElement();
                    if (packetElement == null)
                        return;
                    String ns = iqPacket.getChildElement().getNamespace().getURI();
                    if (iqPacket.getType().equals(IQ.Type.result) && ns.equals("jabber:iq:register") && iqPacket.getFrom().toString().equals(subdomain)) {
                        // Check if we are already registered
                        setRegistered(iqPacket.toString().contains("<registered/>"));
                        throw new PacketRejectedException();
                    } else if (iqPacket.getType().equals(IQ.Type.result) && ns.equals("http://jabber.org/protocol/disco#info") && iqPacket.getFrom().toString().equals(subdomain)) {
                        /*
							 * This is the answer of the disco#info from spark
							 * to our component. add the jabber:iq:register
							 * feature if we are registered
							 */
                        if (isRegistered()) {
                            Log.debug("Modifying disco#info packge to send registered iq feature to Spark user " + iqPacket.getTo().toString());
                            Attribute attribut = new DefaultAttribute("var", "jabber:iq:registered");
                            iqPacket.getChildElement().addElement("feature").add(attribut);
                        }
                    }
                }
            }
        }
    };
    Log.debug("Creating my own listener for jabber:iq:register result to external component " + subdomain);
    interceptorManager.addInterceptor(interceptor);
    IQ askComponent = new IQ();
    askComponent.setTo(to);
    askComponent.setFrom(from);
    askComponent.setType(IQ.Type.get);
    Element query = new DefaultElement(QName.get("query", "jabber:iq:register"));
    askComponent.setChildElement(query);
    // Remove the package intercepter in 1sec
    TimerTask removeInterceptorTask = new TimerTask() {

        @Override
        public void run() {
            Log.debug("Removing my created listener for jabber:iq:register. Component " + subdomain);
            interceptorManager.removeInterceptor(interceptor);
        }
    };
    Timer timer = new Timer();
    timer.schedule(removeInterceptorTask, 1000);
    // Send the register query to component
    dispatchPacket(askComponent);
}
Also used : Packet(org.xmpp.packet.Packet) DefaultAttribute(org.dom4j.tree.DefaultAttribute) Attribute(org.dom4j.Attribute) DefaultElement(org.dom4j.tree.DefaultElement) InterceptorManager(org.jivesoftware.openfire.interceptor.InterceptorManager) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) PacketInterceptor(org.jivesoftware.openfire.interceptor.PacketInterceptor) TimerTask(java.util.TimerTask) Timer(java.util.Timer) PacketRejectedException(org.jivesoftware.openfire.interceptor.PacketRejectedException) DefaultAttribute(org.dom4j.tree.DefaultAttribute) Session(org.jivesoftware.openfire.session.Session)

Example 2 with DefaultAttribute

use of org.dom4j.tree.DefaultAttribute in project Openfire by igniterealtime.

the class IQRosterPayloadProcessor method sendRosterToComponent.

private void sendRosterToComponent(IQ requestPacket, Collection<RosterItem> items, String subdomain) {
    IQ response = IQ.createResultIQ(requestPacket);
    response.setTo(subdomain);
    Element query = new DefaultElement(QName.get("query", "jabber:iq:roster"));
    for (RosterItem i : items) {
        String jid = i.getJid().toString();
        if (!jid.equals(subdomain) && jid.contains(subdomain)) {
            Log.debug("Roster exchange for external component " + subdomain + ". Sending user " + i.getJid().toString());
            Element item = new DefaultElement("item", null);
            item.add(new DefaultAttribute("jid", i.getJid().toString()));
            item.add(new DefaultAttribute("name", i.getNickname()));
            item.add(new DefaultAttribute("subscription", "both"));
            for (String s : i.getGroups()) {
                Element group = new DefaultElement("group");
                group.setText(s);
                item.add(group);
            }
            query.add(item);
        }
    }
    response.setChildElement(query);
    dispatchPacket(response);
}
Also used : RosterItem(org.jivesoftware.openfire.roster.RosterItem) DefaultElement(org.dom4j.tree.DefaultElement) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) DefaultAttribute(org.dom4j.tree.DefaultAttribute)

Aggregations

Element (org.dom4j.Element)2 DefaultAttribute (org.dom4j.tree.DefaultAttribute)2 DefaultElement (org.dom4j.tree.DefaultElement)2 IQ (org.xmpp.packet.IQ)2 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 Attribute (org.dom4j.Attribute)1 InterceptorManager (org.jivesoftware.openfire.interceptor.InterceptorManager)1 PacketInterceptor (org.jivesoftware.openfire.interceptor.PacketInterceptor)1 PacketRejectedException (org.jivesoftware.openfire.interceptor.PacketRejectedException)1 RosterItem (org.jivesoftware.openfire.roster.RosterItem)1 Session (org.jivesoftware.openfire.session.Session)1 Packet (org.xmpp.packet.Packet)1