private void sendFederatedRequests(String originatingServer) throws ComponentException {
   String remoteServer = discoveredServers.get(originatingServer);
   List<Packet> packetsToSend = waitingStanzas.get(originatingServer);
   if (packetsToSend == null) {
     return;
   }
   for (Packet packet : packetsToSend) {
     packet.setTo(remoteServer);
     sendPacket(packet.createCopy());
   }
   waitingStanzas.remove(originatingServer);
 }
  public void process(Packet packet) throws ComponentException {

    logger.debug("Packet payload " + packet.toXML() + " going to federation.");

    String to = packet.getTo().toString();

    String uniqueId = generateUniqueId(packet);
    idMap.put(uniqueId, packet.getID());
    packet.setID(uniqueId);

    sentRemotePackets.put(uniqueId, packet.getFrom());
    try {
      extractNodeDetails(packet);
      // Do we have a map already?
      if (discoveredServers.containsKey(to)) {
        packet.setTo(new JID(discoveredServers.get(to)));
        sendPacket(packet.createCopy());
        return;
      }
      // Are we already discovering a remote server?
      if (!remoteChannelDiscoveryStatus.containsKey(to)) {
        discoverRemoteChannelServer(to, packet.getID());
      } else if (remoteChannelDiscoveryStatus.get(to).equals(NO_CHANNEL_SERVER)) {
        logger.error("No remote channel server for " + to);
        IQ reply = IQ.createResultIQ((IQ) packet);
        reply.setError(
            new PacketError(
                PacketError.Condition.remote_server_not_found, PacketError.Type.cancel));
        component.sendPacket(reply);
        return;
      }
      // Add packet to list
      if (!waitingStanzas.containsKey(to)) {
        waitingStanzas.put(to, new ArrayList<Packet>());
      }
      waitingStanzas.get(to).add(packet);
      logger.debug(
          "Adding packet to waiting stanza list for "
              + to
              + " (size "
              + waitingStanzas.get(to).size()
              + ")");
    } catch (Exception e) {
      logger.error(e);
    }
  }
Beispiel #3
0
  public Packet doAction(Packet packet) throws PacketRejectedException {
    SessionManager sessionManager = SessionManager.getInstance();
    ClientSession clientSession = sessionManager.getSession(packet.getFrom());
    Packet rejectPacket;
    String pfFrom = JiveGlobals.getProperty("pf.From", "packetfilter");

    if (packet instanceof Message) {
      Message in = (Message) packet.createCopy();
      if (clientSession != null && in.getBody() != null) {

        in.setFrom(new JID(pfFrom));
        String rejectMessage =
            JiveGlobals.getProperty(
                "pf.rejectMessage", "Your message was rejected by the packet filter");
        in.setBody(rejectMessage);
        in.setType(Message.Type.error);
        in.setTo(packet.getFrom());
        String rejectSubject = JiveGlobals.getProperty("pf.rejectSubject", "Rejected");
        in.setSubject(rejectSubject);
        clientSession.process(in);
      }

    } else if (packet instanceof Presence) {
      rejectPacket = new Presence();
      rejectPacket.setTo(packet.getFrom());
      rejectPacket.setError(PacketError.Condition.forbidden);

    } else if (packet instanceof IQ) {
      rejectPacket = new IQ();
      rejectPacket.setTo(packet.getFrom());
      rejectPacket.setError(PacketError.Condition.forbidden);
    }
    if (doLog()) {
      Log.info("Rejecting packet from " + packet.getFrom() + " to " + packet.getTo());
    }
    throw new PacketRejectedException();
  }
 private void sendPacket(Packet packet) throws ComponentException {
   packet.setFrom(localServer);
   component.sendPacket(packet.createCopy());
 }