ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject [57/59] [abbrv] git commit: AMBARI-7153. Admin: error printed to log when going to admin view.
Date Thu, 04 Sep 2014 22:36:36 GMT
AMBARI-7153. Admin: error printed to log when going to admin view.


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/1946654b
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/1946654b
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/1946654b

Branch: refs/heads/branch-alerts-dev
Commit: 1946654b71da61d097b3fc139dc2d12e20a116cb
Parents: fcd8d1f
Author: Siddharth Wagle <swagle@hortonworks.com>
Authored: Thu Sep 4 13:40:35 2014 -0700
Committer: Siddharth Wagle <swagle@hortonworks.com>
Committed: Thu Sep 4 13:40:35 2014 -0700

----------------------------------------------------------------------
 .../server/configuration/Configuration.java     |  6 ++++++
 .../authorization/AmbariLdapDataPopulator.java  |  5 ++++-
 ambari-server/src/main/python/ambari-server.py  |  2 ++
 .../AmbariLdapDataPopulatorTest.java            | 22 +++++++++++---------
 .../src/test/python/TestAmbariServer.py         |  9 +++++---
 5 files changed, 30 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/1946654b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
index 0d02b21..dc3a715 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
@@ -118,6 +118,7 @@ public class Configuration {
   public static final String OJDBC_JAR_NAME_DEFAULT = "ojdbc6.jar";
   public static final String MYSQL_JAR_NAME_KEY = "db.mysql.jdbc.name";
   public static final String MYSQL_JAR_NAME_DEFAULT = "mysql-connector-java.jar";
+  public static final String IS_LDAP_CONFIGURED = "ambari.ldap.isConfigured";
   public static final String LDAP_USE_SSL_KEY = "authentication.ldap.useSSL";
   public static final String LDAP_PRIMARY_URL_KEY =
       "authentication.ldap.primaryUrl";
@@ -280,6 +281,7 @@ public class Configuration {
   private static final String LDAP_ADMIN_GROUP_MAPPING_RULES_DEFAULT =
       "Ambari Administrators";
   private static final String LDAP_GROUP_SEARCH_FILTER_DEFAULT = "";
+  private static final String IS_LDAP_CONFIGURED_DEFAULT = "false";
   //TODO for development purposes only, should be changed to 'false'
   private static final String SERVER_PERSISTENCE_TYPE_DEFAULT = "local";
   private static final String SERVER_CONNECTION_MAX_IDLE_TIME =
@@ -804,6 +806,10 @@ public class Configuration {
     return ldapServerProperties;
   }
 
+  public boolean isLdapConfigured() {
+    return Boolean.parseBoolean(properties.getProperty(IS_LDAP_CONFIGURED, IS_LDAP_CONFIGURED_DEFAULT));
+  }
+
   public String getServerOsType() {
     return properties.getProperty(OS_VERSION_KEY, "");
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/1946654b/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariLdapDataPopulator.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariLdapDataPopulator.java
b/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariLdapDataPopulator.java
index b5f9341..a160716 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariLdapDataPopulator.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariLdapDataPopulator.java
@@ -84,12 +84,15 @@ public class AmbariLdapDataPopulator {
    * @return true if enabled
    */
   public boolean isLdapEnabled() {
+    if (!configuration.isLdapConfigured()) {
+      return false;
+    }
     try {
       final LdapTemplate ldapTemplate = loadLdapTemplate();
       ldapTemplate.list(ldapServerProperties.getBaseDN());
       return true;
     } catch (Exception ex) {
-      LOG.error("Could not connect to LDAP server", ex);
+      LOG.error("Could not connect to LDAP server - " + ex.getMessage());
       return false;
     }
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/1946654b/ambari-server/src/main/python/ambari-server.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari-server.py b/ambari-server/src/main/python/ambari-server.py
index 661c937..81b79d1 100755
--- a/ambari-server/src/main/python/ambari-server.py
+++ b/ambari-server/src/main/python/ambari-server.py
@@ -215,6 +215,7 @@ NAGIOS_HTTPS = 'nagios.https'
 JDBC_RCA_PASSWORD_ALIAS = "ambari.db.password"
 CLIENT_SECURITY_KEY = "client.security"
 
+IS_LDAP_CONFIGURED = "ambari.ldap.isConfigured"
 LDAP_MGR_PASSWORD_ALIAS = "ambari.ldap.manager.password"
 LDAP_MGR_PASSWORD_PROPERTY = "authentication.ldap.managerPassword"
 LDAP_MGR_USERNAME_PROPERTY = "authentication.ldap.managerDn"
@@ -3064,6 +3065,7 @@ def setup_ldap():
     pass
 
     # Persisting values
+    ldap_property_value_map[IS_LDAP_CONFIGURED] = "true"
     update_properties(properties, ldap_property_value_map)
     print 'Saving...done'
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/1946654b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapDataPopulatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapDataPopulatorTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapDataPopulatorTest.java
index 868df06..23f53cf 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapDataPopulatorTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapDataPopulatorTest.java
@@ -123,17 +123,18 @@ public class AmbariLdapDataPopulatorTest {
   }
 
   @Test
-  public void testIsLdapEnabled() {
+  public void testIsLdapEnabled_badConfiguration() {
     final Configuration configuration = EasyMock.createNiceMock(Configuration.class);
     final Users users = EasyMock.createNiceMock(Users.class);
 
     final AmbariLdapDataPopulator populator = new AmbariLdapDataPopulatorTestInstance(configuration,
users);
 
-    EasyMock.expect(populator.loadLdapTemplate().list(EasyMock. <String>anyObject())).andReturn(Collections.emptyList()).once();
-    EasyMock.replay(populator.loadLdapTemplate());
+    EasyMock.expect(configuration.isLdapConfigured()).andReturn(true);
+    EasyMock.expect(populator.loadLdapTemplate().list(EasyMock. <String>anyObject())).andThrow(new
NullPointerException()).once();
+    EasyMock.replay(populator.loadLdapTemplate(), configuration);
 
-    populator.isLdapEnabled();
-    EasyMock.verify(populator.loadLdapTemplate());
+    Assert.assertFalse(populator.isLdapEnabled());
+    EasyMock.verify(populator.loadLdapTemplate(), configuration);
   }
 
   @Test
@@ -143,11 +144,12 @@ public class AmbariLdapDataPopulatorTest {
 
     final AmbariLdapDataPopulator populator = new AmbariLdapDataPopulatorTestInstance(configuration,
users);
 
+    EasyMock.expect(configuration.isLdapConfigured()).andReturn(true);
     EasyMock.expect(populator.loadLdapTemplate().list(EasyMock. <String>anyObject())).andReturn(Collections.emptyList()).once();
-    EasyMock.replay(populator.loadLdapTemplate());
+    EasyMock.replay(populator.loadLdapTemplate(),configuration);
 
     Assert.assertTrue(populator.isLdapEnabled());
-    EasyMock.verify(populator.loadLdapTemplate());
+    EasyMock.verify(populator.loadLdapTemplate(), configuration);
   }
 
   @Test
@@ -157,11 +159,11 @@ public class AmbariLdapDataPopulatorTest {
 
     final AmbariLdapDataPopulator populator = new AmbariLdapDataPopulatorTestInstance(configuration,
users);
 
-    EasyMock.expect(populator.loadLdapTemplate().list(EasyMock. <String>anyObject())).andThrow(new
NullPointerException()).once();
-    EasyMock.replay(populator.loadLdapTemplate());
+    EasyMock.expect(configuration.isLdapConfigured()).andReturn(false);
+    EasyMock.replay(populator.loadLdapTemplate(), configuration);
 
     Assert.assertFalse(populator.isLdapEnabled());
-    EasyMock.verify(populator.loadLdapTemplate());
+    EasyMock.verify(populator.loadLdapTemplate(), configuration);
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/ambari/blob/1946654b/ambari-server/src/test/python/TestAmbariServer.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestAmbariServer.py b/ambari-server/src/test/python/TestAmbariServer.py
index 2ad6661..53f0ba1 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -4521,7 +4521,8 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
         "authentication.ldap.groupMembershipAttr": "member",
         "authentication.ldap.baseDn": "base",
         "authentication.ldap.bindAnonymously": "true",
-        "client.security": "ldap"
+        "client.security": "ldap",
+        "ambari.ldap.isConfigured": "true"
       }
 
     sorted_x = sorted(ldap_properties_map.iteritems(), key=operator.itemgetter(0))
@@ -4547,7 +4548,8 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
         "authentication.ldap.groupMembershipAttr": "member",
         "authentication.ldap.baseDn": "base",
         "authentication.ldap.bindAnonymously": "true",
-        "client.security": "ldap"
+        "client.security": "ldap",
+        "ambari.ldap.isConfigured": "true"
       }
 
     sorted_x = sorted(ldap_properties_map.iteritems(), key=operator.itemgetter(0))
@@ -4644,7 +4646,8 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
         "authentication.ldap.groupNamingAttr": "test",
         "client.security": "ldap", \
         ambari_server.LDAP_MGR_PASSWORD_PROPERTY: ambari_server.get_alias_string( \
-          ambari_server.LDAP_MGR_PASSWORD_ALIAS)
+          ambari_server.LDAP_MGR_PASSWORD_ALIAS),
+        "ambari.ldap.isConfigured": "true"
       }
 
     sorted_x = sorted(ldap_properties_map.iteritems(), key=operator.itemgetter(0))


Mime
View raw message