org.xmpp.packet.PacketError Java Examples

The following examples show how to use org.xmpp.packet.PacketError. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransportHandler.java    From Openfire with Apache License 2.0 6 votes vote down vote up
@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);
        }
    }
}
 
Example #2
Source File: IQPrivacyHandler.java    From Openfire with Apache License 2.0 6 votes vote down vote up
/**
 * User has specified a new active list that should be used for the current session.
 *
 * @param packet IQ packet setting new active list for the current session.
 * @param from sender of the IQ packet.
 * @param listName name of the new active list for the current session.
 * @return acknowledge of success.
 */
private IQ setActiveList(IQ packet, JID from, String listName) {
    IQ result = IQ.createResultIQ(packet);
    Element childElement = packet.getChildElement().createCopy();
    result.setChildElement(childElement);

    // Get the list
    PrivacyList list = manager.getPrivacyList(from.getNode(), listName);
    if (list != null) {
        // Get the user session
        ClientSession session = sessionManager.getSession(from);
        if (session != null) {
            // Set the new active list for this session
            session.setActiveList(list);
        }
    }
    else {
        // List not found
        result.setError(PacketError.Condition.item_not_found);
    }
    return result;
}
 
Example #3
Source File: IQSharedGroupHandler.java    From Openfire with Apache License 2.0 6 votes vote down vote up
@Override
public IQ handleIQ(IQ packet) throws UnauthorizedException {
    IQ result = IQ.createResultIQ(packet);
    String username = packet.getFrom().getNode();
    if (!serverName.equals(packet.getFrom().getDomain()) || username == null) {
        // Users of remote servers are not allowed to get their "shared groups". Users of
        // remote servers cannot have shared groups in this server.
        // Besides, anonymous users do not belong to shared groups so answer an error
        result.setChildElement(packet.getChildElement().createCopy());
        result.setError(PacketError.Condition.not_allowed);
        return result;
    }

    Collection<Group> groups = rosterManager.getSharedGroups(username);
    Element sharedGroups = result.setChildElement("sharedgroup",
            "http://www.jivesoftware.org/protocol/sharedgroup");
    for (Group sharedGroup : groups) {
        String displayName = sharedGroup.getProperties().get("sharedRoster.displayName");
        if (displayName != null) {
            sharedGroups.addElement("group").setText(displayName);
        }
    }
    return result;
}
 
Example #4
Source File: IQRosterHandler.java    From Openfire with Apache License 2.0 6 votes vote down vote up
/**
 * Checks the roster groups for error conditions described in RFC 6121 ยง 2.3.3.
 *
 * @param groups The groups.
 * @return An error if the specification is violated or null if everything is fine.
 */
private static PacketError checkGroups(Iterable<String> groups) {
    Set<String> set = new HashSet<>();
    for (String group : groups) {
        if (!set.add(group)) {
            // Duplicate group found.
            // RFC 6121 2.3.3.  Error Cases: 2. The <item/> element contains more than one <group/> element, but there are duplicate groups
            return new PacketError(PacketError.Condition.bad_request, PacketError.Type.modify, "Item contains duplicate groups");
        }
        if (group.isEmpty()) {
            // The server MUST return a <not-acceptable/> stanza error to the client if the roster set contains any of the following violations:
            // 2. The XML character data of the <group/> element is of zero length.
            return new PacketError(PacketError.Condition.not_acceptable, PacketError.Type.modify, "Group is of zero length");
        }
    }
    return null;
}
 
