This is an automated email from the ASF dual-hosted git repository.

JiaLiangC pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 8e65dc3712 AMBARI-26620: Fix LDAPS end-to-end flow on Python 3 + Java 
9+ (#4151)
8e65dc3712 is described below

commit 8e65dc371298d2336d270f4339126716fedf39c6
Author: Manish M Pillai <[email protected]>
AuthorDate: Thu Aug 6 13:47:19 2026 +0530

    AMBARI-26620: Fix LDAPS end-to-end flow on Python 3 + Java 9+ (#4151)
    
    Three bugs blocked the full LDAPS setup flow on Ambari 3.0:
    
    1. serverUtils.py: Encode POST body to bytes in 
perform_changes_via_rest_api()
       Python 3's urllib requires bytes for request.data; json.dumps() returns 
str.
    
    2. setupSecurity.py: Same encoding fix for both POST bodies in sync_ldap()
       Fixes 'POST data should be of type str' error during ambari-server 
sync-ldap.
    
    3. ambari-env.sh: Add --add-opens java.naming/com.sun.jndi.ldap=ALL-UNNAMED
       Java 9+ module system blocked Spring LDAP's reflective access to
       LdapCtxFactory, causing IllegalAccessError on LDAP login via the UI.
    
    Updated 8 sync_ldap unit test assertions in TestAmbariServer.py to expect
    bytes instead of str, keeping the test suite consistent with the fix.
    
    Fixes: ambari-server setup-ldap, sync-ldap --all, and LDAP UI 
authentication.
---
 ambari-server/conf/unix/ambari-env.sh                    |  1 +
 .../src/main/python/ambari_server/serverUtils.py         |  2 +-
 .../src/main/python/ambari_server/setupSecurity.py       |  4 ++--
 ambari-server/src/test/python/TestAmbariServer.py        | 16 ++++++++--------
 4 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/ambari-server/conf/unix/ambari-env.sh 
b/ambari-server/conf/unix/ambari-env.sh
index 297eee3df3..4339038368 100644
--- a/ambari-server/conf/unix/ambari-env.sh
+++ b/ambari-server/conf/unix/ambari-env.sh
@@ -23,6 +23,7 @@ AMBARI_JVM_ARGS="--add-opens java.base/java.lang=ALL-UNNAMED "
 AMBARI_JVM_ARGS+="--add-opens java.base/java.util.regex=ALL-UNNAMED "
 AMBARI_JVM_ARGS+="--add-opens java.base/java.util=ALL-UNNAMED "
 AMBARI_JVM_ARGS+="--add-opens java.base/java.lang.reflect=ALL-UNNAMED "
+AMBARI_JVM_ARGS+="--add-opens java.naming/com.sun.jndi.ldap=ALL-UNNAMED "
 AMBARI_JVM_ARGS+="-Xms512m -Xmx2048m "
 
AMBARI_JVM_ARGS+="-Djava.security.auth.login.config=$ROOT/etc/ambari-server/conf/krb5JAASLogin.conf
 "
 AMBARI_JVM_ARGS+="-Djava.security.krb5.conf=/etc/krb5.conf "
diff --git a/ambari-server/src/main/python/ambari_server/serverUtils.py 
b/ambari-server/src/main/python/ambari_server/serverUtils.py
index 9f75c8b092..a11961bc66 100644
--- a/ambari-server/src/main/python/ambari_server/serverUtils.py
+++ b/ambari-server/src/main/python/ambari_server/serverUtils.py
@@ -262,7 +262,7 @@ def perform_changes_via_rest_api(
   request.add_header("Authorization", f"Basic {admin_auth}")
   request.add_header("X-Requested-By", "ambari")
   if request_data is not None:
-    request.data = json.dumps(request_data)
+    request.data = json.dumps(request_data).encode("utf-8")
   request.get_method = lambda: get_method
 
   with closing(
diff --git a/ambari-server/src/main/python/ambari_server/setupSecurity.py 
b/ambari-server/src/main/python/ambari_server/setupSecurity.py
index 73ab89da0a..8da2db6b29 100644
--- a/ambari-server/src/main/python/ambari_server/setupSecurity.py
+++ b/ambari-server/src/main/python/ambari_server/setupSecurity.py
@@ -626,7 +626,7 @@ def sync_ldap(options):
   if get_verbose():
     sys.stdout.write("\nCalling API " + url + " : " + str(bodies) + "\n")
 
-  request.data = json.dumps(bodies)
+  request.data = json.dumps(bodies).encode("utf-8")
   request.get_method = lambda: "POST"
 
   try:
@@ -646,7 +646,7 @@ def sync_ldap(options):
   request.add_header("Authorization", f"Basic {admin_auth}")
   request.add_header("X-Requested-By", "ambari")
   body = [{"LDAP": {"synced_groups": "*", "synced_users": "*"}}]
-  request.data = json.dumps(body)
+  request.data = json.dumps(body).encode("utf-8")
   request.get_method = lambda: "GET"
   request_in_progress = True
 
diff --git a/ambari-server/src/test/python/TestAmbariServer.py 
b/ambari-server/src/test/python/TestAmbariServer.py
index 6fee1a4b2e..5a71dbeb56 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -8736,7 +8736,7 @@ class TestAmbariServer(TestCase):
 
     self.assertEqual(url, str(request.get_full_url()))
     self.assertEqual(
-      '[{"Event": {"specs": [{"principal_type": "users", "sync_type": "all"}, 
{"principal_type": "groups", "sync_type": "all"}]}}]',
+      b'[{"Event": {"specs": [{"principal_type": "users", "sync_type": "all"}, 
{"principal_type": "groups", "sync_type": "all"}]}}]',
       request.data,
     )
 
