You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by ch...@apache.org on 2025/07/18 09:05:53 UTC
(kyuubi-shaded) branch master updated (b3cfca3 -> b16cc4f)
This is an automated email from the ASF dual-hosted git repository.
chengpan pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/kyuubi-shaded.git
discard b3cfca3 [KYUUBI-SHADED #61] [KYUUBI-SHADED #60] Step 2/2: TSaslServerTransport use SaslServerFactory to create SaslServer
omit 334bb5d [KYUUBI-SHADED #62] [KYUUBI-SHADED #60] Step 1/2: Copy TSaslServerTransport from Thrift 0.16.0
new 3811710 [KYUUBI-SHADED #60] Step 1/2: Copy TSaslServerTransport from Thrift 0.16.0
new b16cc4f [KYUUBI-SHADED #60] Step 2/2: TSaslServerTransport use SaslServerFactory to create SaslServer
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (b3cfca3)
\
N -- N -- N refs/heads/master (b16cc4f)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
(kyuubi-shaded) 01/02: [KYUUBI-SHADED #60] Step 1/2: Copy TSaslServerTransport from Thrift 0.16.0
Posted by ch...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
chengpan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kyuubi-shaded.git
commit 3811710e6ce3e8e2c1e303fb5963755c1f2b7ec2
Author: Cheng Pan <ch...@apache.org>
AuthorDate: Fri Jul 18 16:50:14 2025 +0800
[KYUUBI-SHADED #60] Step 1/2: Copy TSaslServerTransport from Thrift 0.16.0
### _Why are the changes needed?_
The first step of https://github.com/apache/kyuubi-shaded/issues/60, copy before making modifications to achieve a clear diff in the commit history.
### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible
- [ ] Add screenshots for manual tests if appropriate
- [ ] [Run test](https://kyuubi.readthedocs.io/en/master/develop_tools/testing.html#running-tests) locally before make a pull request
Closes #62 from pan3793/copy.
4cb2a5a [Cheng Pan] copy TSaslServerTransport
Authored-by: Cheng Pan <ch...@apache.org>
Signed-off-by: Cheng Pan <ch...@apache.org>
---
kyuubi-relocated-thrift/pom.xml | 7 +
.../thrift/transport/TSaslServerTransport.java | 219 +++++++++++++++++++++
2 files changed, 226 insertions(+)
diff --git a/kyuubi-relocated-thrift/pom.xml b/kyuubi-relocated-thrift/pom.xml
index eec98a2..3fa2c75 100644
--- a/kyuubi-relocated-thrift/pom.xml
+++ b/kyuubi-relocated-thrift/pom.xml
@@ -32,11 +32,18 @@ under the License.
<description>Relocated Thrift classes used by Kyuubi internally.</description>
<properties>
+ <slf4j.version>1.7.36</slf4j.version>
<fb303.version>0.9.3</fb303.version>
<thrift.version>0.16.0</thrift.version>
</properties>
<dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4j.version}</version>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>org.apache.thrift</groupId>
<artifactId>libfb303</artifactId>
diff --git a/kyuubi-relocated-thrift/src/main/java/org/apache/thrift/transport/TSaslServerTransport.java b/kyuubi-relocated-thrift/src/main/java/org/apache/thrift/transport/TSaslServerTransport.java
new file mode 100644
index 0000000..87a91ff
--- /dev/null
+++ b/kyuubi-relocated-thrift/src/main/java/org/apache/thrift/transport/TSaslServerTransport.java
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.thrift.transport;
+
+import java.lang.ref.WeakReference;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.WeakHashMap;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.sasl.Sasl;
+import javax.security.sasl.SaslException;
+import javax.security.sasl.SaslServer;
+import org.apache.thrift.transport.sasl.NegotiationStatus;
+import org.apache.thrift.transport.sasl.TSaslServerDefinition;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Wraps another Thrift <code>TTransport</code>, but performs SASL server negotiation on the call to
+ * <code>open()</code>. This class will wrap ensuing communication over it, if a SASL QOP is
+ * negotiated with the other party.
+ */
+public class TSaslServerTransport extends TSaslTransport {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(TSaslServerTransport.class);
+
+ /**
+ * Mapping from SASL mechanism name -> all the parameters required to instantiate a SASL server.
+ */
+ private Map<String, TSaslServerDefinition> serverDefinitionMap = new HashMap<>();
+
+ /**
+ * Uses the given underlying transport. Assumes that addServerDefinition is called later.
+ *
+ * @param transport Transport underlying this one.
+ */
+ public TSaslServerTransport(TTransport transport) throws TTransportException {
+ super(transport);
+ }
+
+ /**
+ * Creates a <code>SaslServer</code> using the given SASL-specific parameters. See the Java
+ * documentation for <code>Sasl.createSaslServer</code> for the details of the parameters.
+ *
+ * @param transport The underlying Thrift transport.
+ */
+ public TSaslServerTransport(
+ String mechanism,
+ String protocol,
+ String serverName,
+ Map<String, String> props,
+ CallbackHandler cbh,
+ TTransport transport)
+ throws TTransportException {
+ super(transport);
+ addServerDefinition(mechanism, protocol, serverName, props, cbh);
+ }
+
+ private TSaslServerTransport(
+ Map<String, TSaslServerDefinition> serverDefinitionMap, TTransport transport)
+ throws TTransportException {
+ super(transport);
+ this.serverDefinitionMap.putAll(serverDefinitionMap);
+ }
+
+ /**
+ * Add a supported server definition to this transport. See the Java documentation for <code>
+ * Sasl.createSaslServer</code> for the details of the parameters.
+ */
+ public void addServerDefinition(
+ String mechanism,
+ String protocol,
+ String serverName,
+ Map<String, String> props,
+ CallbackHandler cbh) {
+ serverDefinitionMap.put(
+ mechanism, new TSaslServerDefinition(mechanism, protocol, serverName, props, cbh));
+ }
+
+ @Override
+ protected SaslRole getRole() {
+ return SaslRole.SERVER;
+ }
+
+ /**
+ * Performs the server side of the initial portion of the Thrift SASL protocol. Receives the
+ * initial response from the client, creates a SASL server using the mechanism requested by the
+ * client (if this server supports it), and sends the first challenge back to the client.
+ */
+ @Override
+ protected void handleSaslStartMessage() throws TTransportException, SaslException {
+ SaslResponse message = receiveSaslMessage();
+
+ LOGGER.debug("Received start message with status {}", message.status);
+ if (message.status != NegotiationStatus.START) {
+ throw sendAndThrowMessage(
+ NegotiationStatus.ERROR, "Expecting START status, received " + message.status);
+ }
+
+ // Get the mechanism name.
+ String mechanismName = new String(message.payload, StandardCharsets.UTF_8);
+ TSaslServerDefinition serverDefinition = serverDefinitionMap.get(mechanismName);
+ LOGGER.debug("Received mechanism name '{}'", mechanismName);
+
+ if (serverDefinition == null) {
+ throw sendAndThrowMessage(
+ NegotiationStatus.BAD, "Unsupported mechanism type " + mechanismName);
+ }
+ SaslServer saslServer =
+ Sasl.createSaslServer(
+ serverDefinition.mechanism,
+ serverDefinition.protocol,
+ serverDefinition.serverName,
+ serverDefinition.props,
+ serverDefinition.cbh);
+ setSaslServer(saslServer);
+ }
+
+ /**
+ * <code>TTransportFactory</code> to create <code>TSaslServerTransports</code>. Ensures that a
+ * given underlying <code>TTransport</code> instance receives the same <code>TSaslServerTransport
+ * </code>. This is kind of an awful hack to work around the fact that Thrift is designed assuming
+ * that <code>TTransport</code> instances are stateless, and thus the existing <code>TServers
+ * </code> use different <code>TTransport</code> instances for input and output.
+ */
+ public static class Factory extends TTransportFactory {
+
+ /**
+ * This is the implementation of the awful hack described above. <code>WeakHashMap</code> is
+ * used to ensure that we don't leak memory.
+ */
+ private static Map<TTransport, WeakReference<TSaslServerTransport>> transportMap =
+ Collections.synchronizedMap(new WeakHashMap<>());
+
+ /**
+ * Mapping from SASL mechanism name -> all the parameters required to instantiate a SASL server.
+ */
+ private Map<String, TSaslServerDefinition> serverDefinitionMap = new HashMap<>();
+
+ /** Create a new Factory. Assumes that <code>addServerDefinition</code> will be called later. */
+ public Factory() {
+ super();
+ }
+
+ /**
+ * Create a new <code>Factory</code>, initially with the single server definition given. You may
+ * still call <code>addServerDefinition</code> later. See the Java documentation for <code>
+ * Sasl.createSaslServer</code> for the details of the parameters.
+ */
+ public Factory(
+ String mechanism,
+ String protocol,
+ String serverName,
+ Map<String, String> props,
+ CallbackHandler cbh) {
+ super();
+ addServerDefinition(mechanism, protocol, serverName, props, cbh);
+ }
+
+ /**
+ * Add a supported server definition to the transports created by this factory. See the Java
+ * documentation for <code>Sasl.createSaslServer</code> for the details of the parameters.
+ */
+ public void addServerDefinition(
+ String mechanism,
+ String protocol,
+ String serverName,
+ Map<String, String> props,
+ CallbackHandler cbh) {
+ serverDefinitionMap.put(
+ mechanism, new TSaslServerDefinition(mechanism, protocol, serverName, props, cbh));
+ }
+
+ /**
+ * Get a new <code>TSaslServerTransport</code> instance, or reuse the existing one if a <code>
+ * TSaslServerTransport</code> has already been created before using the given <code>TTransport
+ * </code> as an underlying transport. This ensures that a given underlying transport instance
+ * receives the same <code>TSaslServerTransport</code>.
+ */
+ @Override
+ public TTransport getTransport(TTransport base) throws TTransportException {
+ WeakReference<TSaslServerTransport> ret = transportMap.get(base);
+ if (ret == null || ret.get() == null) {
+ LOGGER.debug("transport map does not contain key {}", base);
+ ret = new WeakReference<>(new TSaslServerTransport(serverDefinitionMap, base));
+ try {
+ ret.get().open();
+ } catch (TTransportException e) {
+ LOGGER.debug("failed to open server transport", e);
+ throw new RuntimeException(e);
+ }
+ transportMap.put(base, ret); // No need for putIfAbsent().
+ // Concurrent calls to getTransport() will pass in different TTransports.
+ } else {
+ LOGGER.debug("transport map does contain key {}", base);
+ }
+ return ret.get();
+ }
+ }
+}
(kyuubi-shaded) 02/02: [KYUUBI-SHADED #60] Step 2/2: TSaslServerTransport use SaslServerFactory to create SaslServer
Posted by ch...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
chengpan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kyuubi-shaded.git
commit b16cc4f34a6490b3ec206d5326fe0f9fc00688f7
Author: Cheng Pan <ch...@apache.org>
AuthorDate: Fri Jul 18 17:02:49 2025 +0800
[KYUUBI-SHADED #60] Step 2/2: TSaslServerTransport use SaslServerFactory to create SaslServer
### _Why are the changes needed?_
Define a `SaslServerFactory` and allow [TSaslServerTransport](https://github.com/apache/thrift/blob/0.16.0/lib/java/src/org/apache/thrift/transport/TSaslServerTransport.java) to use `SaslServerFactory` to create `SaslServer` instead of simply calling `Sasl.createSaslServer`
```
public interface SaslServerFactory {
SaslServer create(TSaslServerDefinition d) throws SaslException;
}
```
Close #60
### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible
- [ ] Add screenshots for manual tests if appropriate
- [ ] [Run test](https://kyuubi.readthedocs.io/en/master/develop_tools/testing.html#running-tests) locally before make a pull request
Closes #61 from pan3793/thrift-sasl.
618b3d0 [Cheng Pan] TSaslServerTransport supports custom SaslServerFactory
Authored-by: Cheng Pan <ch...@apache.org>
Signed-off-by: Cheng Pan <ch...@apache.org>
---
.../thrift/transport/TSaslServerTransport.java | 36 +++++++++++++++++-----
1 file changed, 28 insertions(+), 8 deletions(-)
diff --git a/kyuubi-relocated-thrift/src/main/java/org/apache/thrift/transport/TSaslServerTransport.java b/kyuubi-relocated-thrift/src/main/java/org/apache/thrift/transport/TSaslServerTransport.java
index 87a91ff..83363a5 100644
--- a/kyuubi-relocated-thrift/src/main/java/org/apache/thrift/transport/TSaslServerTransport.java
+++ b/kyuubi-relocated-thrift/src/main/java/org/apache/thrift/transport/TSaslServerTransport.java
@@ -43,6 +43,8 @@ public class TSaslServerTransport extends TSaslTransport {
private static final Logger LOGGER = LoggerFactory.getLogger(TSaslServerTransport.class);
+ private SaslServerFactory saslServerFactory = new JdkSaslServerFactory();
+
/**
* Mapping from SASL mechanism name -> all the parameters required to instantiate a SASL server.
*/
@@ -96,6 +98,10 @@ public class TSaslServerTransport extends TSaslTransport {
mechanism, new TSaslServerDefinition(mechanism, protocol, serverName, props, cbh));
}
+ public void setSaslServerFactory(SaslServerFactory f) {
+ this.saslServerFactory = f;
+ }
+
@Override
protected SaslRole getRole() {
return SaslRole.SERVER;
@@ -125,16 +131,22 @@ public class TSaslServerTransport extends TSaslTransport {
throw sendAndThrowMessage(
NegotiationStatus.BAD, "Unsupported mechanism type " + mechanismName);
}
- SaslServer saslServer =
- Sasl.createSaslServer(
- serverDefinition.mechanism,
- serverDefinition.protocol,
- serverDefinition.serverName,
- serverDefinition.props,
- serverDefinition.cbh);
+ SaslServer saslServer = saslServerFactory.create(serverDefinition);
setSaslServer(saslServer);
}
+ public interface SaslServerFactory {
+ SaslServer create(TSaslServerDefinition d) throws SaslException;
+ }
+
+ public static class JdkSaslServerFactory implements SaslServerFactory {
+
+ @Override
+ public SaslServer create(TSaslServerDefinition d) throws SaslException {
+ return Sasl.createSaslServer(d.mechanism, d.protocol, d.serverName, d.props, d.cbh);
+ }
+ }
+
/**
* <code>TTransportFactory</code> to create <code>TSaslServerTransports</code>. Ensures that a
* given underlying <code>TTransport</code> instance receives the same <code>TSaslServerTransport
@@ -156,6 +168,8 @@ public class TSaslServerTransport extends TSaslTransport {
*/
private Map<String, TSaslServerDefinition> serverDefinitionMap = new HashMap<>();
+ private SaslServerFactory saslServerFactory = new JdkSaslServerFactory();
+
/** Create a new Factory. Assumes that <code>addServerDefinition</code> will be called later. */
public Factory() {
super();
@@ -190,6 +204,10 @@ public class TSaslServerTransport extends TSaslTransport {
mechanism, new TSaslServerDefinition(mechanism, protocol, serverName, props, cbh));
}
+ public void setSaslServerFactory(SaslServerFactory f) {
+ this.saslServerFactory = f;
+ }
+
/**
* Get a new <code>TSaslServerTransport</code> instance, or reuse the existing one if a <code>
* TSaslServerTransport</code> has already been created before using the given <code>TTransport
@@ -201,7 +219,9 @@ public class TSaslServerTransport extends TSaslTransport {
WeakReference<TSaslServerTransport> ret = transportMap.get(base);
if (ret == null || ret.get() == null) {
LOGGER.debug("transport map does not contain key {}", base);
- ret = new WeakReference<>(new TSaslServerTransport(serverDefinitionMap, base));
+ TSaslServerTransport t = new TSaslServerTransport(serverDefinitionMap, base);
+ t.setSaslServerFactory(saslServerFactory);
+ ret = new WeakReference<>(t);
try {
ret.get().open();
} catch (TTransportException e) {