Example #5
Source File: IQAdminHandler.java    From Openfire with Apache License 2.0 6 votes vote down vote up
/**
 * Handles the IQ packet sent by an owner or admin of the room. Possible actions are:
 * <ul>
 * <li>Return the list of participants</li>
 * <li>Return the list of moderators</li>
 * <li>Return the list of members</li>
 * <li>Return the list of outcasts</li>
 * <li>Change user's affiliation to member</li>
 * <li>Change user's affiliation to outcast</li>
 * <li>Change user's affiliation to none</li>
 * <li>Change occupant's affiliation to moderator</li>
 * <li>Change occupant's affiliation to participant</li>
 * <li>Change occupant's affiliation to visitor</li>
 * <li>Kick occupants from the room</li>
 * </ul>
 *
 * @param packet the IQ packet sent by an owner or admin of the room.
 * @param role the role of the user that sent the request packet.
 * @throws ForbiddenException If the user is not allowed to perform his request.
 * @throws ConflictException If the desired room nickname is already reserved for the room or
 *                           if the room was going to lose all of its owners.
 * @throws NotAllowedException Thrown if trying to ban an owner or an administrator.
 * @throws CannotBeInvitedException If the user being invited as a result of being added to a members-only room still does not have permission
 */
public void handleIQ(IQ packet, MUCRole role) throws ForbiddenException, ConflictException,
        NotAllowedException, CannotBeInvitedException {
    IQ reply = IQ.createResultIQ(packet);
    Element element = packet.getChildElement();

    // Analyze the action to perform based on the included element
    @SuppressWarnings("unchecked")
    List<Element> itemsList = element.elements("item");
    
    if (!itemsList.isEmpty()) {
        handleItemsElement(role, itemsList, reply);
    }
    else {
        // An unknown and possibly incorrect element was included in the query
        // element so answer a BAD_REQUEST error
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(PacketError.Condition.bad_request);
    }
    if (reply.getTo() != null) {
        // Send a reply only if the sender of the original packet was from a real JID. (i.e. not
        // a packet generated locally)
        router.route(reply);
    }
}
 
Example #6
Source File: IQPrivacyHandler.java    From Openfire with Apache License 2.0 6 votes vote down vote up
/**
 * User has specified that there is no default list that should be used for this user.
 *
 * @param packet IQ packet declining default list for all sessions.
 * @param from sender of the IQ packet.
 * @return acknowledge of success.
 */
private IQ declineDefaultList(IQ packet, JID from) {
    IQ result = IQ.createResultIQ(packet);
    Element childElement = packet.getChildElement().createCopy();
    result.setChildElement(childElement);

    if (sessionManager.getSessionCount(from.getNode()) > 1) {
        // Current default list is being used by more than one session
        result.setError(PacketError.Condition.conflict);
    }
    else {
        // Get the user session
        ClientSession session = sessionManager.getSession(from);
        // Check if a default list was already defined
        if (session.getDefaultList() != null) {
            // Set the existing default list as non-default
            session.getDefaultList().setDefaultList(false);
            // Update the database with the new list state
            provider.updatePrivacyList(from.getNode(), session.getDefaultList());
            session.setDefaultList(null);
        }
    }
    return result;
}
 
Example #7
Source File: PresenceUpdateHandler.java    From Openfire with Apache License 2.0 6 votes vote down vote up
/**
 * Handle presence updates that affect roster subscriptions.
 *
 * @param presence The presence presence to handle
 * @throws PacketException if the packet is null or the packet could not be routed.
 */
public void process(Presence presence) throws PacketException {
    try {
        process((Packet)presence);
    }
    catch (UnauthorizedException e) {
        try {
            LocalSession session = (LocalSession) sessionManager.getSession(presence.getFrom());
            presence = presence.createCopy();
            if (session != null) {
                presence.setFrom(new JID(null, session.getServerName(), null, true));
                presence.setTo(session.getAddress());
            }
            else {
                JID sender = presence.getFrom();
                presence.setFrom(presence.getTo());
                presence.setTo(sender);
            }
            presence.setError(PacketError.Condition.not_authorized);
            deliverer.deliver(presence);
        }
        catch (Exception err) {
            Log.error(LocaleUtils.getLocalizedString("admin.error"), err);
        }
    }
}
 
