|
@@ -22,10 +22,13 @@ import java.io.IOException;
|
|
import java.net.InetSocketAddress;
|
|
import java.net.InetSocketAddress;
|
|
import java.nio.ByteBuffer;
|
|
import java.nio.ByteBuffer;
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
+import java.util.function.Supplier;
|
|
import javax.management.JMException;
|
|
import javax.management.JMException;
|
|
|
|
+import javax.security.auth.callback.CallbackHandler;
|
|
import javax.security.auth.login.AppConfigurationEntry;
|
|
import javax.security.auth.login.AppConfigurationEntry;
|
|
import javax.security.auth.login.Configuration;
|
|
import javax.security.auth.login.Configuration;
|
|
import javax.security.auth.login.LoginException;
|
|
import javax.security.auth.login.LoginException;
|
|
@@ -41,6 +44,7 @@ public abstract class ServerCnxnFactory {
|
|
|
|
|
|
public static final String ZOOKEEPER_SERVER_CNXN_FACTORY = "zookeeper.serverCnxnFactory";
|
|
public static final String ZOOKEEPER_SERVER_CNXN_FACTORY = "zookeeper.serverCnxnFactory";
|
|
private static final String ZOOKEEPER_MAX_CONNECTION = "zookeeper.maxCnxns";
|
|
private static final String ZOOKEEPER_MAX_CONNECTION = "zookeeper.maxCnxns";
|
|
|
|
+ private static final String DIGEST_MD5_USER_PREFIX = "user_";
|
|
public static final int ZOOKEEPER_MAX_CONNECTION_DEFAULT = 0;
|
|
public static final int ZOOKEEPER_MAX_CONNECTION_DEFAULT = 0;
|
|
|
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(ServerCnxnFactory.class);
|
|
private static final Logger LOG = LoggerFactory.getLogger(ServerCnxnFactory.class);
|
|
@@ -113,7 +117,6 @@ public abstract class ServerCnxnFactory {
|
|
|
|
|
|
public abstract void reconfigure(InetSocketAddress addr);
|
|
public abstract void reconfigure(InetSocketAddress addr);
|
|
|
|
|
|
- protected SaslServerCallbackHandler saslServerCallbackHandler;
|
|
|
|
public Login login;
|
|
public Login login;
|
|
|
|
|
|
/** Maximum number of connections allowed from particular host (ip) */
|
|
/** Maximum number of connections allowed from particular host (ip) */
|
|
@@ -269,8 +272,11 @@ public abstract class ServerCnxnFactory {
|
|
|
|
|
|
// jaas.conf entry available
|
|
// jaas.conf entry available
|
|
try {
|
|
try {
|
|
- saslServerCallbackHandler = new SaslServerCallbackHandler(Configuration.getConfiguration());
|
|
|
|
- login = new Login(serverSection, saslServerCallbackHandler, new ZKConfig());
|
|
|
|
|
|
+ Map<String, String> credentials = getDigestMd5Credentials(entries);
|
|
|
|
+ Supplier<CallbackHandler> callbackHandlerSupplier = () -> {
|
|
|
|
+ return new SaslServerCallbackHandler(credentials);
|
|
|
|
+ };
|
|
|
|
+ login = new Login(serverSection, callbackHandlerSupplier, new ZKConfig());
|
|
setLoginUser(login.getUserName());
|
|
setLoginUser(login.getUserName());
|
|
login.startThreadIfNeeded();
|
|
login.startThreadIfNeeded();
|
|
} catch (LoginException e) {
|
|
} catch (LoginException e) {
|
|
@@ -280,6 +286,28 @@ public abstract class ServerCnxnFactory {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * make server credentials map from configuration's server section.
|
|
|
|
+ * @param appConfigurationEntries AppConfigurationEntry List
|
|
|
|
+ * @return Server credentials map
|
|
|
|
+ */
|
|
|
|
+ private static Map<String, String> getDigestMd5Credentials(final AppConfigurationEntry[] appConfigurationEntries) {
|
|
|
|
+ Map<String, String> credentials = new HashMap<>();
|
|
|
|
+ for (AppConfigurationEntry entry : appConfigurationEntries) {
|
|
|
|
+ Map<String, ?> options = entry.getOptions();
|
|
|
|
+ // Populate DIGEST-MD5 user -> password map with JAAS configuration entries from the "Server" section.
|
|
|
|
+ // Usernames are distinguished from other options by prefixing the username with a "user_" prefix.
|
|
|
|
+ for (Map.Entry<String, ?> pair : options.entrySet()) {
|
|
|
|
+ String key = pair.getKey();
|
|
|
|
+ if (key.startsWith(DIGEST_MD5_USER_PREFIX)) {
|
|
|
|
+ String userName = key.substring(DIGEST_MD5_USER_PREFIX.length());
|
|
|
|
+ credentials.put(userName, (String) pair.getValue());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return credentials;
|
|
|
|
+ }
|
|
|
|
+
|
|
private static void setLoginUser(String name) {
|
|
private static void setLoginUser(String name) {
|
|
//Created this method to avoid ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD find bug issue
|
|
//Created this method to avoid ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD find bug issue
|
|
loginUser = name;
|
|
loginUser = name;
|