Search in sources :

Example 6 with Roster

use of org.jivesoftware.openfire.roster.Roster in project Openfire by igniterealtime.

the class MSNSession method completedPendingContactAdd.

/**
     * Completes the addition of groups to a new contact after the contact has been created.
     *
     * @param msnContact Contact that was added.
     */
public void completedPendingContactAdd(MsnContact msnContact) {
    try {
        Roster roster = getTransport().getRosterManager().getRoster(getJID().getNode());
        Email contact = msnContact.getEmail();
        JID contactJID = getTransport().convertIDToJID(contact.toString());
        RosterItem item = roster.getRosterItem(contactJID);
        getBuddyManager().storeBuddy(new MSNBuddy(getBuddyManager(), msnContact));
        syncContactGroups(contact, item.getGroups());
    } catch (UserNotFoundException e) {
        Log.debug("MSN: Unable to find roster when adding pendingcontact for " + getJID());
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) RosterItem(org.jivesoftware.openfire.roster.RosterItem) Email(net.sf.jml.Email) Roster(org.jivesoftware.openfire.roster.Roster) JID(org.xmpp.packet.JID)

Example 7 with Roster

use of org.jivesoftware.openfire.roster.Roster in project Openfire by igniterealtime.

the class MSNSession method completedPendingGroupAdd.

/**
     * Completes the addition of a contact to a new group after the group has been created.
     *
     * @param msnGroup Group that was added.
     */
public void completedPendingGroupAdd(MsnGroup msnGroup) {
    if (!msnPendingGroups.containsKey(msnGroup.getGroupName())) {
        // Nothing to do, no pending.
        return;
    }
    try {
        Roster roster = getTransport().getRosterManager().getRoster(getJID().getNode());
        for (Email contact : msnPendingGroups.get(msnGroup.getGroupName())) {
            JID contactJID = getTransport().convertIDToJID(contact.toString());
            RosterItem item = roster.getRosterItem(contactJID);
            syncContactGroups(contact, item.getGroups());
        }
    } catch (UserNotFoundException e) {
        Log.debug("MSN: Unable to find roster when adding pending group contacts for " + getJID());
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) RosterItem(org.jivesoftware.openfire.roster.RosterItem) Email(net.sf.jml.Email) Roster(org.jivesoftware.openfire.roster.Roster) JID(org.xmpp.packet.JID)

Example 8 with Roster

use of org.jivesoftware.openfire.roster.Roster in project Openfire by igniterealtime.

the class IQRosterPayloadProcessor method handleIQset.

private void handleIQset(IQ myPacket, final String subdomain, final String username) throws PacketRejectedException {
    IQ response = IQ.createResultIQ(myPacket);
    List<Node> nodes = findNodesInDocument(myPacket.getElement().getDocument(), "//roster:item");
    for (Node n : nodes) {
        Roster roster;
        String jid = n.valueOf("@jid");
        String name = n.valueOf("@name");
        String subvalue = n.valueOf("@subscription");
        // causing trouble on register:remove
        if (JiveGlobals.getBooleanProperty("plugin.remoteroster.ignoreSubdomains", true) && jid.equals(subdomain) && subvalue.equals("both"))
            throw new PacketRejectedException();
        if (subvalue.equals("both")) {
            try {
                roster = _rosterManager.getRoster(username);
                List<String> grouplist = new ArrayList<String>();
                List<Node> groupnodes = findNodesInDocument(n.getDocument(), "//roster:group");
                for (Node ne : groupnodes) {
                    String groupName = ne.getText();
                    grouplist.add(groupName);
                }
                boolean rosterPersistent = JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent", true);
                Log.debug("Adding/Updating Contact " + jid + " to roster of " + username);
                try {
                    RosterItem item = roster.getRosterItem(new JID(jid));
                    item.setGroups(grouplist);
                    roster.updateRosterItem(item);
                    // dont send iq-result if just updating user
                    continue;
                } catch (UserNotFoundException exc) {
                // Then we should add him!
                }
                RosterItem item = roster.createRosterItem(new JID(jid), name, grouplist, false, rosterPersistent);
                item.setSubStatus(RosterItem.SUB_BOTH);
                roster.updateRosterItem(item);
            } catch (Exception e) {
                Log.info("Could not add user to Roster although no entry should exist..." + username, e);
            }
            dispatchPacket(response);
        } else if (subvalue.equals("remove")) {
            // we dont need to do this when persistent = false because they will get deleted as soon as gateway is unavailable
            if (JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent", false) && jid.equals(subdomain)) {
                deleteSubdomainItemsFromRoster(username, subdomain);
            }
            // to handle it
            throw new PacketRejectedException();
        }
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) JID(org.xmpp.packet.JID) Node(org.dom4j.Node) IQ(org.xmpp.packet.IQ) ArrayList(java.util.ArrayList) PacketRejectedException(org.jivesoftware.openfire.interceptor.PacketRejectedException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) SharedGroupException(org.jivesoftware.openfire.SharedGroupException) RosterItem(org.jivesoftware.openfire.roster.RosterItem) Roster(org.jivesoftware.openfire.roster.Roster) PacketRejectedException(org.jivesoftware.openfire.interceptor.PacketRejectedException)

Example 9 with Roster

use of org.jivesoftware.openfire.roster.Roster in project Openfire by igniterealtime.

the class IQRosterPayloadProcessor method deleteSubdomainItemsFromRoster.

/**
	 * Searches the users roster for a specific subdomain and deletes all contacts that contain subdomain
	 * 
	 * @param username
	 * @param subdomain
	 */
private void deleteSubdomainItemsFromRoster(String username, String subdomain) {
    try {
        Roster roster = _rosterManager.getRoster(username);
        Collection<RosterItem> items = roster.getRosterItems();
        for (RosterItem item : items) {
            String itemName = item.getJid().toString();
            if (itemName.contains(subdomain)) {
                Log.debug("Removing contact " + item.getJid().toString() + " from contact list because of Unregister.");
                roster.deleteRosterItem(item.getJid(), false);
            }
        }
    } catch (UserNotFoundException e) {
        Log.debug("Couldnt find User!" + e.toString());
    } catch (SharedGroupException e) {
        e.printStackTrace();
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) RosterItem(org.jivesoftware.openfire.roster.RosterItem) Roster(org.jivesoftware.openfire.roster.Roster) SharedGroupException(org.jivesoftware.openfire.SharedGroupException)

Example 10 with Roster

use of org.jivesoftware.openfire.roster.Roster in project Openfire by igniterealtime.

the class IQRosterPayloadProcessor method handleIQget.

private void handleIQget(IQ myPacket, String subdomain, String username) {
    if (JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent", false)) {
        Roster roster;
        try {
            roster = _rosterManager.getRoster(username);
            Collection<RosterItem> items = roster.getRosterItems();
            Log.debug("Sending contacts with subdomain " + subdomain + " from user " + username + " to external Component");
            sendRosterToComponent(myPacket, items, subdomain);
        } catch (UserNotFoundException e) {
            e.printStackTrace();
        }
    } else {
        Log.debug("Sending nonpersistant-RemoteRosterResponse to external Component  for User: " + username);
        sendEmptyRoster(myPacket, subdomain);
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) RosterItem(org.jivesoftware.openfire.roster.RosterItem) Roster(org.jivesoftware.openfire.roster.Roster)

Aggregations

Roster (org.jivesoftware.openfire.roster.Roster)42 RosterItem (org.jivesoftware.openfire.roster.RosterItem)29 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)27 JID (org.xmpp.packet.JID)20 UserAlreadyExistsException (org.jivesoftware.openfire.user.UserAlreadyExistsException)13 SharedGroupException (org.jivesoftware.openfire.SharedGroupException)9 ArrayList (java.util.ArrayList)7 StringTokenizer (java.util.StringTokenizer)4 PacketException (org.jivesoftware.openfire.PacketException)4 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)4 ServiceException (org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException)4 Presence (org.xmpp.packet.Presence)4 NotFoundException (org.jivesoftware.util.NotFoundException)3 IQ (org.xmpp.packet.IQ)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 Email (net.sf.jml.Email)2 XMPPServer (org.jivesoftware.openfire.XMPPServer)2 ServiceException (org.jivesoftware.openfire.exceptions.ServiceException)2 Group (org.jivesoftware.openfire.group.Group)2 PacketRejectedException (org.jivesoftware.openfire.interceptor.PacketRejectedException)2