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
The following commit(s) were added to refs/heads/master by this push:
new b3cfca3 [KYUUBI-SHADED #61] [KYUUBI-SHADED #60] Step 2/2:
TSaslServerTransport use SaslServerFactory to create SaslServer
b3cfca3 is described below
commit b3cfca3581a7345578d6d70af8f30659a3049f09
Author: Cheng Pan <[email protected]>
AuthorDate: Fri Jul 18 17:02:49 2025 +0800
[KYUUBI-SHADED #61] [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 <[email protected]>
Signed-off-by: Cheng Pan <[email protected]>
---
.../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) {