Search in sources :

Example 11 with UserNotFoundException

use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.

the class LocalMUCRoom method broadcastPresence.

/**
     * Broadcasts the specified presence to all room occupants. If the presence belongs to a
     * user whose role cannot be broadcast then the presence will only be sent to the presence's
     * user. On the other hand, the JID of the user that sent the presence won't be included if the
     * room is semi-anon and the target occupant is not a moderator.
     *
     * @param presence the presence to broadcast.
     * @param isJoinPresence If the presence is sent in the context of joining the room.
     */
private void broadcastPresence(Presence presence, boolean isJoinPresence) {
    if (presence == null) {
        return;
    }
    if (!shouldBroadcastPresence(presence)) {
        // Just send the presence to the sender of the presence
        try {
            for (MUCRole occupant : getOccupantsByNickname(presence.getFrom().getResource())) {
                occupant.send(presence);
            }
        } catch (UserNotFoundException e) {
        // Do nothing
        }
        return;
    }
    // Broadcast presence to occupants hosted by other cluster nodes
    BroadcastPresenceRequest request = new BroadcastPresenceRequest(this, presence, isJoinPresence);
    CacheFactory.doClusterTask(request);
    // Broadcast presence to occupants connected to this JVM
    request = new BroadcastPresenceRequest(this, presence, isJoinPresence);
    request.setOriginator(true);
    request.run();
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) MUCRole(org.jivesoftware.openfire.muc.MUCRole) BroadcastPresenceRequest(org.jivesoftware.openfire.muc.cluster.BroadcastPresenceRequest)

Example 12 with UserNotFoundException

use of org.jivesoftware.openfire.user.UserNotFoundException 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 13 with UserNotFoundException

use of org.jivesoftware.openfire.user.UserNotFoundException 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 14 with UserNotFoundException

use of org.jivesoftware.openfire.user.UserNotFoundException 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)

Example 15 with UserNotFoundException

use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.

the class IQvCardHandler method handleIQ.

@Override
public IQ handleIQ(IQ packet) throws UnauthorizedException, PacketException {
    IQ result = IQ.createResultIQ(packet);
    IQ.Type type = packet.getType();
    if (type.equals(IQ.Type.set)) {
        try {
            User user = userManager.getUser(packet.getFrom().getNode());
            Element vcard = packet.getChildElement();
            if (vcard != null) {
                VCardManager.getInstance().setVCard(user.getUsername(), vcard);
            }
        } catch (UserNotFoundException e) {
            result = IQ.createResultIQ(packet);
            result.setChildElement(packet.getChildElement().createCopy());
            result.setError(PacketError.Condition.item_not_found);
        } catch (Exception e) {
            Log.error(e.getMessage(), e);
            result.setError(PacketError.Condition.internal_server_error);
        }
    } else if (type.equals(IQ.Type.get)) {
        JID recipient = packet.getTo();
        // If no TO was specified then get the vCard of the sender of the packet
        if (recipient == null) {
            recipient = packet.getFrom();
        }
        // By default return an empty vCard
        result.setChildElement("vCard", "vcard-temp");
        // Only try to get the vCard values of non-anonymous users
        if (recipient != null) {
            if (recipient.getNode() != null && server.isLocal(recipient)) {
                VCardManager vManager = VCardManager.getInstance();
                Element userVCard = vManager.getVCard(recipient.getNode());
                if (userVCard != null) {
                    // Check if the requester wants to ignore some vCard's fields
                    Element filter = packet.getChildElement().element(QName.get("filter", "vcard-temp-filter"));
                    if (filter != null) {
                        // Create a copy so we don't modify the original vCard
                        userVCard = userVCard.createCopy();
                        // Ignore fields requested by the user
                        for (Iterator toFilter = filter.elementIterator(); toFilter.hasNext(); ) {
                            Element field = (Element) toFilter.next();
                            Element fieldToRemove = userVCard.element(field.getName());
                            if (fieldToRemove != null) {
                                fieldToRemove.detach();
                            }
                        }
                    }
                    result.setChildElement(userVCard);
                }
            } else {
                result = IQ.createResultIQ(packet);
                result.setChildElement(packet.getChildElement().createCopy());
                result.setError(PacketError.Condition.item_not_found);
            }
        } else {
            result = IQ.createResultIQ(packet);
            result.setChildElement(packet.getChildElement().createCopy());
            result.setError(PacketError.Condition.item_not_found);
        }
    } else {
        result.setChildElement(packet.getChildElement().createCopy());
        result.setError(PacketError.Condition.not_acceptable);
    }
    return result;
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) User(org.jivesoftware.openfire.user.User) JID(org.xmpp.packet.JID) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) Iterator(java.util.Iterator) VCardManager(org.jivesoftware.openfire.vcard.VCardManager) PacketException(org.jivesoftware.openfire.PacketException) UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Aggregations

UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)118 JID (org.xmpp.packet.JID)50 Element (org.dom4j.Element)28 Roster (org.jivesoftware.openfire.roster.Roster)27 RosterItem (org.jivesoftware.openfire.roster.RosterItem)26 User (org.jivesoftware.openfire.user.User)25 UserAlreadyExistsException (org.jivesoftware.openfire.user.UserAlreadyExistsException)23 IQ (org.xmpp.packet.IQ)15 ArrayList (java.util.ArrayList)14 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)12 SharedGroupException (org.jivesoftware.openfire.SharedGroupException)11 Group (org.jivesoftware.openfire.group.Group)10 UserManager (org.jivesoftware.openfire.user.UserManager)10 Workgroup (org.jivesoftware.xmpp.workgroup.Workgroup)10 Presence (org.xmpp.packet.Presence)10 NotFoundException (org.jivesoftware.util.NotFoundException)9 SQLException (java.sql.SQLException)8 List (java.util.List)8 IOException (java.io.IOException)7 Connection (java.sql.Connection)7