@Override
    public IQ handleIQ(IQ packet) throws UnauthorizedException {
        IQ.Type type = packet.getType();
        JID from = packet.getFrom();
        if (from.getNode() == null || !UserManager.getInstance().isRegisteredUser(from, false)) {
            // Service is unavailable for anonymous users
            Log.trace("Responding with 'service-unavailable': service unavailable to anonymous users: {}", packet);
            IQ result = IQ.createResultIQ(packet);
            result.setChildElement(packet.getChildElement().createCopy());
            result.setError(PacketError.Condition.service_unavailable);
            return result;
        }
        IQ result = null;
        if (type.equals(IQ.Type.get)) {
            // User wants to retrieve a privacy list or the list of privacy list
            Element child = packet.getChildElement();
            List<Element> elements = child.elements();
            if (elements.isEmpty()) {
                // User requested names of privacy lists
                result = getPrivacyListsNames(packet, from);
            }
            else {
                // User requested a privacy list
                result = getPrivacyList(packet, from);
            }
        }
        else if (type.equals(IQ.Type.set)) {
            Element child = packet.getChildElement();
            Element activeList = child.element("active");
            Element defaultList = child.element("default");
            if (activeList != null) {
                // Active list handling
                String listName = activeList.attributeValue("name");
                if (listName != null) {
                    // User wants to set or change the active list currently being applied by
                    // the server to this session
                    result = setActiveList(packet, from, listName);
                }
                else {
                    // User wants to decline the use of any active list for this session
                    result = declineActiveList(packet, from);

                }
            }
            else if (defaultList != null) {
                // Default list handling
                String listName = defaultList.attributeValue("name");
                if (listName != null) {
                    // User wants to set or change its default list (i.e. which applies
                    // to the user as a whole, not only the sending resource)
                    result = setDefaultList(packet, from, listName);
                }
                else {
                    // User wants to decline the use of a default list
                    result = declineDefaultList(packet, from);
                }
            }
            else {
                // Privacy list handling (create/edit/delete)
                Element list = child.element("list");
                String listName = list.attributeValue("name");
                List<Element> items = list.elements();
                if (!items.isEmpty()) {
                    // User wants to create or edit a privacy list
                    result = updateOrCreateList(packet, from, list);
                }
                else {
                    // User wants to delete a privacy list
                    result = deleteList(packet, from, listName);

                }
            }
        }
        return result;
    }
IQPrivacyHandler is responsible for handling privacy lists.

@author Gaston Dombiak
xmppserver/src/main/java/org/jivesoftware/openfire/handler/IQPrivacyHandler.java