private void packetReceived(Packet packet) throws UnauthorizedException {
        if (packet.getTo() == null || packet.getFrom() == null) {
            Log.debug("ServerStanzaHandler: Closing IncomingServerSession due to packet with no TO or FROM: " +
                    packet.toXML());
            // Send a stream error saying that the packet includes no TO or FROM
            StreamError error = new StreamError(StreamError.Condition.improper_addressing, "Stanza is missing 'from' and/or 'to' address");
            connection.deliverRawText(error.toXML());
            throw new UnauthorizedException("Packet with no TO or FROM attributes");
        }
        else if (!((LocalIncomingServerSession) session).isValidDomain(packet.getFrom().getDomain())) {
            Log.debug("ServerStanzaHandler: Closing IncomingServerSession due to packet with invalid domain: " +
                    packet.toXML());
            // Send a stream error saying that the packet includes an invalid FROM
            StreamError error = new StreamError(StreamError.Condition.invalid_from);
            connection.deliverRawText(error.toXML());
            throw new UnauthorizedException("Packet with invalid FROM attribute: " + packet.getFrom());
        }
    }
Make sure that the received packet has a TO and FROM values defined and that it was sent
from a previously validated domain. If the packet does not matches any of the above
conditions then a PacketRejectedException will be thrown.

@param packet the received packet.
@throws UnauthorizedException if the packet does not include a TO or FROM or if the packet
                                was sent from a domain that was not previously validated.
xmppserver/src/main/java/org/jivesoftware/openfire/net/ServerStanzaHandler.java