Search in sources :

Example 1 with IDNAException

use of gnu.inet.encoding.IDNAException in project Openfire by igniterealtime.

the class IQRosterHandler method handleIQ.

/**
     * Handles all roster queries. There are two major types of queries:
     *
     * <ul>
     *      <li>Roster remove - A forced removal of items from a roster. Roster
     *      removals are the only roster queries allowed to
     *      directly affect the roster from another user.
     *      </li>
     *      <li>Roster management - A local user looking up or updating their
     *      roster.
     *      </li>
     * </ul>
     *
     * @param packet The update packet
     * @return The reply or null if no reply
     */
@Override
public IQ handleIQ(IQ packet) throws UnauthorizedException, PacketException {
    try {
        IQ returnPacket;
        org.xmpp.packet.Roster roster = (org.xmpp.packet.Roster) packet;
        JID recipientJID = packet.getTo();
        // The packet is bound for the server and must be roster management
        if (recipientJID == null || recipientJID.equals(packet.getFrom().asBareJID())) {
            returnPacket = manageRoster(roster);
        } else {
            returnPacket = IQ.createResultIQ(packet);
            // The server MUST return a <forbidden/> stanza error to the client if the sender of the roster set is not authorized to update the roster
            // (where typically only an authenticated resource of the account itself is authorized).
            returnPacket.setError(PacketError.Condition.forbidden);
        }
        return returnPacket;
    } catch (SharedGroupException e) {
        IQ result = IQ.createResultIQ(packet);
        result.setChildElement(packet.getChildElement().createCopy());
        result.setError(PacketError.Condition.not_acceptable);
        return result;
    } catch (Exception e) {
        if (e.getCause() instanceof IDNAException || e.getCause() instanceof IllegalArgumentException) {
            Log.warn(LocaleUtils.getLocalizedString("admin.error") + e.getMessage());
            IQ result = IQ.createResultIQ(packet);
            result.setChildElement(packet.getChildElement().createCopy());
            result.setError(PacketError.Condition.jid_malformed);
            return result;
        } else {
            Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
            IQ result = IQ.createResultIQ(packet);
            result.setChildElement(packet.getChildElement().createCopy());
            result.setError(PacketError.Condition.internal_server_error);
            return result;
        }
    }
}
Also used : IDNAException(gnu.inet.encoding.IDNAException) Roster(org.jivesoftware.openfire.roster.Roster) JID(org.xmpp.packet.JID) IQ(org.xmpp.packet.IQ) SharedGroupException(org.jivesoftware.openfire.SharedGroupException) PacketException(org.jivesoftware.openfire.PacketException) UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) SharedGroupException(org.jivesoftware.openfire.SharedGroupException) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException) IDNAException(gnu.inet.encoding.IDNAException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Aggregations

IDNAException (gnu.inet.encoding.IDNAException)1 PacketException (org.jivesoftware.openfire.PacketException)1 SharedGroupException (org.jivesoftware.openfire.SharedGroupException)1 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)1 Roster (org.jivesoftware.openfire.roster.Roster)1 UserAlreadyExistsException (org.jivesoftware.openfire.user.UserAlreadyExistsException)1 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)1 IQ (org.xmpp.packet.IQ)1 JID (org.xmpp.packet.JID)1