private boolean matchesPacketTypeCondition(Packet packet, JID userJID) { if (filterEverything) { // This includes all type of packets (including subscription-related presences) return true; } Class packetClass = packet.getClass(); if (Message.class.equals(packetClass)) { return filterMessage; } else if (Presence.class.equals(packetClass)) { Presence.Type presenceType = ((Presence) packet).getType(); // Only filter presences of type available or unavailable // (ignore subscription-related presences) if (presenceType == null || presenceType == Presence.Type.unavailable) { // Calculate if packet is being received by the user JID to = packet.getTo(); boolean incoming = to != null && to.toBareJID().equals(userJID.toBareJID()); if (incoming) { return filterPresence_in; } else { return filterPresence_out; } } } else if (IQ.class.equals(packetClass)) { return filterIQ; } return false; }
@Override public void interceptPacket(Packet packet, Session session, boolean read, boolean processed) { if (!processed) { // Ignore packets sent or received by users that are present in the ignore list JID from = packet.getFrom(); JID to = packet.getTo(); if ((from == null || !ignoreList.contains(from.getNode())) && (to == null || !ignoreList.contains(to.getNode()))) { auditor.audit(packet, session); } } } }
String domain = packet.getTo().getDomain(); synchronized (domain.intern()) { packetsProcessor = packetsProcessors.get(domain);
private void sendPacket(Packet packet) throws Exception { // Create a connection to the remote server from the domain where the packet has been sent boolean created; // Make sure that only one cluster node is creating the outgoing connection // TODO: Evaluate why removing the oss part causes nasty s2s and lockup issues. Lock lock = CacheFactory.getLock(domain+"oss", serversCache); try { lock.lock(); created = LocalOutgoingServerSession .authenticateDomain(packet.getFrom().getDomain(), packet.getTo().getDomain()); } finally { lock.unlock(); } if (created) { if (!routingTable.hasServerRoute(new DomainPair(packet.getFrom().getDomain(), packet.getTo().getDomain()))) { throw new Exception("Route created but not found!!!"); } // A connection to the remote server was created so get the route and send the packet routingTable.routePacket(packet.getTo(), packet, false); } else { throw new Exception("Failed to create connection to remote server"); } }
/** * Delivers the given packet based on packet recipient and sender. The * deliverer defers actual routing decisions to other classes. * <h2>Warning</h2> * Be careful to enforce concurrency DbC of concurrent by synchronizing * any accesses to class resources. * * @param packet The packet to route * @throws NullPointerException If the packet is null or the * packet could not be routed */ public void deliver(Packet packet) throws UnauthorizedException, PacketException { if (packet == null) { throw new NullPointerException(); } if (xmppServer != null && xmppServer.isLocal(packet.getTo())) { deliverer.deliver(packet); } else if (transportHandler != null) { transportHandler.process(packet); } else { Log.warn("Could not deliver message: no deliverer available " + packet.toString()); } }
@Override boolean canProcess(Packet packet) { final String senderDomain = packet.getFrom().getDomain(); final String recipDomain = packet.getTo().getDomain(); boolean processed = true; if (!checkOutgoingDomainPair(senderDomain, recipDomain)) { synchronized (("Auth::" + senderDomain).intern()) { if (!checkOutgoingDomainPair(senderDomain, recipDomain) && !authenticateSubdomain(senderDomain, packet.getTo().getDomain())) { // Return error since sender domain was not validated by remote server processed = false; } } } if (!processed) { returnErrorToSender(packet); } return processed; }
@Override public void process(Packet packet) throws UnauthorizedException, PacketException { boolean handled = false; String host = packet.getTo().getDomain(); for (Channel<Packet> channel : transports.values()) { if (channel.getName().equalsIgnoreCase(host)) { channel.add(packet); handled = true; } } if (!handled) { JID recipient = packet.getTo(); JID sender = packet.getFrom(); packet.setError(PacketError.Condition.remote_server_timeout); packet.setFrom(recipient); packet.setTo(sender); try { deliverer.deliver(packet); } catch (PacketException e) { Log.error(LocaleUtils.getLocalizedString("admin.error"), e); } } }
@Override public void process(Packet packet) throws UnauthorizedException, PacketException { StanzaIDUtil.ensureUniqueAndStableStanzaID( packet, packet.getTo() ); if (packet instanceof IQ) { process((IQ)packet); } else if (packet instanceof Message) { process((Message)packet); } else if (packet instanceof Presence) { process((Presence)packet); } }
private boolean matchesPacketSenderCondition(Packet packet, Roster roster, JID userJID) { if (type == null) { // This is the "fall-through" case return true; } boolean isPresence = packet.getClass().equals(Presence.class); boolean incoming = true; if (packet.getFrom() != null) { incoming = !userJID.toBareJID().equals(packet.getFrom().toBareJID()); } boolean matches = false; if (isPresence && !incoming && (filterEverything || filterPresence_out)) { // If this is an outgoing presence and we are filtering by outgoing presence // notification then use the receipient of the packet in the analysis matches = verifyJID(packet.getTo(), roster); } if (!matches && incoming && (filterEverything || filterPresence_in || filterIQ || filterMessage)) { matches = verifyJID(packet.getFrom(), roster); } return matches; }
/** * Keeps a log of the XMPP traffic, releasing the wait lock on response received. */ @Override public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) throws PacketRejectedException { if (!processed && (ping.getTo().getDomain().equals(packet.getFrom().getDomain()) || ping.getTo().getDomain().equals(packet.getTo().getDomain()))) { // Log all traffic to and from the domain. xml.append(packet.toXML()); xml.append('\n'); // If we've received our IQ response, stop the test. if ( packet instanceof IQ ) { final IQ iq = (IQ) packet; if ( iq.isResponse() && ping.getID().equals( iq.getID() ) && ping.getTo().equals( iq.getFrom() ) ) { Log.info("Successful server to server response received."); waitUntil.release(); } } } }
@Override public void sendPrivatePacket(Packet packet, MUCRole senderRole) throws NotFoundException, ForbiddenException { switch (senderRole.getRole()) { // intended fall-through case none: throw new ForbiddenException(); default: case visitor: if (canSendPrivateMessage().equals( "participants" )) throw new ForbiddenException(); case participant: if (canSendPrivateMessage().equals( "moderators" )) throw new ForbiddenException(); case moderator: if (canSendPrivateMessage().equals( "none" )) throw new ForbiddenException(); } String resource = packet.getTo().getResource(); List<MUCRole> occupants = occupantsByNickname.get(resource.toLowerCase()); if (occupants == null || occupants.size() == 0) { throw new NotFoundException(); } for (MUCRole occupant : occupants) { packet.setFrom(senderRole.getRoleAddress()); occupant.send(packet); if(packet instanceof Message) { Message message = (Message) packet; MUCEventDispatcher.privateMessageRecieved(occupant.getUserAddress(), senderRole.getUserAddress(), message); } } }
/** * 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. */ 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); 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 no TO or FROM attributes"); } }
private void returnErrorToSender(Packet packet) { XMPPServer server = XMPPServer.getInstance(); JID from = packet.getFrom(); JID to = packet.getTo(); if (!server.isLocal(from) && !XMPPServer.getInstance().matchesComponent(from) && !server.isLocal(to) && !XMPPServer.getInstance().matchesComponent(to)) { final ClientSession session = sessionManager.getSession( reply.getTo() ); InterceptorManager.getInstance().invokeInterceptors( reply, session, false, false ); routingTable.routePacket( reply.getTo(), reply, true ); InterceptorManager.getInstance().invokeInterceptors( reply, session, false, true );
if (packet.getTo() == null || packet.getFrom() == null) { Log.debug("Closing IncomingServerSession due to packet with no TO or FROM: " + packet.toXML());
@Override public void process(Packet packet) throws UnauthorizedException, PacketException { try { JID recipient = packet.getTo(); // Check if the target domain belongs to a remote server or a component if (server.matchesComponent(recipient) || server.isRemote(recipient)) { routingTable.routePacket(recipient, packet, false); } // The target domain belongs to the local server else if (recipient == null || (recipient.getNode() == null && recipient.getResource() == null)) { // no TO was found so send back the packet to the sender routingTable.routePacket(packet.getFrom(), packet, false); } else if (recipient.getResource() != null || !(packet instanceof Presence)) { // JID is of the form <user@domain/resource> routingTable.routePacket(recipient, packet, false); } else { // JID is of the form <user@domain> for (JID route : routingTable.getRoutes(recipient, null)) { routingTable.routePacket(route, packet, false); } } } catch (Exception e) { Log.error(LocaleUtils.getLocalizedString("admin.error.deliver") + "\n" + packet.toString(), e); } } }
reply.setID(packet.getID()); reply.setTo(packet.getFrom()); reply.setFrom(packet.getTo()); reply.setChildElement(((IQ) packet).getChildElement().createCopy()); reply.setType(IQ.Type.error); reply.setID(packet.getID()); reply.setTo(packet.getFrom()); reply.setFrom(packet.getTo()); reply.setType(Presence.Type.error); reply.setError(PacketError.Condition.remote_server_not_found); reply.setID(packet.getID()); reply.setTo(packet.getFrom()); reply.setFrom(packet.getTo()); reply.setType(Message.Type.error); reply.setThread(((Message)packet).getThread());
/** * Generate a conflict packet to indicate that the nickname being requested/used is already in * use by another user. * * @param packet the packet to be bounced. * @param error the reason why the operation failed. */ private void sendErrorPacket(Packet packet, PacketError.Condition error) { if (packet instanceof IQ) { IQ reply = IQ.createResultIQ((IQ) packet); reply.setChildElement(((IQ) packet).getChildElement().createCopy()); reply.setError(error); router.route(reply); } else { Packet reply = packet.createCopy(); reply.setError(error); reply.setFrom(packet.getTo()); reply.setTo(packet.getFrom()); router.route(reply); } }
!presenceUpdateHandler.hasDirectPresence(packet.getTo(), packet.getFrom())) { Log.debug("Unable to route packet. Packet should only be sent to available sessions and the route is not available. {} ", packet.toXML()); routed = false;
@Override public void interceptPacket(Packet packet, Session session, boolean read, boolean processed) { if (!processed) { // Ignore packets sent or received by users that are present in the ignore list JID from = packet.getFrom(); JID to = packet.getTo(); if ((from == null || !ignoreList.contains(from.getNode())) && (to == null || !ignoreList.contains(to.getNode()))) { auditor.audit(packet, session); } } } }