-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
OF-2534: Support inline XEP-0198 <enable/> in SASL2 Bind2 requests #3480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
guusdk
merged 4 commits into
igniterealtime:main
from
guusdk:OF-2534_Bind2-Support-inline-XEP-0198-enable
Sep 3, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cc2c000
OF-2534: Support inline XEP-0198 <enable/> in SASL2 Bind2 requests
guusdk 07e9925
OF-2534: Prevent potential NullPointerException
guusdk abaca36
OF-2534: Do not retain authenticated state after a failed SASL2 negot…
guusdk f5e37e4
fix copyright headers
guusdk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
xmppserver/src/main/java/org/jivesoftware/openfire/handler/Bind2StreamManagementHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /* | ||
| * Copyright (C) 2026 Ignite Realtime Foundation. All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.jivesoftware.openfire.handler; | ||
|
|
||
| import org.dom4j.Element; | ||
| import org.jivesoftware.openfire.net.Bind2InlineHandler; | ||
| import org.jivesoftware.openfire.session.LocalClientSession; | ||
| import org.jivesoftware.openfire.streammanagement.StreamManagementException; | ||
| import org.jivesoftware.openfire.streammanagement.StreamManager; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.xmpp.packet.PacketError; | ||
|
|
||
| /** | ||
| * A {@link Bind2InlineHandler} that processes XEP-0198 Stream Management {@code <enable/>} elements | ||
| * sent inline within a SASL2 Bind2 request (XEP-0388 / XEP-0386). | ||
| * | ||
| * <p>When a client includes an {@code <enable/>} element in the {@code urn:xmpp:sm:3} namespace | ||
| * inside its Bind2 {@code <bind/>} element, this handler delegates to the session's | ||
| * {@link StreamManager} to enable stream management (and optionally resumption) immediately | ||
| * after resource binding, without requiring a separate round-trip.</p> | ||
| * | ||
| * <p>The {@code <enabled/>} response from the server is added as a child of the {@code <bound/>} | ||
| * element in the SASL2 {@code <success/>} stanza.</p> | ||
| * | ||
| * @see <a href="https://xmpp.org/extensions/xep-0198.html">XEP-0198: Stream Management</a> | ||
| * @see <a href="https://xmpp.org/extensions/xep-0388.html">XEP-0388: Extensible SASL Profile</a> | ||
| */ | ||
| public class Bind2StreamManagementHandler implements Bind2InlineHandler { | ||
|
|
||
| private static final Logger Log = LoggerFactory.getLogger(Bind2StreamManagementHandler.class); | ||
|
|
||
| @Override | ||
| public String getNamespace() { | ||
| return StreamManager.NAMESPACE_V3; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isEnabled() { | ||
| return StreamManager.isStreamManagementActive(); | ||
| } | ||
|
|
||
| /** | ||
| * Handles an {@code <enable/>} element from a Bind2 inline feature request by enabling | ||
| * XEP-0198 stream management on the session. The {@code <enabled/>} response element | ||
| * produced by the stream manager is added as a child of the provided {@code bound} element. | ||
| * | ||
| * <p>Only {@code <enable/>} elements are processed; any other element name is ignored.</p> | ||
| * | ||
| * @param session the client session on which stream management should be enabled | ||
| * @param bound the {@code <bound/>} element to which the {@code <enabled/>} response is added | ||
| * @param element the inline element from the Bind2 request (expected to be {@code <enable/>}) | ||
| * @return {@code true} if the element was an {@code <enable/>} and was processed; | ||
| * {@code false} if the element was not an {@code <enable/>} or processing failed | ||
| */ | ||
| @Override | ||
| public boolean handleElement(LocalClientSession session, Element bound, Element element) { | ||
| if (!"enable".equals(element.getName())) { | ||
| Log.debug("Received unexpected element '{}'; ignoring.", element.getName()); | ||
| return false; | ||
| } | ||
| final String resumeAttr = element.attributeValue("resume"); | ||
| final boolean resume = "true".equalsIgnoreCase(resumeAttr) || "1".equals(resumeAttr) || "yes".equalsIgnoreCase(resumeAttr); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| bound.add(session.getStreamManager().enableAndBuildElement(getNamespace(), resume)); | ||
|
guusdk marked this conversation as resolved.
|
||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Adds the {@code <failed/>} element that XEP-0198 § 9.1.1 requires inside {@code <bound/>} when stream | ||
| * management could not be enabled. | ||
| * | ||
| * The condition is taken from the failure itself where one is available. A handler that declined the request | ||
| * without failing did so because the element was not an {@code <enable/>}, which is a malformed request. | ||
| */ | ||
| @Override | ||
| public void handleFailure(LocalClientSession session, Element bound, Element element, Exception cause) { | ||
| final PacketError.Condition condition; | ||
| if (cause instanceof StreamManagementException sme) { | ||
| condition = sme.getCondition(); | ||
| } else if (cause == null) { | ||
| condition = PacketError.Condition.bad_request; | ||
| } else { | ||
| condition = PacketError.Condition.internal_server_error; | ||
| } | ||
| bound.addElement("failed", StreamManager.NAMESPACE_V3) | ||
| .addElement(condition.toXMPP(), "urn:ietf:params:xml:ns:xmpp-stanzas"); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.