Skip to content

Commit 9701911

Browse files
rahulrane50[Rahul Rane]
andauthored
Adding X509ZNodeGroupAclProvider support in NettyServerCnxnFactory. (#65)
* Adding X509ZNodeGroupAclProvider support in NettyServerCnxnFactory with backward compatibility * Addressed review comments * Addressing review comments about typo and other comments. Co-authored-by: [Rahul Rane] <“[[email protected]]”>
1 parent c36f0e1 commit 9701911

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

zookeeper-server/src/main/java/org/apache/zookeeper/server/NettyServerCnxnFactory.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@
7171
import org.apache.zookeeper.common.X509Exception;
7272
import org.apache.zookeeper.common.X509Exception.SSLContextException;
7373
import org.apache.zookeeper.server.NettyServerCnxn.HandshakeState;
74+
import org.apache.zookeeper.server.auth.AuthenticationProvider;
7475
import org.apache.zookeeper.server.auth.ProviderRegistry;
76+
import org.apache.zookeeper.server.auth.ServerAuthenticationProvider;
7577
import org.apache.zookeeper.server.auth.X509AuthenticationProvider;
7678
import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
7779
import org.slf4j.Logger;
@@ -423,15 +425,29 @@ public void operationComplete(Future<Channel> future) {
423425

424426
String authProviderProp = System.getProperty(x509Util.getSslAuthProviderProperty(), "x509");
425427

426-
X509AuthenticationProvider authProvider = (X509AuthenticationProvider) ProviderRegistry.getProvider(authProviderProp);
428+
// All implementations of the AuthenticationProvider interface should be supported here. Currently
429+
// any custom implementation of X509AuthenticationProvider or ServerAuthenticationProvider is
430+
// supported with backward compatability.
431+
X509AuthenticationProvider authProvider = null;
432+
ServerAuthenticationProvider serverAuthProvider = null;
433+
try {
434+
authProvider = (X509AuthenticationProvider) ProviderRegistry.getProvider(authProviderProp);
435+
} catch (ClassCastException e) {
436+
serverAuthProvider = ProviderRegistry.getServerProvider(authProviderProp);
437+
}
427438

428-
if (authProvider == null) {
439+
if (authProvider == null && serverAuthProvider == null) {
429440
LOG.error("X509 Auth provider not found: {}", authProviderProp);
430441
cnxn.close(ServerCnxn.DisconnectReason.AUTH_PROVIDER_NOT_FOUND);
431442
return;
432443
}
433444

434-
KeeperException.Code code = authProvider.handleAuthentication(cnxn, null);
445+
KeeperException.Code code = KeeperException.Code.AUTHFAILED;
446+
if (authProvider != null) {
447+
code = authProvider.handleAuthentication(cnxn, null);
448+
} else if (serverAuthProvider != null) {
449+
code = serverAuthProvider.handleAuthentication(new ServerAuthenticationProvider.ServerObjs(zkServer, cnxn), null);
450+
}
435451
if (KeeperException.Code.OK != code) {
436452
zkServer.serverStats().incrementAuthFailedCount();
437453
LOG.error("Authentication failed for session 0x{}", Long.toHexString(cnxn.getSessionId()));

zookeeper-server/src/main/java/org/apache/zookeeper/server/auth/znode/groupacl/ZkClientUriDomainMappingHelper.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,15 @@ public ZkClientUriDomainMappingHelper(ZooKeeperServer zks) {
7272

7373
this.rootPath =
7474
X509AuthenticationConfig.getInstance().getZnodeGroupAclClientUriDomainMappingRootPath();
75+
LOG.info("ZkClientUriDomainMappingHelper::ClientUriDomainMapping Client URI domain mapping root path: {}", this.rootPath);
7576
if (rootPath == null) {
7677
throw new IllegalStateException(
7778
"ZkClientUriDomainMappingHelper::ClientUriDomainMapping root path config is not set!");
7879
}
7980

8081
if (zks.getZKDatabase().getNode(rootPath) == null) {
8182
throw new IllegalStateException(
82-
"ZkClientUriDomainMappingHelper::ClientUriDomainMapping root path does not exist!");
83+
"ZkClientUriDomainMappingHelper::ClientUriDomainMapping root path does not exist :" + rootPath);
8384
}
8485

8586
addWatches();
@@ -125,8 +126,11 @@ private void parseZNodeMapping() {
125126
try {
126127
List<String> clientUris =
127128
zks.getZKDatabase().getChildren(rootPath + "/" + domainName, null, null);
128-
clientUris.forEach(
129-
clientUri -> newClientUriToDomainNames.computeIfAbsent(clientUri, k -> new HashSet<>()).add(domainName));
129+
clientUris.forEach(clientUri -> {
130+
LOG.info("ZkClientUriDomainMappingHelper::parseZNodeMapping(): Adding client uri mapping: domainName : {},"
131+
+ " clientUri: {}", domainName, clientUri);
132+
newClientUriToDomainNames.computeIfAbsent(clientUri, k -> new HashSet<>()).add(domainName);
133+
});
130134
} catch (KeeperException.NoNodeException e) {
131135
LOG.warn(
132136
"ZkClientUriDomainMappingHelper::parseZNodeMapping(): No clientUri ZNodes found under domain: {}",

0 commit comments

Comments
 (0)