Example #8
Source File: MultiplexerStanzaHandler.java    From Openfire with Apache License 2.0 6 votes vote down vote up
@Override
protected void processIQ(final IQ packet) {
    if (session.getStatus() != Session.STATUS_AUTHENTICATED) {
        // Session is not authenticated so return error
        IQ reply = new IQ();
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setID(packet.getID());
        reply.setTo(packet.getFrom());
        reply.setFrom(packet.getTo());
        reply.setError(PacketError.Condition.not_authorized);
        session.process(reply);
        return;
    }
    // Process the packet
    packetHandler.handle(packet);
}
 
Example #9
Source File: ComponentStanzaHandler.java    From Openfire with Apache License 2.0 6 votes vote down vote up
@Override
protected void processIQ(IQ packet) throws UnauthorizedException {
    if (session.getStatus() != Session.STATUS_AUTHENTICATED) {
        // Session is not authenticated so return error
        IQ reply = new IQ();
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setID(packet.getID());
        reply.setTo(packet.getFrom());
        reply.setFrom(packet.getTo());
        reply.setError(PacketError.Condition.not_authorized);
        session.process(reply);
        return;
    }
    // Keep track of the component that sent an IQ get/set
    if (packet.getType() == IQ.Type.get || packet.getType() == IQ.Type.set) {
        // Handle subsequent bind packets
        LocalComponentSession componentSession = (LocalComponentSession) session;
        // Get the external component of this session
        LocalComponentSession.LocalExternalComponent component =
                (LocalComponentSession.LocalExternalComponent) componentSession.getExternalComponent();
        component.track(packet);
    }
    super.processIQ(packet);
}
 
Example #10
Source File: UserManagerTest.java    From Openfire with Apache License 2.0 6 votes vote down vote up
@Test
public void isRegisteredUserWillReturnFalseForUnknownRemoteUsers() {

    final AtomicReference<IQResultListener> iqListener = new AtomicReference<>();
    doAnswer(invocationOnMock -> {
        final IQResultListener listener = invocationOnMock.getArgument(1);
        iqListener.set(listener);
        return null;
    }).when(iqRouter).addIQResultListener(any(), any(), anyLong());

    doAnswer(invocationOnMock -> {
        final IQ iq = invocationOnMock.getArgument(0);
        final Element childElement = iq.getChildElement();
        final IQ response = IQ.createResultIQ(iq);
        response.setChildElement(childElement.createCopy());
        response.setError(new PacketError(PacketError.Condition.item_not_found, PacketError.Condition.item_not_found.getDefaultType()));
        iqListener.get().receivedAnswer(response);
        return null;
    }).when(iqRouter).route(any());

    final boolean result = userManager.isRegisteredUser(new JID(USER_ID, REMOTE_XMPP_DOMAIN, null));

    assertThat(result, is(false));
    verify(iqRouter).route(any());
}
 
Example #11
Source File: PubSubModule.java    From Openfire with Apache License 2.0 6 votes vote down vote up
@Override
public void process(Packet packet) {
    try {
        // Check if the packet is a disco request or a packet with namespace iq:register
        if (packet instanceof IQ) {
            if (engine.process(this, (IQ) packet) == null) {
                process((IQ) packet);
            }
        }
        else if (packet instanceof Presence) {
            engine.process(this, (Presence) packet);
        }
        else {
            engine.process(this, (Message) packet);
        }
    }
    catch (Exception e) {
        Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
        if (packet instanceof IQ) {
            // Send internal server error
            IQ reply = IQ.createResultIQ((IQ) packet);
            reply.setError(PacketError.Condition.internal_server_error);
            send(reply);
        }
    }
}
 