@@ -8791,7 +8791,7 @@ class TestAmbariServer(TestCase):
 
     self.assertEqual(url, str(request.get_full_url()))
     self.assertEqual(
-      '[{"Event": {"specs": [{"principal_type": "users", "sync_type": "all", 
"post_process_existing_users": "true"}, {"principal_type": "groups", 
"sync_type": "all", "post_process_existing_users": "true"}]}}]',
+      b'[{"Event": {"specs": [{"principal_type": "users", "sync_type": "all", 
"post_process_existing_users": "true"}, {"principal_type": "groups", 
"sync_type": "all", "post_process_existing_users": "true"}]}}]',
       request.data,
     )
 
@@ -8852,7 +8852,7 @@ class TestAmbariServer(TestCase):
     request = urlopen_mock.call_args_list[0][0][0]
 
     self.assertEqual(
-      '[{"Event": {"specs": [{"principal_type": "users", "sync_type": 
"specific", "names": "bob, tom"}]}}]',
+      b'[{"Event": {"specs": [{"principal_type": "users", "sync_type": 
"specific", "names": "bob, tom"}]}}]',
       request.data,
     )
 
@@ -8913,7 +8913,7 @@ class TestAmbariServer(TestCase):
     request = urlopen_mock.call_args_list[0][0][0]
 
     self.assertEqual(
-      '[{"Event": {"specs": [{"principal_type": "users", "sync_type": 
"specific", "names": "bob, tom", "post_process_existing_users": "true"}]}}]',
+      b'[{"Event": {"specs": [{"principal_type": "users", "sync_type": 
"specific", "names": "bob, tom", "post_process_existing_users": "true"}]}}]',
       request.data,
     )
 
@@ -8974,7 +8974,7 @@ class TestAmbariServer(TestCase):
     request = urlopen_mock.call_args_list[0][0][0]
 
     self.assertEqual(
-      '[{"Event": {"specs": [{"principal_type": "groups", "sync_type": 
"specific", "names": "group1, group2"}]}}]',
+      b'[{"Event": {"specs": [{"principal_type": "groups", "sync_type": 
"specific", "names": "group1, group2"}]}}]',
       request.data,
     )
 
@@ -9035,7 +9035,7 @@ class TestAmbariServer(TestCase):
     request = urlopen_mock.call_args_list[0][0][0]
 
     self.assertEqual(
-      '[{"Event": {"specs": [{"principal_type": "groups", "sync_type": 
"specific", "names": "group1, group2", "post_process_existing_users": 
"true"}]}}]',
+      b'[{"Event": {"specs": [{"principal_type": "groups", "sync_type": 
"specific", "names": "group1, group2", "post_process_existing_users": 
"true"}]}}]',
       request.data,
     )
 
@@ -9141,7 +9141,7 @@ class TestAmbariServer(TestCase):
     request = urlopen_mock.call_args_list[0][0][0]
 
     self.assertEqual(
-      '[{"Event": {"specs": [{"principal_type": "users", "sync_type": 
"existing"}, {"principal_type": "groups", "sync_type": "existing"}]}}]',
+      b'[{"Event": {"specs": [{"principal_type": "users", "sync_type": 
"existing"}, {"principal_type": "groups", "sync_type": "existing"}]}}]',
       request.data,
     )
 
@@ -9194,7 +9194,7 @@ class TestAmbariServer(TestCase):
     request = urlopen_mock.call_args_list[0][0][0]
 
     self.assertEqual(
-      '[{"Event": {"specs": [{"principal_type": "users", "sync_type": 
"existing", "post_process_existing_users": "true"}, {"principal_type": 
"groups", "sync_type": "existing", "post_process_existing_users": "true"}]}}]',
+      b'[{"Event": {"specs": [{"principal_type": "users", "sync_type": 
"existing", "post_process_existing_users": "true"}, {"principal_type": 
"groups", "sync_type": "existing", "post_process_existing_users": "true"}]}}]',
       request.data,
     )
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to