@Override public void route(Packet packet) { // Security: Don't allow users to send packets on behalf of other users packet.setFrom(session.getAddress()); if(packet instanceof IQ) { route((IQ)packet); } else if(packet instanceof Message) { route((Message)packet); } else if(packet instanceof Presence) { route((Presence)packet); } }
@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 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); } } }
public AuditPacket(Packet packet, Session session) { element = docFactory.createElement("packet", "http://www.jivesoftware.org"); creationDate = new Date(); if (session != null && session.getStreamID() != null) { element.addAttribute("streamID", session.getStreamID().toString()); } switch (session == null ? 0 : session.getStatus()) { case Session.STATUS_AUTHENTICATED: element.addAttribute("status", "auth"); break; case Session.STATUS_CLOSED: element.addAttribute("status", "closed"); break; case Session.STATUS_CONNECTED: element.addAttribute("status", "connected"); // This is a workaround. Since we don't want to have an incorrect FROM attribute // value we need to clean up the FROM attribute. The FROM attribute will contain // an incorrect value since we are setting a fake JID until the user actually // authenticates with the server. packet.setFrom((String) null); break; default: element.addAttribute("status", "unknown"); break; } element.addAttribute("timestamp", auditFormat.format(creationDate)); element.add(packet.getElement()); }
/** * 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); } }
@Override public void route(Packet packet) { // Security: Don't allow users to send packets on behalf of other users packet.setFrom(session.getAddress()); if(packet instanceof IQ) { route((IQ)packet); } else if(packet instanceof Message) { route((Message)packet); } else if(packet instanceof Presence) { route((Presence)packet); } }
@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 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); } } }
public AuditPacket(Packet packet, Session session) { element = docFactory.createElement("packet", "http://www.jivesoftware.org"); creationDate = new Date(); if (session != null && session.getStreamID() != null) { element.addAttribute("streamID", session.getStreamID().toString()); } switch (session == null ? 0 : session.getStatus()) { case Session.STATUS_AUTHENTICATED: element.addAttribute("status", "auth"); break; case Session.STATUS_CLOSED: element.addAttribute("status", "closed"); break; case Session.STATUS_CONNECTED: element.addAttribute("status", "connected"); // This is a workaround. Since we don't want to have an incorrect FROM attribute // value we need to clean up the FROM attribute. The FROM attribute will contain // an incorrect value since we are setting a fake JID until the user actually // authenticates with the server. packet.setFrom((String) null); break; default: element.addAttribute("status", "unknown"); break; } element.addAttribute("timestamp", auditFormat.format(creationDate)); element.add(packet.getElement()); }
/** * 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); } }