Example #12
Source File: LocationHandler.java    From openfireLBS with Apache License 2.0 6 votes vote down vote up
private IQ updateLocation(IQ packet) {
	IQ reply = IQ.createResultIQ(packet);

	Element iq = packet.getChildElement();
	JID from = packet.getFrom();
	String username = from.getNode();

	Element item = iq.element("item");
	Double myLon = Double.parseDouble(item.attributeValue("lon"));
	Double myLat = Double.parseDouble(item.attributeValue("lat"));

	boolean f = insertLocation(myLon,myLat,username);
	if (f){
		// reply.setChildElement(iq);
	}else{
		reply.setType(IQ.Type.error);
		reply.setError(PacketError.Condition.internal_server_error);
	}
	
	return reply;
}
 
Example #13
Source File: ComponentStanzaHandler.java    From Openfire with Apache License 2.0 5 votes vote down vote up
@Override
protected void processPresence(Presence packet) throws UnauthorizedException {
    if (session.getStatus() != Session.STATUS_AUTHENTICATED) {
        // Session is not authenticated so return error
        Presence reply = new Presence();
        reply.setID(packet.getID());
        reply.setTo(packet.getFrom());
        reply.setFrom(packet.getTo());
        reply.setError(PacketError.Condition.not_authorized);
        session.process(reply);
        return;
    }
    super.processPresence(packet);
}
 
Example #14
Source File: MultiplexerStanzaHandler.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * Process stanza sent by a client that is connected to a connection manager. The
 * original stanza is wrapped in the route element. Only a single stanza must be
 * wrapped in the route element.
 *
 * @param packet the route element.
 */
private void processRoute(final Route packet) {
    if (session.getStatus() != Session.STATUS_AUTHENTICATED) {
        // Session is not authenticated so return error
        Route reply = new Route(packet.getStreamID());
        reply.setID(packet.getID());
        reply.setTo(packet.getFrom());
        reply.setFrom(packet.getTo());
        reply.setError(PacketError.Condition.not_authorized);
        session.process(reply);
        return;
    }
    // Process the packet
    packetHandler.route(packet);
}
 
Example #15
Source File: ComponentStanzaHandler.java    From Openfire with Apache License 2.0 5 votes vote down vote up
@Override
protected void processMessage(Message packet) throws UnauthorizedException {
    if (session.getStatus() != Session.STATUS_AUTHENTICATED) {
        // Session is not authenticated so return error
        Message reply = new Message();
        reply.setID(packet.getID());
        reply.setTo(packet.getFrom());
        reply.setFrom(packet.getTo());
        reply.setError(PacketError.Condition.not_authorized);
        session.process(reply);
        return;
    }
    super.processMessage(packet);
}
 
Example #16
Source File: IQPrivacyHandler.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * User has specified a new default list that should be used for all session.
 *
 * @param packet IQ packet setting new default list for all sessions.
 * @param from sender of the IQ packet.
 * @param listName name of the new default list for all sessions.
 * @return acknowledge of success.
 */
private IQ setDefaultList(IQ packet, JID from, String listName) {
    IQ result = IQ.createResultIQ(packet);
    Element childElement = packet.getChildElement().createCopy();
    result.setChildElement(childElement);

    if (sessionManager.getSessionCount(from.getNode()) > 1) {
        // Current default list is being used by more than one session
        result.setError(PacketError.Condition.conflict);
    }
    else {
        // Get the list
        PrivacyList list = manager.getPrivacyList(from.getNode(), listName);
        if (list != null) {
            // Get the user session
            ClientSession session = sessionManager.getSession(from);
            PrivacyList oldDefaultList = session.getDefaultList();
            manager.changeDefaultList(from.getNode(), list, oldDefaultList);
            // Set the new default list for this session (the only existing session)
            session.setDefaultList(list);
        }
        else {
            // List not found
            result.setError(PacketError.Condition.item_not_found);
        }
    }
    return result;
}
 
Example #17
Source File: IQPEPHandler.java    From Openfire with Apache License 2.0 5 votes vote down vote up
@Override
public IQ handleIQ(IQ packet) {
    // Do nothing if server is not enabled
    if (!isEnabled()) {
        IQ reply = IQ.createResultIQ(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(PacketError.Condition.service_unavailable);
        return reply;
    }

    if (packet.getTo() == null || packet.getTo().equals( new JID(XMPPServer.getInstance().getServerInfo().getXMPPDomain())) )
    {
        // packet addressed to service itself (not to a node/user)
        switch ( packet.getType() )
        {
            case set:
                return handleIQSetToService(packet );
            case get:
                return handleIQGetToService(packet );
            default:
                return null; // Ignore 'error' and 'result' stanzas.
        }
    }
    else
    {
        // packet was addressed to a node.
        if ( packet.isRequest() ) {
            return handleIQRequestToUser( packet );
        } else {
            return null; // Ignore IQ packets of type 'error' or 'result'.
        }
    }
}
 
Example #18
Source File: MultiplexerPacketHandler.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * Sends an IQ error with the specified condition to the sender of the original
 * IQ packet.
 *
 * @param packet     the packet to be bounced.
 * @param extraError application specific error or null if none.
 * @param error the error.
 */
private void sendErrorPacket(Route packet, PacketError.Condition error, Element extraError) {
    Route reply = new Route(packet.getStreamID());
    reply.setID(packet.getID());
    reply.setFrom(packet.getTo());
    reply.setTo(packet.getFrom());
    reply.setError(error);
    if (extraError != null) {
        // Add specific application error if available
        reply.getError().getElement().add(extraError);
    }
    deliver(reply);
}
 
Example #19
Source File: MultiplexerPacketHandler.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * Sends an IQ error with the specified condition to the sender of the original
 * IQ packet.
 *
 * @param packet     the packet to be bounced.
 * @param extraError application specific error or null if none.
 * @param error the error.
 */
private void sendErrorPacket(IQ packet, PacketError.Condition error, Element extraError) {
    IQ reply = IQ.createResultIQ(packet);
    reply.setChildElement(packet.getChildElement().createCopy());
    reply.setError(error);
    if (extraError != null) {
        // Add specific application error if available
        reply.getError().getElement().add(extraError);
    }
    deliver(reply);
}
 
Example #20
Source File: FileTransferProxy.java    From Openfire with Apache License 2.0 5 votes vote down vote up
@Override
public void process(Packet packet) throws UnauthorizedException, PacketException {
    // Check if the packet is a disco request or a packet with namespace iq:register
    if (packet instanceof IQ) {
        if (handleIQ((IQ) packet)) {
            // Do nothing
        }
        else {
            IQ reply = IQ.createResultIQ((IQ) packet);
            reply.setChildElement(((IQ) packet).getChildElement().createCopy());
            reply.setError(PacketError.Condition.feature_not_implemented);
            router.route(reply);
        }
    }
}
 
Example #21
Source File: IQPrivacyHandler.java    From Openfire with Apache License 2.0 5 votes vote down vote up
private IQ deleteList(IQ packet, JID from, String listName) {
    ClientSession currentSession;
    IQ result = IQ.createResultIQ(packet);
    Element childElement = packet.getChildElement().createCopy();
    result.setChildElement(childElement);
    // Get the list to delete
    PrivacyList list = manager.getPrivacyList(from.getNode(), listName);

    if (list == null) {
        // List to delete was not found
        result.setError(PacketError.Condition.item_not_found);
        return result;
    }
    else {
        currentSession = sessionManager.getSession(from);
        // Check if the list is being used by another session
        for (ClientSession session : sessionManager.getSessions(from.getNode())) {
            if (currentSession == session) {
                // Ignore the active session for this checking
                continue;
            }
            if (list.equals(session.getDefaultList()) || list.equals(session.getActiveList())) {
                // List to delete is being used by another session so return a conflict error
                result.setError(PacketError.Condition.conflict);
                return result;
            }
        }
    }
    // Remove the list from the active session (if it was being used)
    if (list.equals(currentSession.getDefaultList())) {
        currentSession.setDefaultList(null);
    }
    if (list.equals(currentSession.getActiveList())) {
        currentSession.setActiveList(null);
    }
    manager.deletePrivacyList(from.getNode(), listName);
    return result;
}
 
Example #22
Source File: XmppPubSubError.java    From onos with Apache License 2.0 5 votes vote down vote up
public PacketError asPacketError() {
    PacketError packetError = new PacketError(this.baseCondition);
    if (applicationCondition != null) {
        packetError.setApplicationCondition(applicationCondition.toString().toLowerCase(),
                                            PUBSUB_ERROR_NS);
    }
    return packetError;
}
 
Example #23
Source File: DefaultXmppDevice.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void sendError(PacketError packetError) {
    Packet packet = new IQ();
    packet.setTo(this.deviceId.getJid());
    packet.setFrom(new JID(XmppConstants.SERVER_JID));
    packet.setError(packetError);
    this.session.sendPacket(packet);
}
 
Example #24
Source File: LocationHandler.java    From openfireLBS with Apache License 2.0 5 votes vote down vote up
@Override
public IQ handleIQ(IQ packet) throws UnauthorizedException {
	
	System.out.println(">>>>>>>>>>>>> RECV IQ: " + packet.toXML()); // XXX
	
	// get users near me(from JID)
	if (IQ.Type.get.equals(packet.getType())) {
		return getUsersNearme(packet);
	// set from JID's location to ...
	} else if (IQ.Type.set.equals(packet.getType())) {
		JID to = packet.getTo();
		
		// send from JID's location to to JID
		if (to.getNode() != null && !to.getNode().equals("")){  
			XMPPServer.getInstance().getIQRouter().route(packet); // route to another user 
			
			return IQ.createResultIQ(packet);
		// send from JID's location to server , and update ofLocation  
		}else{ 
			return updateLocation(packet);
		}
	} else {
		IQ reply = IQ.createResultIQ(packet);
		reply.setType(IQ.Type.error);
		reply.setError(PacketError.Condition.bad_request);
		return reply;
	}
}
 
Example #25
Source File: IQPrivateHandler.java    From Openfire with Apache License 2.0 5 votes vote down vote up
@Override
public IQ handleIQ(IQ packet) throws UnauthorizedException, PacketException {
    IQ replyPacket = IQ.createResultIQ(packet);

    Element child = packet.getChildElement();
    Element dataElement = child.elementIterator().next();

    if ( !XMPPServer.getInstance().isLocal( packet.getFrom()) || !UserManager.getInstance().isRegisteredUser( packet.getFrom()) ) {
        replyPacket.setChildElement(packet.getChildElement().createCopy());
        replyPacket.setError(PacketError.Condition.service_unavailable);
        replyPacket.getError().setText( "Service available only to locally registered users." );
        return replyPacket;
    }

    if (dataElement != null) {
        if (IQ.Type.get.equals(packet.getType())) {
            Element dataStored = privateStorage.get(packet.getFrom().getNode(), dataElement);
            dataStored.setParent(null);

            child.remove(dataElement);
            child.setParent(null);
            replyPacket.setChildElement(child);
            child.add(dataStored);
        }
        else {
            if (privateStorage.isEnabled()) {
                privateStorage.add(packet.getFrom().getNode(), dataElement);
            } else {
                replyPacket.setChildElement(packet.getChildElement().createCopy());
                replyPacket.setError(PacketError.Condition.service_unavailable);
            }
        }
    }
    else {
        replyPacket.setChildElement("query", "jabber:iq:private");
    }
    return replyPacket;
}
 
Example #26
Source File: LocalMUCRoom.java    From Openfire with Apache License 2.0 5 votes vote down vote up
@Override
public void send(@Nonnull Packet packet, @Nonnull MUCRole sender) {
    if (packet instanceof Message) {
        broadcast((Message)packet, sender);
    }
    else if (packet instanceof Presence) {
        broadcastPresence((Presence)packet, false, sender);
    }
    else if (packet instanceof IQ) {
        IQ reply = IQ.createResultIQ((IQ) packet);
        reply.setChildElement(((IQ) packet).getChildElement());
        reply.setError(PacketError.Condition.bad_request);
        router.route(reply);
    }
}
 
Example #27
Source File: XmppWebSocket.java    From Openfire with Apache License 2.0 5 votes vote down vote up
private void sendPacketError(Element stanza, PacketError.Condition condition) {
    Element reply = stanza.createCopy();
    reply.addAttribute("type", "error");
    reply.addAttribute("to", stanza.attributeValue("from"));
    reply.addAttribute("from", stanza.attributeValue("to"));
    reply.add(new PacketError(condition).getElement());
    deliver(reply.asXML());
}
 
Example #28
Source File: MessageRouter.java    From Openfire with Apache License 2.0 5 votes vote down vote up
private void bounce(Message message) {
    // The bouncing behavior as implemented beyond this point was introduced as part
    // of OF-1852. This kill-switch allows it to be disabled again in case it
    // introduces unwanted side-effects.
    if ( !JiveGlobals.getBooleanProperty( "xmpp.message.bounce", true ) ) {
        log.trace( "Not bouncing a message stanza, as bouncing is disabled by configuration." );
        return;
    }

    // Do nothing if the packet included an error. This intends to prevent scenarios
    // where a stanza that is bounced itself gets bounced, causing a loop.
    if (message.getError() != null) {
        log.trace( "Not bouncing a stanza that included an error (to prevent never-ending loops of bounces-of-bounces)." );
        return;
    }

    // Do nothing if the sender was the server itself
    if (message.getFrom() == null || message.getFrom().toString().equals( serverName )) {
        log.trace( "Not bouncing a stanza that was sent by the server itself." );
        return;
    }
    try {
        log.trace( "Bouncing a message stanza." );

        // Generate a rejection response to the sender
        final Message errorResponse = message.createCopy();
        // return an error stanza to the sender, which SHOULD be <service-unavailable/>
        errorResponse.setError(PacketError.Condition.service_unavailable);
        errorResponse.setFrom(message.getTo());
        errorResponse.setTo(message.getFrom());
        // Send the response
        route(errorResponse);
    }
    catch (Exception e) {
        log.error("An exception occurred while trying to bounce a message.", e);
    }
}
 
Example #29
Source File: IQPrivacyHandler.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the IQ packet containing the details of the specified list. If no list
 * was found or the IQ request contains more than one specified list then an error will
 * be returned.
 *
 * @param packet IQ packet requesting a given list.
 * @param from sender of the IQ packet.
 * @return the IQ packet containing the details of the specified list.
 */
private IQ getPrivacyList(IQ packet, JID from) {
    IQ result = IQ.createResultIQ(packet);
    Element childElement = packet.getChildElement().createCopy();
    result.setChildElement(childElement);

    // Check that only one list was requested
    List<Element> lists = childElement.elements("list");
    if (lists.size() > 1) {
        result.setError(PacketError.Condition.bad_request);
    }
    else {
        String listName = lists.get(0).attributeValue("name");
        PrivacyList list = null;
        if (listName != null) {
            // A list name was specified so get it
            list = manager.getPrivacyList(from.getNode(), listName);
        }
        if (list != null) {
            // Add the privacy list to the result
            childElement = result.setChildElement("query", "jabber:iq:privacy");
            childElement.add(list.asElement());
        }
        else {
            // List not found
            result.setError(PacketError.Condition.item_not_found);
        }
    }
    return result;
}
 
Example #30
Source File: WhitelistAccess.java    From Openfire with Apache License 2.0 4 votes vote down vote up
@Override
public PacketError.Condition getSubsriptionError() {
    return PacketError.Condition.not_allowed;
}