You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by lp...@apache.org on 2017/10/19 12:44:35 UTC

[01/46] ambari git commit: AMBARI-22255. Make the install modal full screen (alexantonenko) [Forced Update!]

Repository: ambari
Updated Branches:
  refs/heads/feature-branch-AMBARI-21307 4c5e25101 -> d3120b009 (forced update)


AMBARI-22255. Make the install modal full screen (alexantonenko)


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 448d6a8b235583a20206b790bee8170de32f27b7
Parents: ce29f8c
Author: Alex Antonenko <aa...@hortonworks.com>
Authored: Tue Oct 17 20:26:49 2017 +0300
Committer: Alex Antonenko <aa...@hortonworks.com>
Committed: Tue Oct 17 20:26:49 2017 +0300

----------------------------------------------------------------------
 ambari-web/app/messages.js             |  1 +
 ambari-web/app/routes/installer.js     |  3 +--
 ambari-web/app/routes/main.js          |  1 +
 ambari-web/app/styles/application.less |  3 +--
 ambari-web/app/styles/common.less      |  2 +-
 ambari-web/app/styles/wizard.less      | 24 +++++++++++++++++++++++-
 ambari-web/app/templates/installer.hbs |  2 +-
 7 files changed, 29 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/448d6a8b/ambari-web/app/messages.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js
index 3c4f038..0123356 100644
--- a/ambari-web/app/messages.js
+++ b/ambari-web/app/messages.js
@@ -21,6 +21,7 @@ Em.I18n.translations = {
   'app.name':'Ambari',
   'app.name.subtitle':'Ambari - {0}',
   'app.name.subtitle.experimental':'Ambari Experimental',
+  'app.name.subtitle.installer':'Cluster Install Wizard',
   'app.reloadPopup.link': 'Reload Page',
   'app.reloadPopup.text': 'Trying to connect to server...',
   'app.reloadPopup.noClusterName.text': 'Failed to retrieve cluster name, trying to reload...',

http://git-wip-us.apache.org/repos/asf/ambari/blob/448d6a8b/ambari-web/app/routes/installer.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/routes/installer.js b/ambari-web/app/routes/installer.js
index ec8f1b9..f1f6659 100644
--- a/ambari-web/app/routes/installer.js
+++ b/ambari-web/app/routes/installer.js
@@ -35,8 +35,7 @@ module.exports = Em.Route.extend(App.RouterRedirections, {
           // check server/web client versions match
           App.router.get('installerController').checkServerClientVersion().done(function () {
 
-            var name = 'Cluster Install Wizard';
-            $('title').text('Ambari - ' + name);
+            $('title').text(Em.I18n.t('app.name.subtitle').format(Em.I18n.t('app.name.subtitle.installer')));
             $('#main').addClass('install-wizard-content');
 
             App.router.get('mainViewsController').loadAmbariViews();

http://git-wip-us.apache.org/repos/asf/ambari/blob/448d6a8b/ambari-web/app/routes/main.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/routes/main.js b/ambari-web/app/routes/main.js
index 7ed18de..d1f9012 100644
--- a/ambari-web/app/routes/main.js
+++ b/ambari-web/app/routes/main.js
@@ -40,6 +40,7 @@ module.exports = Em.Route.extend(App.RouterRedirections, {
           clusterController.loadAmbariProperties().complete(function () {
             App.router.get('mainViewsController').loadAmbariViews();
             clusterController.loadClusterName(false).done(function () {
+              $('#main').removeClass('install-wizard-content');
               if (App.get('testMode')) {
                 router.get('mainController').initialize();
               } else {

http://git-wip-us.apache.org/repos/asf/ambari/blob/448d6a8b/ambari-web/app/styles/application.less
----------------------------------------------------------------------
diff --git a/ambari-web/app/styles/application.less b/ambari-web/app/styles/application.less
index 099f3cf..d40ab8e 100644
--- a/ambari-web/app/styles/application.less
+++ b/ambari-web/app/styles/application.less
@@ -80,7 +80,6 @@ footer {
   color: #666;
   margin-top: -1 * @footer-height - 1;
   height: @footer-height - 60px;
-  margin-left: @side-navigation-width;
 }
 
 .editable-list-container {
@@ -2807,4 +2806,4 @@ a.abort-icon:hover {
 .container-wrap-table {
   padding: 0 10px;
   background-color: @diff-background-equal;
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/448d6a8b/ambari-web/app/styles/common.less
----------------------------------------------------------------------
diff --git a/ambari-web/app/styles/common.less b/ambari-web/app/styles/common.less
index 7753a59..7202342 100644
--- a/ambari-web/app/styles/common.less
+++ b/ambari-web/app/styles/common.less
@@ -186,7 +186,7 @@
 }
 
 @footer-height: 100px;
-@side-navigation-width: 190px;
+@side-navigation-width: 230px;
 
 @default-font-size: 14px;
 @smaller-font-size: 12px;

http://git-wip-us.apache.org/repos/asf/ambari/blob/448d6a8b/ambari-web/app/styles/wizard.less
----------------------------------------------------------------------
diff --git a/ambari-web/app/styles/wizard.less b/ambari-web/app/styles/wizard.less
index 5f60378..cb9eb92 100644
--- a/ambari-web/app/styles/wizard.less
+++ b/ambari-web/app/styles/wizard.less
@@ -659,6 +659,28 @@
   }
 }
 
+.install-wizard-content {
+  #top-nav .navbar.navbar-static-top {
+    margin-bottom: 0;
+  }
+  .navbar-static-top > .main-container,
+  >.main-container {
+    width: 100%;
+  }
+  >.main-container {
+    padding: 0;
+    .wizard {
+      border: none;
+      .wizard-nav {
+        width: 250px;
+      }
+      .wizard-content.col-md-9 {
+        width: calc(~"100% - 250px");
+      }
+    }
+  }
+}
+
 @media all and (max-width: 2560px) {
    .wizard-content {
     #serviceConfig {
@@ -675,4 +697,4 @@
       }
     }
   }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/448d6a8b/ambari-web/app/templates/installer.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/installer.hbs b/ambari-web/app/templates/installer.hbs
index f63664a..73ecff4 100644
--- a/ambari-web/app/templates/installer.hbs
+++ b/ambari-web/app/templates/installer.hbs
@@ -23,7 +23,7 @@
 {{else}}
   <div class="wizard">
     <div class="wizard-body row">
-      <div class="wizard-nav col-md-3">
+      <div class="wizard-nav">
         <ul class="nav nav-pills nav-stacked" {{QAAttr "wizard-nav"}}>
           <li {{QAAttr "wizard-nav-step"}} {{bindAttr class="isStep0:active view.isStep0Disabled:disabled view.isStep0Completed:completed"}}><a href="javascript:void(null);"  {{action gotoStep0 target="controller"}}><i class="step-marker"><span class="step-index">0</span></i><p class="step-name">{{t installer.step0.header}}</p></a></li>
           <li {{QAAttr "wizard-nav-step"}} {{bindAttr class="isStep1:active view.isStep1Disabled:disabled view.isStep1Completed:completed"}}><a href="javascript:void(null);"  {{action gotoStep1 target="controller"}}><i class="step-marker"><span class="step-index">1</span></i><p class="step-name">{{t installer.step1.header}}</p></a></li>


[13/46] ambari git commit: AMBARI-22268. Remove "Hotfix" from Admin Register Version. (Ishan Bhatt via yusaku)

Posted by lp...@apache.org.
AMBARI-22268. Remove "Hotfix" from Admin Register Version. (Ishan Bhatt via yusaku)


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 2ae81d99a55756bd5240a90d550d34ec2ff73927
Parents: 8852f33
Author: Yusaku Sako <yu...@hortonworks.com>
Authored: Wed Oct 18 15:12:07 2017 -0700
Committer: Yusaku Sako <yu...@hortonworks.com>
Committed: Wed Oct 18 15:12:07 2017 -0700

----------------------------------------------------------------------
 .../src/main/resources/ui/admin-web/app/scripts/i18n.config.js     | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/2ae81d99/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js
index 1711543..183a276 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js
@@ -344,7 +344,7 @@ angular.module('ambariAdminConsole')
     'users.alerts.usersEffectivePrivilege': '{{user_name}}\'s effective privilege through its Group(s) is higher than your selected privilege.',
 
     'versions.current': 'Current',
-    'versions.addVersion': 'Add Version or Hotfix',
+    'versions.addVersion': 'Add Version',
     'versions.defaultVersion': '(Default Version Definition)',
     'versions.inUse': 'In Use',
     'versions.installed': 'Installed',


[26/46] ambari git commit: AMBARI-21307 refactoring - renamed, moved classes, variables

Posted by lp...@apache.org.
AMBARI-21307 refactoring - renamed, moved classes, variables


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 3c0b27b3c1783a5b78b241472429d6caf54bffc2
Parents: 2e8d7b1
Author: lpuskas <lp...@apache.org>
Authored: Tue Aug 22 10:03:24 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:41:58 2017 +0200

----------------------------------------------------------------------
 .../api/services/ldap/AmbariConfiguration.java  |  87 +++++++
 .../services/ldap/AmbariConfigurationDTO.java   |  67 -----
 .../ldap/LdapCheckConfigurationRequest.java     |  47 ----
 .../api/services/ldap/LdapConfigOperation.java  |  43 ++++
 .../services/ldap/LdapConfigurationRequest.java |  49 ++++
 .../services/ldap/LdapConfigurationService.java |  53 +---
 .../api/services/ldap/LdapOperationRequest.java |  18 --
 .../server/ldap/LdapConfigurationService.java   |  60 +++++
 .../ldap/LdapConfigurationValidatorService.java |  60 -----
 .../apache/ambari/server/ldap/LdapModule.java   |   4 +-
 .../server/ldap/service/AmbariLdapFacade.java   |  10 +-
 .../ads/DefaultLdapConfigurationService.java    | 243 +++++++++++++++++++
 ...efaultLdapConfigurationValidatorService.java | 243 -------------------
 .../api/services/ldap/LDAPServiceTest.java      |   6 +-
 .../DefaultLdapConfigurationServiceTest.java    | 113 +++++++++
 ...ltLdapConfigurationValidatorServiceTest.java | 113 ---------
 16 files changed, 618 insertions(+), 598 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/3c0b27b3/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/AmbariConfiguration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/AmbariConfiguration.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/AmbariConfiguration.java
new file mode 100644
index 0000000..b5cc921
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/AmbariConfiguration.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.api.services.ldap;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Domain POJO representing generic ambari configuration data.
+ */
+public class AmbariConfiguration {
+
+  /**
+   * The type of the configuration,  eg.: ldap-configuration
+   */
+  private String type;
+
+  /**
+   * Version tag
+   */
+  private String versionTag;
+
+  /**
+   * Version number
+   */
+  private Integer version;
+
+  /**
+   * Created timestamp
+   */
+  private long createdTs;
+
+  private Set<Map<String, Object>> data = Collections.emptySet();
+
+  public String getType() {
+    return type;
+  }
+
+  public void setType(String type) {
+    this.type = type;
+  }
+
+  public Set<Map<String, Object>> getData() {
+    return data;
+  }
+
+  public void setData(Set<Map<String, Object>> data) {
+    this.data = data;
+  }
+
+  public String getVersionTag() {
+    return versionTag;
+  }
+
+  public void setVersionTag(String versionTag) {
+    this.versionTag = versionTag;
+  }
+
+  public Integer getVersion() {
+    return version;
+  }
+
+  public void setVersion(Integer version) {
+    this.version = version;
+  }
+
+  public long getCreatedTs() {
+    return createdTs;
+  }
+
+  public void setCreatedTs(long createdTs) {
+    this.createdTs = createdTs;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3c0b27b3/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/AmbariConfigurationDTO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/AmbariConfigurationDTO.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/AmbariConfigurationDTO.java
deleted file mode 100644
index 1b134fe..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/AmbariConfigurationDTO.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.api.services.ldap;
-
-import java.util.Collections;
-import java.util.Map;
-import java.util.Set;
-
-public class AmbariConfigurationDTO {
-  private String type;
-  private Set<Map<String, Object>> data = Collections.emptySet();
-  private String versionTag;
-  private Integer version;
-  private long createdTs;
-
-  public String getType() {
-    return type;
-  }
-
-  public void setType(String type) {
-    this.type = type;
-  }
-
-  public Set<Map<String, Object>> getData() {
-    return data;
-  }
-
-  public void setData(Set<Map<String, Object>> data) {
-    this.data = data;
-  }
-
-  public String getVersionTag() {
-    return versionTag;
-  }
-
-  public void setVersionTag(String versionTag) {
-    this.versionTag = versionTag;
-  }
-
-  public Integer getVersion() {
-    return version;
-  }
-
-  public void setVersion(Integer version) {
-    this.version = version;
-  }
-
-  public long getCreatedTs() {
-    return createdTs;
-  }
-
-  public void setCreatedTs(long createdTs) {
-    this.createdTs = createdTs;
-  }
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3c0b27b3/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapCheckConfigurationRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapCheckConfigurationRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapCheckConfigurationRequest.java
deleted file mode 100644
index 188f1b9..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapCheckConfigurationRequest.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.api.services.ldap;
-
-
-import com.google.gson.annotations.SerializedName;
-
-public class LdapCheckConfigurationRequest implements LdapOperationRequest {
-
-  @SerializedName("AmbariConfiguration")
-  private AmbariConfigurationDTO ambariConfiguration;
-
-  @SerializedName("RequestInfo")
-  private LdapRequestInfo requestInfo;
-
-  public LdapCheckConfigurationRequest() {
-  }
-
-
-  public AmbariConfigurationDTO getAmbariConfiguration() {
-    return ambariConfiguration;
-  }
-
-  public void setAmbariConfiguration(AmbariConfigurationDTO ambariConfiguration) {
-    this.ambariConfiguration = ambariConfiguration;
-  }
-
-  public LdapRequestInfo getRequestInfo() {
-    return requestInfo;
-  }
-
-  public void setRequestInfo(LdapRequestInfo requestInfo) {
-    this.requestInfo = requestInfo;
-  }
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3c0b27b3/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigOperation.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigOperation.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigOperation.java
new file mode 100644
index 0000000..478d4ff
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigOperation.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.api.services.ldap;
+
+/**
+ * Enumeration for supported operations related to LDAP configuration.
+ */
+public enum LdapConfigOperation {
+  TEST_CONNECTION("test-connection"),
+  TEST_ATTRIBUTES("test-attributes"),
+  DETECT_ATTRIBUTES("detect-attributes");
+
+  private String actionStr;
+
+  LdapConfigOperation(String actionStr) {
+    this.actionStr = actionStr;
+  }
+
+  public static LdapConfigOperation fromAction(String action) {
+    for (LdapConfigOperation val : LdapConfigOperation.values()) {
+      if (val.action().equals(action)) {
+        return val;
+      }
+    }
+    throw new IllegalStateException("Action [ " + action + " ] is not supported");
+  }
+
+  public String action() {
+    return this.actionStr;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3c0b27b3/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationRequest.java
new file mode 100644
index 0000000..2e478c4
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationRequest.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.api.services.ldap;
+
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * Request object wrapping information for LDAP configuration related request calls.
+ */
+public class LdapConfigurationRequest {
+
+  @SerializedName("AmbariConfiguration")
+  private AmbariConfiguration ambariConfiguration;
+
+  @SerializedName("RequestInfo")
+  private LdapRequestInfo requestInfo;
+
+  public LdapConfigurationRequest() {
+  }
+
+  public AmbariConfiguration getAmbariConfiguration() {
+    return ambariConfiguration;
+  }
+
+  public void setAmbariConfiguration(AmbariConfiguration ambariConfiguration) {
+    this.ambariConfiguration = ambariConfiguration;
+  }
+
+  public LdapRequestInfo getRequestInfo() {
+    return requestInfo;
+  }
+
+  public void setRequestInfo(LdapRequestInfo requestInfo) {
+    this.requestInfo = requestInfo;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3c0b27b3/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
index 52244bc..fc6bd41 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
@@ -74,40 +74,13 @@ public class LdapConfigurationService extends AmbariConfigurationService {
   @Inject
   private static LdapConfigurationFactory ldapConfigurationFactory;
 
-  /**
-   * Actions supported by this endpoint
-   */
-  private enum LdapAction {
-    TEST_CONNECTION("test-connection"),
-    TEST_ATTRIBUTES("test-attributes"),
-    DETECT_ATTRIBUTES("detect-attributes");
-
-    private String actionStr;
-
-    LdapAction(String actionStr) {
-      this.actionStr = actionStr;
-    }
-
-    public static LdapAction fromAction(String action) {
-      for (LdapAction val : LdapAction.values()) {
-        if (val.action().equals(action)) {
-          return val;
-        }
-      }
-      throw new IllegalStateException("Action [ " + action + " ] is not supported");
-    }
-
-    public String action() {
-      return this.actionStr;
-    }
-  }
 
   @POST
   @ApiIgnore // until documented
   @Path("/validate")
   @Consumes(MediaType.APPLICATION_JSON)
   @Produces(MediaType.APPLICATION_JSON)
-  public Response validateConfiguration(LdapCheckConfigurationRequest ldapCheckConfigurationRequest) {
+  public Response validateConfiguration(LdapConfigurationRequest ldapConfigurationRequest) {
 
     authorize();
 
@@ -116,12 +89,12 @@ public class LdapConfigurationService extends AmbariConfigurationService {
     Result result = new ResultImpl(new ResultStatus(ResultStatus.STATUS.OK));
     try {
 
-      validateRequest(ldapCheckConfigurationRequest);
+      validateRequest(ldapConfigurationRequest);
 
       AmbariLdapConfiguration ambariLdapConfiguration = ldapConfigurationFactory.createLdapConfiguration(
-        ldapCheckConfigurationRequest.getAmbariConfiguration().getData().iterator().next());
+        ldapConfigurationRequest.getAmbariConfiguration().getData().iterator().next());
 
-      LdapAction action = LdapAction.fromAction(ldapCheckConfigurationRequest.getRequestInfo().getAction());
+      LdapConfigOperation action = LdapConfigOperation.fromAction(ldapConfigurationRequest.getRequestInfo().getAction());
       switch (action) {
 
         case TEST_CONNECTION:
@@ -133,7 +106,7 @@ public class LdapConfigurationService extends AmbariConfigurationService {
         case TEST_ATTRIBUTES:
 
           LOGGER.info("Testing LDAP attributes ....");
-          groups = ldapFacade.checkLdapAttibutes(ldapCheckConfigurationRequest.getRequestInfo().getParameters(), ambariLdapConfiguration);
+          groups = ldapFacade.checkLdapAttibutes(ldapConfigurationRequest.getRequestInfo().getParameters(), ambariLdapConfiguration);
           setResult(groups, result);
 
           break;
@@ -161,24 +134,24 @@ public class LdapConfigurationService extends AmbariConfigurationService {
     result.getResultTree().addChild(resource, "payload");
   }
 
-  private void validateRequest(LdapCheckConfigurationRequest ldapCheckConfigurationRequest) {
+  private void validateRequest(LdapConfigurationRequest ldapConfigurationRequest) {
     String errMsg;
 
-    if (null == ldapCheckConfigurationRequest) {
+    if (null == ldapConfigurationRequest) {
       errMsg = "No ldap configuraiton request provided";
       LOGGER.error(errMsg);
       throw new IllegalArgumentException(errMsg);
     }
 
-    if (null == ldapCheckConfigurationRequest.getRequestInfo()) {
-      errMsg = String.format("No request information provided. Request: [%s]", ldapCheckConfigurationRequest);
+    if (null == ldapConfigurationRequest.getRequestInfo()) {
+      errMsg = String.format("No request information provided. Request: [%s]", ldapConfigurationRequest);
       LOGGER.error(errMsg);
       throw new IllegalArgumentException(errMsg);
     }
 
-    if (null == ldapCheckConfigurationRequest.getAmbariConfiguration()
-      || ldapCheckConfigurationRequest.getAmbariConfiguration().getData().size() != 1) {
-      errMsg = String.format("No / Invalid configuration data provided. Request: [%s]", ldapCheckConfigurationRequest);
+    if (null == ldapConfigurationRequest.getAmbariConfiguration()
+      || ldapConfigurationRequest.getAmbariConfiguration().getData().size() != 1) {
+      errMsg = String.format("No / Invalid configuration data provided. Request: [%s]", ldapConfigurationRequest);
       LOGGER.error(errMsg);
       throw new IllegalArgumentException(errMsg);
     }
@@ -202,7 +175,7 @@ public class LdapConfigurationService extends AmbariConfigurationService {
 
   }
 
-  Set<RoleAuthorization> requiredAuthorizations() {
+  private Set<RoleAuthorization> requiredAuthorizations() {
     return Sets.newHashSet(RoleAuthorization.AMBARI_MANAGE_CONFIGURATION);
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/3c0b27b3/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapOperationRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapOperationRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapOperationRequest.java
deleted file mode 100644
index 06f6c40..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapOperationRequest.java
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.api.services.ldap;
-
-public interface LdapOperationRequest {
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3c0b27b3/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationService.java
new file mode 100644
index 0000000..69a641f
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationService.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap;
+
+import java.util.Set;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.ldap.service.AmbariLdapException;
+import org.apache.directory.ldap.client.api.LdapConnection;
+
+/**
+ * Collection of operations for validating ldap configuration.
+ * It's intended to decouple implementations using different libraries.
+ */
+public interface LdapConfigurationService {
+
+  /**
+   * Tests the connection based on the provided configuration.
+   *
+   * @param ldapConnection connection instance
+   * @param configuration  the ambari ldap configuration instance
+   * @throws AmbariLdapException if the connection is not possible
+   */
+  void checkConnection(LdapConnection ldapConnection, AmbariLdapConfiguration configuration) throws AmbariLdapException;
+
+
+  /**
+   * Implements LDAP user related configuration settings validation logic.
+   * Implementers communicate with the LDAP server (search, bind) to validate attributes in the provided configuration
+   * instance
+   *
+   * @param ldapConnection connection instance used to connect to the LDAP server
+   * @param testUserName   the test username
+   * @param testPassword   the test password
+   * @param configuration  the available ldap configuration
+   * @return The DN of the found user entry
+   * @throws AmbariException if the connection couldn't be estabilisheds
+   */
+  String checkUserAttributes(LdapConnection ldapConnection, String testUserName, String testPassword, AmbariLdapConfiguration configuration) throws AmbariLdapException;
+
+  /**
+   * Checks whether the group related LDAP attributes in the configuration are correct.
+   *
+   * @throws AmbariException if the attributes are not valid
+   */
+  Set<String> checkGroupAttributes(LdapConnection ldapConnection, String userDn, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException;
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3c0b27b3/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationValidatorService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationValidatorService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationValidatorService.java
deleted file mode 100644
index 7efa3b7..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationValidatorService.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap;
-
-import java.util.Set;
-
-import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.ldap.service.AmbariLdapException;
-import org.apache.directory.ldap.client.api.LdapConnection;
-
-/**
- * Collection of operations for validating ldap configuration.
- * It's intended to decouple implementations using different libraries.
- */
-public interface LdapConfigurationValidatorService {
-
-  /**
-   * Tests the connection based on the provided configuration.
-   *
-   * @param ldapConnection connection instance
-   * @param configuration  the ambari ldap configuration instance
-   * @throws AmbariLdapException if the connection is not possible
-   */
-  void checkConnection(LdapConnection ldapConnection, AmbariLdapConfiguration configuration) throws AmbariLdapException;
-
-
-  /**
-   * Implements LDAP user related configuration settings validation logic.
-   * Implementers communicate with the LDAP server (search, bind) to validate attributes in the provided configuration
-   * instance
-   *
-   * @param ldapConnection connection instance used to connect to the LDAP server
-   * @param testUserName   the test username
-   * @param testPassword   the test password
-   * @param configuration  the available ldap configuration
-   * @return The DN of the found user entry
-   * @throws AmbariException if the connection couldn't be estabilisheds
-   */
-  String checkUserAttributes(LdapConnection ldapConnection, String testUserName, String testPassword, AmbariLdapConfiguration configuration) throws AmbariLdapException;
-
-  /**
-   * Checks whether the group related LDAP attributes in the configuration are correct.
-   *
-   * @throws AmbariException if the attributes are not valid
-   */
-  Set<String> checkGroupAttributes(LdapConnection ldapConnection, String userDn, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException;
-
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3c0b27b3/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
index a4ad2ee..3ae4587 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
@@ -18,7 +18,7 @@ package org.apache.ambari.server.ldap;
 import org.apache.ambari.server.ldap.service.AmbariLdapFacade;
 import org.apache.ambari.server.ldap.service.LdapConnectionService;
 import org.apache.ambari.server.ldap.service.LdapFacade;
-import org.apache.ambari.server.ldap.service.ads.DefaultLdapConfigurationValidatorService;
+import org.apache.ambari.server.ldap.service.ads.DefaultLdapConfigurationService;
 import org.apache.ambari.server.ldap.service.ads.DefaultLdapConnectionService;
 
 import com.google.inject.AbstractModule;
@@ -32,7 +32,7 @@ public class LdapModule extends AbstractModule {
   @Override
   protected void configure() {
     bind(LdapFacade.class).to(AmbariLdapFacade.class);
-    bind(LdapConfigurationValidatorService.class).to(DefaultLdapConfigurationValidatorService.class);
+    bind(LdapConfigurationService.class).to(DefaultLdapConfigurationService.class);
     bind(LdapConnectionService.class).to(DefaultLdapConnectionService.class);
 
     install(new FactoryModuleBuilder().build(LdapConfigurationFactory.class));

http://git-wip-us.apache.org/repos/asf/ambari/blob/3c0b27b3/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
index eec47ce..683ed43 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
@@ -22,7 +22,7 @@ import javax.inject.Inject;
 import javax.inject.Singleton;
 
 import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.LdapConfigurationValidatorService;
+import org.apache.ambari.server.ldap.LdapConfigurationService;
 import org.apache.directory.ldap.client.api.LdapConnection;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -49,7 +49,7 @@ public class AmbariLdapFacade implements LdapFacade {
   }
 
   @Inject
-  private LdapConfigurationValidatorService ldapConfigurationValidatorService;
+  private LdapConfigurationService ldapConfigurationService;
 
   @Inject
   private LdapConnectionService ldapConnectionService;
@@ -63,7 +63,7 @@ public class AmbariLdapFacade implements LdapFacade {
     try {
       LOGGER.info("Validating LDAP connection related configuration based on: {}", ambariLdapConfiguration);
       LdapConnection connection = ldapConnectionService.createLdapConnection(ambariLdapConfiguration);
-      ldapConfigurationValidatorService.checkConnection(connection, ambariLdapConfiguration);
+      ldapConfigurationService.checkConnection(connection, ambariLdapConfiguration);
     } catch (AmbariLdapException e) {
       LOGGER.error("Validating LDAP connection configuration failed", e);
       throw e;
@@ -90,10 +90,10 @@ public class AmbariLdapFacade implements LdapFacade {
     LdapConnection ldapConnection = ldapConnectionService.createLdapConnection(ldapConfiguration);
 
     LOGGER.info("Testing LDAP user attributes with test user: {}", userName);
-    String userDn = ldapConfigurationValidatorService.checkUserAttributes(ldapConnection, userName, testUserPass, ldapConfiguration);
+    String userDn = ldapConfigurationService.checkUserAttributes(ldapConnection, userName, testUserPass, ldapConfiguration);
 
     LOGGER.info("Testing LDAP group attributes with test user dn: {}", userDn);
-    Set<String> groups = ldapConfigurationValidatorService.checkGroupAttributes(ldapConnection, userDn, ldapConfiguration);
+    Set<String> groups = ldapConfigurationService.checkGroupAttributes(ldapConnection, userDn, ldapConfiguration);
 
     return groups;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/3c0b27b3/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
new file mode 100644
index 0000000..abc9201
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
@@ -0,0 +1,243 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Set;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.LdapConfigurationService;
+import org.apache.ambari.server.ldap.service.AmbariLdapException;
+import org.apache.ambari.server.ldap.service.LdapConnectionService;
+import org.apache.directory.api.ldap.codec.decorators.SearchResultEntryDecorator;
+import org.apache.directory.api.ldap.model.constants.SchemaConstants;
+import org.apache.directory.api.ldap.model.cursor.EntryCursor;
+import org.apache.directory.api.ldap.model.cursor.SearchCursor;
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.message.Response;
+import org.apache.directory.api.ldap.model.message.SearchRequest;
+import org.apache.directory.api.ldap.model.message.SearchRequestImpl;
+import org.apache.directory.api.ldap.model.message.SearchScope;
+import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.search.FilterBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+
+/**
+ * Implementation of the validation logic using the Apache Directory API.
+ */
+@Singleton
+public class DefaultLdapConfigurationService implements LdapConfigurationService {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapConfigurationService.class);
+
+  @Inject
+  private LdapConnectionService ldapConnectionService;
+
+  /**
+   * Facilitating the instantiation
+   */
+  @Inject
+  public DefaultLdapConfigurationService() {
+  }
+
+  @Override
+  public void checkConnection(LdapConnection ldapConnection, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+    try {
+      bind(ambariLdapConfiguration, ldapConnection);
+    } catch (LdapException e) {
+      LOGGER.error("Could not connect to the LDAP server", e);
+      throw new AmbariLdapException(e);
+    }
+  }
+
+
+  /**
+   * Checks the user attributes provided in the configuration instance by issuing a search for a (known) test user in the LDAP.
+   * Attributes are considered correct if there is at least one entry found.
+   *
+   * Invalid attributes are signaled by throwing an exception.
+   *
+   * @param testUserName            the test username
+   * @param testPassword            the test password
+   * @param ambariLdapConfiguration configuration instance holding ldap configuration details
+   * @return the DN of the test user
+   * @throws AmbariException if the attributes are not valid or any errors occurs
+   */
+  @Override
+  public String checkUserAttributes(LdapConnection ldapConnection, String testUserName, String testPassword, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+    SearchCursor searchCursor = null;
+    String userDn = null;
+    try {
+      LOGGER.info("Checking user attributes for user {} r ...", testUserName);
+
+      // bind anonimously or with manager data
+      bind(ambariLdapConfiguration, ldapConnection);
+
+      // set up a filter based on the provided attributes
+      String filter = FilterBuilder.and(
+        FilterBuilder.equal(SchemaConstants.OBJECT_CLASS_AT, ambariLdapConfiguration.userObjectClass()),
+        FilterBuilder.equal(ambariLdapConfiguration.userNameAttribute(), testUserName))
+        .toString();
+
+      LOGGER.info("Searching for the user: {} using the search filter: {}", testUserName, filter);
+      EntryCursor entryCursor = ldapConnection.search(new Dn(ambariLdapConfiguration.userSearchBase()), filter, SearchScope.SUBTREE);
+
+      // collecting search result entries
+      List<Entry> users = Lists.newArrayList();
+      for (Entry entry : entryCursor) {
+        users.add(entry);
+        userDn = entry.getDn().getNormName();
+      }
+
+      // there should be at least one user found
+      if (users.isEmpty()) {
+        String msg = String.format("There are no users found using the filter: [ %s ]. Try changing the attribute values", filter);
+        LOGGER.error(msg);
+        throw new Exception(msg);
+      }
+
+      LOGGER.info("Attibute validation succeeded. Filter: {}", filter);
+
+    } catch (Exception e) {
+
+      LOGGER.error("User attributes validation failed.", e);
+      throw new AmbariLdapException(e.getMessage(), e);
+
+    } finally {
+      closeResources(ldapConnection, searchCursor);
+    }
+    return userDn;
+  }
+
+
+  @Override
+  public Set<String> checkGroupAttributes(LdapConnection ldapConnection, String userDn, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+    SearchCursor searchCursor = null;
+    Set<Response> groupResponses = Sets.newHashSet();
+
+    try {
+      LOGGER.info("Checking group attributes for user dn {} ...", userDn);
+
+      bind(ambariLdapConfiguration, ldapConnection);
+
+      // set up a filter based on the provided attributes
+      String filter = FilterBuilder.and(
+        FilterBuilder.equal(SchemaConstants.OBJECT_CLASS_AT, ambariLdapConfiguration.groupObjectClass()),
+        FilterBuilder.equal(ambariLdapConfiguration.groupMemberAttribute(), userDn)
+      ).toString();
+
+      LOGGER.info("Searching for the groups the user dn: {} is member of using the search filter: {}", userDn, filter);
+
+      // assemble a search request
+      SearchRequest searchRequest = new SearchRequestImpl();
+      searchRequest.setFilter(filter);
+      searchRequest.setBase(new Dn(ambariLdapConfiguration.groupSearchBase()));
+      searchRequest.setScope(SearchScope.SUBTREE);
+      searchRequest.addAttributes(ambariLdapConfiguration.groupMemberAttribute(), ambariLdapConfiguration.groupNameAttribute());
+
+      // perform the search
+      searchCursor = ldapConnection.search(searchRequest);
+
+      for (Response response : searchCursor) {
+        groupResponses.add(response);
+      }
+
+    } catch (Exception e) {
+
+      LOGGER.error("User attributes validation failed.", e);
+      throw new AmbariLdapException(e.getMessage(), e);
+
+    } finally {
+      closeResources(ldapConnection, searchCursor);
+    }
+
+    return processGroupResults(groupResponses, ambariLdapConfiguration);
+  }
+
+  /**
+   * Binds to the LDAP server (anonimously or wit manager credentials)
+   *
+   * @param ambariLdapConfiguration configuration instance
+   * @param connection              connection instance
+   * @throws LdapException if the bind operation fails
+   */
+  private void bind(AmbariLdapConfiguration ambariLdapConfiguration, LdapConnection connection) throws LdapException {
+    LOGGER.info("Connecting to LDAP ....");
+    if (!ambariLdapConfiguration.bindAnonimously()) {
+      LOGGER.debug("Anonimous binding not supported, binding with the manager detailas...");
+      connection.bind(ambariLdapConfiguration.managerDn(), ambariLdapConfiguration.managerPassword());
+    } else {
+      LOGGER.debug("Binding anonimously ...");
+      connection.bind();
+    }
+
+    if (!connection.isConnected()) {
+      LOGGER.error("Not connected to the LDAP server. Connection instance: {}", connection);
+      throw new IllegalStateException("The connection to the LDAP server is not alive");
+    }
+    LOGGER.info("Connected to LDAP.");
+  }
+
+
+  /**
+   * Extracts meaningful values from the search result.
+   *
+   * @param groupResponses          the result entries returned by the search
+   * @param ambariLdapConfiguration holds the keys of the meaningful attributes
+   * @return a set with the group names the test user belongs to
+   */
+  private Set<String> processGroupResults(Set<Response> groupResponses, AmbariLdapConfiguration ambariLdapConfiguration) {
+    Set<String> groupStrSet = Sets.newHashSet();
+    for (Response response : groupResponses) {
+      Entry entry = ((SearchResultEntryDecorator) response).getEntry();
+      groupStrSet.add(entry.get(ambariLdapConfiguration.groupNameAttribute()).get().getString());
+    }
+
+    LOGGER.debug("Extracted group names from group search responses: {}", groupStrSet);
+    return groupStrSet;
+  }
+
+  private void closeResources(LdapConnection connection, SearchCursor searchCursor) {
+    LOGGER.debug("Housekeeping: closing the connection and the search cursor ...");
+
+    if (null != searchCursor) {
+      // this method is idempotent
+      searchCursor.close();
+    }
+
+    if (null != connection) {
+      try {
+        connection.close();
+      } catch (IOException e) {
+        LOGGER.error("Exception occurred while closing the connection", e);
+      }
+    }
+  }
+
+}
+
+
+

http://git-wip-us.apache.org/repos/asf/ambari/blob/3c0b27b3/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationValidatorService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationValidatorService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationValidatorService.java
deleted file mode 100644
index 040983a..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationValidatorService.java
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.service.ads;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.Set;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.LdapConfigurationValidatorService;
-import org.apache.ambari.server.ldap.service.AmbariLdapException;
-import org.apache.ambari.server.ldap.service.LdapConnectionService;
-import org.apache.directory.api.ldap.codec.decorators.SearchResultEntryDecorator;
-import org.apache.directory.api.ldap.model.constants.SchemaConstants;
-import org.apache.directory.api.ldap.model.cursor.EntryCursor;
-import org.apache.directory.api.ldap.model.cursor.SearchCursor;
-import org.apache.directory.api.ldap.model.entry.Entry;
-import org.apache.directory.api.ldap.model.exception.LdapException;
-import org.apache.directory.api.ldap.model.message.Response;
-import org.apache.directory.api.ldap.model.message.SearchRequest;
-import org.apache.directory.api.ldap.model.message.SearchRequestImpl;
-import org.apache.directory.api.ldap.model.message.SearchScope;
-import org.apache.directory.api.ldap.model.name.Dn;
-import org.apache.directory.ldap.client.api.LdapConnection;
-import org.apache.directory.ldap.client.api.search.FilterBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-
-/**
- * Implementation of the validation logic using the Apache Directory API.
- */
-@Singleton
-public class DefaultLdapConfigurationValidatorService implements LdapConfigurationValidatorService {
-
-  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapConfigurationValidatorService.class);
-
-  @Inject
-  private LdapConnectionService ldapConnectionService;
-
-  /**
-   * Facilitating the instantiation
-   */
-  @Inject
-  public DefaultLdapConfigurationValidatorService() {
-  }
-
-  @Override
-  public void checkConnection(LdapConnection ldapConnection, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
-    try {
-      bind(ambariLdapConfiguration, ldapConnection);
-    } catch (LdapException e) {
-      LOGGER.error("Could not connect to the LDAP server", e);
-      throw new AmbariLdapException(e);
-    }
-  }
-
-
-  /**
-   * Checks the user attributes provided in the configuration instance by issuing a search for a (known) test user in the LDAP.
-   * Attributes are considered correct if there is at least one entry found.
-   *
-   * Invalid attributes are signaled by throwing an exception.
-   *
-   * @param testUserName            the test username
-   * @param testPassword            the test password
-   * @param ambariLdapConfiguration configuration instance holding ldap configuration details
-   * @return the DN of the test user
-   * @throws AmbariException if the attributes are not valid or any errors occurs
-   */
-  @Override
-  public String checkUserAttributes(LdapConnection ldapConnection, String testUserName, String testPassword, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
-    SearchCursor searchCursor = null;
-    String userDn = null;
-    try {
-      LOGGER.info("Checking user attributes for user {} r ...", testUserName);
-
-      // bind anonimously or with manager data
-      bind(ambariLdapConfiguration, ldapConnection);
-
-      // set up a filter based on the provided attributes
-      String filter = FilterBuilder.and(
-        FilterBuilder.equal(SchemaConstants.OBJECT_CLASS_AT, ambariLdapConfiguration.userObjectClass()),
-        FilterBuilder.equal(ambariLdapConfiguration.userNameAttribute(), testUserName))
-        .toString();
-
-      LOGGER.info("Searching for the user: {} using the search filter: {}", testUserName, filter);
-      EntryCursor entryCursor = ldapConnection.search(new Dn(ambariLdapConfiguration.userSearchBase()), filter, SearchScope.SUBTREE);
-
-      // collecting search result entries
-      List<Entry> users = Lists.newArrayList();
-      for (Entry entry : entryCursor) {
-        users.add(entry);
-        userDn = entry.getDn().getNormName();
-      }
-
-      // there should be at least one user found
-      if (users.isEmpty()) {
-        String msg = String.format("There are no users found using the filter: [ %s ]. Try changing the attribute values", filter);
-        LOGGER.error(msg);
-        throw new Exception(msg);
-      }
-
-      LOGGER.info("Attibute validation succeeded. Filter: {}", filter);
-
-    } catch (Exception e) {
-
-      LOGGER.error("User attributes validation failed.", e);
-      throw new AmbariLdapException(e.getMessage(), e);
-
-    } finally {
-      closeResources(ldapConnection, searchCursor);
-    }
-    return userDn;
-  }
-
-
-  @Override
-  public Set<String> checkGroupAttributes(LdapConnection ldapConnection, String userDn, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
-    SearchCursor searchCursor = null;
-    Set<Response> groupResponses = Sets.newHashSet();
-
-    try {
-      LOGGER.info("Checking group attributes for user dn {} ...", userDn);
-
-      bind(ambariLdapConfiguration, ldapConnection);
-
-      // set up a filter based on the provided attributes
-      String filter = FilterBuilder.and(
-        FilterBuilder.equal(SchemaConstants.OBJECT_CLASS_AT, ambariLdapConfiguration.groupObjectClass()),
-        FilterBuilder.equal(ambariLdapConfiguration.groupMemberAttribute(), userDn)
-      ).toString();
-
-      LOGGER.info("Searching for the groups the user dn: {} is member of using the search filter: {}", userDn, filter);
-
-      // assemble a search request
-      SearchRequest searchRequest = new SearchRequestImpl();
-      searchRequest.setFilter(filter);
-      searchRequest.setBase(new Dn(ambariLdapConfiguration.groupSearchBase()));
-      searchRequest.setScope(SearchScope.SUBTREE);
-      searchRequest.addAttributes(ambariLdapConfiguration.groupMemberAttribute(), ambariLdapConfiguration.groupNameAttribute());
-
-      // perform the search
-      searchCursor = ldapConnection.search(searchRequest);
-
-      for (Response response : searchCursor) {
-        groupResponses.add(response);
-      }
-
-    } catch (Exception e) {
-
-      LOGGER.error("User attributes validation failed.", e);
-      throw new AmbariLdapException(e.getMessage(), e);
-
-    } finally {
-      closeResources(ldapConnection, searchCursor);
-    }
-
-    return processGroupResults(groupResponses, ambariLdapConfiguration);
-  }
-
-  /**
-   * Binds to the LDAP server (anonimously or wit manager credentials)
-   *
-   * @param ambariLdapConfiguration configuration instance
-   * @param connection              connection instance
-   * @throws LdapException if the bind operation fails
-   */
-  private void bind(AmbariLdapConfiguration ambariLdapConfiguration, LdapConnection connection) throws LdapException {
-    LOGGER.info("Connecting to LDAP ....");
-    if (!ambariLdapConfiguration.bindAnonimously()) {
-      LOGGER.debug("Anonimous binding not supported, binding with the manager detailas...");
-      connection.bind(ambariLdapConfiguration.managerDn(), ambariLdapConfiguration.managerPassword());
-    } else {
-      LOGGER.debug("Binding anonimously ...");
-      connection.bind();
-    }
-
-    if (!connection.isConnected()) {
-      LOGGER.error("Not connected to the LDAP server. Connection instance: {}", connection);
-      throw new IllegalStateException("The connection to the LDAP server is not alive");
-    }
-    LOGGER.info("Connected to LDAP.");
-  }
-
-
-  /**
-   * Extracts meaningful values from the search result.
-   *
-   * @param groupResponses          the result entries returned by the search
-   * @param ambariLdapConfiguration holds the keys of the meaningful attributes
-   * @return a set with the group names the test user belongs to
-   */
-  private Set<String> processGroupResults(Set<Response> groupResponses, AmbariLdapConfiguration ambariLdapConfiguration) {
-    Set<String> groupStrSet = Sets.newHashSet();
-    for (Response response : groupResponses) {
-      Entry entry = ((SearchResultEntryDecorator) response).getEntry();
-      groupStrSet.add(entry.get(ambariLdapConfiguration.groupNameAttribute()).get().getString());
-    }
-
-    LOGGER.debug("Extracted group names from group search responses: {}", groupStrSet);
-    return groupStrSet;
-  }
-
-  private void closeResources(LdapConnection connection, SearchCursor searchCursor) {
-    LOGGER.debug("Housekeeping: closing the connection and the search cursor ...");
-
-    if (null != searchCursor) {
-      // this method is idempotent
-      searchCursor.close();
-    }
-
-    if (null != connection) {
-      try {
-        connection.close();
-      } catch (IOException e) {
-        LOGGER.error("Exception occurred while closing the connection", e);
-      }
-    }
-  }
-
-}
-
-
-

http://git-wip-us.apache.org/repos/asf/ambari/blob/3c0b27b3/ambari-server/src/test/java/org/apache/ambari/server/api/services/ldap/LDAPServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/ldap/LDAPServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/services/ldap/LDAPServiceTest.java
index f20cd1f..5e8eac6 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/services/ldap/LDAPServiceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/services/ldap/LDAPServiceTest.java
@@ -46,11 +46,11 @@ public class LDAPServiceTest {
 
 
     // WHEN
-    LdapCheckConfigurationRequest ldapCheckConfigurationRequest = gsonJsonProvider.fromJson(JSON_STRING, LdapCheckConfigurationRequest.class);
-    // LdapCheckConfigurationRequest ldapCheckConfigurationRequest = objectMapper.readValue(JSON_STRING, LdapCheckConfigurationRequest.class);
+    LdapConfigurationRequest ldapConfigurationRequest = gsonJsonProvider.fromJson(JSON_STRING, LdapConfigurationRequest.class);
+    // LdapConfigurationRequest ldapConfigurationRequest = objectMapper.readValue(JSON_STRING, LdapConfigurationRequest.class);
 
     // THEN
-    Assert.assertNotNull(ldapCheckConfigurationRequest);
+    Assert.assertNotNull(ldapConfigurationRequest);
 
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/3c0b27b3/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
new file mode 100644
index 0000000..2b7448e
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Map;
+
+import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.LdapConfigurationService;
+import org.apache.ambari.server.ldap.service.LdapConnectionService;
+import org.apache.directory.api.ldap.model.constants.SchemaConstants;
+import org.apache.directory.api.ldap.model.cursor.EntryCursor;
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.apache.directory.api.ldap.model.message.SearchScope;
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.LdapConnectionConfig;
+import org.apache.directory.ldap.client.api.LdapNetworkConnection;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Maps;
+
+public class DefaultLdapConfigurationServiceTest {
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapConfigurationService.class);
+  private static final String TEST_USER = "einstein";
+
+  LdapConfigurationService ldapConfigurationService = new DefaultLdapConfigurationService();
+
+
+  @Test
+  public void testCheckAttributes() throws Exception {
+
+    // WHEN
+    LdapConnectionConfig config = new LdapConnectionConfig();
+    config.setLdapHost("localhost");
+    config.setLdapPort(389);
+    LdapConnection connection = new LdapNetworkConnection(config);
+
+    // THEN
+    connection.anonymousBind();
+
+
+    EntryCursor cursor = connection.search("dc=dev,dc=local", "(objectclass=*)", SearchScope.ONELEVEL);
+
+    for (Entry entry : cursor) {
+      assertNotNull(entry);
+      System.out.println(entry);
+    }
+
+    cursor.close();
+
+  }
+
+  @Test
+  public void testCheckUserAttributes() throws Exception {
+    // GIVEN
+    Map<String, Object> ldapPropsMap = Maps.newHashMap();
+
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BIND_ANONIMOUSLY.propertyName(), "true");
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_HOST.propertyName(), "ldap.forumsys.com");
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_PORT.propertyName(), "389");
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BASE_DN.propertyName(), "dc=example,dc=com");
+
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_OBJECT_CLASS.propertyName(), SchemaConstants.PERSON_OC);
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_NAME_ATTRIBUTE.propertyName(), SchemaConstants.UID_AT);
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_SEARCH_BASE.propertyName(), "dc=example,dc=com");
+
+
+    AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(ldapPropsMap);
+    LdapConnectionService connectionService = new DefaultLdapConnectionService();
+    LdapNetworkConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
+
+    ldapConfigurationService.checkUserAttributes(ldapConnection, "einstein", "", ambariLdapConfiguration);
+  }
+
+  @Test
+  public void testRetrieveGorupsForuser() throws Exception {
+    // GIVEN
+    Map<String, Object> ldapPropsMap = Maps.newHashMap();
+
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BIND_ANONIMOUSLY.propertyName(), "true");
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_HOST.propertyName(), "ldap.forumsys.com");
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_PORT.propertyName(), "389");
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BASE_DN.propertyName(), "dc=example,dc=com");
+
+
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_OBJECT_CLASS.propertyName(), SchemaConstants.GROUP_OF_UNIQUE_NAMES_OC);
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_NAME_ATTRIBUTE.propertyName(), SchemaConstants.CN_AT);
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_MEMBER_ATTRIBUTE.propertyName(), SchemaConstants.UNIQUE_MEMBER_AT);
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_SEARCH_BASE.propertyName(), "dc=example,dc=com");
+
+
+    AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(ldapPropsMap);
+    LdapConnectionService connectionService = new DefaultLdapConnectionService();
+    LdapNetworkConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
+
+    ldapConfigurationService.checkGroupAttributes(ldapConnection, "uid=einstein,dc=example,dc=com", ambariLdapConfiguration);
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/3c0b27b3/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationValidatorServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationValidatorServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationValidatorServiceTest.java
deleted file mode 100644
index 1c7f75d..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationValidatorServiceTest.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.service.ads;
-
-import static org.junit.Assert.assertNotNull;
-
-import java.util.Map;
-
-import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.LdapConfigurationValidatorService;
-import org.apache.ambari.server.ldap.service.LdapConnectionService;
-import org.apache.directory.api.ldap.model.constants.SchemaConstants;
-import org.apache.directory.api.ldap.model.cursor.EntryCursor;
-import org.apache.directory.api.ldap.model.entry.Entry;
-import org.apache.directory.api.ldap.model.message.SearchScope;
-import org.apache.directory.ldap.client.api.LdapConnection;
-import org.apache.directory.ldap.client.api.LdapConnectionConfig;
-import org.apache.directory.ldap.client.api.LdapNetworkConnection;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.Maps;
-
-public class DefaultLdapConfigurationValidatorServiceTest {
-  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapConfigurationValidatorService.class);
-  private static final String TEST_USER = "einstein";
-
-  LdapConfigurationValidatorService ldapConfigurationValidatorService = new DefaultLdapConfigurationValidatorService();
-
-
-  @Test
-  public void testCheckAttributes() throws Exception {
-
-    // WHEN
-    LdapConnectionConfig config = new LdapConnectionConfig();
-    config.setLdapHost("localhost");
-    config.setLdapPort(389);
-    LdapConnection connection = new LdapNetworkConnection(config);
-
-    // THEN
-    connection.anonymousBind();
-
-
-    EntryCursor cursor = connection.search("dc=dev,dc=local", "(objectclass=*)", SearchScope.ONELEVEL);
-
-    for (Entry entry : cursor) {
-      assertNotNull(entry);
-      System.out.println(entry);
-    }
-
-    cursor.close();
-
-  }
-
-  @Test
-  public void testCheckUserAttributes() throws Exception {
-    // GIVEN
-    Map<String, Object> ldapPropsMap = Maps.newHashMap();
-
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BIND_ANONIMOUSLY.propertyName(), "true");
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_HOST.propertyName(), "ldap.forumsys.com");
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_PORT.propertyName(), "389");
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BASE_DN.propertyName(), "dc=example,dc=com");
-
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_OBJECT_CLASS.propertyName(), SchemaConstants.PERSON_OC);
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_NAME_ATTRIBUTE.propertyName(), SchemaConstants.UID_AT);
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_SEARCH_BASE.propertyName(), "dc=example,dc=com");
-
-
-    AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(ldapPropsMap);
-    LdapConnectionService connectionService = new DefaultLdapConnectionService();
-    LdapNetworkConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
-
-    ldapConfigurationValidatorService.checkUserAttributes(ldapConnection, "einstein", "", ambariLdapConfiguration);
-  }
-
-  @Test
-  public void testRetrieveGorupsForuser() throws Exception {
-    // GIVEN
-    Map<String, Object> ldapPropsMap = Maps.newHashMap();
-
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BIND_ANONIMOUSLY.propertyName(), "true");
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_HOST.propertyName(), "ldap.forumsys.com");
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_PORT.propertyName(), "389");
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BASE_DN.propertyName(), "dc=example,dc=com");
-
-
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_OBJECT_CLASS.propertyName(), SchemaConstants.GROUP_OF_UNIQUE_NAMES_OC);
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_NAME_ATTRIBUTE.propertyName(), SchemaConstants.CN_AT);
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_MEMBER_ATTRIBUTE.propertyName(), SchemaConstants.UNIQUE_MEMBER_AT);
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_SEARCH_BASE.propertyName(), "dc=example,dc=com");
-
-
-    AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(ldapPropsMap);
-    LdapConnectionService connectionService = new DefaultLdapConnectionService();
-    LdapNetworkConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
-
-    ldapConfigurationValidatorService.checkGroupAttributes(ldapConnection, "uid=einstein,dc=example,dc=com", ambariLdapConfiguration);
-  }
-}
\ No newline at end of file


[08/46] ambari git commit: AMBARI-22265. Mahout service check failure after patch upgrade (ncole)

Posted by lp...@apache.org.
AMBARI-22265. Mahout service check failure after patch upgrade (ncole)


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 29d1139235ddfa9e21909aa188ef2dcb30014bfb
Parents: 84342f6
Author: Nate Cole <nc...@hortonworks.com>
Authored: Wed Oct 18 13:34:43 2017 -0400
Committer: Nate Cole <nc...@hortonworks.com>
Committed: Wed Oct 18 13:34:43 2017 -0400

----------------------------------------------------------------------
 .../resources/stacks/HDP/2.0.6/properties/stack_packages.json     | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/29d11392/ambari-server/src/main/resources/stacks/HDP/2.0.6/properties/stack_packages.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.6/properties/stack_packages.json b/ambari-server/src/main/resources/stacks/HDP/2.0.6/properties/stack_packages.json
index b8655d7..20b12a9 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0.6/properties/stack_packages.json
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0.6/properties/stack_packages.json
@@ -1177,7 +1177,8 @@
     },
     "upgrade-dependencies" : {
       "YARN": ["TEZ"],
-      "TEZ": ["YARN"]
+      "TEZ": ["YARN"],
+      "MAHOUT": ["MAPREDUCE2"]
     }    
   }
 }


[37/46] ambari git commit: AMBARI-21307 Refactor - using the LdapConnectionTemplate for ldap operations

Posted by lp...@apache.org.
http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java
deleted file mode 100644
index 878d1f0..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.service.ads;
-
-
-import java.util.Map;
-
-import org.apache.ambari.server.ldap.domain.AmbariLdapConfigKeys;
-import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.domain.TestAmbariLdapConfigurationFactory;
-import org.apache.ambari.server.ldap.service.LdapConnectionService;
-import org.apache.directory.api.ldap.model.constants.SchemaConstants;
-import org.apache.directory.ldap.client.api.LdapConnection;
-import org.easymock.EasyMockRule;
-import org.easymock.TestSubject;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.Maps;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-
-public class DefaultLdapAttributeDetectionServiceTest {
-
-  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapAttributeDetectionServiceTest.class);
-
-  @Rule
-  public EasyMockRule mocks = new EasyMockRule(this);
-
-  private AmbariLdapConfiguration testLdapConfiguration;
-  private TestAmbariLdapConfigurationFactory ldapConfigurationFactory = new TestAmbariLdapConfigurationFactory();
-
-  private LdapConnection connection;
-
-  @TestSubject
-  private DefaultLdapAttributeDetectionService attributeDetectionService = new DefaultLdapAttributeDetectionService();
-
-  @Before
-  public void before() {
-
-    Map<String, Object> initialProps = Maps.newHashMap();
-    initialProps.put(AmbariLdapConfigKeys.BIND_DN.key(), "");
-    testLdapConfiguration = ldapConfigurationFactory.createLdapConfiguration(initialProps);
-  }
-
-  @Test
-  public void testShouldUserNameAttributeBeDetectedWhenSearchReturnsValidUsers() throws Exception {
-    // GIVEN
-// a set of entries returned from the LDAP search
-
-    // WHEN
-    AmbariLdapConfiguration ambariLdapConfiguration = attributeDetectionService.detectLdapUserAttributes(connection, testLdapConfiguration);
-
-    // THEN
-    Assert.assertNotNull(ambariLdapConfiguration);
-    Assert.assertEquals("The username attribute is not the expected", "uid", ambariLdapConfiguration.userNameAttribute());
-
-  }
-
-
-  @Test
-  public void functionalTest() throws Exception {
-    // GIVEN
-    AmbariLdapConfiguration ambariLdapConfiguration = ldapConfigurationFactory.createLdapConfiguration(getTestPropertiesMap());
-    LdapConnectionService connectionService = new DefaultLdapConnectionService();
-    LdapConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
-
-    // WHEN
-    AmbariLdapConfiguration config = attributeDetectionService.detectLdapUserAttributes(ldapConnection, ambariLdapConfiguration);
-    config = attributeDetectionService.detectLdapGroupAttributes(ldapConnection, ambariLdapConfiguration);
-
-    Gson gson = new GsonBuilder().create();
-    LOGGER.info(gson.toJson(config));
-
-    // THEN
-    ldapConnection.close();
-
-  }
-
-  private Map<String, Object> getTestPropertiesMap() {
-    Map<String, Object> ldapPropsMap = Maps.newHashMap();
-
-    ldapPropsMap.put(AmbariLdapConfigKeys.ANONYMOUS_BIND.key(), "true");
-    ldapPropsMap.put(AmbariLdapConfigKeys.SERVER_HOST.key(), "ldap.forumsys.com");
-    ldapPropsMap.put(AmbariLdapConfigKeys.SERVER_PORT.key(), "389");
-    ldapPropsMap.put(AmbariLdapConfigKeys.BIND_DN.key(), "cn=read-only-admin,dc=example,dc=com");
-    ldapPropsMap.put(AmbariLdapConfigKeys.BIND_PASSWORD.key(), "password");
-    ldapPropsMap.put(AmbariLdapConfigKeys.DN_ATTRIBUTE.key(), SchemaConstants.CN_AT);
-
-    ldapPropsMap.put(AmbariLdapConfigKeys.USER_SEARCH_BASE.key(), "dc=example,dc=com");
-    ldapPropsMap.put(AmbariLdapConfigKeys.GROUP_SEARCH_BASE.key(), "dc=example,dc=com");
-
-    return ldapPropsMap;
-
-  }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
deleted file mode 100644
index 2844054..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.service.ads;
-
-import static org.junit.Assert.assertNotNull;
-
-import java.util.Map;
-
-import org.apache.ambari.server.ldap.domain.AmbariLdapConfigKeys;
-import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.domain.TestAmbariLdapConfigurationFactory;
-import org.apache.ambari.server.ldap.service.LdapConfigurationService;
-import org.apache.ambari.server.ldap.service.LdapConnectionService;
-import org.apache.directory.api.ldap.model.constants.SchemaConstants;
-import org.apache.directory.api.ldap.model.cursor.EntryCursor;
-import org.apache.directory.api.ldap.model.entry.Entry;
-import org.apache.directory.api.ldap.model.message.SearchScope;
-import org.apache.directory.ldap.client.api.LdapConnection;
-import org.apache.directory.ldap.client.api.LdapConnectionConfig;
-import org.apache.directory.ldap.client.api.LdapNetworkConnection;
-import org.apache.directory.ldap.client.api.search.FilterBuilder;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.Maps;
-
-public class DefaultLdapConfigurationServiceTest {
-  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapConfigurationService.class);
-  private static final String TEST_USER = "einstein";
-
-  private TestAmbariLdapConfigurationFactory ldapConfigurationFactory = new TestAmbariLdapConfigurationFactory();
-
-  LdapConfigurationService ldapConfigurationService = new DefaultLdapConfigurationService();
-
-
-  @Test
-  public void testCheckAttributes() throws Exception {
-
-    // WHEN
-    LdapConnectionConfig config = new LdapConnectionConfig();
-    config.setLdapHost("172.22.112.167");
-    config.setLdapPort(389);
-    LdapConnection connection = new LdapNetworkConnection(config);
-
-    // THEN
-    connection.bind("CN=Robert Levas,CN=Users,DC=HWQE,DC=HORTONWORKS,DC=COM", "Hadoop1234");
-
-    String filter = FilterBuilder.and(
-      FilterBuilder.equal(SchemaConstants.OBJECT_CLASS_AT, "person"),
-      FilterBuilder.equal("name", "User1 Levas")).toString();
-
-    EntryCursor cursor = connection.search("OU=levas,DC=hwqe,DC=hortonworks,DC=com", filter, SearchScope.SUBTREE);
-
-    for (Entry entry : cursor) {
-      assertNotNull(entry);
-      System.out.println(entry);
-    }
-
-    cursor.close();
-
-  }
-
-  @Test
-  public void testCheckUserAttributes() throws Exception {
-    // GIVEN
-    Map<String, Object> ldapPropsMap = Maps.newHashMap();
-
-    ldapPropsMap.put(AmbariLdapConfigKeys.ANONYMOUS_BIND.key(), "true");
-    ldapPropsMap.put(AmbariLdapConfigKeys.SERVER_HOST.key(), "ldap.forumsys.com");
-    ldapPropsMap.put(AmbariLdapConfigKeys.SERVER_PORT.key(), "389");
-    ldapPropsMap.put(AmbariLdapConfigKeys.BIND_DN.key(), "dc=example,dc=com");
-
-    ldapPropsMap.put(AmbariLdapConfigKeys.USER_OBJECT_CLASS.key(), SchemaConstants.PERSON_OC);
-    ldapPropsMap.put(AmbariLdapConfigKeys.USER_NAME_ATTRIBUTE.key(), SchemaConstants.UID_AT);
-    ldapPropsMap.put(AmbariLdapConfigKeys.USER_SEARCH_BASE.key(), "dc=example,dc=com");
-
-
-    AmbariLdapConfiguration ambariLdapConfiguration = ldapConfigurationFactory.createLdapConfiguration(ldapPropsMap);
-    LdapConnectionService connectionService = new DefaultLdapConnectionService();
-    LdapConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
-
-    ldapConfigurationService.checkUserAttributes(ldapConnection, "einstein", "", ambariLdapConfiguration);
-  }
-
-  @Test
-  public void testRetrieveGorupsForuser() throws Exception {
-    // GIVEN
-    Map<String, Object> ldapPropsMap = Maps.newHashMap();
-
-    ldapPropsMap.put(AmbariLdapConfigKeys.ANONYMOUS_BIND.key(), "true");
-    ldapPropsMap.put(AmbariLdapConfigKeys.SERVER_HOST.key(), "ldap.forumsys.com");
-    ldapPropsMap.put(AmbariLdapConfigKeys.SERVER_PORT.key(), "389");
-    ldapPropsMap.put(AmbariLdapConfigKeys.BIND_DN.key(), "dc=example,dc=com");
-
-    ldapPropsMap.put(AmbariLdapConfigKeys.USER_OBJECT_CLASS.key(), SchemaConstants.PERSON_OC);
-    ldapPropsMap.put(AmbariLdapConfigKeys.USER_NAME_ATTRIBUTE.key(), SchemaConstants.UID_AT);
-    ldapPropsMap.put(AmbariLdapConfigKeys.USER_SEARCH_BASE.key(), "dc=example,dc=com");
-
-
-    AmbariLdapConfiguration ambariLdapConfiguration = ldapConfigurationFactory.createLdapConfiguration(ldapPropsMap);
-    LdapConnectionService connectionService = new DefaultLdapConnectionService();
-    LdapConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
-
-    ldapConfigurationService.checkGroupAttributes(ldapConnection, "uid=einstein,dc=example,dc=com", ambariLdapConfiguration);
-  }
-
-  @Test
-  public void testListSupportedProperties(){
-    StringBuilder sb = new StringBuilder().append(System.lineSeparator());
-    for (AmbariLdapConfigKeys configKey : AmbariLdapConfigKeys.values()) {
-      sb.append(configKey.key()).append(System.lineSeparator());
-    }
-    LOGGER.info(sb.toString());
-
-  }
-}
\ No newline at end of file


[03/46] ambari git commit: AMBARI-22254. RU: RU failed on 'Updating configuration sqoop-atlas-application.properties' (ncole)

Posted by lp...@apache.org.
AMBARI-22254. RU: RU failed on 'Updating configuration sqoop-atlas-application.properties' (ncole)


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: c924ebdb6da802ab70f95c6f974087645a600b78
Parents: 53f028e
Author: Nate Cole <nc...@hortonworks.com>
Authored: Tue Oct 17 13:38:10 2017 -0400
Committer: Nate Cole <nc...@hortonworks.com>
Committed: Tue Oct 17 14:18:24 2017 -0400

----------------------------------------------------------------------
 .../serveraction/upgrades/ConfigureAction.java  |  5 ++++
 .../ambari/server/state/stack/UpgradePack.java  | 30 +++++++++++++++++++-
 .../state/stack/upgrade/ClusterGrouping.java    | 13 +++++++++
 .../state/stack/upgrade/ConfigureTask.java      | 16 +++++++++++
 .../internal/UpgradeResourceProviderTest.java   | 13 +++++++++
 .../state/stack/ConfigUpgradeValidityTest.java  | 10 +++++++
 6 files changed, 86 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c924ebdb/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/ConfigureAction.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/ConfigureAction.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/ConfigureAction.java
index a7f910f..f15a507 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/ConfigureAction.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/ConfigureAction.java
@@ -183,6 +183,11 @@ public class ConfigureAction extends AbstractUpgradeServerAction {
     String configType = commandParameters.get(ConfigureTask.PARAMETER_CONFIG_TYPE);
     String serviceName = cluster.getServiceByConfigType(configType);
 
+    // !!! we couldn't get the service based on its config type, so try the associated
+    if (StringUtils.isBlank(serviceName)) {
+      serviceName = commandParameters.get(ConfigureTask.PARAMETER_ASSOCIATED_SERVICE);
+    }
+
     RepositoryVersionEntity sourceRepoVersion = upgradeContext.getSourceRepositoryVersion(serviceName);
     RepositoryVersionEntity targetRepoVersion = upgradeContext.getTargetRepositoryVersion(serviceName);
     StackId sourceStackId = sourceRepoVersion.getStackId();

http://git-wip-us.apache.org/repos/asf/ambari/blob/c924ebdb/ambari-server/src/main/java/org/apache/ambari/server/state/stack/UpgradePack.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/UpgradePack.java b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/UpgradePack.java
index 256b71d..7c32f37 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/UpgradePack.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/UpgradePack.java
@@ -37,11 +37,13 @@ import javax.xml.bind.annotation.XmlValue;
 
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.state.stack.upgrade.ClusterGrouping;
+import org.apache.ambari.server.state.stack.upgrade.ConfigureTask;
 import org.apache.ambari.server.state.stack.upgrade.Direction;
 import org.apache.ambari.server.state.stack.upgrade.Grouping;
 import org.apache.ambari.server.state.stack.upgrade.ServiceCheckGrouping;
 import org.apache.ambari.server.state.stack.upgrade.Task;
 import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
+import org.apache.commons.collections.CollectionUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -446,7 +448,7 @@ public class UpgradePack {
   private void initializeProcessingComponentMappings() {
     m_process = new LinkedHashMap<>();
 
-    if (null == processing || processing.isEmpty()) {
+    if (CollectionUtils.isEmpty(processing)) {
       return;
     }
 
@@ -574,6 +576,32 @@ public class UpgradePack {
 
         throw new RuntimeException(error);
       }
+
+      // !!! check for config tasks and mark the associated service
+      initializeTasks(service.name, preTasks);
+      initializeTasks(service.name, postTasks);
+      initializeTasks(service.name, tasks);
+      initializeTasks(service.name, preDowngradeTasks);
+      initializeTasks(service.name, postDowngradeTasks);
+    }
+
+    /**
+     * Checks for config tasks and marks the associated service.
+     * @param service
+     *          the service name
+     * @param tasks
+     *          the list of tasks to check
+     */
+    private void initializeTasks(String service, List<Task> tasks) {
+      if (CollectionUtils.isEmpty(tasks)) {
+        return;
+      }
+
+      for (Task task : tasks) {
+        if (Task.Type.CONFIGURE == task.getType()) {
+          ((ConfigureTask) task).associatedService = service;
+        }
+      }
     }
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/c924ebdb/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ClusterGrouping.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ClusterGrouping.java b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ClusterGrouping.java
index 65038e2..5bc3d8f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ClusterGrouping.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ClusterGrouping.java
@@ -27,6 +27,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlAttribute;
@@ -126,6 +127,18 @@ public class ClusterGrouping extends Grouping {
       return Objects.toStringHelper(this).add("id", id).add("title",
           title).omitNullValues().toString();
     }
+
+    /**
+     * If a task is found that is configure, set its associated service.  This is used
+     * if the configuration type cannot be isolated by service.
+     */
+    void afterUnmarshal(Unmarshaller unmarshaller, Object parent) {
+      if (task.getType().equals(Task.Type.CONFIGURE) && StringUtils.isNotEmpty(service)) {
+        ((ConfigureTask) task).associatedService = service;
+      }
+    }
+
+
   }
 
   public class ClusterBuilder extends StageWrapperBuilder {

http://git-wip-us.apache.org/repos/asf/ambari/blob/c924ebdb/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ConfigureTask.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ConfigureTask.java b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ConfigureTask.java
index f88691d..75b5f59 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ConfigureTask.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ConfigureTask.java
@@ -26,6 +26,7 @@ import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
 import javax.xml.bind.annotation.XmlType;
 
 import org.apache.ambari.server.serveraction.upgrades.ConfigureAction;
@@ -91,6 +92,11 @@ public class ConfigureTask extends ServerSideActionTask {
    */
   public static final String PARAMETER_INSERTIONS = "configure-task-insertions";
 
+  /**
+   * The associated service for the config task
+   */
+  public static final String PARAMETER_ASSOCIATED_SERVICE = "configure-task-associated-service";
+
   public static final String actionVerb = "Configuring";
 
   /**
@@ -114,6 +120,12 @@ public class ConfigureTask extends ServerSideActionTask {
   public boolean supportsPatch = false;
 
   /**
+   * The associated service is the service where this config task is specified
+   */
+  @XmlTransient
+  public String associatedService;
+
+  /**
    * {@inheritDoc}
    */
   @Override
@@ -236,6 +248,10 @@ public class ConfigureTask extends ServerSideActionTask {
       configParameters.put(ConfigureTask.PARAMETER_INSERTIONS, m_gson.toJson(insertions));
     }
 
+    if (StringUtils.isNotEmpty(associatedService)) {
+      configParameters.put(ConfigureTask.PARAMETER_ASSOCIATED_SERVICE, associatedService);
+    }
+
     return configParameters;
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/c924ebdb/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
index 20adac2..d6b1ab3 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
@@ -45,6 +45,7 @@ import org.apache.ambari.server.Role;
 import org.apache.ambari.server.RoleCommand;
 import org.apache.ambari.server.actionmanager.ActionManager;
 import org.apache.ambari.server.actionmanager.ExecutionCommandWrapper;
+import org.apache.ambari.server.actionmanager.ExecutionCommandWrapperFactory;
 import org.apache.ambari.server.actionmanager.HostRoleCommand;
 import org.apache.ambari.server.actionmanager.HostRoleStatus;
 import org.apache.ambari.server.actionmanager.Stage;
@@ -67,12 +68,14 @@ import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.dao.ExecutionCommandDAO;
 import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
 import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
 import org.apache.ambari.server.orm.dao.RequestDAO;
 import org.apache.ambari.server.orm.dao.StackDAO;
 import org.apache.ambari.server.orm.dao.StageDAO;
 import org.apache.ambari.server.orm.dao.UpgradeDAO;
+import org.apache.ambari.server.orm.entities.ExecutionCommandEntity;
 import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.orm.entities.RequestEntity;
@@ -100,6 +103,7 @@ import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.UpgradeContext;
 import org.apache.ambari.server.state.UpgradeHelper;
 import org.apache.ambari.server.state.UpgradeState;
+import org.apache.ambari.server.state.stack.upgrade.ConfigureTask;
 import org.apache.ambari.server.state.stack.upgrade.Direction;
 import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
 import org.apache.ambari.server.topology.TopologyManager;
@@ -1832,6 +1836,15 @@ public class UpgradeResourceProviderTest extends EasyMockSupport {
       if (StringUtils.isNotBlank(command.getCustomCommandName()) &&
           command.getCustomCommandName().equals(ConfigureAction.class.getName())) {
         foundConfigTask = true;
+
+        ExecutionCommandDAO dao = injector.getInstance(ExecutionCommandDAO.class);
+        ExecutionCommandEntity entity = dao.findByPK(command.getTaskId());
+        ExecutionCommandWrapperFactory factory = injector.getInstance(ExecutionCommandWrapperFactory.class);
+        ExecutionCommandWrapper wrapper = factory.createFromJson(new String(entity.getCommand()));
+        Map<String, String> params = wrapper.getExecutionCommand().getCommandParams();
+        assertTrue(params.containsKey(ConfigureTask.PARAMETER_ASSOCIATED_SERVICE));
+        assertEquals("ZOOKEEPER", params.get(ConfigureTask.PARAMETER_ASSOCIATED_SERVICE));
+
         break;
       }
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c924ebdb/ambari-server/src/test/java/org/apache/ambari/server/state/stack/ConfigUpgradeValidityTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/stack/ConfigUpgradeValidityTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/stack/ConfigUpgradeValidityTest.java
index 2259e30..2930590 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/stack/ConfigUpgradeValidityTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/stack/ConfigUpgradeValidityTest.java
@@ -45,6 +45,7 @@ import org.apache.ambari.server.state.stack.upgrade.Task.Type;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.filefilter.FileFilterUtils;
 import org.apache.commons.io.filefilter.IOFileFilter;
+import org.apache.commons.lang.StringUtils;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -128,6 +129,12 @@ public class ConfigUpgradeValidityTest {
                   ConfigureTask configureTask = (ConfigureTask) executionStage.task;
                   assertIdDefinitionExists(configureTask.id, configUpgradePack, upgradePack,
                       sourceStack);
+
+                  if (StringUtils.isNotBlank(executionStage.service)) {
+                    Assert.assertEquals(executionStage.service, configureTask.associatedService);
+                  } else {
+                    Assert.assertTrue(null == configureTask.associatedService);
+                  }
                 }
               }
             }
@@ -144,6 +151,7 @@ public class ConfigUpgradeValidityTest {
                   ConfigureTask configureTask = (ConfigureTask) preTask;
                   assertIdDefinitionExists(configureTask.id, configUpgradePack, upgradePack,
                       sourceStack);
+                  Assert.assertTrue(StringUtils.isNotBlank(configureTask.associatedService));
                 }
               }
 
@@ -153,6 +161,7 @@ public class ConfigUpgradeValidityTest {
                     ConfigureTask configureTask = (ConfigureTask) task;
                     assertIdDefinitionExists(configureTask.id, configUpgradePack, upgradePack,
                         sourceStack);
+                    Assert.assertTrue(StringUtils.isNotBlank(configureTask.associatedService));
                   }
                 }
               }
@@ -163,6 +172,7 @@ public class ConfigUpgradeValidityTest {
                     ConfigureTask configureTask = (ConfigureTask) postTask;
                     assertIdDefinitionExists(configureTask.id, configUpgradePack, upgradePack,
                         sourceStack);
+                    Assert.assertTrue(StringUtils.isNotBlank(configureTask.associatedService));
                   }
                 }
               }


[35/46] ambari git commit: AMBARI-21307 Extracted config keys into an enum. Organized code (created domain package, moved classes)

Posted by lp...@apache.org.
AMBARI-21307 Extracted config keys into an enum. Organized code (created domain package, moved classes)


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 6fc9fadeaa7ef88e96ff015d167589c83ed536d1
Parents: 25d6edf
Author: lpuskas <lp...@apache.org>
Authored: Thu Sep 14 16:33:41 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:42:01 2017 +0200

----------------------------------------------------------------------
 .../services/ldap/LdapConfigurationService.java |   4 +-
 .../server/ldap/AmbariLdapConfiguration.java    | 232 -------------------
 .../server/ldap/LdapConfigurationFactory.java   |  34 ---
 .../apache/ambari/server/ldap/LdapModule.java   |   2 +
 .../ldap/domain/AmbariLdapConfiguration.java    | 180 ++++++++++++++
 .../ldap/domain/LdapConfigurationFactory.java   |  34 +++
 .../ldap/service/AmbariLdapConfigKeys.java      |  72 ++++++
 .../AmbariLdapConfigurationProvider.java        |   4 +-
 .../server/ldap/service/AmbariLdapFacade.java   |   2 +-
 .../service/LdapAttributeDetectionService.java  |   2 +-
 .../ldap/service/LdapConfigurationService.java  |   2 +-
 .../ldap/service/LdapConnectionService.java     |   2 +-
 .../ambari/server/ldap/service/LdapFacade.java  |   2 +-
 .../DefaultLdapAttributeDetectionService.java   |  15 +-
 .../ads/DefaultLdapConfigurationService.java    |   2 +-
 .../ads/DefaultLdapConnectionService.java       |  16 +-
 ...efaultLdapAttributeDetectionServiceTest.java |  21 +-
 .../DefaultLdapConfigurationServiceTest.java    |  31 +--
 18 files changed, 334 insertions(+), 323 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/6fc9fade/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
index ae47a87..ff95066 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
@@ -46,8 +46,8 @@ import org.apache.ambari.server.api.services.ResultImpl;
 import org.apache.ambari.server.api.services.ResultStatus;
 import org.apache.ambari.server.controller.internal.ResourceImpl;
 import org.apache.ambari.server.controller.spi.Resource;
-import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.LdapConfigurationFactory;
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.domain.LdapConfigurationFactory;
 import org.apache.ambari.server.ldap.service.LdapFacade;
 import org.apache.ambari.server.security.authorization.AuthorizationException;
 import org.apache.ambari.server.security.authorization.AuthorizationHelper;

http://git-wip-us.apache.org/repos/asf/ambari/blob/6fc9fade/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
deleted file mode 100644
index 5bdda7a..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ambari.server.ldap;
-
-import java.util.Map;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.inject.assistedinject.Assisted;
-
-/**
- * This class is an immutable representation of all the LDAP related configurationMap entries.
- */
-@Singleton
-public class AmbariLdapConfiguration {
-
-  private static final Logger LOGGER = LoggerFactory.getLogger(AmbariLdapConfiguration.class);
-
-  /**
-   * Constants representing supported LDAP related property names
-   */
-  public enum AmbariLdapConfig {
-
-    LDAP_ENABLED("ambari.ldap.authentication.enabled"),
-    SERVER_HOST("ambari.ldap.connectivity.server.host"),
-    SERVER_PORT("ambari.ldap.connectivity.server.port"),
-    USE_SSL("ambari.ldap.connectivity.use_ssl"),
-
-    TRUST_STORE("ambari.ldap.connectivity.trust_store"),
-    TRUST_STORE_TYPE("ambari.ldap.connectivity.trust_store.type"),
-    TRUST_STORE_PATH("ambari.ldap.connectivity.trust_store.path"),
-    TRUST_STORE_PASSWORD("ambari.ldap.connectivity.trust_store.password"),
-    ANONYMOUS_BIND("ambari.ldap.connectivity.anonymous_bind"),
-
-    BIND_DN("ambari.ldap.connectivity.bind_dn"),
-    BIND_PASSWORD("ambari.ldap.connectivity.bind_password"),
-
-    ATTR_DETECTION("ambari.ldap.attributes.detection"), // manual | auto
-
-    DN_ATTRIBUTE("ambari.ldap.attributes.dn_attr"),
-
-    USER_OBJECT_CLASS("ambari.ldap.attributes.user.object_class"),
-    USER_NAME_ATTRIBUTE("ambari.ldap.attributes.user.name_attr"),
-    USER_GROUP_MEMBER_ATTRIBUTE("ambari.ldap.attributes.user.group_member_attr"),
-    USER_SEARCH_BASE("ambari.ldap.attributes.user.search_base"),
-
-    GROUP_OBJECT_CLASS("ambari.ldap.attributes.group.object_class"),
-    GROUP_NAME_ATTRIBUTE("ambari.ldap.attributes.group.name_attr"),
-    GROUP_MEMBER_ATTRIBUTE("ambari.ldap.attributes.group.member_attr"),
-    GROUP_SEARCH_BASE("ambari.ldap.attributes.group.search_base"),
-
-    USER_SEARCH_FILTER("ambari.ldap.advanced.user_search_filter"),
-    USER_MEMBER_REPLACE_PATTERN("ambari.ldap.advanced.user_member_replace_pattern"),
-    USER_MEMBER_FILTER("ambari.ldap.advanced.user_member_filter"),
-
-    GROUP_SEARCH_FILTER("ambari.ldap.advanced.group_search_filter"),
-    GROUP_MEMBER_REPLACE_PATTERN("ambari.ldap.advanced.group_member_replace_pattern"),
-    GROUP_MEMBER_FILTER("ambari.ldap.advanced.group_member_filter"),
-
-    FORCE_LOWERCASE_USERNAMES("ambari.ldap.advanced.force_lowercase_usernames"),
-    REFERRAL_HANDLING("ambari.ldap.advanced.referrals"), // folow
-    PAGINATION_ENABLED("ambari.ldap.advanced.pagination_enabled"); // true | false
-
-    private String propertyName;
-
-    AmbariLdapConfig(String propName) {
-      this.propertyName = propName;
-    }
-
-    public String key() {
-      return this.propertyName;
-    }
-  }
-
-  private final Map<String, Object> configurationMap;
-
-  private Object configValue(AmbariLdapConfig ambariLdapConfig) {
-    Object value = null;
-    if (configurationMap.containsKey(ambariLdapConfig.key())) {
-      value = configurationMap.get(ambariLdapConfig.key());
-    } else {
-      LOGGER.warn("Ldap configuration property [{}] hasn't been set", ambariLdapConfig.key());
-    }
-    return value;
-  }
-
-  public void setValueFor(AmbariLdapConfig ambariLdapConfig, Object value) {
-    configurationMap.put(ambariLdapConfig.key(), value);
-  }
-
-  @Inject
-  public AmbariLdapConfiguration(@Assisted Map<String, Object> configuration) {
-    this.configurationMap = configuration;
-  }
-
-  public boolean ldapEnabled() {
-    return Boolean.valueOf((String) configValue(AmbariLdapConfig.LDAP_ENABLED));
-  }
-
-  public String serverHost() {
-    return (String) configValue(AmbariLdapConfig.SERVER_HOST);
-  }
-
-  public int serverPort() {
-    return Integer.valueOf((String) configValue(AmbariLdapConfig.SERVER_PORT));
-  }
-
-  public boolean useSSL() {
-    return Boolean.valueOf((String) configValue(AmbariLdapConfig.USE_SSL));
-  }
-
-  public String trustStore() {
-    return (String) configValue(AmbariLdapConfig.TRUST_STORE);
-  }
-
-  public String trustStoreType() {
-    return (String) configValue(AmbariLdapConfig.TRUST_STORE_TYPE);
-  }
-
-  public String trustStorePath() {
-    return (String) configValue(AmbariLdapConfig.TRUST_STORE_PATH);
-  }
-
-  public String trustStorePassword() {
-    return (String) configValue(AmbariLdapConfig.TRUST_STORE_PASSWORD);
-  }
-
-  public boolean anonymousBind() {
-    return Boolean.valueOf((String) configValue(AmbariLdapConfig.ANONYMOUS_BIND));
-  }
-
-  public String bindDn() {
-    return (String) configValue(AmbariLdapConfig.BIND_DN);
-  }
-
-  public String bindPassword() {
-    return (String) configValue(AmbariLdapConfig.BIND_PASSWORD);
-  }
-
-  public String attributeDetection() {
-    return (String) configValue(AmbariLdapConfig.ATTR_DETECTION);
-  }
-
-  public String dnAttribute() {
-    return (String) configValue(AmbariLdapConfig.DN_ATTRIBUTE);
-  }
-
-  public String userObjectClass() {
-    return (String) configValue(AmbariLdapConfig.USER_OBJECT_CLASS);
-  }
-
-  public String userNameAttribute() {
-    return (String) configValue(AmbariLdapConfig.USER_NAME_ATTRIBUTE);
-  }
-
-  public String userSearchBase() {
-    return (String) configValue(AmbariLdapConfig.USER_SEARCH_BASE);
-  }
-
-  public String groupObjectClass() {
-    return (String) configValue(AmbariLdapConfig.GROUP_OBJECT_CLASS);
-  }
-
-  public String groupNameAttribute() {
-    return (String) configValue(AmbariLdapConfig.GROUP_NAME_ATTRIBUTE);
-  }
-
-  public String groupMemberAttribute() {
-    return (String) configValue(AmbariLdapConfig.GROUP_MEMBER_ATTRIBUTE);
-  }
-
-  public String groupSearchBase() {
-    return (String) configValue(AmbariLdapConfig.GROUP_SEARCH_BASE);
-  }
-
-  public String userSearchFilter() {
-    return (String) configValue(AmbariLdapConfig.USER_SEARCH_FILTER);
-  }
-
-  public String userMemberReplacePattern() {
-    return (String) configValue(AmbariLdapConfig.USER_MEMBER_REPLACE_PATTERN);
-  }
-
-  public String userMemberFilter() {
-    return (String) configValue(AmbariLdapConfig.USER_MEMBER_FILTER);
-  }
-
-  public String groupSearchFilter() {
-    return (String) configValue(AmbariLdapConfig.GROUP_SEARCH_FILTER);
-  }
-
-  public String groupMemberReplacePattern() {
-    return (String) configValue(AmbariLdapConfig.GROUP_MEMBER_REPLACE_PATTERN);
-  }
-
-  public String groupMemberFilter() {
-    return (String) configValue(AmbariLdapConfig.GROUP_MEMBER_FILTER);
-  }
-
-  public boolean forceLowerCaseUserNames() {
-    return Boolean.valueOf((String) configValue(AmbariLdapConfig.FORCE_LOWERCASE_USERNAMES));
-  }
-
-  public boolean paginationEnabled() {
-    return Boolean.valueOf((String) configValue(AmbariLdapConfig.PAGINATION_ENABLED));
-  }
-
-  public String referralHandling() {
-    return (String) configValue(AmbariLdapConfig.REFERRAL_HANDLING);
-  }
-
-
-  @Override
-  public String toString() {
-    return configurationMap.toString();
-  }
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/6fc9fade/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationFactory.java
deleted file mode 100644
index 67ac092..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationFactory.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap;
-
-import java.util.Map;
-
-/**
- * Factory interface for AmbariLdapConfiguration instances.
- * It's registered as a factory in the GUICE context ( so no implementations required)
- *
- * To be extended with other factory methods upon needs.
- */
-public interface LdapConfigurationFactory {
-
-  /**
-   * Creates an AmbariLdapConfiguration instance with the provided map of configuration settings.
-   *
-   * @param configuration a map where keys are the configuration properties and values are the configuration values
-   * @return an AmbariLdapConfiguration instance
-   */
-  AmbariLdapConfiguration createLdapConfiguration(Map<String, Object> configuration);
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/6fc9fade/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
index 0be69d4..83a73d1 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
@@ -15,6 +15,8 @@
 
 package org.apache.ambari.server.ldap;
 
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.domain.LdapConfigurationFactory;
 import org.apache.ambari.server.ldap.service.AmbariLdapConfigurationProvider;
 import org.apache.ambari.server.ldap.service.AmbariLdapFacade;
 import org.apache.ambari.server.ldap.service.LdapAttributeDetectionService;

http://git-wip-us.apache.org/repos/asf/ambari/blob/6fc9fade/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfiguration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfiguration.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfiguration.java
new file mode 100644
index 0000000..072393a
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfiguration.java
@@ -0,0 +1,180 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.ambari.server.ldap.domain;
+
+import java.util.Map;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.apache.ambari.server.ldap.service.AmbariLdapConfigKeys;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.assistedinject.Assisted;
+
+/**
+ * This class is an immutable representation of all the LDAP related configurationMap entries.
+ */
+@Singleton
+public class AmbariLdapConfiguration {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(AmbariLdapConfiguration.class);
+
+  private final Map<String, Object> configurationMap;
+
+  private Object configValue(AmbariLdapConfigKeys ambariLdapConfigKeys) {
+    Object value = null;
+    if (configurationMap.containsKey(ambariLdapConfigKeys.key())) {
+      value = configurationMap.get(ambariLdapConfigKeys.key());
+    } else {
+      LOGGER.warn("Ldap configuration property [{}] hasn't been set", ambariLdapConfigKeys.key());
+    }
+    return value;
+  }
+
+  public void setValueFor(AmbariLdapConfigKeys ambariLdapConfigKeys, Object value) {
+    configurationMap.put(ambariLdapConfigKeys.key(), value);
+  }
+
+  // intentionally package private, instances to be created through the factory
+  @Inject
+  AmbariLdapConfiguration(@Assisted Map<String, Object> configuration) {
+    this.configurationMap = configuration;
+  }
+
+  public boolean ldapEnabled() {
+    return Boolean.valueOf((String) configValue(AmbariLdapConfigKeys.LDAP_ENABLED));
+  }
+
+  public String serverHost() {
+    return (String) configValue(AmbariLdapConfigKeys.SERVER_HOST);
+  }
+
+  public int serverPort() {
+    return Integer.valueOf((String) configValue(AmbariLdapConfigKeys.SERVER_PORT));
+  }
+
+  public boolean useSSL() {
+    return Boolean.valueOf((String) configValue(AmbariLdapConfigKeys.USE_SSL));
+  }
+
+  public String trustStore() {
+    return (String) configValue(AmbariLdapConfigKeys.TRUST_STORE);
+  }
+
+  public String trustStoreType() {
+    return (String) configValue(AmbariLdapConfigKeys.TRUST_STORE_TYPE);
+  }
+
+  public String trustStorePath() {
+    return (String) configValue(AmbariLdapConfigKeys.TRUST_STORE_PATH);
+  }
+
+  public String trustStorePassword() {
+    return (String) configValue(AmbariLdapConfigKeys.TRUST_STORE_PASSWORD);
+  }
+
+  public boolean anonymousBind() {
+    return Boolean.valueOf((String) configValue(AmbariLdapConfigKeys.ANONYMOUS_BIND));
+  }
+
+  public String bindDn() {
+    return (String) configValue(AmbariLdapConfigKeys.BIND_DN);
+  }
+
+  public String bindPassword() {
+    return (String) configValue(AmbariLdapConfigKeys.BIND_PASSWORD);
+  }
+
+  public String attributeDetection() {
+    return (String) configValue(AmbariLdapConfigKeys.ATTR_DETECTION);
+  }
+
+  public String dnAttribute() {
+    return (String) configValue(AmbariLdapConfigKeys.DN_ATTRIBUTE);
+  }
+
+  public String userObjectClass() {
+    return (String) configValue(AmbariLdapConfigKeys.USER_OBJECT_CLASS);
+  }
+
+  public String userNameAttribute() {
+    return (String) configValue(AmbariLdapConfigKeys.USER_NAME_ATTRIBUTE);
+  }
+
+  public String userSearchBase() {
+    return (String) configValue(AmbariLdapConfigKeys.USER_SEARCH_BASE);
+  }
+
+  public String groupObjectClass() {
+    return (String) configValue(AmbariLdapConfigKeys.GROUP_OBJECT_CLASS);
+  }
+
+  public String groupNameAttribute() {
+    return (String) configValue(AmbariLdapConfigKeys.GROUP_NAME_ATTRIBUTE);
+  }
+
+  public String groupMemberAttribute() {
+    return (String) configValue(AmbariLdapConfigKeys.GROUP_MEMBER_ATTRIBUTE);
+  }
+
+  public String groupSearchBase() {
+    return (String) configValue(AmbariLdapConfigKeys.GROUP_SEARCH_BASE);
+  }
+
+  public String userSearchFilter() {
+    return (String) configValue(AmbariLdapConfigKeys.USER_SEARCH_FILTER);
+  }
+
+  public String userMemberReplacePattern() {
+    return (String) configValue(AmbariLdapConfigKeys.USER_MEMBER_REPLACE_PATTERN);
+  }
+
+  public String userMemberFilter() {
+    return (String) configValue(AmbariLdapConfigKeys.USER_MEMBER_FILTER);
+  }
+
+  public String groupSearchFilter() {
+    return (String) configValue(AmbariLdapConfigKeys.GROUP_SEARCH_FILTER);
+  }
+
+  public String groupMemberReplacePattern() {
+    return (String) configValue(AmbariLdapConfigKeys.GROUP_MEMBER_REPLACE_PATTERN);
+  }
+
+  public String groupMemberFilter() {
+    return (String) configValue(AmbariLdapConfigKeys.GROUP_MEMBER_FILTER);
+  }
+
+  public boolean forceLowerCaseUserNames() {
+    return Boolean.valueOf((String) configValue(AmbariLdapConfigKeys.FORCE_LOWERCASE_USERNAMES));
+  }
+
+  public boolean paginationEnabled() {
+    return Boolean.valueOf((String) configValue(AmbariLdapConfigKeys.PAGINATION_ENABLED));
+  }
+
+  public String referralHandling() {
+    return (String) configValue(AmbariLdapConfigKeys.REFERRAL_HANDLING);
+  }
+
+
+  @Override
+  public String toString() {
+    return configurationMap.toString();
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/6fc9fade/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/LdapConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/LdapConfigurationFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/LdapConfigurationFactory.java
new file mode 100644
index 0000000..f9a74da
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/LdapConfigurationFactory.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.domain;
+
+import java.util.Map;
+
+/**
+ * Factory interface for AmbariLdapConfiguration instances.
+ * It's registered as a factory in the GUICE context ( so no implementations required)
+ *
+ * To be extended with other factory methods upon needs.
+ */
+public interface LdapConfigurationFactory {
+
+  /**
+   * Creates an AmbariLdapConfiguration instance with the provided map of configuration settings.
+   *
+   * @param configuration a map where keys are the configuration properties and values are the configuration values
+   * @return an AmbariLdapConfiguration instance
+   */
+  AmbariLdapConfiguration createLdapConfiguration(Map<String, Object> configuration);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/6fc9fade/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigKeys.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigKeys.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigKeys.java
new file mode 100644
index 0000000..9cf4e56
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigKeys.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service;
+
+/**
+ * Constants representing supported LDAP related property names
+ * // todo extend this with validation information, description, defaults maybe
+ */
+public enum AmbariLdapConfigKeys {
+
+  LDAP_ENABLED("ambari.ldap.authentication.enabled"),
+  SERVER_HOST("ambari.ldap.connectivity.server.host"),
+  SERVER_PORT("ambari.ldap.connectivity.server.port"),
+  USE_SSL("ambari.ldap.connectivity.use_ssl"),
+
+  TRUST_STORE("ambari.ldap.connectivity.trust_store"),
+  TRUST_STORE_TYPE("ambari.ldap.connectivity.trust_store.type"),
+  TRUST_STORE_PATH("ambari.ldap.connectivity.trust_store.path"),
+  TRUST_STORE_PASSWORD("ambari.ldap.connectivity.trust_store.password"),
+  ANONYMOUS_BIND("ambari.ldap.connectivity.anonymous_bind"),
+
+  BIND_DN("ambari.ldap.connectivity.bind_dn"),
+  BIND_PASSWORD("ambari.ldap.connectivity.bind_password"),
+
+  ATTR_DETECTION("ambari.ldap.attributes.detection"), // manual | auto
+
+  DN_ATTRIBUTE("ambari.ldap.attributes.dn_attr"),
+
+  USER_OBJECT_CLASS("ambari.ldap.attributes.user.object_class"),
+  USER_NAME_ATTRIBUTE("ambari.ldap.attributes.user.name_attr"),
+  USER_GROUP_MEMBER_ATTRIBUTE("ambari.ldap.attributes.user.group_member_attr"),
+  USER_SEARCH_BASE("ambari.ldap.attributes.user.search_base"),
+
+  GROUP_OBJECT_CLASS("ambari.ldap.attributes.group.object_class"),
+  GROUP_NAME_ATTRIBUTE("ambari.ldap.attributes.group.name_attr"),
+  GROUP_MEMBER_ATTRIBUTE("ambari.ldap.attributes.group.member_attr"),
+  GROUP_SEARCH_BASE("ambari.ldap.attributes.group.search_base"),
+
+  USER_SEARCH_FILTER("ambari.ldap.advanced.user_search_filter"),
+  USER_MEMBER_REPLACE_PATTERN("ambari.ldap.advanced.user_member_replace_pattern"),
+  USER_MEMBER_FILTER("ambari.ldap.advanced.user_member_filter"),
+
+  GROUP_SEARCH_FILTER("ambari.ldap.advanced.group_search_filter"),
+  GROUP_MEMBER_REPLACE_PATTERN("ambari.ldap.advanced.group_member_replace_pattern"),
+  GROUP_MEMBER_FILTER("ambari.ldap.advanced.group_member_filter"),
+
+  FORCE_LOWERCASE_USERNAMES("ambari.ldap.advanced.force_lowercase_usernames"),
+  REFERRAL_HANDLING("ambari.ldap.advanced.referrals"), // folow
+  PAGINATION_ENABLED("ambari.ldap.advanced.pagination_enabled"); // true | false
+
+  private String propertyName;
+
+  AmbariLdapConfigKeys(String propName) {
+    this.propertyName = propName;
+  }
+
+  public String key() {
+    return this.propertyName;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/6fc9fade/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java
index 80ed828..af9f2e7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java
@@ -23,8 +23,8 @@ import javax.inject.Singleton;
 
 import org.apache.ambari.server.events.AmbariLdapConfigChangedEvent;
 import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
-import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.LdapConfigurationFactory;
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.domain.LdapConfigurationFactory;
 import org.apache.ambari.server.orm.dao.AmbariConfigurationDAO;
 import org.apache.ambari.server.orm.entities.AmbariConfigurationEntity;
 import org.apache.ambari.server.security.authorization.AmbariLdapAuthenticationProvider;

http://git-wip-us.apache.org/repos/asf/ambari/blob/6fc9fade/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
index 689a072..7a6ad5a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
@@ -21,7 +21,7 @@ import java.util.Set;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 
-import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
 import org.apache.directory.ldap.client.api.LdapConnection;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;

http://git-wip-us.apache.org/repos/asf/ambari/blob/6fc9fade/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapAttributeDetectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapAttributeDetectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapAttributeDetectionService.java
index 4cfa81e..90e3b8b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapAttributeDetectionService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapAttributeDetectionService.java
@@ -14,7 +14,7 @@
 
 package org.apache.ambari.server.ldap.service;
 
-import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
 
 /**
  * Contract defining operations to detect user and group attributes.

http://git-wip-us.apache.org/repos/asf/ambari/blob/6fc9fade/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConfigurationService.java
index 06566cc..5c376c9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConfigurationService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConfigurationService.java
@@ -17,7 +17,7 @@ package org.apache.ambari.server.ldap.service;
 import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
 import org.apache.directory.ldap.client.api.LdapConnection;
 
 /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/6fc9fade/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionService.java
index b4daeaa..6f1e1ff 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionService.java
@@ -14,7 +14,7 @@
 
 package org.apache.ambari.server.ldap.service;
 
-import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
 import org.apache.directory.ldap.client.api.LdapConnection;
 
 /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/6fc9fade/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
index 3ae913c..ef84d1b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
@@ -17,7 +17,7 @@ package org.apache.ambari.server.ldap.service;
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
 
 /**
  * The contract defining all the operations required by the application when communicating with an arbitrary LDAP server.

http://git-wip-us.apache.org/repos/asf/ambari/blob/6fc9fade/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
index b499b65..ed24015 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
@@ -17,7 +17,8 @@ package org.apache.ambari.server.ldap.service.ads;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 
-import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.service.AmbariLdapConfigKeys;
 import org.apache.ambari.server.ldap.service.AmbariLdapException;
 import org.apache.ambari.server.ldap.service.LdapAttributeDetectionService;
 import org.apache.ambari.server.ldap.service.ads.detectors.GroupMemberAttrDetector;
@@ -112,9 +113,9 @@ public class DefaultLdapAttributeDetectionService implements LdapAttributeDetect
         }
       }
 
-      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.USER_NAME_ATTRIBUTE, userNameAttrDetector.detect());
-      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.USER_OBJECT_CLASS, userObjectClassDetector.detect());
-      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.USER_GROUP_MEMBER_ATTRIBUTE, userGroupMemberAttrDetector.detect());
+      ambariLdapConfiguration.setValueFor(AmbariLdapConfigKeys.USER_NAME_ATTRIBUTE, userNameAttrDetector.detect());
+      ambariLdapConfiguration.setValueFor(AmbariLdapConfigKeys.USER_OBJECT_CLASS, userObjectClassDetector.detect());
+      ambariLdapConfiguration.setValueFor(AmbariLdapConfigKeys.USER_GROUP_MEMBER_ATTRIBUTE, userGroupMemberAttrDetector.detect());
 
       LOGGER.info("Decorated ambari ldap config : [{}]", ambariLdapConfiguration);
 
@@ -177,9 +178,9 @@ public class DefaultLdapAttributeDetectionService implements LdapAttributeDetect
         }
       }
 
-      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.GROUP_NAME_ATTRIBUTE, groupNameAttrDetector.detect());
-      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.GROUP_OBJECT_CLASS, groupObjectClassDetector.detect());
-      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.GROUP_MEMBER_ATTRIBUTE, groupMemberAttrDetector.detect());
+      ambariLdapConfiguration.setValueFor(AmbariLdapConfigKeys.GROUP_NAME_ATTRIBUTE, groupNameAttrDetector.detect());
+      ambariLdapConfiguration.setValueFor(AmbariLdapConfigKeys.GROUP_OBJECT_CLASS, groupObjectClassDetector.detect());
+      ambariLdapConfiguration.setValueFor(AmbariLdapConfigKeys.GROUP_MEMBER_ATTRIBUTE, groupMemberAttrDetector.detect());
 
       LOGGER.info("Decorated ambari ldap config : [{}]", ambariLdapConfiguration);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/6fc9fade/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
index 0a309cd..7214fd3 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
@@ -20,7 +20,7 @@ import java.util.Set;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 
-import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
 import org.apache.ambari.server.ldap.service.AmbariLdapException;
 import org.apache.ambari.server.ldap.service.LdapConfigurationService;
 import org.apache.directory.api.ldap.codec.decorators.SearchResultEntryDecorator;

http://git-wip-us.apache.org/repos/asf/ambari/blob/6fc9fade/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionService.java
index 457e23e..1e9c612 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionService.java
@@ -12,25 +12,11 @@
  * limitations under the License.
  */
 
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
 package org.apache.ambari.server.ldap.service.ads;
 
 import javax.inject.Singleton;
 
-import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
 import org.apache.ambari.server.ldap.service.LdapConnectionService;
 import org.apache.directory.ldap.client.api.LdapConnection;
 import org.apache.directory.ldap.client.api.LdapConnectionConfig;

http://git-wip-us.apache.org/repos/asf/ambari/blob/6fc9fade/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java
index 3d335bf..2920588 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java
@@ -17,7 +17,8 @@ package org.apache.ambari.server.ldap.service.ads;
 
 import java.util.Map;
 
-import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.service.AmbariLdapConfigKeys;
 import org.apache.ambari.server.ldap.service.LdapConnectionService;
 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
 import org.apache.directory.ldap.client.api.LdapConnection;
@@ -51,7 +52,7 @@ public class DefaultLdapAttributeDetectionServiceTest {
   public void before() {
 
     Map<String, Object> initialProps = Maps.newHashMap();
-    initialProps.put(AmbariLdapConfiguration.AmbariLdapConfig.BIND_DN.key(), "");
+    initialProps.put(AmbariLdapConfigKeys.BIND_DN.key(), "");
     testLdapConfiguration = new AmbariLdapConfiguration(initialProps);
   }
 
@@ -92,15 +93,15 @@ public class DefaultLdapAttributeDetectionServiceTest {
   private Map<String, Object> getTestPropertiesMap() {
     Map<String, Object> ldapPropsMap = Maps.newHashMap();
 
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.ANONYMOUS_BIND.key(), "true");
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.SERVER_HOST.key(), "ldap.forumsys.com");
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.SERVER_PORT.key(), "389");
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.BIND_DN.key(), "cn=read-only-admin,dc=example,dc=com");
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.BIND_PASSWORD.key(), "password");
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.DN_ATTRIBUTE.key(), SchemaConstants.CN_AT);
+    ldapPropsMap.put(AmbariLdapConfigKeys.ANONYMOUS_BIND.key(), "true");
+    ldapPropsMap.put(AmbariLdapConfigKeys.SERVER_HOST.key(), "ldap.forumsys.com");
+    ldapPropsMap.put(AmbariLdapConfigKeys.SERVER_PORT.key(), "389");
+    ldapPropsMap.put(AmbariLdapConfigKeys.BIND_DN.key(), "cn=read-only-admin,dc=example,dc=com");
+    ldapPropsMap.put(AmbariLdapConfigKeys.BIND_PASSWORD.key(), "password");
+    ldapPropsMap.put(AmbariLdapConfigKeys.DN_ATTRIBUTE.key(), SchemaConstants.CN_AT);
 
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.USER_SEARCH_BASE.key(), "dc=example,dc=com");
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.GROUP_SEARCH_BASE.key(), "dc=example,dc=com");
+    ldapPropsMap.put(AmbariLdapConfigKeys.USER_SEARCH_BASE.key(), "dc=example,dc=com");
+    ldapPropsMap.put(AmbariLdapConfigKeys.GROUP_SEARCH_BASE.key(), "dc=example,dc=com");
 
     return ldapPropsMap;
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/6fc9fade/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
index 1ba6110..449d003 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
@@ -18,7 +18,8 @@ import static org.junit.Assert.assertNotNull;
 
 import java.util.Map;
 
-import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.service.AmbariLdapConfigKeys;
 import org.apache.ambari.server.ldap.service.LdapConfigurationService;
 import org.apache.ambari.server.ldap.service.LdapConnectionService;
 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
@@ -74,14 +75,14 @@ public class DefaultLdapConfigurationServiceTest {
     // GIVEN
     Map<String, Object> ldapPropsMap = Maps.newHashMap();
 
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.ANONYMOUS_BIND.key(), "true");
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.SERVER_HOST.key(), "ldap.forumsys.com");
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.SERVER_PORT.key(), "389");
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.BIND_DN.key(), "dc=example,dc=com");
+    ldapPropsMap.put(AmbariLdapConfigKeys.ANONYMOUS_BIND.key(), "true");
+    ldapPropsMap.put(AmbariLdapConfigKeys.SERVER_HOST.key(), "ldap.forumsys.com");
+    ldapPropsMap.put(AmbariLdapConfigKeys.SERVER_PORT.key(), "389");
+    ldapPropsMap.put(AmbariLdapConfigKeys.BIND_DN.key(), "dc=example,dc=com");
 
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.USER_OBJECT_CLASS.key(), SchemaConstants.PERSON_OC);
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.USER_NAME_ATTRIBUTE.key(), SchemaConstants.UID_AT);
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.USER_SEARCH_BASE.key(), "dc=example,dc=com");
+    ldapPropsMap.put(AmbariLdapConfigKeys.USER_OBJECT_CLASS.key(), SchemaConstants.PERSON_OC);
+    ldapPropsMap.put(AmbariLdapConfigKeys.USER_NAME_ATTRIBUTE.key(), SchemaConstants.UID_AT);
+    ldapPropsMap.put(AmbariLdapConfigKeys.USER_SEARCH_BASE.key(), "dc=example,dc=com");
 
 
     AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(ldapPropsMap);
@@ -96,14 +97,14 @@ public class DefaultLdapConfigurationServiceTest {
     // GIVEN
     Map<String, Object> ldapPropsMap = Maps.newHashMap();
 
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.ANONYMOUS_BIND.key(), "true");
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.SERVER_HOST.key(), "ldap.forumsys.com");
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.SERVER_PORT.key(), "389");
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.BIND_DN.key(), "dc=example,dc=com");
+    ldapPropsMap.put(AmbariLdapConfigKeys.ANONYMOUS_BIND.key(), "true");
+    ldapPropsMap.put(AmbariLdapConfigKeys.SERVER_HOST.key(), "ldap.forumsys.com");
+    ldapPropsMap.put(AmbariLdapConfigKeys.SERVER_PORT.key(), "389");
+    ldapPropsMap.put(AmbariLdapConfigKeys.BIND_DN.key(), "dc=example,dc=com");
 
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.USER_OBJECT_CLASS.key(), SchemaConstants.PERSON_OC);
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.USER_NAME_ATTRIBUTE.key(), SchemaConstants.UID_AT);
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.USER_SEARCH_BASE.key(), "dc=example,dc=com");
+    ldapPropsMap.put(AmbariLdapConfigKeys.USER_OBJECT_CLASS.key(), SchemaConstants.PERSON_OC);
+    ldapPropsMap.put(AmbariLdapConfigKeys.USER_NAME_ATTRIBUTE.key(), SchemaConstants.UID_AT);
+    ldapPropsMap.put(AmbariLdapConfigKeys.USER_SEARCH_BASE.key(), "dc=example,dc=com");
 
 
     AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(ldapPropsMap);


[27/46] ambari git commit: AMBARI-21307 implemented user attribute detection. Organized code

Posted by lp...@apache.org.
AMBARI-21307 implemented user attribute detection. Organized code


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: b05842b2908190e6a79c7f3e336106644bb08808
Parents: 4afe981
Author: lpuskas <lp...@apache.org>
Authored: Tue Sep 12 08:10:47 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:41:59 2017 +0200

----------------------------------------------------------------------
 .../services/ldap/LdapConfigurationService.java |   2 +-
 .../server/ldap/AmbariLdapConfiguration.java    |   9 ++
 .../server/ldap/service/AmbariLdapFacade.java   |   2 +-
 .../server/ldap/service/AttributeDetector.java  |  38 ++++++
 .../service/LdapAttributeDetectionService.java  |   7 +-
 .../ambari/server/ldap/service/LdapFacade.java  |   2 +-
 .../server/ldap/service/LdapSearchService.java  |  18 ---
 .../ads/DefaultAttributeDetectionService.java   | 132 ++++++++++++++++++-
 .../ads/DefaultLdapConfigurationService.java    |   2 +-
 .../ldap/service/ads/ObjectClassDetector.java   |  81 ++++++++++++
 .../ads/OccurranceAndWeightBasedDetector.java   |  81 ++++++++++++
 .../service/ads/UserNameAttributeDetector.java  |  75 +++++++++++
 .../DefaultAttributeDetectionServiceTest.java   |  35 ++---
 13 files changed, 440 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b05842b2/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
index 1b8427b..66809c3 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
@@ -107,7 +107,7 @@ public class LdapConfigurationService extends AmbariConfigurationService {
         case TEST_ATTRIBUTES:
 
           LOGGER.info("Testing LDAP attributes ....");
-          groups = ldapFacade.checkLdapAttibutes(ldapConfigurationRequest.getRequestInfo().getParameters(), ambariLdapConfiguration);
+          groups = ldapFacade.checkLdapAttributes(ldapConfigurationRequest.getRequestInfo().getParameters(), ambariLdapConfiguration);
           setResult(groups, result);
 
           break;

http://git-wip-us.apache.org/repos/asf/ambari/blob/b05842b2/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
index 76faeed..e28c6ed 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
@@ -98,6 +98,10 @@ public class AmbariLdapConfiguration {
     return value;
   }
 
+  public void setValueFor(AmbariLdapConfig ambariLdapConfig, Object value) {
+    configurationMap.put(ambariLdapConfig.key(), value);
+  }
+
   @Inject
   public AmbariLdapConfiguration(@Assisted Map<String, Object> configuration) {
     this.configurationMap = configuration;
@@ -219,4 +223,9 @@ public class AmbariLdapConfiguration {
     return (String) configValue(AmbariLdapConfig.REFERRAL_HANDLING);
   }
 
+
+  @Override
+  public String toString() {
+    return configurationMap.toString();
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/b05842b2/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
index 16bf6b7..f159418 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
@@ -90,7 +90,7 @@ public class AmbariLdapFacade implements LdapFacade {
   }
 
   @Override
-  public Set<String> checkLdapAttibutes(Map<String, Object> parameters, AmbariLdapConfiguration ldapConfiguration) throws AmbariLdapException {
+  public Set<String> checkLdapAttributes(Map<String, Object> parameters, AmbariLdapConfiguration ldapConfiguration) throws AmbariLdapException {
     String userName = getTestUserNameFromParameters(parameters);
     String testUserPass = getTestUserPasswordFromParameters(parameters);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/b05842b2/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AttributeDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AttributeDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AttributeDetector.java
new file mode 100644
index 0000000..3e20a6a
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AttributeDetector.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service;
+
+/**
+ * Operations for detecting LDAP related settings.
+ * Attributes and values are detected based on a sample set of results returned from a search
+ */
+public interface AttributeDetector<T> {
+
+  /**
+   * Collects potential attribute names or values from a set of result entries.
+   *
+   * @param entry a result entry returned by a search operation
+   */
+  void collect(T entry);
+
+  /**
+   * Implements the decision based on whiche the "best" possible attribute or value is selected.
+   *
+   * @return the most probable attribute name or value (based on the logic in the implementer)
+   */
+  String detect();
+
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/b05842b2/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapAttributeDetectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapAttributeDetectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapAttributeDetectionService.java
index 70a8977..4cfa81e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapAttributeDetectionService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapAttributeDetectionService.java
@@ -15,12 +15,11 @@
 package org.apache.ambari.server.ldap.service;
 
 import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
-import org.apache.directory.ldap.client.api.LdapConnection;
 
 /**
  * Contract defining operations to detect user and group attributes.
  */
-public interface LdapAttributeDetectionService {
+public interface LdapAttributeDetectionService<T> {
 
   /**
    * Decorates the passed in configuration with the detected ldap user attribute values
@@ -29,7 +28,7 @@ public interface LdapAttributeDetectionService {
    * @param ambariLdapConfiguration configuration instance holding connection details
    * @return the configuration decorated with user related attributes
    */
-  AmbariLdapConfiguration detectLdapUserAttributes(LdapConnection ldapConnection, AmbariLdapConfiguration ambariLdapConfiguration);
+  AmbariLdapConfiguration detectLdapUserAttributes(T ldapConnection, AmbariLdapConfiguration ambariLdapConfiguration);
 
   /**
    * Decorates the passed in configuration with the detected ldap group attribute values
@@ -38,6 +37,6 @@ public interface LdapAttributeDetectionService {
    * @param ambariLdapConfiguration configuration instance holding connection details
    * @return the configuration decorated with group related attributes
    */
-  AmbariLdapConfiguration detectLdapGroupAttributes(LdapConnection ldapConnection, AmbariLdapConfiguration ambariLdapConfiguration);
+  AmbariLdapConfiguration detectLdapGroupAttributes(T ldapConnection, AmbariLdapConfiguration ambariLdapConfiguration);
 }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/b05842b2/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
index 76b16c4..7cd25da 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
@@ -48,5 +48,5 @@ public interface LdapFacade {
    * @param ambariLdapConfiguration configutration instance with available attributes
    * @throws AmbariLdapException if the attribute checking fails
    */
-  Set<String> checkLdapAttibutes(Map<String, Object> parameters, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException;
+  Set<String> checkLdapAttributes(Map<String, Object> parameters, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException;
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/b05842b2/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapSearchService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapSearchService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapSearchService.java
deleted file mode 100644
index f1abc8b..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapSearchService.java
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.service;
-
-public interface LdapSearchService {
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/b05842b2/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionService.java
index 55d0765..710adf1 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionService.java
@@ -14,19 +14,47 @@
 
 package org.apache.ambari.server.ldap.service.ads;
 
+import java.util.Set;
+
 import javax.inject.Inject;
 import javax.inject.Singleton;
 
 import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.service.AmbariLdapException;
+import org.apache.ambari.server.ldap.service.AttributeDetector;
 import org.apache.ambari.server.ldap.service.LdapAttributeDetectionService;
+import org.apache.directory.api.ldap.model.cursor.SearchCursor;
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.apache.directory.api.ldap.model.message.Response;
+import org.apache.directory.api.ldap.model.message.SearchRequest;
+import org.apache.directory.api.ldap.model.message.SearchRequestImpl;
+import org.apache.directory.api.ldap.model.message.SearchResultEntry;
+import org.apache.directory.api.ldap.model.message.SearchScope;
+import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.api.util.Strings;
 import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.search.FilterBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.Sets;
+
 @Singleton
-public class DefaultAttributeDetectionService implements LdapAttributeDetectionService {
+public class DefaultAttributeDetectionService implements LdapAttributeDetectionService<LdapConnection> {
 
   private static final Logger LOGGER = LoggerFactory.getLogger(DefaultAttributeDetectionService.class);
+  private static final int SAMPLE_RESULT_SIZE = 50;
+
+  // ordered list of possible username attribute values (the most significant valus should be first)
+
+  private static final Set<String> USER_OBJECT_CLASS_VALUES = Sets.newHashSet("person", "posixAccount");
+  private static final Set<String> USER_GROUP_MEMBER_ATTR_VALUES = Sets.newHashSet("memberOf", "ismemberOf");
+
+  @Inject
+  private UserNameAttributeDetector userNameAttrDetector = new UserNameAttributeDetector(); // todo remove instantition
+
+  @Inject
+  private ObjectClassDetector objectClassDetector = new ObjectClassDetector(); // todo remove instantition
 
   @Inject
   public DefaultAttributeDetectionService() {
@@ -36,7 +64,72 @@ public class DefaultAttributeDetectionService implements LdapAttributeDetectionS
   public AmbariLdapConfiguration detectLdapUserAttributes(LdapConnection connection, AmbariLdapConfiguration ambariLdapConfiguration) {
     LOGGER.info("Detecting LDAP user attributes ...");
 
-    return null;
+    // perform a search using the user search base
+    if (Strings.isEmpty(ambariLdapConfiguration.userSearchBase())) {
+      LOGGER.warn("No user search base provided");
+      return ambariLdapConfiguration;
+    }
+
+    SearchCursor searchCursor = null;
+
+    try {
+      // todo should the bind operation be done in the facade?
+      connection.bind(ambariLdapConfiguration.bindDn(), ambariLdapConfiguration.bindPassword());
+
+      SearchRequest searchRequest = assembleSearchRequest(ambariLdapConfiguration);
+
+      // do the search
+      searchCursor = connection.search(searchRequest);
+
+      int processedUserCnt = 0;
+
+      while (searchCursor.next()) {
+
+        if (processedUserCnt >= SAMPLE_RESULT_SIZE) {
+          LOGGER.debug("The maximum count of results for attribute detection has exceeded. Quit user attribute detection.");
+          break;
+        }
+
+        Response response = searchCursor.get();
+        // process the SearchResultEntry
+
+        if (response instanceof SearchResultEntry) {
+          Entry resultEntry = ((SearchResultEntry) response).getEntry();
+          LOGGER.info("Processing sample entry: [{}]", resultEntry.getDn());
+          userNameAttrDetector.collect(resultEntry);
+          objectClassDetector.collect(resultEntry);
+          processedUserCnt++;
+        }
+      }
+
+      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.USER_NAME_ATTRIBUTE, userNameAttrDetector.detect());
+      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.USER_OBJECT_CLASS, objectClassDetector.detect());
+
+      LOGGER.info("Decorated ambari ldap config : [{}]", ambariLdapConfiguration);
+
+    } catch (Exception e) {
+
+      LOGGER.error("Ldap operation failed", e);
+    } finally {
+      // housekeeping
+      if (null != searchCursor) {
+        searchCursor.close();
+      }
+    }
+
+    return ambariLdapConfiguration;
+  }
+
+  private void detectUserAttributes(Entry resultEntry, AttributeDetector attributeDetector) {
+
+    attributeDetector.collect(resultEntry);
+
+//    Set<String> objectClasses = detectUserObjectClass(resultEntry);
+//    if (!objectClasses.isEmpty()) {
+//      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.USER_OBJECT_CLASS, StringUtils.join(objectClasses, ","));
+//    }
+
+
   }
 
   @Override
@@ -44,4 +137,39 @@ public class DefaultAttributeDetectionService implements LdapAttributeDetectionS
     LOGGER.info("Detecting LDAP group attributes ...");
     return null;
   }
+
+  private SearchRequest assembleSearchRequest(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+    try {
+
+      SearchRequest req = new SearchRequestImpl();
+      req.setScope(SearchScope.SUBTREE);
+      req.addAttributes("*");
+      req.setTimeLimit(0);
+      req.setBase(new Dn(ambariLdapConfiguration.userSearchBase()));
+      // the filter must be set!
+      req.setFilter(FilterBuilder.present(ambariLdapConfiguration.dnAttribute()).toString());
+
+      return req;
+
+    } catch (Exception e) {
+      LOGGER.error("Could not assemble ldap search request", e);
+      throw new AmbariLdapException(e);
+    }
+  }
+
+
+  private Set<String> detectUserObjectClass(Entry entry) {
+    LOGGER.info("Detecting user object class. Attributes: {}", entry.getAttributes());
+    throw new UnsupportedOperationException("Not yet implemented");
+  }
+
+  private String detectGroupNameAttribute(Entry entry) {
+    throw new UnsupportedOperationException("Not yet implemented");
+  }
+
+  private Set<String> detectGroupObjectClass(Entry entry) {
+    throw new UnsupportedOperationException("Not yet implemented");
+  }
+
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/b05842b2/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
index db8c77f..fa2e44b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
@@ -190,7 +190,7 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
       LOGGER.debug("Anonimous binding not supported, binding with the manager detailas...");
       connection.bind(ambariLdapConfiguration.bindDn(), ambariLdapConfiguration.bindPassword());
     } else {
-      LOGGER.debug("Binding anonimously ...");
+      LOGGER.debug("Binding anonymously ...");
       connection.bind();
     }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/b05842b2/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/ObjectClassDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/ObjectClassDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/ObjectClassDetector.java
new file mode 100644
index 0000000..2613517
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/ObjectClassDetector.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads;
+
+import java.util.Map;
+
+import javax.inject.Inject;
+
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Maps;
+
+public class ObjectClassDetector extends OccurranceAndWeightBasedDetector {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(ObjectClassDetector.class);
+  private Map<String, Integer> occurranceMap = Maps.newHashMap();
+  private Map<String, Integer> weightsMap = Maps.newHashMap();
+
+
+  private enum ObjectClassValue {
+    PERSON("person", 1),
+    POSIX_ACCOUNT("posixAccount", 1);
+
+    private String ocVal;
+    private Integer weight;
+
+    ObjectClassValue(String attr, Integer weght) {
+      this.ocVal = attr;
+      this.weight = weght;
+    }
+
+    Integer weight() {
+      return this.weight;
+    }
+
+    String ocVal() {
+      return this.ocVal;
+    }
+
+  }
+
+  @Inject
+  public ObjectClassDetector() {
+    for (ObjectClassValue ocVal : ObjectClassValue.values()) {
+      occurranceMap.put(ocVal.ocVal(), 0);
+      weightsMap.put(ocVal.ocVal(), ocVal.weight());
+    }
+
+  }
+
+  @Override
+  protected Map<String, Integer> occurranceMap() {
+    return occurranceMap;
+  }
+
+  @Override
+  protected Map<String, Integer> weightsMap() {
+    return weightsMap;
+  }
+
+  @Override
+  protected boolean applies(Entry entry, String value) {
+    LOGGER.info("Checking for object class [{}] in entry [{}]", value, entry.getDn());
+    return entry.hasObjectClass(value);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/b05842b2/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/OccurranceAndWeightBasedDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/OccurranceAndWeightBasedDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/OccurranceAndWeightBasedDetector.java
new file mode 100644
index 0000000..32dc238
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/OccurranceAndWeightBasedDetector.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads;
+
+import java.util.Map;
+
+import org.apache.ambari.server.ldap.service.AttributeDetector;
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class OccurranceAndWeightBasedDetector implements AttributeDetector<Entry> {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(OccurranceAndWeightBasedDetector.class);
+
+  protected abstract Map<String, Integer> occurranceMap();
+
+  protected abstract Map<String, Integer> weightsMap();
+
+  protected abstract boolean applies(Entry entry, String value);
+
+  @Override
+  public String detect() {
+    Map.Entry<String, Integer> selectedEntry = null;
+
+    for (Map.Entry<String, Integer> entry : occurranceMap().entrySet()) {
+      if (selectedEntry == null) {
+
+        selectedEntry = entry;
+        LOGGER.info("Initial name attribute: {}", selectedEntry);
+        continue;
+
+      }
+
+      if (selectedEntry.getValue() < entry.getValue()) {
+
+        LOGGER.info("Changing potential name attribute from : [{}] to: [{}]", selectedEntry, entry);
+        selectedEntry = entry;
+
+      }
+    }
+    return selectedEntry.getKey();
+  }
+
+  @Override
+  public void collect(Entry entry) {
+    LOGGER.info("Detecting ldap attributes/values ...");
+
+    for (String attributeValue : occurranceMap().keySet()) {
+      if (applies(entry, attributeValue)) {
+
+        Integer cnt = occurranceMap().get(attributeValue).intValue();
+        if (weightsMap().containsKey(attributeValue)) {
+          cnt = cnt + weightsMap().get(attributeValue);
+        } else {
+          cnt = cnt + 1;
+        }
+        occurranceMap().put(attributeValue, cnt);
+
+        LOGGER.info("Collected potential name attr: {}, count: {}", attributeValue, cnt);
+
+      } else {
+        LOGGER.info("The result entry doesn't contain the attribute: [{}]", attributeValue);
+      }
+    }
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/b05842b2/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/UserNameAttributeDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/UserNameAttributeDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/UserNameAttributeDetector.java
new file mode 100644
index 0000000..bbb4b43
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/UserNameAttributeDetector.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads;
+
+import java.util.Map;
+
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Maps;
+
+public class UserNameAttributeDetector extends OccurranceAndWeightBasedDetector {
+  private static final Logger LOGGER = LoggerFactory.getLogger(UserNameAttributeDetector.class);
+
+  private Map<String, Integer> occurranceMap = Maps.newHashMap();
+  private Map<String, Integer> weightsMap = Maps.newHashMap();
+
+  private enum NameAttrs {
+    SAM_ACCOUNT_NAME("sAMAccountName", 5),
+    UID("uid", 3),
+    CN("cn", 1);
+
+    private String attrName;
+    private Integer weight;
+
+    NameAttrs(String attr, Integer weght) {
+      this.attrName = attr;
+      this.weight = weght;
+    }
+
+    Integer weight() {
+      return this.weight;
+    }
+
+    String attrName() {
+      return this.attrName;
+    }
+
+  }
+
+  public UserNameAttributeDetector() {
+    for (NameAttrs nameAttr : NameAttrs.values()) {
+      occurranceMap.put(nameAttr.attrName(), 0);
+      weightsMap.put(nameAttr.attrName(), nameAttr.weight());
+    }
+  }
+
+  protected Map<String, Integer> occurranceMap() {
+    return occurranceMap;
+  }
+
+  protected Map<String, Integer> weightsMap() {
+    return weightsMap;
+  }
+
+  @Override
+  protected boolean applies(Entry entry, String value) {
+    LOGGER.info("Checking for attribute  [{}] in entry [{}]", value, entry.getDn());
+    return entry.containsAttribute(value);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/b05842b2/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionServiceTest.java
index 5b3ac20..5cddf1a 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionServiceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionServiceTest.java
@@ -69,13 +69,31 @@ public class DefaultAttributeDetectionServiceTest {
   }
 
 
+  @Test
+  public void functionalTest() throws Exception {
+    // GIVEN
+    AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(getTestPropertiesMap());
+    LdapConnectionService connectionService = new DefaultLdapConnectionService();
+    LdapNetworkConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
+
+    // WHEN
+    AmbariLdapConfiguration config = attributeDetectionService.detectLdapUserAttributes(ldapConnection, ambariLdapConfiguration);
+
+    // THEN
+
+    ldapConnection.close();
+
+  }
+
   private Map<String, Object> getTestPropertiesMap() {
     Map<String, Object> ldapPropsMap = Maps.newHashMap();
 
     ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.ANONYMOUS_BIND.key(), "true");
     ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.SERVER_HOST.key(), "ldap.forumsys.com");
     ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.SERVER_PORT.key(), "389");
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.BIND_DN.key(), "dc=example,dc=com");
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.BIND_DN.key(), "cn=read-only-admin,dc=example,dc=com");
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.BIND_PASSWORD.key(), "password");
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.DN_ATTRIBUTE.key(), SchemaConstants.CN_AT);
 
     ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.USER_OBJECT_CLASS.key(), SchemaConstants.PERSON_OC);
     ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.USER_NAME_ATTRIBUTE.key(), SchemaConstants.UID_AT);
@@ -84,19 +102,4 @@ public class DefaultAttributeDetectionServiceTest {
     return ldapPropsMap;
 
   }
-
-  @Test
-  public void functionalTest() throws Exception {
-    // GIVEN
-    AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(getTestPropertiesMap());
-    LdapConnectionService connectionService = new DefaultLdapConnectionService();
-    LdapNetworkConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
-
-
-    // WHEN
-    AmbariLdapConfiguration config = attributeDetectionService.detectLdapUserAttributes(ldapConnection, ambariLdapConfiguration);
-
-    // THEN
-
-  }
 }
\ No newline at end of file


[15/46] ambari git commit: Added swagger annotations to the new endpoint

Posted by lp...@apache.org.
Added swagger annotations to the new endpoint


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: afc57b7481bef15ab8d1d04d5814a2760d024795
Parents: f55185c
Author: Balázs Bence Sári <bs...@hortonworks.com>
Authored: Thu Jul 6 18:36:18 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:41:56 2017 +0200

----------------------------------------------------------------------
 .../AmbariConfigurationRequestSwagger.java      | 48 +++++++++++++++
 .../AmbariConfigurationResponseSwagger.java     | 40 +++++++++++++
 .../services/AmbariConfigurationService.java    | 62 +++++++++++++++++---
 3 files changed, 143 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/afc57b74/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationRequestSwagger.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationRequestSwagger.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationRequestSwagger.java
new file mode 100644
index 0000000..d6714f9
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationRequestSwagger.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.server.api.services;
+
+import java.util.Map;
+
+import org.apache.ambari.server.controller.ApiModel;
+import org.apache.ambari.server.orm.entities.ConfigurationBaseEntity;
+
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * Request data model for {@link org.apache.ambari.server.api.services.AmbariConfigurationService}
+ */
+public interface AmbariConfigurationRequestSwagger extends ApiModel {
+
+  @ApiModelProperty(name = "AmbariConfiguration")
+  AmbariConfigurationRequestInfo getAmbariConfiguration();
+
+  interface AmbariConfigurationRequestInfo {
+    @ApiModelProperty
+    Long getId();
+
+    @ApiModelProperty
+    Map<String, Object> getData();
+
+    @ApiModelProperty
+    String getType();
+
+    @ApiModelProperty
+    Long getVersion();
+
+    @ApiModelProperty(name = "version_tag")
+    String getVersionTag();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/afc57b74/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationResponseSwagger.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationResponseSwagger.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationResponseSwagger.java
new file mode 100644
index 0000000..c55ac1d
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationResponseSwagger.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.server.api.services;
+
+import java.util.Map;
+
+import org.apache.ambari.server.controller.ApiModel;
+
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * Response data model for {@link org.apache.ambari.server.api.services.AmbariConfigurationService}
+ */
+public interface AmbariConfigurationResponseSwagger extends ApiModel {
+
+  @ApiModelProperty(name = "AmbariConfiguration")
+  AmbariConfigurationResponseInfo getAmbariConfigurationResponse();
+
+  interface AmbariConfigurationResponseInfo {
+    @ApiModelProperty
+    Long getId();
+
+    @ApiModelProperty
+    Map<String, Object> getData();
+
+    @ApiModelProperty
+    String getType();
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/afc57b74/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java
index 0fa6e44..0c159b9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java
@@ -70,9 +70,12 @@ import io.swagger.annotations.ApiResponses;
  * </pre>
  */
 @Path("/configurations/")
-@Api(value = "/configurations", description = "Endpoint for Ambari configuration related operations")
+@Api(value = "Ambari Configurations", description = "Endpoint for Ambari configuration related operations")
 public class AmbariConfigurationService extends BaseService {
 
+  private static final String AMBARI_CONFIGURATION_REQUEST_TYPE =
+      "org.apache.ambari.server.api.services.AmbariConfigurationRequestSwagger";
+
   /**
    * Creates an ambari configuration resource.
    *
@@ -83,9 +86,10 @@ public class AmbariConfigurationService extends BaseService {
    */
   @POST
   @Produces(MediaType.TEXT_PLAIN)
-  @ApiOperation(value = "Creates an ambari configuration resource")
+  @ApiOperation(value = "Creates an ambari configuration resource",
+      nickname = "AmbariConfigurationService#createAmbariConfiguration")
   @ApiImplicitParams({
-    @ApiImplicitParam(dataType = "", paramType = PARAM_TYPE_BODY)
+      @ApiImplicitParam(dataType = AMBARI_CONFIGURATION_REQUEST_TYPE, paramType = PARAM_TYPE_BODY)
   })
   @ApiResponses({
     @ApiResponse(code = HttpStatus.SC_CREATED, message = MSG_SUCCESSFUL_OPERATION),
@@ -103,7 +107,26 @@ public class AmbariConfigurationService extends BaseService {
 
   @GET
   @Produces(MediaType.TEXT_PLAIN)
-  @ApiOperation(value = "Retrieve ambari configuration resources")
+  @ApiOperation(value = "Retrieve all ambari configuration resources",
+      nickname = "AmbariConfigurationService#getAmbariConfigurations",
+      notes = "Returns all Ambari configurations.",
+      response = AmbariConfigurationResponseSwagger.class,
+      responseContainer = RESPONSE_CONTAINER_LIST)
+  @ApiImplicitParams({
+      @ApiImplicitParam(name = QUERY_FIELDS, value = QUERY_FILTER_DESCRIPTION,
+          defaultValue = "AmbariConfiguration/data, AmbariConfiguration/id, AmbariConfiguration/type",
+          dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY),
+      @ApiImplicitParam(name = QUERY_SORT, value = QUERY_SORT_DESCRIPTION,
+          defaultValue = "AmbariConfiguration/id",
+          dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY),
+      @ApiImplicitParam(name = QUERY_PAGE_SIZE, value = QUERY_PAGE_SIZE_DESCRIPTION, defaultValue = DEFAULT_PAGE_SIZE, dataType = DATA_TYPE_INT, paramType = PARAM_TYPE_QUERY),
+      @ApiImplicitParam(name = QUERY_FROM, value = QUERY_FROM_DESCRIPTION, defaultValue = DEFAULT_FROM, dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY),
+      @ApiImplicitParam(name = QUERY_TO, value = QUERY_TO_DESCRIPTION, dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY)
+  })
+  @ApiResponses(value = {
+      @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION),
+      @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR)
+  })
   public Response getAmbariConfigurations(String body, @Context HttpHeaders headers, @Context UriInfo uri) {
     return handleRequest(headers, body, uri, Request.Type.GET, createResource(Resource.Type.AmbariConfiguration,
       Collections.EMPTY_MAP));
@@ -112,7 +135,18 @@ public class AmbariConfigurationService extends BaseService {
   @GET
   @Path("{configurationId}")
   @Produces(MediaType.TEXT_PLAIN)
-  @ApiOperation(value = "Retrieve ambari configuration resource")
+  @ApiOperation(value = "Retrieve the details of an ambari configuration resource",
+      nickname = "AmbariConfigurationService#getAmbariConfiguration",
+      response = AmbariConfigurationResponseSwagger.class)
+  @ApiImplicitParams({
+      @ApiImplicitParam(name = QUERY_FIELDS, value = QUERY_FILTER_DESCRIPTION, defaultValue = "AmbariConfiguration/*",
+          dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY)
+  })
+  @ApiResponses(value = {
+      @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION),
+      @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND),
+      @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR)
+  })
   public Response getAmbariConfiguration(String body, @Context HttpHeaders headers, @Context UriInfo uri,
                                          @PathParam("configurationId") String configurationId) {
     return handleRequest(headers, body, uri, Request.Type.GET, createResource(Resource.Type.AmbariConfiguration,
@@ -121,7 +155,20 @@ public class AmbariConfigurationService extends BaseService {
 
   @PUT
   @Produces(MediaType.TEXT_PLAIN)
-  @ApiOperation(value = "Update ambari configuration resources")
+  @ApiOperation(value = "Updates ambari configuration resources - Not implemented yet",
+    nickname = "AmbariConfigurationService#updateAmbariConfiguration")
+  @ApiImplicitParams({
+      @ApiImplicitParam(dataType = AMBARI_CONFIGURATION_REQUEST_TYPE, paramType = PARAM_TYPE_BODY)
+  })
+  @ApiResponses({
+      @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION),
+      @ApiResponse(code = HttpStatus.SC_ACCEPTED, message = MSG_REQUEST_ACCEPTED),
+      @ApiResponse(code = HttpStatus.SC_BAD_REQUEST, message = MSG_INVALID_ARGUMENTS),
+      @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND),
+      @ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = MSG_NOT_AUTHENTICATED),
+      @ApiResponse(code = HttpStatus.SC_FORBIDDEN, message = MSG_PERMISSION_DENIED),
+      @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR),
+  })
   public Response updateAmbariConfiguration() {
     throw new UnsupportedOperationException("Not yet implemented");
   }
@@ -129,7 +176,8 @@ public class AmbariConfigurationService extends BaseService {
   @DELETE
   @Path("{configurationId}")
   @Produces(MediaType.TEXT_PLAIN)
-  @ApiOperation(value = "Deletes an ambari configuration resource")
+  @ApiOperation(value = "Deletes an ambari configuration resource",
+      nickname = "AmbariConfigurationService#deleteAmbariConfiguration")
   @ApiResponses({
     @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION),
     @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND),


[04/46] ambari git commit: AMBARI-22258. Use correct property attribute setter fn(). while setting 'tez.runtime.io.sort.mb' maximum value.

Posted by lp...@apache.org.
AMBARI-22258. Use correct property attribute setter fn(). while setting 'tez.runtime.io.sort.mb' maximum value.


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: b9f26708dd19c444918ea9b21150f66236fcdf2d
Parents: c924ebd
Author: Swapan Shridhar <ss...@hortonworks.com>
Authored: Tue Oct 17 13:03:31 2017 -0700
Committer: Swapan Shridhar <ss...@hortonworks.com>
Committed: Tue Oct 17 13:04:52 2017 -0700

----------------------------------------------------------------------
 .../src/main/resources/stacks/HDP/2.5/services/stack_advisor.py | 3 ++-
 .../src/test/python/stacks/2.5/common/test_stack_advisor.py     | 5 ++++-
 2 files changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b9f26708/ambari-server/src/main/resources/stacks/HDP/2.5/services/stack_advisor.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.5/services/stack_advisor.py b/ambari-server/src/main/resources/stacks/HDP/2.5/services/stack_advisor.py
index 92ce9b9..b6f2478 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.5/services/stack_advisor.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.5/services/stack_advisor.py
@@ -860,6 +860,7 @@ class HDP25StackAdvisor(HDP24StackAdvisor):
     putHiveInteractiveEnvProperty = self.putProperty(configurations, "hive-interactive-env", services)
     putHiveInteractiveEnvPropertyAttribute = self.putPropertyAttribute(configurations, "hive-interactive-env")
     putTezInteractiveSiteProperty = self.putProperty(configurations, "tez-interactive-site", services)
+    putTezInteractiveSitePropertyAttribute = self.putPropertyAttribute(configurations, "tez-interactive-site")
     llap_daemon_selected_queue_name = None
     selected_queue_is_ambari_managed_llap = None  # Queue named 'llap' at root level is Ambari managed.
     llap_selected_queue_am_percent = None
@@ -1331,7 +1332,7 @@ class HDP25StackAdvisor(HDP24StackAdvisor):
     putTezInteractiveSiteProperty('tez.runtime.io.sort.mb', tez_runtime_io_sort_mb)
     if "tez-site" in services["configurations"] and "tez.runtime.sorter.class" in services["configurations"]["tez-site"]["properties"]:
       if services["configurations"]["tez-site"]["properties"]["tez.runtime.sorter.class"] == "LEGACY":
-        putTezInteractiveSiteProperty("tez.runtime.io.sort.mb", "maximum", 1800)
+        putTezInteractiveSitePropertyAttribute("tez.runtime.io.sort.mb", "maximum", 1800)
 
     putTezInteractiveSiteProperty('tez.runtime.unordered.output.buffer.size-mb', tez_runtime_unordered_output_buffer_size)
     putHiveInteractiveSiteProperty('hive.auto.convert.join.noconditionaltask.size', hive_auto_convert_join_noconditionaltask_size)

http://git-wip-us.apache.org/repos/asf/ambari/blob/b9f26708/ambari-server/src/test/python/stacks/2.5/common/test_stack_advisor.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.5/common/test_stack_advisor.py b/ambari-server/src/test/python/stacks/2.5/common/test_stack_advisor.py
index cf462de..407e78d 100644
--- a/ambari-server/src/test/python/stacks/2.5/common/test_stack_advisor.py
+++ b/ambari-server/src/test/python/stacks/2.5/common/test_stack_advisor.py
@@ -4446,7 +4446,8 @@ class TestHDP25StackAdvisor(TestCase):
           },
         "tez-site": {
           "properties": {
-            "tez.am.resource.memory.mb": "1024"
+            "tez.am.resource.memory.mb": "1024",
+            "tez.runtime.sorter.class": "LEGACY"
           }
         },
       }
@@ -4481,6 +4482,8 @@ class TestHDP25StackAdvisor(TestCase):
 
     self.assertEqual(configurations['hive-interactive-site']['properties']['hive.llap.io.memory.size'], '186368')
     self.assertEqual(configurations['hive-interactive-env']['properties']['llap_heap_size'], '9830')
+    self.assertEqual(configurations['tez-interactive-site']['properties']['tez.runtime.io.sort.mb'], '1092')
+    self.assertEquals(configurations['tez-interactive-site']['property_attributes']['tez.runtime.io.sort.mb'], {'maximum': '1800'})
 
 
 


[22/46] ambari git commit: AMBARI-21307 Draft skimplementation for the user related ldap config attribute validation

Posted by lp...@apache.org.
AMBARI-21307 Draft skimplementation for the user related ldap config attribute validation


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 5f2fbc15414c615085185b7f610f9eb459f3906c
Parents: 5f35e4d
Author: lpuskas <lp...@apache.org>
Authored: Tue Jul 18 17:48:07 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:41:57 2017 +0200

----------------------------------------------------------------------
 ambari-project/pom.xml                          |   1 +
 ambari-server/pom.xml                           |   5 +
 .../AmbariConfigurationRequestSwagger.java      |   1 -
 .../services/ldap/AmbariConfigurationDTO.java   |  67 +++++++
 .../ldap/LdapCheckConfigurationRequest.java     |  47 +++++
 .../api/services/ldap/LdapOperationRequest.java |  18 ++
 .../api/services/ldap/LdapRequestInfo.java      |  61 +++++++
 .../api/services/ldap/LdapRestService.java      | 132 ++++++++++++++
 .../ambari/server/controller/AmbariServer.java  |   3 +-
 .../server/controller/ControllerModule.java     |   1 +
 .../server/ldap/AmbariLdapConfiguration.java    | 129 ++++++++++++++
 .../server/ldap/LdapConfigurationFactory.java   |  21 +++
 .../ldap/LdapConfigurationValidatorService.java |  52 ++++++
 .../apache/ambari/server/ldap/LdapModule.java   |  37 ++++
 .../ldap/service/AmbariLdapException.java       |  33 ++++
 .../server/ldap/service/AmbariLdapFacade.java   | 107 +++++++++++
 .../ambari/server/ldap/service/LdapFacade.java  |  52 ++++++
 .../server/ldap/service/LdapSearchService.java  |  18 ++
 .../ad/AdLdapConfigurationValidatorService.java | 177 +++++++++++++++++++
 .../service/ad/LdapConfigurationConverter.java  |  50 ++++++
 .../api/services/ldap/LDAPServiceTest.java      |  85 +++++++++
 ...AdLdapConfigurationValidatorServiceTest.java | 129 ++++++++++++++
 22 files changed, 1224 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/5f2fbc15/ambari-project/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-project/pom.xml b/ambari-project/pom.xml
index 00ba1bc..e4d4423 100644
--- a/ambari-project/pom.xml
+++ b/ambari-project/pom.xml
@@ -31,6 +31,7 @@
     <ambari.dir>${project.parent.basedir}</ambari.dir>
     <powermock.version>1.6.3</powermock.version>
     <jetty.version>8.1.19.v20160209</jetty.version>
+    <ldap-api.version>1.0.0</ldap-api.version>
     <checkstyle.version>6.19</checkstyle.version> <!-- last version that does not require Java 8 -->
     <swagger.version>1.5.10</swagger.version>
     <swagger.maven.plugin.version>3.1.4</swagger.maven.plugin.version>

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f2fbc15/ambari-server/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-server/pom.xml b/ambari-server/pom.xml
index e250da7..8d52821 100644
--- a/ambari-server/pom.xml
+++ b/ambari-server/pom.xml
@@ -1689,6 +1689,11 @@
       <version>4.2.2</version>
     </dependency>
     <dependency>
+      <groupId>org.apache.directory.api</groupId>
+      <artifactId>api-all</artifactId>
+      <version>${ldap-api.version}</version>
+    </dependency>
+    <dependency>
       <groupId>com.networknt</groupId>
       <artifactId>json-schema-validator</artifactId>
       <version>0.1.10</version>

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f2fbc15/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationRequestSwagger.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationRequestSwagger.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationRequestSwagger.java
index d6714f9..5e8094e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationRequestSwagger.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationRequestSwagger.java
@@ -16,7 +16,6 @@ package org.apache.ambari.server.api.services;
 import java.util.Map;
 
 import org.apache.ambari.server.controller.ApiModel;
-import org.apache.ambari.server.orm.entities.ConfigurationBaseEntity;
 
 import io.swagger.annotations.ApiModelProperty;
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f2fbc15/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/AmbariConfigurationDTO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/AmbariConfigurationDTO.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/AmbariConfigurationDTO.java
new file mode 100644
index 0000000..1b134fe
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/AmbariConfigurationDTO.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.api.services.ldap;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+public class AmbariConfigurationDTO {
+  private String type;
+  private Set<Map<String, Object>> data = Collections.emptySet();
+  private String versionTag;
+  private Integer version;
+  private long createdTs;
+
+  public String getType() {
+    return type;
+  }
+
+  public void setType(String type) {
+    this.type = type;
+  }
+
+  public Set<Map<String, Object>> getData() {
+    return data;
+  }
+
+  public void setData(Set<Map<String, Object>> data) {
+    this.data = data;
+  }
+
+  public String getVersionTag() {
+    return versionTag;
+  }
+
+  public void setVersionTag(String versionTag) {
+    this.versionTag = versionTag;
+  }
+
+  public Integer getVersion() {
+    return version;
+  }
+
+  public void setVersion(Integer version) {
+    this.version = version;
+  }
+
+  public long getCreatedTs() {
+    return createdTs;
+  }
+
+  public void setCreatedTs(long createdTs) {
+    this.createdTs = createdTs;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f2fbc15/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapCheckConfigurationRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapCheckConfigurationRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapCheckConfigurationRequest.java
new file mode 100644
index 0000000..188f1b9
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapCheckConfigurationRequest.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.api.services.ldap;
+
+
+import com.google.gson.annotations.SerializedName;
+
+public class LdapCheckConfigurationRequest implements LdapOperationRequest {
+
+  @SerializedName("AmbariConfiguration")
+  private AmbariConfigurationDTO ambariConfiguration;
+
+  @SerializedName("RequestInfo")
+  private LdapRequestInfo requestInfo;
+
+  public LdapCheckConfigurationRequest() {
+  }
+
+
+  public AmbariConfigurationDTO getAmbariConfiguration() {
+    return ambariConfiguration;
+  }
+
+  public void setAmbariConfiguration(AmbariConfigurationDTO ambariConfiguration) {
+    this.ambariConfiguration = ambariConfiguration;
+  }
+
+  public LdapRequestInfo getRequestInfo() {
+    return requestInfo;
+  }
+
+  public void setRequestInfo(LdapRequestInfo requestInfo) {
+    this.requestInfo = requestInfo;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f2fbc15/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapOperationRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapOperationRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapOperationRequest.java
new file mode 100644
index 0000000..06f6c40
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapOperationRequest.java
@@ -0,0 +1,18 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.api.services.ldap;
+
+public interface LdapOperationRequest {
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f2fbc15/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapRequestInfo.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapRequestInfo.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapRequestInfo.java
new file mode 100644
index 0000000..eeecfee
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapRequestInfo.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.api.services.ldap;
+
+import java.util.Map;
+
+import org.apache.ambari.server.controller.RequestPostRequest;
+
+/**
+ * Bean holding LDAP request specific request information.
+ */
+public class LdapRequestInfo implements RequestPostRequest.RequestInfo {
+
+  // no-arg costructor facilitating JSON serialization
+  public LdapRequestInfo() {
+  }
+
+  private String action;
+
+  private Map<String, Object> parameters;
+
+  @Override
+  public String getAction() {
+    return action;
+  }
+
+  public void setAction(String action) {
+    this.action = action;
+  }
+
+  public void setParameters(Map<String, Object> parameters) {
+    this.parameters = parameters;
+  }
+
+  @Override
+  public String getCommand() {
+    return null;
+  }
+
+  @Override
+  public RequestPostRequest.OperationLevel getOperationLevel() {
+    return null;
+  }
+
+  @Override
+  public Map<String, Object> getParameters() {
+    return parameters;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f2fbc15/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapRestService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapRestService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapRestService.java
new file mode 100644
index 0000000..33b10fa
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapRestService.java
@@ -0,0 +1,132 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.api.services.ldap;
+
+import javax.inject.Inject;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.ambari.annotations.ApiIgnore;
+import org.apache.ambari.server.StaticallyInject;
+import org.apache.ambari.server.api.services.BaseService;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultImpl;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.LdapConfigurationFactory;
+import org.apache.ambari.server.ldap.service.LdapFacade;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Endpoint designated to LDAP specific operations.
+ */
+@StaticallyInject
+@Path("/ldap")
+public class LdapRestService extends BaseService {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(LdapRestService.class);
+
+  @Inject
+  private static LdapFacade ldapFacade;
+
+  @Inject
+  private static LdapConfigurationFactory ldapConfigurationFactory;
+
+  @POST
+  @ApiIgnore // until documented
+  @Path("/action") // todo this needs to be moved under the resource
+  @Consumes(MediaType.APPLICATION_JSON)
+  public Response validateConfiguration(LdapCheckConfigurationRequest ldapCheckConfigurationRequest) {
+
+    Result result = new ResultImpl(new ResultStatus(ResultStatus.STATUS.OK));
+    try {
+
+      validateRequest(ldapCheckConfigurationRequest);
+
+      AmbariLdapConfiguration ambariLdapConfiguration = ldapConfigurationFactory.createLdapConfiguration(
+        ldapCheckConfigurationRequest.getAmbariConfiguration().getData().iterator().next());
+
+      switch (ldapCheckConfigurationRequest.getRequestInfo().getAction()) {
+        case "test-connection":
+
+          LOGGER.info("Testing connection to the LDAP server ...");
+          ldapFacade.checkConnection(ambariLdapConfiguration);
+
+          break;
+        case "test-attributes":
+
+          LOGGER.info("Testing LDAP attributes ....");
+          ldapFacade.checkLdapAttibutes(ldapCheckConfigurationRequest.getRequestInfo().getParameters(), ambariLdapConfiguration);
+
+          break;
+        case "detect-attributes":
+
+          LOGGER.info("Detecting LDAP attributes ...");
+          ldapFacade.detectAttributes(ambariLdapConfiguration);
+
+          break;
+        default:
+          LOGGER.warn("No action provided ...");
+          throw new IllegalArgumentException("No request action provided");
+      }
+
+    } catch (Exception e) {
+      result = new ResultImpl(new ResultStatus(ResultStatus.STATUS.BAD_REQUEST, e));
+    }
+
+    return Response.status(result.getStatus().getStatusCode()).entity(getResultSerializer().serialize(result)).build();
+  }
+
+  private void validateRequest(LdapCheckConfigurationRequest ldapCheckConfigurationRequest) {
+    String errMsg;
+
+    if (null == ldapCheckConfigurationRequest) {
+      errMsg = "No ldap configuraiton request provided";
+      LOGGER.error(errMsg);
+      throw new IllegalArgumentException(errMsg);
+    }
+
+    if (null == ldapCheckConfigurationRequest.getRequestInfo()) {
+      errMsg = String.format("No request information provided. Request: [%s]", ldapCheckConfigurationRequest);
+      LOGGER.error(errMsg);
+      throw new IllegalArgumentException(errMsg);
+    }
+
+    if (null == ldapCheckConfigurationRequest.getAmbariConfiguration()
+      || ldapCheckConfigurationRequest.getAmbariConfiguration().getData().size() != 1) {
+      errMsg = String.format("No / Invalid configuration data provided. Request: [%s]", ldapCheckConfigurationRequest);
+      LOGGER.error(errMsg);
+      throw new IllegalArgumentException(errMsg);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f2fbc15/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
index 8988be0..6ceed4a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
@@ -77,6 +77,7 @@ import org.apache.ambari.server.controller.internal.ViewPermissionResourceProvid
 import org.apache.ambari.server.controller.metrics.ThreadPoolEnabledPropertyProvider;
 import org.apache.ambari.server.controller.utilities.KerberosChecker;
 import org.apache.ambari.server.controller.utilities.KerberosIdentityCleaner;
+import org.apache.ambari.server.ldap.LdapModule;
 import org.apache.ambari.server.metrics.system.MetricsService;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.PersistenceType;
@@ -1061,7 +1062,7 @@ public class AmbariServer {
 
   public static void main(String[] args) throws Exception {
     logStartup();
-    Injector injector = Guice.createInjector(new ControllerModule(), new AuditLoggerModule());
+    Injector injector = Guice.createInjector(new ControllerModule(), new AuditLoggerModule(), new LdapModule());
 
     AmbariServer server = null;
     try {

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f2fbc15/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
index b79d122..4f30b15 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
@@ -510,6 +510,7 @@ public class ControllerModule extends AbstractModule {
     install(new FactoryModuleBuilder().implement(CollectionPersisterService.class, CsvFilePersisterService.class).build(CollectionPersisterServiceFactory.class));
 
     install(new FactoryModuleBuilder().build(ConfigureClusterTaskFactory.class));
+
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f2fbc15/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
new file mode 100644
index 0000000..519f400
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.server.ldap;
+
+import java.util.Map;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.assistedinject.Assisted;
+
+/**
+ * This class is an immutable representation of all the LDAP related configurationMap entries.
+ */
+@Singleton
+public class AmbariLdapConfiguration {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(AmbariLdapConfiguration.class);
+
+  /**
+   * Constants representing supported LDAP related property names
+   */
+  public enum LdapConfigProperty {
+    LDAP_CONFIGURED("ambari.ldap.configured"),
+    AUTOMATIC_ATTRIBUTE_DETECTION("ambari.ldap.automatic.attribute.detection"),
+
+    USE_SSL("ambari.ldap.usessl"),
+    LDAP_SERVER_HOST("ambari.ldap.server.host"),
+    LDAP_SERVER_PORT("ambari.ldap.server.port"),
+    BASE_DN("ambari.ldap.base.dn"),
+
+    BIND_ANONIMOUSLY("ambari.ldap.bindanonymously"),
+    MANAGER_DN("ambari.ldap.managerdn"),
+    MANAGER_PASSWORD("ambari.ldap.managerpassword"),
+    USER_OBJECT_CLASS("ambari.ldap.user.object.class"),
+    USER_NAME_ATTRIBUTE("ambari.ldap.user.name.attribute"),
+    USER_SEARCH_BASE("ambari.ldap.user.search.Base"),
+
+    GROUP_OBJECT_CLASS("ambari.ldap.group.object.class"),
+    GROUP_NAME_ATTRIBUTE("ambari.ldap.group.name.attribute"),
+    GROUP_MEMBER_ATTRIBUTE("ambari.ldap.group.member.attribute"),
+    GROUP_SEARCH_BASE("ambari.ldap.group.member.attribute"),
+    DN_ATTRIBUTE("authentication.ldap.dnAttribute");
+
+    private String propertyName;
+
+    LdapConfigProperty(String propertyName) {
+      this.propertyName = propertyName;
+    }
+
+    public String propertyName() {
+      return this.propertyName;
+    }
+  }
+
+  private final Map<String, Object> configurationMap;
+
+  private Object configurationValue(LdapConfigProperty ldapConfigProperty) {
+    Object value = null;
+    if (configurationMap.containsKey(ldapConfigProperty.propertyName)) {
+      value = configurationMap.get(ldapConfigProperty.propertyName);
+    } else {
+      LOGGER.warn("Ldap configuration property [{}] hasn't been set", ldapConfigProperty.propertyName());
+    }
+
+    return value;
+  }
+
+  @Inject
+  public AmbariLdapConfiguration(@Assisted Map<String, Object> configuration) {
+    this.configurationMap = configuration;
+  }
+
+
+  public String ldapServerHost() {
+    return (String) configurationValue(LdapConfigProperty.LDAP_SERVER_HOST);
+  }
+
+  public int ldapServerPort() {
+    return Integer.valueOf((String) configurationValue(LdapConfigProperty.LDAP_SERVER_PORT));
+  }
+
+  public boolean useSSL() {
+    return Boolean.valueOf((String) configurationValue(LdapConfigProperty.USE_SSL));
+  }
+
+  public boolean bindAnonimously() {
+    return Boolean.valueOf((String) configurationValue(LdapConfigProperty.BIND_ANONIMOUSLY));
+  }
+
+  public String managerDn() {
+    return (String) configurationValue(LdapConfigProperty.MANAGER_DN);
+  }
+
+  public String managerPassword() {
+    return (String) configurationValue(LdapConfigProperty.MANAGER_PASSWORD);
+  }
+
+  public boolean automaticAttributeDetection() {
+    return Boolean.valueOf((String) configurationValue(LdapConfigProperty.AUTOMATIC_ATTRIBUTE_DETECTION));
+  }
+
+  public String baseDn() {
+    return (String) configurationValue(LdapConfigProperty.BASE_DN);
+  }
+
+  public String userObjectClass() {
+    return (String) configurationValue(LdapConfigProperty.USER_OBJECT_CLASS);
+  }
+
+  public String userNameAttribute() {
+    return (String) configurationValue(LdapConfigProperty.USER_NAME_ATTRIBUTE);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f2fbc15/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationFactory.java
new file mode 100644
index 0000000..bcd6e39
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationFactory.java
@@ -0,0 +1,21 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap;
+
+import java.util.Map;
+
+public interface LdapConfigurationFactory {
+  AmbariLdapConfiguration createLdapConfiguration(Map<String, Object> configuration);
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f2fbc15/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationValidatorService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationValidatorService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationValidatorService.java
new file mode 100644
index 0000000..4667721
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationValidatorService.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.ldap.service.AmbariLdapException;
+
+/**
+ * Collection of operations for validating ldap configuration.
+ * It's intended to decouple implementations using different libraries.
+ */
+public interface LdapConfigurationValidatorService {
+
+  /**
+   * Tests the connection based on the provided configuration.
+   *
+   * @param configuration the ambari ldap configuration instance
+   * @throws AmbariLdapException if the connection is not possible
+   */
+  void checkConnection(AmbariLdapConfiguration configuration) throws AmbariLdapException;
+
+  /**
+   * Checks whether the group related LDAP attributes in the configuration are correct.
+   *
+   * @param configuration the configuration instance holding the available properties
+   * @throws AmbariException if the attributes are not valid
+   */
+  void checkGroupAttributes(AmbariLdapConfiguration configuration) throws AmbariException;
+
+  /**
+   * Tries to connect to the LDAP server with the given credentials.
+   * Primarily used for testing the user before performing other operations (eg. attribute detection)s
+   *
+   * @param username      the username
+   * @param password      the password
+   * @param configuration the available ldap configuration
+   * @throws AmbariException if the connection couldn't be estabilished
+   */
+  void checkUserAttributes(String username, String password, AmbariLdapConfiguration configuration) throws AmbariException;
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f2fbc15/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
new file mode 100644
index 0000000..625ce8b
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.ambari.server.ldap;
+
+import org.apache.ambari.server.ldap.service.AmbariLdapFacade;
+import org.apache.ambari.server.ldap.service.LdapFacade;
+import org.apache.ambari.server.ldap.service.ad.AdLdapConfigurationValidatorService;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.assistedinject.FactoryModuleBuilder;
+
+/**
+ * GUICE configuration module for setting up LDAP related infrastructure.
+ */
+public class LdapModule extends AbstractModule {
+
+  @Override
+  protected void configure() {
+    bind(LdapFacade.class).to(AmbariLdapFacade.class);
+    bind(LdapConfigurationValidatorService.class).to(AdLdapConfigurationValidatorService.class);
+
+    install(new FactoryModuleBuilder().build(LdapConfigurationFactory.class));
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f2fbc15/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapException.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapException.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapException.java
new file mode 100644
index 0000000..cb38acc
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapException.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service;
+
+public class AmbariLdapException extends Exception {
+  public AmbariLdapException() {
+    super();
+  }
+
+  public AmbariLdapException(String message) {
+    super(message);
+  }
+
+  public AmbariLdapException(String message, Throwable cause) {
+    super(message, cause);
+  }
+
+  public AmbariLdapException(Throwable cause) {
+    super(cause);
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f2fbc15/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
new file mode 100644
index 0000000..abd028a
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.ambari.server.ldap.service;
+
+import java.util.Map;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.LdapConfigurationValidatorService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Singleton
+public class AmbariLdapFacade implements LdapFacade {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(AmbariLdapFacade.class);
+
+  private enum Parameters {
+    TEST_USER_NAME("ldap.test.user.name"),
+    TEST_USER_PASSWORD("ldap.test.user.password");
+
+    private String parameterKey;
+
+    Parameters(String parameterKey) {
+      this.parameterKey = parameterKey;
+    }
+
+    private String getParameterKey() {
+      return parameterKey;
+    }
+
+  }
+
+  @Inject
+  private LdapConfigurationValidatorService ldapConfigurationValidatorService;
+
+  @Inject
+  public AmbariLdapFacade() {
+  }
+
+  @Override
+  public void checkConnection(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariException {
+    try {
+      LOGGER.info("Validating LDAP connection related configuration based on: {}", ambariLdapConfiguration);
+      ldapConfigurationValidatorService.checkConnection(ambariLdapConfiguration);
+    } catch (AmbariLdapException e) {
+      LOGGER.error("Validating LDAP connection configuration failed", e);
+      throw new AmbariException("Validating LDAP connection configuration failed", e);
+    }
+    LOGGER.info("Validating LDAP connection related configuration: SUCCESS");
+  }
+
+
+  @Override
+  public void detectAttributes(AmbariLdapConfiguration ambariLdapConfiguration) {
+    LOGGER.info("Detecting LDAP configuration attributes ...");
+    throw new UnsupportedOperationException("Not yet implemented");
+  }
+
+  @Override
+  public void checkLdapAttibutes(Map<String, Object> parameters, AmbariLdapConfiguration ldapConfiguration) throws AmbariException {
+    String userName = getTestUserNameFromParameters(parameters);
+    String testUserPass = getTestUserPasswordFromParameters(parameters);
+
+    if (null == userName) {
+      throw new IllegalArgumentException("No test user available for testing LDAP attributes");
+    }
+
+    LOGGER.info("Testing LDAP attributes with test user: {}", userName);
+    ldapConfigurationValidatorService.checkUserAttributes(userName, testUserPass, ldapConfiguration);
+  }
+
+
+  private String getTestUserNameFromParameters(Map<String, Object> parameters) {
+    return (String) parameterValue(parameters, Parameters.TEST_USER_NAME);
+  }
+
+  private String getTestUserPasswordFromParameters(Map<String, Object> parameters) {
+    return (String) parameterValue(parameters, Parameters.TEST_USER_PASSWORD);
+  }
+
+  private Object parameterValue(Map<String, Object> parameters, Parameters parameter) {
+    Object value = null;
+    if (parameters.containsKey(parameter.getParameterKey())) {
+      value = parameters.get(parameter.getParameterKey());
+    } else {
+      LOGGER.warn("Parameter [{}] is missing from parameters", parameter.getParameterKey());
+    }
+    return value;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f2fbc15/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
new file mode 100644
index 0000000..38553f0
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service;
+
+import java.util.Map;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+
+/**
+ * The contract defining all the operations required by the application when communicating with an arbitrary LDAP server.
+ * This interface is intended to decouple LDAP specific details from the application.
+ */
+public interface LdapFacade {
+
+  /**
+   * Tests the connection to the LDAP server based on the provided configuration.
+   *
+   * @param ambariLdapConfiguration the available ldap related configuration
+   * @throws AmbariException if the connection fails or other problems occur during the operation
+   */
+  void checkConnection(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariException;
+
+
+  /**
+   * Runs the user and group attribute detection algorithms
+   *
+   * @param ambariLdapConfiguration
+   */
+  void detectAttributes(AmbariLdapConfiguration ambariLdapConfiguration);
+
+  /**
+   * Checks user and group related LDAP configuration attributes in the configuration object with the help of the provided parameters
+   *
+   * @param parameters              a map of property name and value pairs holding information to facilitate checking the attributes
+   * @param ambariLdapConfiguration configutration instance with available attributes
+   * @throws AmbariException if the attribute checking fails
+   */
+  void checkLdapAttibutes(Map<String, Object> parameters, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariException;
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f2fbc15/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapSearchService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapSearchService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapSearchService.java
new file mode 100644
index 0000000..f1abc8b
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapSearchService.java
@@ -0,0 +1,18 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service;
+
+public interface LdapSearchService {
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f2fbc15/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/AdLdapConfigurationValidatorService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/AdLdapConfigurationValidatorService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/AdLdapConfigurationValidatorService.java
new file mode 100644
index 0000000..11e8655
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/AdLdapConfigurationValidatorService.java
@@ -0,0 +1,177 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ad;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.LdapConfigurationValidatorService;
+import org.apache.ambari.server.ldap.service.AmbariLdapException;
+import org.apache.directory.api.ldap.model.cursor.EntryCursor;
+import org.apache.directory.api.ldap.model.cursor.SearchCursor;
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.apache.directory.api.ldap.model.message.SearchScope;
+import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.ldap.client.api.LdapConnectionConfig;
+import org.apache.directory.ldap.client.api.LdapNetworkConnection;
+import org.apache.directory.ldap.client.api.search.FilterBuilder;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Lists;
+
+/**
+ * Implementation of the validation logic using the Apache Directory API.
+ */
+@Singleton
+public class AdLdapConfigurationValidatorService implements LdapConfigurationValidatorService {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(AdLdapConfigurationValidatorService.class);
+
+  @Inject
+  private LdapConfigurationConverter ldapConfigurationConverter;
+
+  /**
+   * Facilitating the instantiation
+   */
+  @Inject
+  public AdLdapConfigurationValidatorService() {
+  }
+
+  @Override
+  public void checkConnection(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+    try {
+      LOGGER.info("Testing the connection based on the configuration: {}", ambariLdapConfiguration);
+
+      LdapConnectionConfig connectionConfig = ldapConfigurationConverter.getLdapConnectionConfig(ambariLdapConfiguration);
+      LdapNetworkConnection connection = new LdapNetworkConnection(connectionConfig);
+
+      if (ambariLdapConfiguration.bindAnonimously()) {
+        LOGGER.debug("Binding anonimously ...");
+        connection.bind();
+      } else {
+        LOGGER.debug("Binding with manager DN and manager password ...");
+        connection.bind(ambariLdapConfiguration.managerDn(), ambariLdapConfiguration.managerPassword());
+      }
+
+      if (connection.isConnected()) {
+        LOGGER.info("Successfully connected to the LDAP server.");
+      }
+
+      connection.close();
+
+    } catch (Exception e) {
+      LOGGER.warn("Could not bind to the LDAP server base don the provided configuration ...");
+      throw new AmbariLdapException(e);
+    }
+  }
+
+
+  /**
+   * Checks the user attributes provided in the configuration instance by issuing a search for a (known) test user in the LDAP.
+   * Attributes are considered correct if there is at least one entry found.
+   *
+   * Invalid attributes are signaled by throwing an exception.
+   *
+   * @param username                the username
+   * @param password                the password
+   * @param ambariLdapConfiguration configuration instance holding ldap configuration details
+   * @throws AmbariException if the attributes are not valid or any errors occurs
+   */
+  @Override
+  public void checkUserAttributes(String username, String password, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariException {
+    LdapNetworkConnection connection = null;
+    SearchCursor searchCursor = null;
+    try {
+      LOGGER.info("Checking user attributes for user {} r ...", username);
+
+      LdapConnectionConfig connectionConfig = ldapConfigurationConverter.getLdapConnectionConfig(ambariLdapConfiguration);
+      connection = new LdapNetworkConnection(connectionConfig);
+
+
+      if (!ambariLdapConfiguration.bindAnonimously()) {
+        LOGGER.debug("Anonimous binding not supported, binding with the manager detailas...");
+        connection.bind(ambariLdapConfiguration.managerDn(), ambariLdapConfiguration.managerPassword());
+      } else {
+        LOGGER.debug("Binding anonimously ...");
+        connection.bind();
+      }
+
+      if (!connection.isConnected()) {
+        LOGGER.error("Not connected to the LDAP server. Connection instance: {}", connection);
+        throw new IllegalStateException("The connection to the LDAP server is not alive");
+      }
+
+      // set up a filter based on the provided attributes
+      String filter = FilterBuilder.and(
+        FilterBuilder.equal(SchemaConstants.OBJECT_CLASS_AT, ambariLdapConfiguration.userObjectClass()),
+        FilterBuilder.equal(ambariLdapConfiguration.userNameAttribute(), username))
+        .toString();
+
+      LOGGER.info("Searching for the user: {} using the search filter: {}", username, filter);
+      EntryCursor entryCursor = connection.search(new Dn(ambariLdapConfiguration.baseDn()), filter, SearchScope.SUBTREE);
+
+      // collecting search result entries
+      List<Entry> users = Lists.newArrayList();
+      for (Entry entry : entryCursor) {
+        users.add(entry);
+      }
+
+      // there should be at least one user found
+      if (users.isEmpty()) {
+        String msg = String.format("There are no users found using the filter: [ %s ]. Try changing the attribute values", filter);
+        LOGGER.error(msg);
+        throw new Exception(msg);
+      }
+
+      LOGGER.info("Attibute validation succeeded. Filter: {}", filter);
+
+    } catch (Exception e) {
+
+      LOGGER.error("Error while checking user attributes.");
+      throw new AmbariException("Error while checking user attributes", e);
+
+    } finally {
+
+      LOGGER.debug("Closing the connection and searchresult ...");
+
+      if (null != searchCursor) {
+        searchCursor.close();
+      }
+
+      if (null != connection) {
+        try {
+          connection.close();
+        } catch (IOException e) {
+          LOGGER.error("Exception occurred while closing the connection", e);
+        }
+      }
+
+    }
+  }
+
+  @Override
+  public void checkGroupAttributes(AmbariLdapConfiguration configuration) throws AmbariException {
+
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f2fbc15/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/LdapConfigurationConverter.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/LdapConfigurationConverter.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/LdapConfigurationConverter.java
new file mode 100644
index 0000000..a8839f1
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/LdapConfigurationConverter.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ad;
+
+import javax.inject.Singleton;
+
+import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.directory.ldap.client.api.LdapConnectionConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Converts between ambari specific ldap types and the 3rd party ldap library
+ */
+@Singleton
+public class LdapConfigurationConverter {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(LdapConfigurationConverter.class);
+
+  /**
+   * Creates a {@link LdapConnectionConfig} instance based on the provided ambari specific configurations
+   *
+   * @param ambariAmbariLdapConfiguration
+   * @return
+   */
+  public LdapConnectionConfig getLdapConnectionConfig(AmbariLdapConfiguration ambariAmbariLdapConfiguration) {
+    LOGGER.debug("Creating a configuration instance based on the ambari configuration: {}", ambariAmbariLdapConfiguration);
+
+    LdapConnectionConfig ldapConnectionConfig = new LdapConnectionConfig();
+    ldapConnectionConfig.setLdapHost(ambariAmbariLdapConfiguration.ldapServerHost());
+    ldapConnectionConfig.setLdapPort(ambariAmbariLdapConfiguration.ldapServerPort());
+    ldapConnectionConfig.setUseSsl(ambariAmbariLdapConfiguration.useSSL());
+
+    //todo set the other values as required
+    return ldapConnectionConfig;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f2fbc15/ambari-server/src/test/java/org/apache/ambari/server/api/services/ldap/LDAPServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/ldap/LDAPServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/services/ldap/LDAPServiceTest.java
new file mode 100644
index 0000000..f20cd1f
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/services/ldap/LDAPServiceTest.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.api.services.ldap;
+
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.LdapConnectionConfig;
+import org.apache.directory.ldap.client.api.LdapNetworkConnection;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+public class LDAPServiceTest {
+
+  private static String JSON_STRING = "{\n" +
+    "  \"AmbariConfiguration\": {\n" +
+    "    \"type\": \"ldap-config\",\n" +
+    "    \"data\": [{\n" +
+    "        \"authentication.ldap.primaryUrl\": \"localhost:33389\",\n" +
+    "        \"authentication.ldap.secondaryUrl\": \"localhost:333\",\n" +
+    "        \"authentication.ldap.baseDn\": \"dc=ambari,dc=apache,dc=org\"\n" +
+    "      }]\n" +
+    "  }\n" +
+    "}";
+
+  @Test
+  public void testJaxRsJsonTransformation() throws Exception {
+    // GIVEN
+    ObjectMapper objectMapper = new ObjectMapper();
+
+    Gson gsonJsonProvider = new GsonBuilder().create();
+
+
+    // WHEN
+    LdapCheckConfigurationRequest ldapCheckConfigurationRequest = gsonJsonProvider.fromJson(JSON_STRING, LdapCheckConfigurationRequest.class);
+    // LdapCheckConfigurationRequest ldapCheckConfigurationRequest = objectMapper.readValue(JSON_STRING, LdapCheckConfigurationRequest.class);
+
+    // THEN
+    Assert.assertNotNull(ldapCheckConfigurationRequest);
+
+  }
+
+
+  @Test
+  public void testLdapConnection() throws Exception {
+    // GIVEN
+    LdapConnection connection = new LdapNetworkConnection("localhost", 389);
+
+    // WHEN
+    connection.bind();
+    // THEN
+
+  }
+
+
+  @Test
+  public void testLdapConnectionConfigs() throws Exception {
+    // GIVEN
+    LdapConnectionConfig config = new LdapConnectionConfig();
+    config.setLdapHost("localhost");
+    config.setLdapPort(389);
+
+    // WHEN
+    LdapConnection connection = new LdapNetworkConnection(config);
+
+    // THEN
+    connection.anonymousBind();
+
+    Assert.assertNotNull(connection);
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f2fbc15/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ad/AdLdapConfigurationValidatorServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ad/AdLdapConfigurationValidatorServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ad/AdLdapConfigurationValidatorServiceTest.java
new file mode 100644
index 0000000..0f57099
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ad/AdLdapConfigurationValidatorServiceTest.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ad;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Map;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.LdapConfigurationValidatorService;
+import org.apache.directory.api.ldap.model.cursor.EntryCursor;
+import org.apache.directory.api.ldap.model.cursor.SearchCursor;
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.apache.directory.api.ldap.model.message.Response;
+import org.apache.directory.api.ldap.model.message.SearchRequest;
+import org.apache.directory.api.ldap.model.message.SearchRequestImpl;
+import org.apache.directory.api.ldap.model.message.SearchResultEntry;
+import org.apache.directory.api.ldap.model.message.SearchScope;
+import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.LdapConnectionConfig;
+import org.apache.directory.ldap.client.api.LdapNetworkConnection;
+import org.apache.directory.ldap.client.api.search.FilterBuilder;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Maps;
+
+public class AdLdapConfigurationValidatorServiceTest {
+  private static final Logger LOGGER = LoggerFactory.getLogger(AdLdapConfigurationValidatorService.class);
+  private static final String TEST_USER = "Jocika10";
+
+  LdapConfigurationValidatorService ldapConfigurationValidatorService = new AdLdapConfigurationValidatorService();
+
+
+  @Test
+  public void testCheckAttributes() throws Exception {
+
+    // WHEN
+    LdapConnectionConfig config = new LdapConnectionConfig();
+    config.setLdapHost("localhost");
+    config.setLdapPort(389);
+    LdapConnection connection = new LdapNetworkConnection(config);
+
+    // THEN
+    connection.anonymousBind();
+
+
+    EntryCursor cursor = connection.search("dc=dev,dc=local", "(objectclass=*)", SearchScope.ONELEVEL);
+
+    for (Entry entry : cursor) {
+      assertNotNull(entry);
+      System.out.println(entry);
+    }
+
+    cursor.close();
+
+  }
+
+  @Test
+  public void testCheckUserAttributes() throws Exception {
+    Map<String, Object> ldapPropsMap = Maps.newHashMap();
+
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BIND_ANONIMOUSLY.propertyName(), true);
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_HOST.propertyName(), "localhost");
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_PORT.propertyName(), "389");
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BASE_DN.propertyName(), "dc=dev,dc=local");
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_OBJECT_CLASS.propertyName(), SchemaConstants.PERSON_OC);
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_NAME_ATTRIBUTE.propertyName(), SchemaConstants.UID_AT);
+
+    AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(ldapPropsMap);
+
+
+    try {
+      LOGGER.info("Authenticating user {} against the LDAP server ...", TEST_USER);
+      LdapConfigurationConverter ldapConfigurationConverter = new LdapConfigurationConverter();
+
+      LdapConnectionConfig connectionConfig = ldapConfigurationConverter.getLdapConnectionConfig(ambariLdapConfiguration);
+      LdapNetworkConnection connection = new LdapNetworkConnection(connectionConfig);
+
+      String filter = FilterBuilder.and(
+        FilterBuilder.equal(SchemaConstants.OBJECT_CLASS_AT, ambariLdapConfiguration.userObjectClass()),
+        FilterBuilder.equal(ambariLdapConfiguration.userNameAttribute(), TEST_USER))
+        .toString();
+
+      SearchRequest searchRequest = new SearchRequestImpl();
+      searchRequest.setBase(new Dn(ambariLdapConfiguration.baseDn()));
+      searchRequest.setFilter(filter);
+      searchRequest.setScope(SearchScope.SUBTREE);
+
+      LOGGER.info("loking up user: {} based on the filtr: {}", TEST_USER, filter);
+
+      connection.bind();
+      SearchCursor searchCursor = connection.search(searchRequest);
+
+      while (searchCursor.next()) {
+        Response response = searchCursor.get();
+
+        // process the SearchResultEntry
+        if (response instanceof SearchResultEntry) {
+          Entry resultEntry = ((SearchResultEntry) response).getEntry();
+          System.out.println(resultEntry);
+        }
+      }
+
+      searchCursor.close();
+
+    } catch (Exception e) {
+      throw new AmbariException("Error during user authentication check", e);
+    }
+
+  }
+
+}
\ No newline at end of file


[20/46] ambari git commit: AMBARI-21307 Groups for the test user returned to the caller

Posted by lp...@apache.org.
AMBARI-21307 Groups for the test user returned to the caller


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 5790e88a3cc836ce328a6bdb489b4a3b0f978a13
Parents: a65608b
Author: lpuskas <lp...@apache.org>
Authored: Tue Aug 8 15:50:29 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:41:57 2017 +0200

----------------------------------------------------------------------
 .../api/services/ldap/LdapRestService.java      | 16 +++++-
 .../server/ldap/AmbariLdapConfiguration.java    |  2 +-
 .../apache/ambari/server/ldap/LdapModule.java   |  3 +
 .../server/ldap/service/AmbariLdapFacade.java   |  3 +-
 .../ambari/server/ldap/service/LdapFacade.java  |  3 +-
 ...efaultLdapConfigurationValidatorService.java | 25 ++++++---
 .../ad/DefaultLdapConnectionService.java        |  2 +-
 ...ltLdapConfigurationValidatorServiceTest.java | 59 +++-----------------
 8 files changed, 49 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/5790e88a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapRestService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapRestService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapRestService.java
index 33b10fa..8578204 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapRestService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapRestService.java
@@ -28,6 +28,8 @@
 
 package org.apache.ambari.server.api.services.ldap;
 
+import java.util.Set;
+
 import javax.inject.Inject;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.POST;
@@ -41,12 +43,16 @@ import org.apache.ambari.server.api.services.BaseService;
 import org.apache.ambari.server.api.services.Result;
 import org.apache.ambari.server.api.services.ResultImpl;
 import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.controller.internal.ResourceImpl;
+import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
 import org.apache.ambari.server.ldap.LdapConfigurationFactory;
 import org.apache.ambari.server.ldap.service.LdapFacade;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.Sets;
+
 /**
  * Endpoint designated to LDAP specific operations.
  */
@@ -68,6 +74,8 @@ public class LdapRestService extends BaseService {
   @Consumes(MediaType.APPLICATION_JSON)
   public Response validateConfiguration(LdapCheckConfigurationRequest ldapCheckConfigurationRequest) {
 
+    Set<String> groups = Sets.newHashSet();
+
     Result result = new ResultImpl(new ResultStatus(ResultStatus.STATUS.OK));
     try {
 
@@ -86,7 +94,11 @@ public class LdapRestService extends BaseService {
         case "test-attributes":
 
           LOGGER.info("Testing LDAP attributes ....");
-          ldapFacade.checkLdapAttibutes(ldapCheckConfigurationRequest.getRequestInfo().getParameters(), ambariLdapConfiguration);
+          groups = ldapFacade.checkLdapAttibutes(ldapCheckConfigurationRequest.getRequestInfo().getParameters(), ambariLdapConfiguration);
+          // todo factor out the resource creation, design better the structure in the response
+          Resource resource = new ResourceImpl(Resource.Type.AmbariConfiguration);
+          resource.setProperty("groups", groups);
+          result.getResultTree().addChild(resource, "payload");
 
           break;
         case "detect-attributes":
@@ -101,7 +113,7 @@ public class LdapRestService extends BaseService {
       }
 
     } catch (Exception e) {
-      result = new ResultImpl(new ResultStatus(ResultStatus.STATUS.BAD_REQUEST, e));
+      result.setResultStatus(new ResultStatus(ResultStatus.STATUS.BAD_REQUEST, e));
     }
 
     return Response.status(result.getStatus().getStatusCode()).entity(getResultSerializer().serialize(result)).build();

http://git-wip-us.apache.org/repos/asf/ambari/blob/5790e88a/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
index a6ff80b..8ab587b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
@@ -48,7 +48,7 @@ public class AmbariLdapConfiguration {
     MANAGER_PASSWORD("ambari.ldap.managerpassword"),
     USER_OBJECT_CLASS("ambari.ldap.user.object.class"),
     USER_NAME_ATTRIBUTE("ambari.ldap.user.name.attribute"),
-    USER_SEARCH_BASE("ambari.ldap.user.search.Base"),
+    USER_SEARCH_BASE("ambari.ldap.user.search.base"),
 
     GROUP_OBJECT_CLASS("ambari.ldap.group.object.class"),
     GROUP_NAME_ATTRIBUTE("ambari.ldap.group.name.attribute"),

http://git-wip-us.apache.org/repos/asf/ambari/blob/5790e88a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
index 545f220..1b49159 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
@@ -16,8 +16,10 @@
 package org.apache.ambari.server.ldap;
 
 import org.apache.ambari.server.ldap.service.AmbariLdapFacade;
+import org.apache.ambari.server.ldap.service.LdapConnectionService;
 import org.apache.ambari.server.ldap.service.LdapFacade;
 import org.apache.ambari.server.ldap.service.ad.DefaultLdapConfigurationValidatorService;
+import org.apache.ambari.server.ldap.service.ad.DefaultLdapConnectionService;
 
 import com.google.inject.AbstractModule;
 import com.google.inject.assistedinject.FactoryModuleBuilder;
@@ -31,6 +33,7 @@ public class LdapModule extends AbstractModule {
   protected void configure() {
     bind(LdapFacade.class).to(AmbariLdapFacade.class);
     bind(LdapConfigurationValidatorService.class).to(DefaultLdapConfigurationValidatorService.class);
+    bind(LdapConnectionService.class).to(DefaultLdapConnectionService.class);
 
     install(new FactoryModuleBuilder().build(LdapConfigurationFactory.class));
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/5790e88a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
index abb464b..eec47ce 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
@@ -79,7 +79,7 @@ public class AmbariLdapFacade implements LdapFacade {
   }
 
   @Override
-  public void checkLdapAttibutes(Map<String, Object> parameters, AmbariLdapConfiguration ldapConfiguration) throws AmbariLdapException {
+  public Set<String> checkLdapAttibutes(Map<String, Object> parameters, AmbariLdapConfiguration ldapConfiguration) throws AmbariLdapException {
     String userName = getTestUserNameFromParameters(parameters);
     String testUserPass = getTestUserPasswordFromParameters(parameters);
 
@@ -95,6 +95,7 @@ public class AmbariLdapFacade implements LdapFacade {
     LOGGER.info("Testing LDAP group attributes with test user dn: {}", userDn);
     Set<String> groups = ldapConfigurationValidatorService.checkGroupAttributes(ldapConnection, userDn, ldapConfiguration);
 
+    return groups;
   }
 
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/5790e88a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
index 7bb1198..eadff7d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
@@ -15,6 +15,7 @@
 package org.apache.ambari.server.ldap.service;
 
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
 
@@ -47,5 +48,5 @@ public interface LdapFacade {
    * @param ambariLdapConfiguration configutration instance with available attributes
    * @throws AmbariLdapException if the attribute checking fails
    */
-  void checkLdapAttibutes(Map<String, Object> parameters, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException;
+  Set<String> checkLdapAttibutes(Map<String, Object> parameters, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException;
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/5790e88a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorService.java
index 838ef4c..a8503ca 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorService.java
@@ -37,7 +37,6 @@ import org.apache.directory.api.ldap.model.message.SearchRequestImpl;
 import org.apache.directory.api.ldap.model.message.SearchScope;
 import org.apache.directory.api.ldap.model.name.Dn;
 import org.apache.directory.ldap.client.api.LdapConnection;
-import org.apache.directory.ldap.client.api.LdapNetworkConnection;
 import org.apache.directory.ldap.client.api.search.FilterBuilder;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.slf4j.Logger;
@@ -84,18 +83,18 @@ public class DefaultLdapConfigurationValidatorService implements LdapConfigurati
    * @param testUserName            the test username
    * @param testPassword            the test password
    * @param ambariLdapConfiguration configuration instance holding ldap configuration details
+   * @return the DN of the test user
    * @throws AmbariException if the attributes are not valid or any errors occurs
    */
   @Override
   public String checkUserAttributes(LdapConnection ldapConnection, String testUserName, String testPassword, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
-    LdapNetworkConnection connection = null;
     SearchCursor searchCursor = null;
     String userDn = null;
     try {
       LOGGER.info("Checking user attributes for user {} r ...", testUserName);
 
       // bind anonimously or with manager data
-      bind(ambariLdapConfiguration, connection);
+      bind(ambariLdapConfiguration, ldapConnection);
 
       // set up a filter based on the provided attributes
       String filter = FilterBuilder.and(
@@ -104,7 +103,7 @@ public class DefaultLdapConfigurationValidatorService implements LdapConfigurati
         .toString();
 
       LOGGER.info("Searching for the user: {} using the search filter: {}", testUserName, filter);
-      EntryCursor entryCursor = connection.search(new Dn(ambariLdapConfiguration.userSearchBase()), filter, SearchScope.SUBTREE);
+      EntryCursor entryCursor = ldapConnection.search(new Dn(ambariLdapConfiguration.userSearchBase()), filter, SearchScope.SUBTREE);
 
       // collecting search result entries
       List<Entry> users = Lists.newArrayList();
@@ -128,7 +127,7 @@ public class DefaultLdapConfigurationValidatorService implements LdapConfigurati
       throw new AmbariLdapException(e.getMessage(), e);
 
     } finally {
-      closeResources(connection, searchCursor);
+      closeResources(ldapConnection, searchCursor);
     }
     return userDn;
   }
@@ -172,14 +171,19 @@ public class DefaultLdapConfigurationValidatorService implements LdapConfigurati
       throw new AmbariLdapException(e.getMessage(), e);
 
     } finally {
-
       closeResources(ldapConnection, searchCursor);
-
     }
 
     return processGroupResults(groupResponses, ambariLdapConfiguration);
   }
 
+  /**
+   * Binds to the LDAP server (anonimously or wit manager credentials)
+   *
+   * @param ambariLdapConfiguration configuration instance
+   * @param connection              connection instance
+   * @throws LdapException if the bind operation fails
+   */
   private void bind(AmbariLdapConfiguration ambariLdapConfiguration, LdapConnection connection) throws LdapException {
     LOGGER.info("Connecting to LDAP ....");
     if (!ambariLdapConfiguration.bindAnonimously()) {
@@ -198,6 +202,13 @@ public class DefaultLdapConfigurationValidatorService implements LdapConfigurati
   }
 
 
+  /**
+   * Extracts meaningful values from the search result.
+   *
+   * @param groupResponses          the result entries returned by the search
+   * @param ambariLdapConfiguration holds the keys of the meaningful attributes
+   * @return a set with the group names the test user belongs to
+   */
   private Set<String> processGroupResults(Set<Response> groupResponses, AmbariLdapConfiguration ambariLdapConfiguration) {
     Set<String> groupStrSet = Sets.newHashSet();
     for (Response response : groupResponses) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/5790e88a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConnectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConnectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConnectionService.java
index b5559d9..25dc1f2 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConnectionService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConnectionService.java
@@ -56,7 +56,7 @@ public class DefaultLdapConnectionService implements LdapConnectionService {
     ldapConnectionConfig.setLdapPort(ambariAmbariLdapConfiguration.ldapServerPort());
     ldapConnectionConfig.setUseSsl(ambariAmbariLdapConfiguration.useSSL());
 
-    //todo set the other values as required
+    // todo set the other values as required
     return ldapConnectionConfig;
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/5790e88a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorServiceTest.java
index 5c9d304..663ea12 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorServiceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorServiceTest.java
@@ -18,23 +18,15 @@ import static org.junit.Assert.assertNotNull;
 
 import java.util.Map;
 
-import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
 import org.apache.ambari.server.ldap.LdapConfigurationValidatorService;
 import org.apache.ambari.server.ldap.service.LdapConnectionService;
 import org.apache.directory.api.ldap.model.cursor.EntryCursor;
-import org.apache.directory.api.ldap.model.cursor.SearchCursor;
 import org.apache.directory.api.ldap.model.entry.Entry;
-import org.apache.directory.api.ldap.model.message.Response;
-import org.apache.directory.api.ldap.model.message.SearchRequest;
-import org.apache.directory.api.ldap.model.message.SearchRequestImpl;
-import org.apache.directory.api.ldap.model.message.SearchResultEntry;
 import org.apache.directory.api.ldap.model.message.SearchScope;
-import org.apache.directory.api.ldap.model.name.Dn;
 import org.apache.directory.ldap.client.api.LdapConnection;
 import org.apache.directory.ldap.client.api.LdapConnectionConfig;
 import org.apache.directory.ldap.client.api.LdapNetworkConnection;
-import org.apache.directory.ldap.client.api.search.FilterBuilder;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -75,57 +67,24 @@ public class DefaultLdapConfigurationValidatorServiceTest {
 
   @Test
   public void testCheckUserAttributes() throws Exception {
+    // GIVEN
     Map<String, Object> ldapPropsMap = Maps.newHashMap();
 
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BIND_ANONIMOUSLY.propertyName(), false);
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BIND_ANONIMOUSLY.propertyName(), "true");
     ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_HOST.propertyName(), "ldap.forumsys.com");
     ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_PORT.propertyName(), "389");
     ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BASE_DN.propertyName(), "dc=example,dc=com");
+
     ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_OBJECT_CLASS.propertyName(), SchemaConstants.PERSON_OC);
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_OBJECT_CLASS.propertyName(), SchemaConstants.GROUP_OF_UNIQUE_NAMES_OC);
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_NAME_ATTRIBUTE.propertyName(), SchemaConstants.CN_AT);
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_MEMBER_ATTRIBUTE.propertyName(), SchemaConstants.UNIQUE_MEMBER_AT);
     ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_NAME_ATTRIBUTE.propertyName(), SchemaConstants.UID_AT);
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_SEARCH_BASE.propertyName(), "dc=example,dc=com");
 
-    AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(ldapPropsMap);
-
-
-    try {
-      LOGGER.info("Authenticating user {} against the LDAP server ...", TEST_USER);
-      LdapConnectionService connectionService = new DefaultLdapConnectionService();
-      LdapNetworkConnection connection = connectionService.createLdapConnection(ambariLdapConfiguration);
-
-      String filter = FilterBuilder.and(
-        FilterBuilder.equal(SchemaConstants.OBJECT_CLASS_AT, ambariLdapConfiguration.userObjectClass()),
-        FilterBuilder.equal(ambariLdapConfiguration.userNameAttribute(), TEST_USER))
-        .toString();
-
-      SearchRequest searchRequest = new SearchRequestImpl();
-      searchRequest.setBase(new Dn(ambariLdapConfiguration.baseDn()));
-      searchRequest.setFilter(filter);
-      searchRequest.setScope(SearchScope.SUBTREE);
 
-      LOGGER.info("loking up user: {} based on the filtr: {}", TEST_USER, filter);
-
-      connection.bind();
-      SearchCursor searchCursor = connection.search(searchRequest);
-
-      while (searchCursor.next()) {
-        Response response = searchCursor.get();
-
-        // process the SearchResultEntry
-        if (response instanceof SearchResultEntry) {
-          Entry resultEntry = ((SearchResultEntry) response).getEntry();
-          System.out.println(resultEntry);
-        }
-      }
-
-      searchCursor.close();
-
-    } catch (Exception e) {
-      throw new AmbariException("Error during user authentication check", e);
-    }
+    AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(ldapPropsMap);
+    LdapConnectionService connectionService = new DefaultLdapConnectionService();
+    LdapNetworkConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
 
+    ldapConfigurationValidatorService.checkUserAttributes(ldapConnection, "einstein", "", ambariLdapConfiguration);
   }
 
   @Test
@@ -138,8 +97,6 @@ public class DefaultLdapConfigurationValidatorServiceTest {
     ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_PORT.propertyName(), "389");
     ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BASE_DN.propertyName(), "dc=example,dc=com");
 
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_OBJECT_CLASS.propertyName(), SchemaConstants.PERSON_OC);
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_NAME_ATTRIBUTE.propertyName(), SchemaConstants.UID_AT);
 
     ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_OBJECT_CLASS.propertyName(), SchemaConstants.GROUP_OF_UNIQUE_NAMES_OC);
     ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_NAME_ATTRIBUTE.propertyName(), SchemaConstants.CN_AT);


[42/46] ambari git commit: AMBARI-21307 Added unit tests. Improved logging, refactoring: rename, organized classes into packages

Posted by lp...@apache.org.
AMBARI-21307 Added unit tests. Improved logging, refactoring: rename, organized classes into packages


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 3bb03e989424413b188474ee009f90d76951fb18
Parents: 010ff38
Author: lpuskas <lp...@apache.org>
Authored: Fri Oct 13 17:19:41 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:42:02 2017 +0200

----------------------------------------------------------------------
 .../apache/ambari/server/ldap/LdapModule.java   |   2 +-
 .../AmbariLdapConfigurationProvider.java        |  13 +-
 .../server/ldap/service/AmbariLdapFacade.java   |   2 +-
 .../service/LdapConnectionConfigService.java    |   4 +-
 .../ads/DefaultLdapConfigurationService.java    |  38 +++-
 .../ads/DefaultLdapConnectionConfigService.java | 116 ++++++++++
 .../DefaultLdapConnectionConfigService.java     | 116 ----------
 .../server/ldap/LdapModuleFunctionalTest.java   |   4 +-
 ...estAmbariAmbariLdapConfigurationFactory.java |  29 ---
 .../TestAmbariLdapConfigurationFactory.java     |  29 +++
 .../ldap/service/AmbariLdapFacadeTest.java      |   4 +-
 .../DefaultLdapConfigurationServiceTest.java    | 221 +++++++++++++++++++
 12 files changed, 414 insertions(+), 164 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/3bb03e98/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
index 4abf4e7..67e84dc 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
@@ -25,7 +25,7 @@ import org.apache.ambari.server.ldap.service.LdapConnectionConfigService;
 import org.apache.ambari.server.ldap.service.LdapFacade;
 import org.apache.ambari.server.ldap.service.ads.DefaultLdapAttributeDetectionService;
 import org.apache.ambari.server.ldap.service.ads.DefaultLdapConfigurationService;
-import org.apache.ambari.server.ldap.service.ads.detectors.DefaultLdapConnectionConfigService;
+import org.apache.ambari.server.ldap.service.ads.DefaultLdapConnectionConfigService;
 
 import com.google.inject.AbstractModule;
 import com.google.inject.assistedinject.FactoryModuleBuilder;

http://git-wip-us.apache.org/repos/asf/ambari/blob/3bb03e98/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java
index 9fad896..c88d420 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java
@@ -36,7 +36,8 @@ import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 
 /**
- * Provider implementation for LDAP configurations. It needs to be registered in the related GUICE module as a provider
+ * Provider implementation for LDAP configurations.
+ * It needs to be registered in the related GUICE module as a provider.
  * It's responsible for managing LDAP configurations in the application.
  * Whenever requested, this provider returns an AmbariLdapConfiguration which is always in sync with the persisted LDAP
  * configuration resource.
@@ -85,15 +86,15 @@ public class AmbariLdapConfigurationProvider implements Provider<AmbariLdapConfi
     AmbariConfigurationEntity configEntity = null;
 
     LOGGER.info("Loading LDAP configuration ...");
-    if (null != configurationId) {
+    if (null == configurationId) {
 
-      LOGGER.debug("Reloading configuration based on the provied id: {}", configurationId);
-      configEntity = ambariConfigurationDAOProvider.get().findByPK(configurationId);
+      LOGGER.debug("Initial loading of the ldap configuration ...");
+      configEntity = ambariConfigurationDAOProvider.get().getLdapConfiguration();
 
     } else {
 
-      LOGGER.debug("Initial loading of the ldap configuration ...");
-      configEntity = ambariConfigurationDAOProvider.get().getLdapConfiguration();
+      LOGGER.debug("Reloading configuration based on the provied id: {}", configurationId);
+      configEntity = ambariConfigurationDAOProvider.get().findByPK(configurationId);
 
     }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/3bb03e98/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
index bbfbc8e..0118840 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
@@ -33,7 +33,7 @@ public class AmbariLdapFacade implements LdapFacade {
   /**
    * Additional parameters expected to be provided along with the configuration
    */
-  protected enum Parameters {
+  public enum Parameters {
     TEST_USER_NAME("ambari.ldap.test.user.name"),
     TEST_USER_PASSWORD("ambari.ldap.test.user.password");
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/3bb03e98/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionConfigService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionConfigService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionConfigService.java
index e2055bb..a882075 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionConfigService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionConfigService.java
@@ -18,7 +18,9 @@ import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
 import org.apache.directory.ldap.client.api.LdapConnectionConfig;
 
 /**
- * Contract for creating connection configuration instances
+ * Contract for creating connection configuration instances.
+ * Implementers are in charge for implementing any required custom logic based on the ambari configuration properties.
+ * (Eg.: using custom key stores etc...)
  */
 public interface LdapConnectionConfigService {
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/3bb03e98/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
index 60c1272..d80a636 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
@@ -58,7 +58,7 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
 
   @Override
   public void checkConnection(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
-
+    LOGGER.info("Trying to connect to the LDAP server using provided configuration...");
     LdapConnectionTemplate ldapConnectionTemplate = ldapConnectionTemplateFactory.create(ambariLdapConfiguration);
 
     // check if the connection from the connection pool of the template is connected
@@ -74,6 +74,8 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
       throw new AmbariLdapException("Could not connect to the LDAP server. Configuration: " + ambariLdapConfiguration);
     }
 
+    LOGGER.info("Successfully conencted to the LDAP.");
+
   }
 
   /**
@@ -92,7 +94,7 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
   public String checkUserAttributes(String testUserName, String testPassword, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
     String userDn;
     try {
-      LOGGER.info("Checking user attributes for user {} r ...", testUserName);
+      LOGGER.info("Checking user attributes for user [{}] ...", testUserName);
 
       // set up a filter based on the provided attributes
       String filter = FilterBuilder.and(
@@ -100,10 +102,15 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
         FilterBuilder.equal(ambariLdapConfiguration.userNameAttribute(), testUserName))
         .toString();
 
-      LOGGER.info("Searching for the user: {} using the search filter: {}", testUserName, filter);
+      LOGGER.info("Searching for the user: [{}] using the search filter: [{}]", testUserName, filter);
       userDn = ldapConnectionTemplateFactory.create(ambariLdapConfiguration).searchFirst(new Dn(ambariLdapConfiguration.userSearchBase()), filter, SearchScope.SUBTREE, getUserDnNameEntryMapper(ambariLdapConfiguration));
 
-      LOGGER.info("Attribute validation succeeded. Filter: {}", filter);
+      if (null == userDn) {
+        LOGGER.info("Could not find user based on the provided configuration. User attributes are not complete ");
+        throw new AmbariLdapException("User attribute configuration incomplete");
+      }
+      LOGGER.info("Attribute validation succeeded. Filter: [{}]", filter);
+
 
     } catch (Exception e) {
 
@@ -126,7 +133,7 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
   public Set<String> checkGroupAttributes(String userDn, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
     List<String> groups = Lists.newArrayList();
     try {
-      LOGGER.info("Checking group attributes for user dn {} ...", userDn);
+      LOGGER.info("Checking group attributes for user dn: [{}] ...", userDn);
 
       // set up a filter based on the provided attributes
       String filter = FilterBuilder.and(
@@ -134,7 +141,7 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
         FilterBuilder.equal(ambariLdapConfiguration.groupMemberAttribute(), userDn)
       ).toString();
 
-      LOGGER.info("Searching for the groups the user dn: {} is member of using the search filter: {}", userDn, filter);
+      LOGGER.info("Searching for the groups the user dn: [{}] is member of using the search filter: [{}]", userDn, filter);
       LdapConnectionTemplate ldapConnectionTemplate = ldapConnectionTemplateFactory.create(ambariLdapConfiguration);
 
       // assemble a search request
@@ -145,6 +152,13 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
       // perform the search
       groups = ldapConnectionTemplate.search(searchRequest, getGroupNameEntryMapper(ambariLdapConfiguration));
 
+      if (groups == null || groups.isEmpty()) {
+        LOGGER.info("No groups found for the user dn. Group attributes configuration is incomplete");
+        throw new AmbariLdapException("Group attribute ldap configuration is incomplete");
+      }
+
+      LOGGER.info("Group attribute configuration check succeeded.");
+
     } catch (Exception e) {
 
       LOGGER.error("User attributes validation failed.", e);
@@ -156,6 +170,12 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
   }
 
 
+  /**
+   * Entry mapper for handling user search results.
+   *
+   * @param ambariLdapConfiguration ambari ldap configuration values
+   * @return user dn entry mapper instance
+   */
   private EntryMapper<String> getGroupNameEntryMapper(AmbariLdapConfiguration ambariLdapConfiguration) {
 
     EntryMapper<String> entryMapper = new EntryMapper<String>() {
@@ -168,6 +188,12 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
     return entryMapper;
   }
 
+  /**
+   * Entry mapper for handling group searches.
+   *
+   * @param ambariLdapConfiguration ambari ldap configuration values
+   * @return
+   */
   private EntryMapper<String> getUserDnNameEntryMapper(AmbariLdapConfiguration ambariLdapConfiguration) {
 
     EntryMapper<String> entryMapper = new EntryMapper<String>() {

http://git-wip-us.apache.org/repos/asf/ambari/blob/3bb03e98/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionConfigService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionConfigService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionConfigService.java
new file mode 100644
index 0000000..9bc2daf
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionConfigService.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads;
+
+import static javax.net.ssl.TrustManagerFactory.getDefaultAlgorithm;
+
+import java.io.FileInputStream;
+import java.security.KeyStore;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
+
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.service.AmbariLdapException;
+import org.apache.ambari.server.ldap.service.LdapConnectionConfigService;
+import org.apache.directory.api.util.Strings;
+import org.apache.directory.ldap.client.api.LdapConnectionConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Singleton
+public class DefaultLdapConnectionConfigService implements LdapConnectionConfigService {
+
+  private static Logger LOG = LoggerFactory.getLogger(DefaultLdapConnectionConfigService.class);
+
+  @Inject
+  public DefaultLdapConnectionConfigService() {
+  }
+
+  @Override
+  public LdapConnectionConfig createLdapConnectionConfig(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+
+    LOG.debug("Assembling ldap connection config based on: {}", ambariLdapConfiguration);
+
+    LdapConnectionConfig config = new LdapConnectionConfig();
+    config.setLdapHost(ambariLdapConfiguration.serverHost());
+    config.setLdapPort(ambariLdapConfiguration.serverPort());
+    config.setName(ambariLdapConfiguration.bindDn());
+    config.setCredentials(ambariLdapConfiguration.bindPassword());
+    config.setUseSsl(ambariLdapConfiguration.useSSL());
+
+    // todo implement proper validation logic here: identify optional/mandatory settings
+    // todo suggest proper naming
+    if ("custom".equals(ambariLdapConfiguration.trustStore())) {
+      LOG.info("Using custom trust manager configuration");
+      config.setTrustManagers(trustManagers(ambariLdapConfiguration));
+    }
+
+
+    return config;
+  }
+
+
+  /**
+   * Configure the trustmanagers to use the custom keystore.
+   *
+   * @param ambariLdapConfiguration congiguration instance holding current values
+   * @return the array of trust managers
+   * @throws AmbariLdapException if an error occurs while setting up the connection
+   */
+  private TrustManager[] trustManagers(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+    try {
+
+      TrustManagerFactory tmFactory = TrustManagerFactory.getInstance(getDefaultAlgorithm());
+      tmFactory.init(keyStore(ambariLdapConfiguration));
+      return tmFactory.getTrustManagers();
+
+    } catch (Exception e) {
+
+      LOG.error("Failed to initialize trust managers", e);
+      throw new AmbariLdapException(e);
+
+    }
+
+  }
+
+  private KeyStore keyStore(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+
+    // validating configuration settings
+    if (Strings.isEmpty(ambariLdapConfiguration.trustStoreType())) {
+      throw new AmbariLdapException("Key Store Type must be specified");
+    }
+
+    if (Strings.isEmpty(ambariLdapConfiguration.trustStorePath())) {
+      throw new AmbariLdapException("Key Store Path must be specified");
+    }
+
+    try {
+
+      KeyStore ks = KeyStore.getInstance(ambariLdapConfiguration.trustStoreType());
+      FileInputStream fis = new FileInputStream(ambariLdapConfiguration.trustStorePath());
+      ks.load(fis, ambariLdapConfiguration.trustStorePassword().toCharArray());
+      return ks;
+
+    } catch (Exception e) {
+
+      LOG.error("Failed to create keystore", e);
+      throw new AmbariLdapException(e);
+
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3bb03e98/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/DefaultLdapConnectionConfigService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/DefaultLdapConnectionConfigService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/DefaultLdapConnectionConfigService.java
deleted file mode 100644
index b12cc85..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/DefaultLdapConnectionConfigService.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.service.ads.detectors;
-
-import static javax.net.ssl.TrustManagerFactory.getDefaultAlgorithm;
-
-import java.io.FileInputStream;
-import java.security.KeyStore;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.TrustManagerFactory;
-
-import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.service.AmbariLdapException;
-import org.apache.ambari.server.ldap.service.LdapConnectionConfigService;
-import org.apache.directory.api.util.Strings;
-import org.apache.directory.ldap.client.api.LdapConnectionConfig;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Singleton
-public class DefaultLdapConnectionConfigService implements LdapConnectionConfigService {
-
-  private static Logger LOG = LoggerFactory.getLogger(DefaultLdapConnectionConfigService.class);
-
-  @Inject
-  public DefaultLdapConnectionConfigService() {
-  }
-
-  @Override
-  public LdapConnectionConfig createLdapConnectionConfig(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
-
-    LOG.debug("Assembling ldap connection config based on: {}", ambariLdapConfiguration);
-
-    LdapConnectionConfig config = new LdapConnectionConfig();
-    config.setLdapHost(ambariLdapConfiguration.serverHost());
-    config.setLdapPort(ambariLdapConfiguration.serverPort());
-    config.setName(ambariLdapConfiguration.bindDn());
-    config.setCredentials(ambariLdapConfiguration.bindPassword());
-    config.setUseSsl(ambariLdapConfiguration.useSSL());
-
-    // todo implement proper validation logic here: identify optional/mandatory settings
-    // todo suggest proper naming
-    if ("custom".equals(ambariLdapConfiguration.trustStore())) {
-      LOG.info("Using custom trust manager configuration");
-      config.setTrustManagers(trustManagers(ambariLdapConfiguration));
-    }
-
-
-    return config;
-  }
-
-
-  /**
-   * Configure the trustmanagers to use the custom keystore.
-   *
-   * @param ambariLdapConfiguration congiguration instance holding current values
-   * @return the array of trust managers
-   * @throws AmbariLdapException if an error occurs while setting up the connection
-   */
-  private TrustManager[] trustManagers(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
-    try {
-
-      TrustManagerFactory tmFactory = TrustManagerFactory.getInstance(getDefaultAlgorithm());
-      tmFactory.init(keyStore(ambariLdapConfiguration));
-      return tmFactory.getTrustManagers();
-
-    } catch (Exception e) {
-
-      LOG.error("Failed to initialize trust managers", e);
-      throw new AmbariLdapException(e);
-
-    }
-
-  }
-
-  private KeyStore keyStore(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
-
-    // validating configuration settings
-    if (Strings.isEmpty(ambariLdapConfiguration.trustStoreType())) {
-      throw new AmbariLdapException("Key Store Type must be specified");
-    }
-
-    if (Strings.isEmpty(ambariLdapConfiguration.trustStorePath())) {
-      throw new AmbariLdapException("Key Store Path must be specified");
-    }
-
-    try {
-
-      KeyStore ks = KeyStore.getInstance(ambariLdapConfiguration.trustStoreType());
-      FileInputStream fis = new FileInputStream(ambariLdapConfiguration.trustStorePath());
-      ks.load(fis, ambariLdapConfiguration.trustStorePassword().toCharArray());
-      return ks;
-
-    } catch (Exception e) {
-
-      LOG.error("Failed to create keystore", e);
-      throw new AmbariLdapException(e);
-
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3bb03e98/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
index f3f0644..91f4e10 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
@@ -18,7 +18,7 @@ import java.util.Map;
 
 import org.apache.ambari.server.ldap.domain.AmbariLdapConfigKeys;
 import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.domain.TestAmbariAmbariLdapConfigurationFactory;
+import org.apache.ambari.server.ldap.domain.TestAmbariLdapConfigurationFactory;
 import org.apache.ambari.server.ldap.service.LdapConfigurationService;
 import org.apache.ambari.server.ldap.service.LdapFacade;
 import org.apache.ambari.server.ldap.service.ads.LdapConnectionTemplateFactory;
@@ -47,7 +47,7 @@ public class LdapModuleFunctionalTest {
 
   private static Injector injector;
   private static Module testModule;
-  private static TestAmbariAmbariLdapConfigurationFactory ldapConfigurationFactory = new TestAmbariAmbariLdapConfigurationFactory();
+  private static TestAmbariLdapConfigurationFactory ldapConfigurationFactory = new TestAmbariLdapConfigurationFactory();
 
   @BeforeClass
   public static void beforeClass() throws Exception {

http://git-wip-us.apache.org/repos/asf/ambari/blob/3bb03e98/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/TestAmbariAmbariLdapConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/TestAmbariAmbariLdapConfigurationFactory.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/TestAmbariAmbariLdapConfigurationFactory.java
deleted file mode 100644
index 1155494..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/TestAmbariAmbariLdapConfigurationFactory.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.domain;
-
-
-import java.util.Map;
-
-/**
- * Implementation used for testing purposes only!
- */
-public class TestAmbariAmbariLdapConfigurationFactory implements AmbariLdapConfigurationFactory {
-
-  @Override
-  public AmbariLdapConfiguration createLdapConfiguration(Map<String, Object> configuration) {
-    return new AmbariLdapConfiguration(configuration);
-  }
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3bb03e98/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/TestAmbariLdapConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/TestAmbariLdapConfigurationFactory.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/TestAmbariLdapConfigurationFactory.java
new file mode 100644
index 0000000..aa26498
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/TestAmbariLdapConfigurationFactory.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.domain;
+
+
+import java.util.Map;
+
+/**
+ * Implementation used for testing purposes only!
+ */
+public class TestAmbariLdapConfigurationFactory implements AmbariLdapConfigurationFactory {
+
+  @Override
+  public AmbariLdapConfiguration createLdapConfiguration(Map<String, Object> configuration) {
+    return new AmbariLdapConfiguration(configuration);
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3bb03e98/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/AmbariLdapFacadeTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/AmbariLdapFacadeTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/AmbariLdapFacadeTest.java
index 8552f86..db0e5a9 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/AmbariLdapFacadeTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/AmbariLdapFacadeTest.java
@@ -20,7 +20,7 @@ import java.util.Set;
 import org.apache.ambari.server.ldap.domain.AmbariLdapConfigKeys;
 import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
 import org.apache.ambari.server.ldap.domain.AmbariLdapConfigurationFactory;
-import org.apache.ambari.server.ldap.domain.TestAmbariAmbariLdapConfigurationFactory;
+import org.apache.ambari.server.ldap.domain.TestAmbariLdapConfigurationFactory;
 import org.easymock.Capture;
 import org.easymock.EasyMock;
 import org.easymock.EasyMockRule;
@@ -63,7 +63,7 @@ public class AmbariLdapFacadeTest extends EasyMockSupport {
 
   @Before
   public void before() {
-    ambariLdapConfigurationFactory = new TestAmbariAmbariLdapConfigurationFactory();
+    ambariLdapConfigurationFactory = new TestAmbariLdapConfigurationFactory();
     ambariLdapConfiguration = ambariLdapConfigurationFactory.createLdapConfiguration(Maps.newHashMap());
     ambariLdapConfigurationCapture = Capture.newInstance();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/3bb03e98/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
new file mode 100644
index 0000000..4d6d2a6
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
@@ -0,0 +1,221 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfigKeys;
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.domain.TestAmbariLdapConfigurationFactory;
+import org.apache.ambari.server.ldap.service.AmbariLdapException;
+import org.apache.ambari.server.ldap.service.LdapConfigurationService;
+import org.apache.directory.api.ldap.model.message.SearchRequest;
+import org.apache.directory.api.ldap.model.message.SearchRequestImpl;
+import org.apache.directory.api.ldap.model.message.SearchScope;
+import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.ldap.client.template.ConnectionCallback;
+import org.apache.directory.ldap.client.template.EntryMapper;
+import org.apache.directory.ldap.client.template.LdapConnectionTemplate;
+import org.easymock.EasyMock;
+import org.easymock.EasyMockRule;
+import org.easymock.EasyMockSupport;
+import org.easymock.Mock;
+import org.easymock.MockType;
+import org.easymock.TestSubject;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+public class DefaultLdapConfigurationServiceTest extends EasyMockSupport {
+  @Rule
+  public EasyMockRule mocks = new EasyMockRule(this);
+
+  @Mock(type = MockType.STRICT)
+  private LdapConnectionTemplateFactory ldapConnectionTemplateFactory;
+
+  @Mock(type = MockType.STRICT)
+  private LdapConnectionTemplate ldapConnectionTemplateMock;
+
+
+  @TestSubject
+  private LdapConfigurationService ldapConfigurationService = new DefaultLdapConfigurationService();
+
+  @Before
+  public void before() {
+    resetAll();
+  }
+
+  @Test
+  public void testShouldConnectionCheckSucceedWhenConnectionCallbackSucceeds() throws Exception {
+    // GIVEN
+    AmbariLdapConfiguration ambariLdapConfiguration = new TestAmbariLdapConfigurationFactory().createLdapConfiguration(Maps.newHashMap());
+
+    // the cllback returns TRUE
+    EasyMock.expect(ldapConnectionTemplateMock.execute(EasyMock.anyObject(ConnectionCallback.class))).andReturn(Boolean.TRUE);
+    EasyMock.expect(ldapConnectionTemplateFactory.create(ambariLdapConfiguration)).andReturn(ldapConnectionTemplateMock);
+
+    replayAll();
+    // WHEN
+    ldapConfigurationService.checkConnection(ambariLdapConfiguration);
+
+    // THEN
+    // no exceptions are thrown
+
+  }
+
+  @Test(expected = AmbariLdapException.class)
+  public void testShouldConnectionCheckFailWhenConnectionCallbackFails() throws Exception {
+
+    // GIVEN
+    AmbariLdapConfiguration ambariLdapConfiguration = new TestAmbariLdapConfigurationFactory().createLdapConfiguration(Maps.newHashMap());
+
+    // the callback returns FALSE
+    EasyMock.expect(ldapConnectionTemplateMock.execute(EasyMock.anyObject(ConnectionCallback.class))).andReturn(Boolean.FALSE);
+    EasyMock.expect(ldapConnectionTemplateFactory.create(ambariLdapConfiguration)).andReturn(ldapConnectionTemplateMock);
+
+    replayAll();
+    // WHEN
+    ldapConfigurationService.checkConnection(ambariLdapConfiguration);
+
+    // THEN
+    // exception is thrown
+
+  }
+
+  @Test
+  public void testShouldUserAttributeConfigurationCheckSucceedWhenUserDnIsFound() throws Exception {
+    // GIVEN
+    Map<String, Object> configMap = Maps.newHashMap();
+    configMap.put(AmbariLdapConfigKeys.USER_OBJECT_CLASS.key(), "person");
+    configMap.put(AmbariLdapConfigKeys.USER_NAME_ATTRIBUTE.key(), "uid");
+
+    AmbariLdapConfiguration ambariLdapConfiguration = new TestAmbariLdapConfigurationFactory().createLdapConfiguration(configMap);
+
+    // the callback returns FALSE
+    EasyMock.expect(ldapConnectionTemplateFactory.create(ambariLdapConfiguration)).andReturn(ldapConnectionTemplateMock);
+    // users found with dn
+    EasyMock.expect(ldapConnectionTemplateMock.searchFirst(EasyMock.anyObject(Dn.class), EasyMock.anyString(), EasyMock.anyObject(SearchScope.class),
+      EasyMock.anyObject(EntryMapper.class))).andReturn("dn");
+
+    replayAll();
+    // WHEN
+    String userDn = ldapConfigurationService.checkUserAttributes("testUser", "testPassword", ambariLdapConfiguration);
+
+    // THEN
+    Assert.assertEquals("The found userDn is not the expected one", userDn, "dn");
+
+  }
+
+  @Test(expected = AmbariLdapException.class)
+  public void testShouldUserAttributeConfigurationCheckFailWhenNoUsersFound() throws Exception {
+    // GIVEN
+    Map<String, Object> configMap = Maps.newHashMap();
+    configMap.put(AmbariLdapConfigKeys.USER_OBJECT_CLASS.key(), "posixAccount");
+    configMap.put(AmbariLdapConfigKeys.USER_NAME_ATTRIBUTE.key(), "dn");
+
+    AmbariLdapConfiguration ambariLdapConfiguration = new TestAmbariLdapConfigurationFactory().createLdapConfiguration(configMap);
+
+    // the callback returns FALSE
+    EasyMock.expect(ldapConnectionTemplateFactory.create(ambariLdapConfiguration)).andReturn(ldapConnectionTemplateMock);
+
+    // no users found, the returned dn is null
+    EasyMock.expect(ldapConnectionTemplateMock.searchFirst(EasyMock.anyObject(Dn.class), EasyMock.anyString(),
+      EasyMock.anyObject(SearchScope.class),
+      EasyMock.anyObject(EntryMapper.class))).andReturn(null);
+
+    replayAll();
+    // WHEN
+    String userDn = ldapConfigurationService.checkUserAttributes("testUser", "testPassword",
+      ambariLdapConfiguration);
+
+    // THEN
+    Assert.assertEquals("The found userDn is not the expected one", userDn, "dn");
+
+  }
+
+
+  @Test
+  public void testShouldGroupAttributeConfigurationCheckSucceedWhenGroupForUserDnIsFound() throws Exception {
+    // GIVEN
+
+    Map<String, Object> configMap = groupConfigObjectMap();
+
+    SearchRequest sr = new SearchRequestImpl();
+
+    AmbariLdapConfiguration ambariLdapConfiguration = new TestAmbariLdapConfigurationFactory().createLdapConfiguration(configMap);
+
+    // the callback returns FALSE
+    EasyMock.expect(ldapConnectionTemplateFactory.create(ambariLdapConfiguration)).andReturn(ldapConnectionTemplateMock);
+
+    EasyMock.expect(ldapConnectionTemplateMock.newSearchRequest(EasyMock.anyObject(Dn.class), EasyMock.anyString(),
+      EasyMock.anyObject(SearchScope.class))).andReturn(sr);
+
+    EasyMock.expect(ldapConnectionTemplateMock.search(EasyMock.anyObject(SearchRequest.class), EasyMock.anyObject(EntryMapper.class)))
+      .andReturn(Lists.newArrayList("userGroup"));
+
+    replayAll();
+    // WHEN
+    Set<String> userGroups = ldapConfigurationService.checkGroupAttributes("userDn", ambariLdapConfiguration);
+
+    // THEN
+    Assert.assertNotNull("No groups found", userGroups);
+
+  }
+
+
+  @Test(expected = AmbariLdapException.class)
+  public void testShouldGroupAttributeConfigurationCheckFailWhenNoGroupsForUserDnFound() throws Exception {
+    // GIVEN
+
+    Map<String, Object> configMap = groupConfigObjectMap();
+
+    SearchRequest sr = new SearchRequestImpl();
+
+    AmbariLdapConfiguration ambariLdapConfiguration = new TestAmbariLdapConfigurationFactory().createLdapConfiguration(configMap);
+
+    // the callback returns FALSE
+    EasyMock.expect(ldapConnectionTemplateFactory.create(ambariLdapConfiguration)).andReturn(ldapConnectionTemplateMock);
+
+    EasyMock.expect(ldapConnectionTemplateMock.newSearchRequest(EasyMock.anyObject(Dn.class), EasyMock.anyString(),
+      EasyMock.anyObject(SearchScope.class))).andReturn(sr);
+
+    EasyMock.expect(ldapConnectionTemplateMock.search(EasyMock.anyObject(SearchRequest.class), EasyMock.anyObject(EntryMapper.class)))
+      .andReturn(Lists.newArrayList());
+
+    replayAll();
+    // WHEN
+    Set<String> userGroups = ldapConfigurationService.checkGroupAttributes("userDn", ambariLdapConfiguration);
+
+    // THEN
+    Assert.assertNotNull("No groups found", userGroups);
+
+  }
+
+  private Map<String, Object> groupConfigObjectMap() {
+    Map<String, Object> configMap = Maps.newHashMap();
+    configMap.put(AmbariLdapConfigKeys.GROUP_OBJECT_CLASS.key(), "groupOfNames");
+    configMap.put(AmbariLdapConfigKeys.GROUP_SEARCH_BASE.key(), "dc=example,dc=com");
+    configMap.put(AmbariLdapConfigKeys.GROUP_NAME_ATTRIBUTE.key(), "uid");
+    configMap.put(AmbariLdapConfigKeys.GROUP_MEMBER_ATTRIBUTE.key(), "member");
+    return configMap;
+  }
+
+
+}
\ No newline at end of file


[32/46] ambari git commit:  AMBARI-21307 Implemented more detectors. Organized the code

Posted by lp...@apache.org.
 AMBARI-21307 Implemented more detectors. Organized the code


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 92f2cc5b59fdb4efa8c71d4f55b7709d7ec95525
Parents: b05842b
Author: lpuskas <lp...@apache.org>
Authored: Tue Sep 12 11:58:45 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:42:00 2017 +0200

----------------------------------------------------------------------
 .../server/ldap/AmbariLdapConfiguration.java    |   1 +
 .../ads/DefaultAttributeDetectionService.java   | 134 ++++++++++++++-----
 .../ldap/service/ads/ObjectClassDetector.java   |  81 -----------
 .../ads/OccurranceAndWeightBasedDetector.java   |  81 -----------
 .../service/ads/UserNameAttributeDetector.java  |  75 -----------
 .../ads/detectors/GroupMemberAttrDetector.java  |  56 ++++++++
 .../ads/detectors/GroupNameAttrDetector.java    |  61 +++++++++
 .../ads/detectors/GroupObjectClassDetector.java |  64 +++++++++
 .../OccurranceAndWeightBasedDetector.java       | 103 ++++++++++++++
 .../detectors/UserGroupMemberAttrDetector.java  |  56 ++++++++
 .../ads/detectors/UserNameAttrDetector.java     |  60 +++++++++
 .../ads/detectors/UserObjectClassDetector.java  |  64 +++++++++
 .../DefaultAttributeDetectionServiceTest.java   |  10 +-
 13 files changed, 571 insertions(+), 275 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/92f2cc5b/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
index e28c6ed..ebb567d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
@@ -56,6 +56,7 @@ public class AmbariLdapConfiguration {
 
     USER_OBJECT_CLASS("ambari.ldap.attributes.user.object_class"),
     USER_NAME_ATTRIBUTE("ambari.ldap.attributes.user.name_attr"),
+    USER_GROUP_MEMBER_ATTRIBUTE("ambari.ldap.attributes.user.group_member_attr"),
     USER_SEARCH_BASE("ambari.ldap.attributes.user.search_base"),
 
     GROUP_OBJECT_CLASS("ambari.ldap.attributes.group.object_class"),

http://git-wip-us.apache.org/repos/asf/ambari/blob/92f2cc5b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionService.java
index 710adf1..b3a4fde 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionService.java
@@ -14,15 +14,18 @@
 
 package org.apache.ambari.server.ldap.service.ads;
 
-import java.util.Set;
-
 import javax.inject.Inject;
 import javax.inject.Singleton;
 
 import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
 import org.apache.ambari.server.ldap.service.AmbariLdapException;
-import org.apache.ambari.server.ldap.service.AttributeDetector;
 import org.apache.ambari.server.ldap.service.LdapAttributeDetectionService;
+import org.apache.ambari.server.ldap.service.ads.detectors.GroupMemberAttrDetector;
+import org.apache.ambari.server.ldap.service.ads.detectors.GroupNameAttrDetector;
+import org.apache.ambari.server.ldap.service.ads.detectors.GroupObjectClassDetector;
+import org.apache.ambari.server.ldap.service.ads.detectors.UserGroupMemberAttrDetector;
+import org.apache.ambari.server.ldap.service.ads.detectors.UserNameAttrDetector;
+import org.apache.ambari.server.ldap.service.ads.detectors.UserObjectClassDetector;
 import org.apache.directory.api.ldap.model.cursor.SearchCursor;
 import org.apache.directory.api.ldap.model.entry.Entry;
 import org.apache.directory.api.ldap.model.message.Response;
@@ -37,24 +40,29 @@ import org.apache.directory.ldap.client.api.search.FilterBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.collect.Sets;
-
 @Singleton
 public class DefaultAttributeDetectionService implements LdapAttributeDetectionService<LdapConnection> {
 
   private static final Logger LOGGER = LoggerFactory.getLogger(DefaultAttributeDetectionService.class);
   private static final int SAMPLE_RESULT_SIZE = 50;
 
-  // ordered list of possible username attribute values (the most significant valus should be first)
 
-  private static final Set<String> USER_OBJECT_CLASS_VALUES = Sets.newHashSet("person", "posixAccount");
-  private static final Set<String> USER_GROUP_MEMBER_ATTR_VALUES = Sets.newHashSet("memberOf", "ismemberOf");
+  @Inject
+  private UserNameAttrDetector userNameAttrDetector = new UserNameAttrDetector(); // todo remove instantition
+
+  @Inject
+  private UserObjectClassDetector userObjectClassDetector = new UserObjectClassDetector(); // todo remove instantition
 
   @Inject
-  private UserNameAttributeDetector userNameAttrDetector = new UserNameAttributeDetector(); // todo remove instantition
+  private UserGroupMemberAttrDetector userGroupMemberAttrDetector = new UserGroupMemberAttrDetector(); // todo remove instantition
 
   @Inject
-  private ObjectClassDetector objectClassDetector = new ObjectClassDetector(); // todo remove instantition
+  private GroupNameAttrDetector groupNameAttrDetector = new GroupNameAttrDetector(); // todo remove instantition
+
+  @Inject
+  private GroupObjectClassDetector groupObjectClassDetector = new GroupObjectClassDetector(); // todo remove instantition
+
+  private GroupMemberAttrDetector groupMemberAttrDetector = new GroupMemberAttrDetector(); // todo remove instantition
 
   @Inject
   public DefaultAttributeDetectionService() {
@@ -76,7 +84,7 @@ public class DefaultAttributeDetectionService implements LdapAttributeDetectionS
       // todo should the bind operation be done in the facade?
       connection.bind(ambariLdapConfiguration.bindDn(), ambariLdapConfiguration.bindPassword());
 
-      SearchRequest searchRequest = assembleSearchRequest(ambariLdapConfiguration);
+      SearchRequest searchRequest = assembleUserSearchRequest(ambariLdapConfiguration);
 
       // do the search
       searchCursor = connection.search(searchRequest);
@@ -95,15 +103,19 @@ public class DefaultAttributeDetectionService implements LdapAttributeDetectionS
 
         if (response instanceof SearchResultEntry) {
           Entry resultEntry = ((SearchResultEntry) response).getEntry();
-          LOGGER.info("Processing sample entry: [{}]", resultEntry.getDn());
+          LOGGER.info("Processing sample entry with dn: [{}]", resultEntry.getDn());
+
           userNameAttrDetector.collect(resultEntry);
-          objectClassDetector.collect(resultEntry);
+          userObjectClassDetector.collect(resultEntry);
+          userGroupMemberAttrDetector.collect(resultEntry);
+
           processedUserCnt++;
         }
       }
 
       ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.USER_NAME_ATTRIBUTE, userNameAttrDetector.detect());
-      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.USER_OBJECT_CLASS, objectClassDetector.detect());
+      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.USER_OBJECT_CLASS, userObjectClassDetector.detect());
+      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.USER_GROUP_MEMBER_ATTRIBUTE, userGroupMemberAttrDetector.detect());
 
       LOGGER.info("Decorated ambari ldap config : [{}]", ambariLdapConfiguration);
 
@@ -120,25 +132,72 @@ public class DefaultAttributeDetectionService implements LdapAttributeDetectionS
     return ambariLdapConfiguration;
   }
 
-  private void detectUserAttributes(Entry resultEntry, AttributeDetector attributeDetector) {
 
-    attributeDetector.collect(resultEntry);
+  @Override
+  public AmbariLdapConfiguration detectLdapGroupAttributes(LdapConnection connection, AmbariLdapConfiguration ambariLdapConfiguration) {
+    LOGGER.info("Detecting LDAP group attributes ...");
 
-//    Set<String> objectClasses = detectUserObjectClass(resultEntry);
-//    if (!objectClasses.isEmpty()) {
-//      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.USER_OBJECT_CLASS, StringUtils.join(objectClasses, ","));
-//    }
+    // perform a search using the user search base
+    if (Strings.isEmpty(ambariLdapConfiguration.groupSearchBase())) {
+      LOGGER.warn("No group search base provided");
+      return ambariLdapConfiguration;
+    }
 
+    SearchCursor searchCursor = null;
 
-  }
+    try {
+      // todo should the bind operation be done in the facade?
+      connection.bind(ambariLdapConfiguration.bindDn(), ambariLdapConfiguration.bindPassword());
 
-  @Override
-  public AmbariLdapConfiguration detectLdapGroupAttributes(LdapConnection connection, AmbariLdapConfiguration ambariLdapConfiguration) {
-    LOGGER.info("Detecting LDAP group attributes ...");
-    return null;
+      SearchRequest searchRequest = assembleGroupSearchRequest(ambariLdapConfiguration);
+
+      // do the search
+      searchCursor = connection.search(searchRequest);
+
+      int processedGroupCnt = 0;
+
+      while (searchCursor.next()) {
+
+        if (processedGroupCnt >= SAMPLE_RESULT_SIZE) {
+          LOGGER.debug("The maximum number of results for attribute detection has exceeded. Quit  detection.");
+          break;
+        }
+
+        Response response = searchCursor.get();
+        // process the SearchResultEntry
+
+        if (response instanceof SearchResultEntry) {
+          Entry resultEntry = ((SearchResultEntry) response).getEntry();
+          LOGGER.info("Processing sample entry with dn: [{}]", resultEntry.getDn());
+
+          groupNameAttrDetector.collect(resultEntry);
+          groupObjectClassDetector.collect(resultEntry);
+          groupMemberAttrDetector.collect(resultEntry);
+
+          processedGroupCnt++;
+        }
+      }
+
+      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.GROUP_NAME_ATTRIBUTE, groupNameAttrDetector.detect());
+      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.GROUP_OBJECT_CLASS, groupObjectClassDetector.detect());
+      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.GROUP_MEMBER_ATTRIBUTE, groupMemberAttrDetector.detect());
+
+      LOGGER.info("Decorated ambari ldap config : [{}]", ambariLdapConfiguration);
+
+    } catch (Exception e) {
+
+      LOGGER.error("Ldap operation failed", e);
+    } finally {
+      // housekeeping
+      if (null != searchCursor) {
+        searchCursor.close();
+      }
+    }
+
+    return ambariLdapConfiguration;
   }
 
-  private SearchRequest assembleSearchRequest(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+  private SearchRequest assembleUserSearchRequest(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
     try {
 
       SearchRequest req = new SearchRequestImpl();
@@ -157,18 +216,23 @@ public class DefaultAttributeDetectionService implements LdapAttributeDetectionS
     }
   }
 
+  private SearchRequest assembleGroupSearchRequest(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+    try {
 
-  private Set<String> detectUserObjectClass(Entry entry) {
-    LOGGER.info("Detecting user object class. Attributes: {}", entry.getAttributes());
-    throw new UnsupportedOperationException("Not yet implemented");
-  }
+      SearchRequest req = new SearchRequestImpl();
+      req.setScope(SearchScope.SUBTREE);
+      req.addAttributes("*");
+      req.setTimeLimit(0);
+      req.setBase(new Dn(ambariLdapConfiguration.groupSearchBase()));
+      // the filter must be set!
+      req.setFilter(FilterBuilder.present(ambariLdapConfiguration.dnAttribute()).toString());
 
-  private String detectGroupNameAttribute(Entry entry) {
-    throw new UnsupportedOperationException("Not yet implemented");
-  }
+      return req;
 
-  private Set<String> detectGroupObjectClass(Entry entry) {
-    throw new UnsupportedOperationException("Not yet implemented");
+    } catch (Exception e) {
+      LOGGER.error("Could not assemble ldap search request", e);
+      throw new AmbariLdapException(e);
+    }
   }
 
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/92f2cc5b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/ObjectClassDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/ObjectClassDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/ObjectClassDetector.java
deleted file mode 100644
index 2613517..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/ObjectClassDetector.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.service.ads;
-
-import java.util.Map;
-
-import javax.inject.Inject;
-
-import org.apache.directory.api.ldap.model.entry.Entry;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.Maps;
-
-public class ObjectClassDetector extends OccurranceAndWeightBasedDetector {
-
-  private static final Logger LOGGER = LoggerFactory.getLogger(ObjectClassDetector.class);
-  private Map<String, Integer> occurranceMap = Maps.newHashMap();
-  private Map<String, Integer> weightsMap = Maps.newHashMap();
-
-
-  private enum ObjectClassValue {
-    PERSON("person", 1),
-    POSIX_ACCOUNT("posixAccount", 1);
-
-    private String ocVal;
-    private Integer weight;
-
-    ObjectClassValue(String attr, Integer weght) {
-      this.ocVal = attr;
-      this.weight = weght;
-    }
-
-    Integer weight() {
-      return this.weight;
-    }
-
-    String ocVal() {
-      return this.ocVal;
-    }
-
-  }
-
-  @Inject
-  public ObjectClassDetector() {
-    for (ObjectClassValue ocVal : ObjectClassValue.values()) {
-      occurranceMap.put(ocVal.ocVal(), 0);
-      weightsMap.put(ocVal.ocVal(), ocVal.weight());
-    }
-
-  }
-
-  @Override
-  protected Map<String, Integer> occurranceMap() {
-    return occurranceMap;
-  }
-
-  @Override
-  protected Map<String, Integer> weightsMap() {
-    return weightsMap;
-  }
-
-  @Override
-  protected boolean applies(Entry entry, String value) {
-    LOGGER.info("Checking for object class [{}] in entry [{}]", value, entry.getDn());
-    return entry.hasObjectClass(value);
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/92f2cc5b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/OccurranceAndWeightBasedDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/OccurranceAndWeightBasedDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/OccurranceAndWeightBasedDetector.java
deleted file mode 100644
index 32dc238..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/OccurranceAndWeightBasedDetector.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.service.ads;
-
-import java.util.Map;
-
-import org.apache.ambari.server.ldap.service.AttributeDetector;
-import org.apache.directory.api.ldap.model.entry.Entry;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public abstract class OccurranceAndWeightBasedDetector implements AttributeDetector<Entry> {
-
-  private static final Logger LOGGER = LoggerFactory.getLogger(OccurranceAndWeightBasedDetector.class);
-
-  protected abstract Map<String, Integer> occurranceMap();
-
-  protected abstract Map<String, Integer> weightsMap();
-
-  protected abstract boolean applies(Entry entry, String value);
-
-  @Override
-  public String detect() {
-    Map.Entry<String, Integer> selectedEntry = null;
-
-    for (Map.Entry<String, Integer> entry : occurranceMap().entrySet()) {
-      if (selectedEntry == null) {
-
-        selectedEntry = entry;
-        LOGGER.info("Initial name attribute: {}", selectedEntry);
-        continue;
-
-      }
-
-      if (selectedEntry.getValue() < entry.getValue()) {
-
-        LOGGER.info("Changing potential name attribute from : [{}] to: [{}]", selectedEntry, entry);
-        selectedEntry = entry;
-
-      }
-    }
-    return selectedEntry.getKey();
-  }
-
-  @Override
-  public void collect(Entry entry) {
-    LOGGER.info("Detecting ldap attributes/values ...");
-
-    for (String attributeValue : occurranceMap().keySet()) {
-      if (applies(entry, attributeValue)) {
-
-        Integer cnt = occurranceMap().get(attributeValue).intValue();
-        if (weightsMap().containsKey(attributeValue)) {
-          cnt = cnt + weightsMap().get(attributeValue);
-        } else {
-          cnt = cnt + 1;
-        }
-        occurranceMap().put(attributeValue, cnt);
-
-        LOGGER.info("Collected potential name attr: {}, count: {}", attributeValue, cnt);
-
-      } else {
-        LOGGER.info("The result entry doesn't contain the attribute: [{}]", attributeValue);
-      }
-    }
-  }
-
-
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/92f2cc5b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/UserNameAttributeDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/UserNameAttributeDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/UserNameAttributeDetector.java
deleted file mode 100644
index bbb4b43..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/UserNameAttributeDetector.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.service.ads;
-
-import java.util.Map;
-
-import org.apache.directory.api.ldap.model.entry.Entry;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.Maps;
-
-public class UserNameAttributeDetector extends OccurranceAndWeightBasedDetector {
-  private static final Logger LOGGER = LoggerFactory.getLogger(UserNameAttributeDetector.class);
-
-  private Map<String, Integer> occurranceMap = Maps.newHashMap();
-  private Map<String, Integer> weightsMap = Maps.newHashMap();
-
-  private enum NameAttrs {
-    SAM_ACCOUNT_NAME("sAMAccountName", 5),
-    UID("uid", 3),
-    CN("cn", 1);
-
-    private String attrName;
-    private Integer weight;
-
-    NameAttrs(String attr, Integer weght) {
-      this.attrName = attr;
-      this.weight = weght;
-    }
-
-    Integer weight() {
-      return this.weight;
-    }
-
-    String attrName() {
-      return this.attrName;
-    }
-
-  }
-
-  public UserNameAttributeDetector() {
-    for (NameAttrs nameAttr : NameAttrs.values()) {
-      occurranceMap.put(nameAttr.attrName(), 0);
-      weightsMap.put(nameAttr.attrName(), nameAttr.weight());
-    }
-  }
-
-  protected Map<String, Integer> occurranceMap() {
-    return occurranceMap;
-  }
-
-  protected Map<String, Integer> weightsMap() {
-    return weightsMap;
-  }
-
-  @Override
-  protected boolean applies(Entry entry, String value) {
-    LOGGER.info("Checking for attribute  [{}] in entry [{}]", value, entry.getDn());
-    return entry.containsAttribute(value);
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/92f2cc5b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java
new file mode 100644
index 0000000..6931736
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads.detectors;
+
+import org.apache.directory.api.ldap.model.entry.Entry;
+
+public class GroupMemberAttrDetector extends OccurranceAndWeightBasedDetector {
+
+  private enum GroupMemberAttr {
+
+    MEMBER("member", 1),
+    MEMBER_UID("memberUid", 1),
+    UNIQUE_MEMBER("uniqueMember", 1);
+
+    private String attrName;
+    private Integer weight;
+
+    GroupMemberAttr(String attr, Integer weght) {
+      this.attrName = attr;
+      this.weight = weght;
+    }
+
+    Integer weight() {
+      return this.weight;
+    }
+
+    String attrName() {
+      return this.attrName;
+    }
+
+  }
+
+  public GroupMemberAttrDetector() {
+    for (GroupMemberAttr groupMemberAttr : GroupMemberAttr.values()) {
+      occurranceMap().put(groupMemberAttr.attrName(), 0);
+      weightsMap().put(groupMemberAttr.attrName(), groupMemberAttr.weight());
+    }
+  }
+
+  @Override
+  protected boolean applies(Entry entry, String value) {
+    return entry.containsAttribute(value);
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/92f2cc5b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupNameAttrDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupNameAttrDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupNameAttrDetector.java
new file mode 100644
index 0000000..f868383
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupNameAttrDetector.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads.detectors;
+
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class GroupNameAttrDetector extends OccurranceAndWeightBasedDetector {
+  private static final Logger LOGGER = LoggerFactory.getLogger(UserNameAttrDetector.class);
+
+  private enum GroupNameAttr {
+
+    DISTINGUISHED_NAME("distinguishedName", 1),
+
+    CN("cn", 1);
+
+    private String attrName;
+    private Integer weight;
+
+    GroupNameAttr(String attr, Integer weght) {
+      this.attrName = attr;
+      this.weight = weght;
+    }
+
+    Integer weight() {
+      return this.weight;
+    }
+
+    String attrName() {
+      return this.attrName;
+    }
+
+  }
+
+  public GroupNameAttrDetector() {
+
+    for (GroupNameAttr groupNameAttr : GroupNameAttr.values()) {
+      occurranceMap().put(groupNameAttr.attrName(), 0);
+      weightsMap().put(groupNameAttr.attrName(), groupNameAttr.weight());
+    }
+  }
+
+
+  @Override
+  protected boolean applies(Entry entry, String value) {
+    return entry.containsAttribute(value);
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/92f2cc5b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupObjectClassDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupObjectClassDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupObjectClassDetector.java
new file mode 100644
index 0000000..fddc5a5
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupObjectClassDetector.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads.detectors;
+
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class GroupObjectClassDetector extends OccurranceAndWeightBasedDetector {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(GroupObjectClassDetector.class);
+
+  private enum ObjectClassValue {
+
+    GROUP("group", 1),
+
+    GROUP_OF_NAMES("groupOfNames", 1),
+
+    POSIX_GROUP("posixGroup", 1),
+
+    GROUP_OF_UNIQUE_NAMES("groupOfUniqueNames", 1);
+
+    private String ocVal;
+    private Integer weight;
+
+    ObjectClassValue(String attr, Integer weght) {
+      this.ocVal = attr;
+      this.weight = weght;
+    }
+
+    Integer weight() {
+      return this.weight;
+    }
+
+    String ocVal() {
+      return this.ocVal;
+    }
+
+  }
+
+  public GroupObjectClassDetector() {
+    for (ObjectClassValue ocVal : ObjectClassValue.values()) {
+      occurranceMap().put(ocVal.ocVal(), 0);
+      weightsMap().put(ocVal.ocVal(), ocVal.weight());
+    }
+  }
+
+  @Override
+  protected boolean applies(Entry entry, String value) {
+    return entry.hasObjectClass(value);
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/92f2cc5b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurranceAndWeightBasedDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurranceAndWeightBasedDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurranceAndWeightBasedDetector.java
new file mode 100644
index 0000000..8aaf6c1
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurranceAndWeightBasedDetector.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads.detectors;
+
+import java.util.Map;
+
+import org.apache.ambari.server.ldap.service.AttributeDetector;
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Maps;
+
+public abstract class OccurranceAndWeightBasedDetector implements AttributeDetector<Entry> {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(OccurranceAndWeightBasedDetector.class);
+
+  private Map<String, Integer> occurranceMap = Maps.newHashMap();
+  private Map<String, Integer> weightsMap = Maps.newHashMap();
+
+  protected Map<String, Integer> occurranceMap() {
+    return occurranceMap;
+  }
+
+  protected Map<String, Integer> weightsMap() {
+    return weightsMap;
+  }
+
+
+  protected abstract boolean applies(Entry entry, String value);
+
+  @Override
+  public String detect() {
+    LOGGER.info("Calculating the most probable attribute/value ...");
+    Map.Entry<String, Integer> selectedEntry = null;
+
+    for (Map.Entry<String, Integer> entry : occurranceMap().entrySet()) {
+      if (selectedEntry == null) {
+
+        selectedEntry = entry;
+        LOGGER.debug("Initial attribute / value entry: {}", selectedEntry);
+        continue;
+
+      }
+
+      if (selectedEntry.getValue() < entry.getValue()) {
+
+        LOGGER.info("Changing potential attribute / value entry from : [{}] to: [{}]", selectedEntry, entry);
+        selectedEntry = entry;
+
+      }
+    }
+
+    // check whether the selected entry is valid (has occured in the sample result set)
+    String detectedVal = "N/A";
+
+    if (selectedEntry.getValue() > 0) {
+      detectedVal = selectedEntry.getKey();
+    } else {
+      LOGGER.warn("Unable to detect attribute or attribute value");
+    }
+
+    LOGGER.info("Detected attribute or value: [{}]", detectedVal);
+    return detectedVal;
+  }
+
+  @Override
+  public void collect(Entry entry) {
+    LOGGER.info("Collecting ldap attributes/values form entry with dn: [{]]", entry.getDn());
+
+    for (String attributeValue : occurranceMap().keySet()) {
+      if (applies(entry, attributeValue)) {
+
+        Integer cnt = occurranceMap().get(attributeValue).intValue();
+        if (weightsMap().containsKey(attributeValue)) {
+          cnt = cnt + weightsMap().get(attributeValue);
+        } else {
+          cnt = cnt + 1;
+        }
+        occurranceMap().put(attributeValue, cnt);
+
+        LOGGER.info("Collected potential name attr: {}, count: {}", attributeValue, cnt);
+
+      } else {
+        LOGGER.info("The result entry doesn't contain the attribute: [{}]", attributeValue);
+      }
+    }
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/92f2cc5b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java
new file mode 100644
index 0000000..c3f2ab4
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads.detectors;
+
+import org.apache.directory.api.ldap.model.entry.Entry;
+
+public class UserGroupMemberAttrDetector extends OccurranceAndWeightBasedDetector {
+  private static String[] userGroupMemAttrValues = {"memberOf", "ismemberOf"};
+
+  private enum UserGroupMemberAttr {
+
+    MEMBER_OF("memberOf", 1),
+    IS_MEMBER_OF("ismemberOf", 1);
+
+    private String attrName;
+    private Integer weight;
+
+    UserGroupMemberAttr(String attr, Integer weght) {
+      this.attrName = attr;
+      this.weight = weght;
+    }
+
+    Integer weight() {
+      return this.weight;
+    }
+
+    String attrName() {
+      return this.attrName;
+    }
+
+  }
+
+  public UserGroupMemberAttrDetector() {
+    for (UserGroupMemberAttr userGroupMemberAttr : UserGroupMemberAttr.values()) {
+      occurranceMap().put(userGroupMemberAttr.attrName(), 0);
+      weightsMap().put(userGroupMemberAttr.attrName(), userGroupMemberAttr.weight);
+    }
+  }
+
+  @Override
+  protected boolean applies(Entry entry, String value) {
+    return entry.containsAttribute(value);
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/92f2cc5b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserNameAttrDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserNameAttrDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserNameAttrDetector.java
new file mode 100644
index 0000000..40bf09b
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserNameAttrDetector.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads.detectors;
+
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class UserNameAttrDetector extends OccurranceAndWeightBasedDetector {
+  private static final Logger LOGGER = LoggerFactory.getLogger(UserNameAttrDetector.class);
+
+  private enum UserNameAttrs {
+    SAM_ACCOUNT_NAME("sAMAccountName", 5),
+    UID("uid", 3),
+    CN("cn", 1);
+
+    private String attrName;
+    private Integer weight;
+
+    UserNameAttrs(String attr, Integer weght) {
+      this.attrName = attr;
+      this.weight = weght;
+    }
+
+    Integer weight() {
+      return this.weight;
+    }
+
+    String attrName() {
+      return this.attrName;
+    }
+
+  }
+
+  public UserNameAttrDetector() {
+    for (UserNameAttrs nameAttr : UserNameAttrs.values()) {
+      occurranceMap().put(nameAttr.attrName(), 0);
+      weightsMap().put(nameAttr.attrName(), nameAttr.weight());
+    }
+  }
+
+  @Override
+  protected boolean applies(Entry entry, String value) {
+    LOGGER.info("Checking for attribute  [{}] in entry [{}]", value, entry.getDn());
+    return entry.containsAttribute(value);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/92f2cc5b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserObjectClassDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserObjectClassDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserObjectClassDetector.java
new file mode 100644
index 0000000..97b3c52
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserObjectClassDetector.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads.detectors;
+
+import javax.inject.Inject;
+
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class UserObjectClassDetector extends OccurranceAndWeightBasedDetector {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(UserObjectClassDetector.class);
+
+  private enum ObjectClassValue {
+    PERSON("person", 1),
+    POSIX_ACCOUNT("posixAccount", 1);
+
+    private String ocVal;
+    private Integer weight;
+
+    ObjectClassValue(String attr, Integer weght) {
+      this.ocVal = attr;
+      this.weight = weght;
+    }
+
+    Integer weight() {
+      return this.weight;
+    }
+
+    String ocVal() {
+      return this.ocVal;
+    }
+
+  }
+
+  @Inject
+  public UserObjectClassDetector() {
+    for (ObjectClassValue ocVal : ObjectClassValue.values()) {
+      occurranceMap().put(ocVal.ocVal(), 0);
+      weightsMap().put(ocVal.ocVal(), ocVal.weight());
+    }
+
+  }
+
+  @Override
+  protected boolean applies(Entry entry, String value) {
+    LOGGER.info("Checking for object class [{}] in entry [{}]", value, entry.getDn());
+    return entry.hasObjectClass(value);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/92f2cc5b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionServiceTest.java
index 5cddf1a..08f2d6c 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionServiceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionServiceTest.java
@@ -32,6 +32,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.Maps;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
 
 public class DefaultAttributeDetectionServiceTest {
 
@@ -78,9 +80,12 @@ public class DefaultAttributeDetectionServiceTest {
 
     // WHEN
     AmbariLdapConfiguration config = attributeDetectionService.detectLdapUserAttributes(ldapConnection, ambariLdapConfiguration);
+    config = attributeDetectionService.detectLdapGroupAttributes(ldapConnection, ambariLdapConfiguration);
 
-    // THEN
+    Gson gson = new GsonBuilder().create();
+    LOGGER.info(gson.toJson(config));
 
+    // THEN
     ldapConnection.close();
 
   }
@@ -95,9 +100,8 @@ public class DefaultAttributeDetectionServiceTest {
     ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.BIND_PASSWORD.key(), "password");
     ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.DN_ATTRIBUTE.key(), SchemaConstants.CN_AT);
 
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.USER_OBJECT_CLASS.key(), SchemaConstants.PERSON_OC);
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.USER_NAME_ATTRIBUTE.key(), SchemaConstants.UID_AT);
     ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.USER_SEARCH_BASE.key(), "dc=example,dc=com");
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.GROUP_SEARCH_BASE.key(), "dc=example,dc=com");
 
     return ldapPropsMap;
 


[06/46] ambari git commit: AMBARI-22250. Upgrade option not showing in stack versions. (Ishan Bhatt via yusaku)

Posted by lp...@apache.org.
AMBARI-22250. Upgrade option not showing in stack versions. (Ishan Bhatt via yusaku)


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: ee509e08fa25545953d78450997b3a47bf68f904
Parents: 881e15d
Author: Yusaku Sako <yu...@hortonworks.com>
Authored: Tue Oct 17 15:41:20 2017 -0700
Committer: Yusaku Sako <yu...@hortonworks.com>
Committed: Tue Oct 17 15:41:20 2017 -0700

----------------------------------------------------------------------
 .../views/main/admin/stack_upgrade/upgrade_version_box_view.js   | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/ee509e08/ambari-web/app/views/main/admin/stack_upgrade/upgrade_version_box_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/admin/stack_upgrade/upgrade_version_box_view.js b/ambari-web/app/views/main/admin/stack_upgrade/upgrade_version_box_view.js
index 355ad88..c0786a3 100644
--- a/ambari-web/app/views/main/admin/stack_upgrade/upgrade_version_box_view.js
+++ b/ambari-web/app/views/main/admin/stack_upgrade/upgrade_version_box_view.js
@@ -279,9 +279,9 @@ App.UpgradeVersionBoxView = Em.View.extend({
         default:
           var isVersionColumnView = this.get('isVersionColumnView');
           var stackServices = this.get('content.stackServices');
-          var isUpgradable = stackServices && stackServices.some( function(stackService){
+          var isUpgradable = stackServices && (this.get('content.isStandard') || stackServices.some( function(stackService){
               return stackService.get('isUpgradable');
-          });
+          }));
           var isPatch = this.get('content.isPatch');
           var isMaint = this.get('content.isMaint');
 


[38/46] ambari git commit: AMBARI-21307 Refactor - using the LdapConnectionTemplate for ldap operations

Posted by lp...@apache.org.
AMBARI-21307 Refactor - using the LdapConnectionTemplate for ldap operations


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 1939f092a42f4bca292aa8b5ca0756294ce78111
Parents: 1de16c8
Author: lpuskas <lp...@apache.org>
Authored: Wed Oct 4 15:54:34 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:42:01 2017 +0200

----------------------------------------------------------------------
 .../services/ldap/LdapConfigurationService.java |   6 +-
 .../server/controller/ControllerModule.java     |   2 +-
 .../apache/ambari/server/ldap/LdapModule.java   |  12 +-
 .../domain/AmbariLdapConfigurationFactory.java  |  34 +++++
 .../ldap/domain/LdapConfigurationFactory.java   |  34 -----
 .../AmbariLdapConfigurationProvider.java        |   5 +-
 .../server/ldap/service/AmbariLdapFacade.java   |  36 +----
 .../server/ldap/service/AttributeDetector.java  |   2 +-
 .../service/LdapAttributeDetectionService.java  |   8 +-
 .../ldap/service/LdapConfigurationService.java  |  22 +--
 .../ldap/service/LdapConnectionService.java     |  43 ------
 .../service/LdapConnectionTemplateProvider.java |  56 ++++++++
 .../DefaultLdapAttributeDetectionService.java   | 129 ++++++-----------
 .../ads/DefaultLdapConfigurationService.java    | 110 +++++++-------
 .../ads/DefaultLdapConnectionService.java       |  86 -----------
 .../ads/LdapConnectionTemplateFactory.java      |  95 ++++++++++++
 .../ads/detectors/GroupMemberAttrDetector.java  |   4 +-
 .../ads/detectors/GroupNameAttrDetector.java    |   4 +-
 .../ads/detectors/GroupObjectClassDetector.java |   4 +-
 .../OccurranceAndWeightBasedDetector.java       | 103 -------------
 .../OccurrenceAndWeightBasedDetector.java       | 103 +++++++++++++
 .../detectors/UserGroupMemberAttrDetector.java  |   4 +-
 .../ads/detectors/UserNameAttrDetector.java     |   4 +-
 .../ads/detectors/UserObjectClassDetector.java  |   4 +-
 .../server/ldap/LdapModuleFunctionalTest.java   | 143 +++++++++++++++++++
 .../domain/AmbariLdapConfigurationTest.java     |  19 ---
 ...estAmbariAmbariLdapConfigurationFactory.java |  29 ++++
 .../TestAmbariLdapConfigurationFactory.java     |  29 ----
 ...efaultLdapAttributeDetectionServiceTest.java | 112 ---------------
 .../DefaultLdapConfigurationServiceTest.java    | 129 -----------------
 30 files changed, 601 insertions(+), 770 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
index ff95066..13f8835 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
@@ -47,7 +47,7 @@ import org.apache.ambari.server.api.services.ResultStatus;
 import org.apache.ambari.server.controller.internal.ResourceImpl;
 import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.domain.LdapConfigurationFactory;
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfigurationFactory;
 import org.apache.ambari.server.ldap.service.LdapFacade;
 import org.apache.ambari.server.security.authorization.AuthorizationException;
 import org.apache.ambari.server.security.authorization.AuthorizationHelper;
@@ -72,7 +72,7 @@ public class LdapConfigurationService extends AmbariConfigurationService {
   private static LdapFacade ldapFacade;
 
   @Inject
-  private static LdapConfigurationFactory ldapConfigurationFactory;
+  private static AmbariLdapConfigurationFactory ambariLdapConfigurationFactory;
 
 
   @POST
@@ -93,7 +93,7 @@ public class LdapConfigurationService extends AmbariConfigurationService {
 
       validateRequest(ldapConfigurationRequest);
 
-      AmbariLdapConfiguration ambariLdapConfiguration = ldapConfigurationFactory.createLdapConfiguration(
+      AmbariLdapConfiguration ambariLdapConfiguration = ambariLdapConfigurationFactory.createLdapConfiguration(
         ldapConfigurationRequest.getAmbariConfiguration().getData().iterator().next());
 
       LdapConfigOperation action = LdapConfigOperation.fromAction(ldapConfigurationRequest.getRequestInfo().getAction());

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
index 4f30b15..1425e1b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
@@ -62,8 +62,8 @@ import org.apache.ambari.server.cleanup.ClasspathScannerUtils;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.configuration.Configuration.ConnectionPoolType;
 import org.apache.ambari.server.configuration.Configuration.DatabaseType;
-import org.apache.ambari.server.controller.internal.AmbariConfigurationResourceProvider;
 import org.apache.ambari.server.controller.internal.AlertTargetResourceProvider;
+import org.apache.ambari.server.controller.internal.AmbariConfigurationResourceProvider;
 import org.apache.ambari.server.controller.internal.ClusterStackVersionResourceProvider;
 import org.apache.ambari.server.controller.internal.ComponentResourceProvider;
 import org.apache.ambari.server.controller.internal.CredentialResourceProvider;

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
index 83a73d1..d59264a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
@@ -16,16 +16,16 @@
 package org.apache.ambari.server.ldap;
 
 import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.domain.LdapConfigurationFactory;
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfigurationFactory;
 import org.apache.ambari.server.ldap.service.AmbariLdapConfigurationProvider;
 import org.apache.ambari.server.ldap.service.AmbariLdapFacade;
 import org.apache.ambari.server.ldap.service.LdapAttributeDetectionService;
 import org.apache.ambari.server.ldap.service.LdapConfigurationService;
-import org.apache.ambari.server.ldap.service.LdapConnectionService;
+import org.apache.ambari.server.ldap.service.LdapConnectionTemplateProvider;
 import org.apache.ambari.server.ldap.service.LdapFacade;
 import org.apache.ambari.server.ldap.service.ads.DefaultLdapAttributeDetectionService;
 import org.apache.ambari.server.ldap.service.ads.DefaultLdapConfigurationService;
-import org.apache.ambari.server.ldap.service.ads.DefaultLdapConnectionService;
+import org.apache.directory.ldap.client.template.LdapConnectionTemplate;
 
 import com.google.inject.AbstractModule;
 import com.google.inject.assistedinject.FactoryModuleBuilder;
@@ -39,12 +39,14 @@ public class LdapModule extends AbstractModule {
   protected void configure() {
     bind(LdapFacade.class).to(AmbariLdapFacade.class);
     bind(LdapConfigurationService.class).to(DefaultLdapConfigurationService.class);
-    bind(LdapConnectionService.class).to(DefaultLdapConnectionService.class);
     bind(LdapAttributeDetectionService.class).to(DefaultLdapAttributeDetectionService.class);
 
     // this binding requires the JPA module!
     bind(AmbariLdapConfiguration.class).toProvider(AmbariLdapConfigurationProvider.class);
 
-    install(new FactoryModuleBuilder().build(LdapConfigurationFactory.class));
+    // bind to the provider implementation (let GUICE deal with instantiating 3rd party instances)
+    bind(LdapConnectionTemplate.class).toProvider(LdapConnectionTemplateProvider.class);
+
+    install(new FactoryModuleBuilder().build(AmbariLdapConfigurationFactory.class));
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigurationFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigurationFactory.java
new file mode 100644
index 0000000..2b9f24b
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigurationFactory.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.domain;
+
+import java.util.Map;
+
+/**
+ * Factory interface for AmbariLdapConfiguration instances.
+ * It's registered as a factory in the GUICE context (so no implementations required)
+ *
+ * To be extended with other factory methods upon needs.
+ */
+public interface AmbariLdapConfigurationFactory {
+
+  /**
+   * Creates an AmbariLdapConfiguration instance with the provided map of configuration settings.
+   *
+   * @param configuration a map where keys are the configuration properties and values are the configuration values
+   * @return an AmbariLdapConfiguration instance
+   */
+  AmbariLdapConfiguration createLdapConfiguration(Map<String, Object> configuration);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/LdapConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/LdapConfigurationFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/LdapConfigurationFactory.java
deleted file mode 100644
index bf8f825..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/LdapConfigurationFactory.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.domain;
-
-import java.util.Map;
-
-/**
- * Factory interface for AmbariLdapConfiguration instances.
- * It's registered as a factory in the GUICE context (so no implementations required)
- *
- * To be extended with other factory methods upon needs.
- */
-public interface LdapConfigurationFactory {
-
-  /**
-   * Creates an AmbariLdapConfiguration instance with the provided map of configuration settings.
-   *
-   * @param configuration a map where keys are the configuration properties and values are the configuration values
-   * @return an AmbariLdapConfiguration instance
-   */
-  AmbariLdapConfiguration createLdapConfiguration(Map<String, Object> configuration);
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java
index af9f2e7..9fad896 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java
@@ -24,7 +24,7 @@ import javax.inject.Singleton;
 import org.apache.ambari.server.events.AmbariLdapConfigChangedEvent;
 import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
 import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.domain.LdapConfigurationFactory;
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfigurationFactory;
 import org.apache.ambari.server.orm.dao.AmbariConfigurationDAO;
 import org.apache.ambari.server.orm.entities.AmbariConfigurationEntity;
 import org.apache.ambari.server.security.authorization.AmbariLdapAuthenticationProvider;
@@ -57,7 +57,7 @@ public class AmbariLdapConfigurationProvider implements Provider<AmbariLdapConfi
   private Provider<AmbariConfigurationDAO> ambariConfigurationDAOProvider;
 
   @Inject
-  private LdapConfigurationFactory ldapConfigurationFactory;
+  private AmbariLdapConfigurationFactory ldapConfigurationFactory;
 
   private Gson gson = new GsonBuilder().create();
 
@@ -107,6 +107,7 @@ public class AmbariLdapConfigurationProvider implements Provider<AmbariLdapConfi
     return instance;
   }
 
+  // On changing the configuration, the provider gets updated with the fresh value
   @Subscribe
   public void ambariLdapConfigChanged(AmbariLdapConfigChangedEvent event) {
     LOGGER.info("LDAP config changed event received: {}", event);

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
index 7a6ad5a..c75b0c4 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
@@ -22,7 +22,6 @@ import javax.inject.Inject;
 import javax.inject.Singleton;
 
 import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
-import org.apache.directory.ldap.client.api.LdapConnection;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -54,9 +53,6 @@ public class AmbariLdapFacade implements LdapFacade {
   private LdapConfigurationService ldapConfigurationService;
 
   @Inject
-  private LdapConnectionService ldapConnectionService;
-
-  @Inject
   private LdapAttributeDetectionService ldapAttributeDetectionService;
 
   @Inject
@@ -65,13 +61,8 @@ public class AmbariLdapFacade implements LdapFacade {
 
   @Override
   public void checkConnection(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
-    LdapConnection connection = null;
     try {
-
-      LOGGER.info("Validating LDAP connection related configuration based on: {}", ambariLdapConfiguration);
-      connection = ldapConnectionService.getBoundLdapConnection(ambariLdapConfiguration);
-
-      ldapConfigurationService.checkConnection(connection, ambariLdapConfiguration);
+      ldapConfigurationService.checkConnection(ambariLdapConfiguration);
       LOGGER.info("Validating LDAP connection related configuration: SUCCESS");
 
     } catch (Exception e) {
@@ -79,13 +70,6 @@ public class AmbariLdapFacade implements LdapFacade {
       LOGGER.error("Validating LDAP connection configuration failed", e);
       throw new AmbariLdapException(e);
 
-    } finally {
-      try {
-        connection.unBind();
-        connection.close();
-      } catch (Exception e) {
-        throw new AmbariLdapException(e);
-      }
     }
 
   }
@@ -95,14 +79,13 @@ public class AmbariLdapFacade implements LdapFacade {
   public AmbariLdapConfiguration detectAttributes(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
     LOGGER.info("Detecting LDAP configuration attributes ...");
 
-    LdapConnection connection = ldapConnectionService.getBoundLdapConnection(ambariLdapConfiguration);
     try {
 
       // decorate the configuration with detected user attributes
-      ambariLdapConfiguration = ldapAttributeDetectionService.detectLdapUserAttributes(connection, ambariLdapConfiguration);
+      ambariLdapConfiguration = ldapAttributeDetectionService.detectLdapUserAttributes(ambariLdapConfiguration);
 
       // decorate the configuration with detected group attributes
-      ambariLdapConfiguration = ldapAttributeDetectionService.detectLdapGroupAttributes(connection, ambariLdapConfiguration);
+      ambariLdapConfiguration = ldapAttributeDetectionService.detectLdapGroupAttributes(ambariLdapConfiguration);
       return ambariLdapConfiguration;
 
     } catch (Exception e) {
@@ -110,13 +93,6 @@ public class AmbariLdapFacade implements LdapFacade {
       LOGGER.error("Error during LDAP attribute detection", e);
       throw new AmbariLdapException(e);
 
-    } finally {
-      try {
-        connection.unBind();
-        connection.close();
-      } catch (Exception e) {
-        throw new AmbariLdapException(e);
-      }
     }
   }
 
@@ -129,14 +105,12 @@ public class AmbariLdapFacade implements LdapFacade {
       throw new IllegalArgumentException("No test user available for testing LDAP attributes");
     }
 
-    LdapConnection ldapConnection = ldapConnectionService.getBoundLdapConnection(ldapConfiguration);
-
     LOGGER.info("Testing LDAP user attributes with test user: {}", userName);
-    String userDn = ldapConfigurationService.checkUserAttributes(ldapConnection, userName, testUserPass, ldapConfiguration);
+    String userDn = ldapConfigurationService.checkUserAttributes(userName, testUserPass, ldapConfiguration);
 
     // todo handle the case where group membership is stored in the user rather than the group
     LOGGER.info("Testing LDAP group attributes with test user dn: {}", userDn);
-    Set<String> groups = ldapConfigurationService.checkGroupAttributes(ldapConnection, userDn, ldapConfiguration);
+    Set<String> groups = ldapConfigurationService.checkGroupAttributes(userDn, ldapConfiguration);
 
     return groups;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AttributeDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AttributeDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AttributeDetector.java
index 1b28148..c694b17 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AttributeDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AttributeDetector.java
@@ -29,7 +29,7 @@ public interface AttributeDetector<T> {
   void collect(T entry);
 
   /**
-   * Implements the decision based on whiche the "best" possible attribute or value is selected.
+   * Implements the decision based on which the "best" possible attribute or value is selected.
    *
    * @return the most probable attribute name or value (based on the logic in the implementer)
    */

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapAttributeDetectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapAttributeDetectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapAttributeDetectionService.java
index 90e3b8b..6cd369b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapAttributeDetectionService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapAttributeDetectionService.java
@@ -19,24 +19,22 @@ import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
 /**
  * Contract defining operations to detect user and group attributes.
  */
-public interface LdapAttributeDetectionService<T> {
+public interface LdapAttributeDetectionService {
 
   /**
    * Decorates the passed in configuration with the detected ldap user attribute values
    *
-   * @param ldapConnection          the connection instance to LDAP
    * @param ambariLdapConfiguration configuration instance holding connection details
    * @return the configuration decorated with user related attributes
    */
-  AmbariLdapConfiguration detectLdapUserAttributes(T ldapConnection, AmbariLdapConfiguration ambariLdapConfiguration);
+  AmbariLdapConfiguration detectLdapUserAttributes(AmbariLdapConfiguration ambariLdapConfiguration);
 
   /**
    * Decorates the passed in configuration with the detected ldap group attribute values
    *
-   * @param ldapConnection          the connection instance to LDAP
    * @param ambariLdapConfiguration configuration instance holding connection details
    * @return the configuration decorated with group related attributes
    */
-  AmbariLdapConfiguration detectLdapGroupAttributes(T ldapConnection, AmbariLdapConfiguration ambariLdapConfiguration);
+  AmbariLdapConfiguration detectLdapGroupAttributes(AmbariLdapConfiguration ambariLdapConfiguration);
 }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConfigurationService.java
index 5c376c9..4b82aa2 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConfigurationService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConfigurationService.java
@@ -18,7 +18,6 @@ import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
-import org.apache.directory.ldap.client.api.LdapConnection;
 
 /**
  * Collection of operations for validating ldap configuration.
@@ -29,11 +28,10 @@ public interface LdapConfigurationService {
   /**
    * Tests the connection based on the provided configuration.
    *
-   * @param ldapConnection connection instance
-   * @param configuration  the ambari ldap configuration instance
+   * @param configuration the ambari ldap configuration instance
    * @throws AmbariLdapException if the connection is not possible
    */
-  void checkConnection(LdapConnection ldapConnection, AmbariLdapConfiguration configuration) throws AmbariLdapException;
+  void checkConnection(AmbariLdapConfiguration configuration) throws AmbariLdapException;
 
 
   /**
@@ -41,20 +39,22 @@ public interface LdapConfigurationService {
    * Implementers communicate with the LDAP server (search, bind) to validate attributes in the provided configuration
    * instance
    *
-   * @param ldapConnection connection instance used to connect to the LDAP server
-   * @param testUserName   the test username
-   * @param testPassword   the test password
-   * @param configuration  the available ldap configuration
+   * @param testUserName  the test username
+   * @param testPassword  the test password
+   * @param configuration the available ldap configuration
    * @return The DN of the found user entry
    * @throws AmbariException if the connection couldn't be estabilisheds
    */
-  String checkUserAttributes(LdapConnection ldapConnection, String testUserName, String testPassword, AmbariLdapConfiguration configuration) throws AmbariLdapException;
+  String checkUserAttributes(String testUserName, String testPassword, AmbariLdapConfiguration configuration) throws AmbariLdapException;
 
   /**
    * Checks whether the group related LDAP attributes in the configuration are correct.
    *
-   * @throws AmbariException if the attributes are not valid
+   * @param userDn
+   * @param ambariLdapConfiguration
+   * @return
+   * @throws AmbariLdapException
    */
-  Set<String> checkGroupAttributes(LdapConnection ldapConnection, String userDn, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException;
+  Set<String> checkGroupAttributes(String userDn, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException;
 
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionService.java
deleted file mode 100644
index 6f1e1ff..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionService.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.service;
-
-import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
-import org.apache.directory.ldap.client.api.LdapConnection;
-
-/**
- * Contract defining factory methods for creating LDAP connection instances.
- * Implementers contain the logic of creating different connection instances and the afferent boilerplate code.
- */
-public interface LdapConnectionService {
-
-  /**
-   * Creates an LdapConnection instance based on the provided configuration
-   *
-   * @param ambariLdapConfiguration configuration instance with information for creating the connection instance
-   * @return a set up LdapConnection instance
-   */
-  LdapConnection createLdapConnection(AmbariLdapConfiguration ambariLdapConfiguration);
-
-  /**
-   * Creates an LdapConnection instance and binds to the LDAP server based on the provided configuration entries
-   *
-   * @param ambariLdapConfiguration ambari configuration instance
-   * @return
-   */
-  LdapConnection getBoundLdapConnection(AmbariLdapConfiguration ambariLdapConfiguration);
-
-
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionTemplateProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionTemplateProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionTemplateProvider.java
new file mode 100644
index 0000000..5ed06e3
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionTemplateProvider.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service;
+
+
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
+import org.apache.directory.ldap.client.api.DefaultLdapConnectionFactory;
+import org.apache.directory.ldap.client.api.LdapConnectionConfig;
+import org.apache.directory.ldap.client.api.LdapConnectionFactory;
+import org.apache.directory.ldap.client.api.LdapConnectionPool;
+import org.apache.directory.ldap.client.api.ValidatingPoolableLdapConnectionFactory;
+import org.apache.directory.ldap.client.template.LdapConnectionTemplate;
+
+public class LdapConnectionTemplateProvider implements Provider<LdapConnectionTemplate> {
+
+  // Inject the persisted configuration (when available) check the provider implementation for details.
+  @Inject
+  private Provider<AmbariLdapConfiguration> ambariLdapConfigurationProvider;
+
+  @Override
+  public LdapConnectionTemplate get() {
+    return new LdapConnectionTemplate(new LdapConnectionPool(
+      new ValidatingPoolableLdapConnectionFactory(getLdapConnectionFactory())));
+  }
+
+  private LdapConnectionConfig getLdapConnectionConfig() {
+    LdapConnectionConfig config = new LdapConnectionConfig();
+    config.setLdapHost(ambariLdapConfigurationProvider.get().serverHost());
+    config.setLdapPort(ambariLdapConfigurationProvider.get().serverPort());
+    config.setName(ambariLdapConfigurationProvider.get().bindDn());
+    config.setCredentials(ambariLdapConfigurationProvider.get().bindPassword());
+
+    return config;
+  }
+
+  private LdapConnectionFactory getLdapConnectionFactory() {
+    return new DefaultLdapConnectionFactory(getLdapConnectionConfig());
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
index cddb952..639d48d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
@@ -14,6 +14,8 @@
 
 package org.apache.ambari.server.ldap.service.ads;
 
+import java.util.List;
+
 import javax.inject.Inject;
 import javax.inject.Singleton;
 
@@ -27,27 +29,23 @@ import org.apache.ambari.server.ldap.service.ads.detectors.GroupObjectClassDetec
 import org.apache.ambari.server.ldap.service.ads.detectors.UserGroupMemberAttrDetector;
 import org.apache.ambari.server.ldap.service.ads.detectors.UserNameAttrDetector;
 import org.apache.ambari.server.ldap.service.ads.detectors.UserObjectClassDetector;
-import org.apache.directory.api.ldap.model.cursor.SearchCursor;
 import org.apache.directory.api.ldap.model.entry.Entry;
-import org.apache.directory.api.ldap.model.message.Response;
+import org.apache.directory.api.ldap.model.exception.LdapException;
 import org.apache.directory.api.ldap.model.message.SearchRequest;
-import org.apache.directory.api.ldap.model.message.SearchRequestImpl;
-import org.apache.directory.api.ldap.model.message.SearchResultEntry;
 import org.apache.directory.api.ldap.model.message.SearchScope;
-import org.apache.directory.api.ldap.model.name.Dn;
 import org.apache.directory.api.util.Strings;
-import org.apache.directory.ldap.client.api.LdapConnection;
 import org.apache.directory.ldap.client.api.search.FilterBuilder;
+import org.apache.directory.ldap.client.template.EntryMapper;
+import org.apache.directory.ldap.client.template.LdapConnectionTemplate;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @Singleton
-public class DefaultLdapAttributeDetectionService implements LdapAttributeDetectionService<LdapConnection> {
+public class DefaultLdapAttributeDetectionService implements LdapAttributeDetectionService {
 
   private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapAttributeDetectionService.class);
   private static final int SAMPLE_RESULT_SIZE = 50;
 
-
   @Inject
   private UserNameAttrDetector userNameAttrDetector;
 
@@ -67,12 +65,18 @@ public class DefaultLdapAttributeDetectionService implements LdapAttributeDetect
   private GroupMemberAttrDetector groupMemberAttrDetector;
 
   @Inject
+  private LdapConnectionTemplateFactory ldapConnectionTemplateFactory;
+
+
+  @Inject
   public DefaultLdapAttributeDetectionService() {
   }
 
   @Override
-  public AmbariLdapConfiguration detectLdapUserAttributes(LdapConnection connection, AmbariLdapConfiguration ambariLdapConfiguration) {
+  public AmbariLdapConfiguration detectLdapUserAttributes(AmbariLdapConfiguration ambariLdapConfiguration) {
     LOGGER.info("Detecting LDAP user attributes ...");
+    LdapConnectionTemplate ldapConnectionTemplate = ldapConnectionTemplateFactory.create(ambariLdapConfiguration);
+
 
     // perform a search using the user search base
     if (Strings.isEmpty(ambariLdapConfiguration.userSearchBase())) {
@@ -80,37 +84,21 @@ public class DefaultLdapAttributeDetectionService implements LdapAttributeDetect
       return ambariLdapConfiguration;
     }
 
-    SearchCursor searchCursor = null;
-
     try {
 
-      SearchRequest searchRequest = assembleUserSearchRequest(ambariLdapConfiguration);
+      SearchRequest searchRequest = assembleUserSearchRequest(ldapConnectionTemplate, ambariLdapConfiguration);
 
       // do the search
-      searchCursor = connection.search(searchRequest);
-
-      int processedUserCnt = 0;
-
-      while (searchCursor.next()) {
+      List<Entry> entries = ldapConnectionTemplate.search(searchRequest, getEntryMapper());
 
-        if (processedUserCnt >= SAMPLE_RESULT_SIZE) {
-          LOGGER.debug("The maximum count of results for attribute detection has exceeded. Quit user attribute detection.");
-          break;
-        }
+      for (Entry entry : entries) {
 
-        Response response = searchCursor.get();
-        // process the SearchResultEntry
+        LOGGER.info("Processing sample entry with dn: [{}]", entry.getDn());
 
-        if (response instanceof SearchResultEntry) {
-          Entry resultEntry = ((SearchResultEntry) response).getEntry();
-          LOGGER.info("Processing sample entry with dn: [{}]", resultEntry.getDn());
+        userNameAttrDetector.collect(entry);
+        userObjectClassDetector.collect(entry);
+        userGroupMemberAttrDetector.collect(entry);
 
-          userNameAttrDetector.collect(resultEntry);
-          userObjectClassDetector.collect(resultEntry);
-          userGroupMemberAttrDetector.collect(resultEntry);
-
-          processedUserCnt++;
-        }
       }
 
       ambariLdapConfiguration.setValueFor(AmbariLdapConfigKeys.USER_NAME_ATTRIBUTE, userNameAttrDetector.detect());
@@ -120,13 +108,7 @@ public class DefaultLdapAttributeDetectionService implements LdapAttributeDetect
       LOGGER.info("Decorated ambari ldap config : [{}]", ambariLdapConfiguration);
 
     } catch (Exception e) {
-
       LOGGER.error("Ldap operation failed", e);
-    } finally {
-      // housekeeping
-      if (null != searchCursor) {
-        searchCursor.close();
-      }
     }
 
     return ambariLdapConfiguration;
@@ -134,7 +116,7 @@ public class DefaultLdapAttributeDetectionService implements LdapAttributeDetect
 
 
   @Override
-  public AmbariLdapConfiguration detectLdapGroupAttributes(LdapConnection connection, AmbariLdapConfiguration ambariLdapConfiguration) {
+  public AmbariLdapConfiguration detectLdapGroupAttributes(AmbariLdapConfiguration ambariLdapConfiguration) {
     LOGGER.info("Detecting LDAP group attributes ...");
 
     // perform a search using the user search base
@@ -143,39 +125,23 @@ public class DefaultLdapAttributeDetectionService implements LdapAttributeDetect
       return ambariLdapConfiguration;
     }
 
-    SearchCursor searchCursor = null;
+    LdapConnectionTemplate ldapConnectionTemplate = ldapConnectionTemplateFactory.create(ambariLdapConfiguration);
 
     try {
-      // todo should the bind operation be done in the facade?
-      connection.bind(ambariLdapConfiguration.bindDn(), ambariLdapConfiguration.bindPassword());
 
-      SearchRequest searchRequest = assembleGroupSearchRequest(ambariLdapConfiguration);
+      SearchRequest searchRequest = assembleGroupSearchRequest(ldapConnectionTemplate, ambariLdapConfiguration);
 
       // do the search
-      searchCursor = connection.search(searchRequest);
-
-      int processedGroupCnt = 0;
-
-      while (searchCursor.next()) {
+      List<Entry> groupEntries = ldapConnectionTemplate.search(searchRequest, getEntryMapper());
 
-        if (processedGroupCnt >= SAMPLE_RESULT_SIZE) {
-          LOGGER.debug("The maximum number of results for attribute detection has exceeded. Quit  detection.");
-          break;
-        }
 
-        Response response = searchCursor.get();
-        // process the SearchResultEntry
+      for (Entry groupEntry : groupEntries) {
 
-        if (response instanceof SearchResultEntry) {
-          Entry resultEntry = ((SearchResultEntry) response).getEntry();
-          LOGGER.info("Processing sample entry with dn: [{}]", resultEntry.getDn());
+        LOGGER.info("Processing sample entry with dn: [{}]", groupEntry.getDn());
+        groupNameAttrDetector.collect(groupEntry);
+        groupObjectClassDetector.collect(groupEntry);
+        groupMemberAttrDetector.collect(groupEntry);
 
-          groupNameAttrDetector.collect(resultEntry);
-          groupObjectClassDetector.collect(resultEntry);
-          groupMemberAttrDetector.collect(resultEntry);
-
-          processedGroupCnt++;
-        }
       }
 
       ambariLdapConfiguration.setValueFor(AmbariLdapConfigKeys.GROUP_NAME_ATTRIBUTE, groupNameAttrDetector.detect());
@@ -187,26 +153,17 @@ public class DefaultLdapAttributeDetectionService implements LdapAttributeDetect
     } catch (Exception e) {
 
       LOGGER.error("Ldap operation failed", e);
-    } finally {
-      // housekeeping
-      if (null != searchCursor) {
-        searchCursor.close();
-      }
     }
 
     return ambariLdapConfiguration;
   }
 
-  private SearchRequest assembleUserSearchRequest(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+  private SearchRequest assembleUserSearchRequest(LdapConnectionTemplate ldapConnectionTemplate, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
     try {
 
-      SearchRequest req = new SearchRequestImpl();
-      req.setScope(SearchScope.SUBTREE);
-      req.addAttributes("*");
-      req.setTimeLimit(0);
-      req.setBase(new Dn(ambariLdapConfiguration.userSearchBase()));
-      // the filter must be set!
-      req.setFilter(FilterBuilder.present(ambariLdapConfiguration.dnAttribute()).toString());
+      SearchRequest req = ldapConnectionTemplate.newSearchRequest(ambariLdapConfiguration.userSearchBase(),
+        FilterBuilder.present(ambariLdapConfiguration.dnAttribute()).toString(), SearchScope.SUBTREE);
+      req.setSizeLimit(SAMPLE_RESULT_SIZE);
 
       return req;
 
@@ -216,16 +173,12 @@ public class DefaultLdapAttributeDetectionService implements LdapAttributeDetect
     }
   }
 
-  private SearchRequest assembleGroupSearchRequest(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+  private SearchRequest assembleGroupSearchRequest(LdapConnectionTemplate ldapConnectionTemplate, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
     try {
 
-      SearchRequest req = new SearchRequestImpl();
-      req.setScope(SearchScope.SUBTREE);
-      req.addAttributes("*");
-      req.setTimeLimit(0);
-      req.setBase(new Dn(ambariLdapConfiguration.groupSearchBase()));
-      // the filter must be set!
-      req.setFilter(FilterBuilder.present(ambariLdapConfiguration.dnAttribute()).toString());
+      SearchRequest req = ldapConnectionTemplate.newSearchRequest(ambariLdapConfiguration.groupSearchBase(),
+        FilterBuilder.present(ambariLdapConfiguration.dnAttribute()).toString(), SearchScope.SUBTREE);
+      req.setSizeLimit(SAMPLE_RESULT_SIZE);
 
       return req;
 
@@ -236,4 +189,12 @@ public class DefaultLdapAttributeDetectionService implements LdapAttributeDetect
   }
 
 
+  public EntryMapper<Entry> getEntryMapper() {
+    return new EntryMapper<Entry>() {
+      @Override
+      public Entry map(Entry entry) throws LdapException {
+        return entry;
+      }
+    };
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
index 7214fd3..bbe4d0a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
@@ -14,6 +14,7 @@
 
 package org.apache.ambari.server.ldap.service.ads;
 
+import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
@@ -23,23 +24,22 @@ import javax.inject.Singleton;
 import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
 import org.apache.ambari.server.ldap.service.AmbariLdapException;
 import org.apache.ambari.server.ldap.service.LdapConfigurationService;
-import org.apache.directory.api.ldap.codec.decorators.SearchResultEntryDecorator;
 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
-import org.apache.directory.api.ldap.model.cursor.EntryCursor;
-import org.apache.directory.api.ldap.model.cursor.SearchCursor;
 import org.apache.directory.api.ldap.model.entry.Entry;
-import org.apache.directory.api.ldap.model.message.Response;
+import org.apache.directory.api.ldap.model.exception.LdapException;
 import org.apache.directory.api.ldap.model.message.SearchRequest;
 import org.apache.directory.api.ldap.model.message.SearchRequestImpl;
 import org.apache.directory.api.ldap.model.message.SearchScope;
 import org.apache.directory.api.ldap.model.name.Dn;
 import org.apache.directory.ldap.client.api.LdapConnection;
 import org.apache.directory.ldap.client.api.search.FilterBuilder;
+import org.apache.directory.ldap.client.template.ConnectionCallback;
+import org.apache.directory.ldap.client.template.EntryMapper;
+import org.apache.directory.ldap.client.template.LdapConnectionTemplate;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
 
 /**
  * Implementation of the validation logic using the Apache Directory API.
@@ -50,13 +50,27 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
   private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapConfigurationService.class);
 
   @Inject
+  private LdapConnectionTemplateFactory ldapConnectionTemplateFactory;
+
+  @Inject
   public DefaultLdapConfigurationService() {
   }
 
+
   @Override
-  public void checkConnection(LdapConnection ldapConnection, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+  public void checkConnection(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+
+    LdapConnectionTemplate ldapConnectionTemplate = ldapConnectionTemplateFactory.create(ambariLdapConfiguration);
 
-    if (!ldapConnection.isConnected()) {
+    // check if the connection from the connection pool of the template is connected
+    Boolean isConnected = ldapConnectionTemplate.execute(new ConnectionCallback<Boolean>() {
+      @Override
+      public Boolean doWithConnection(LdapConnection connection) throws LdapException {
+        return connection.isConnected();
+      }
+    });
+
+    if (!isConnected) {
       LOGGER.error("Could not connect to the LDAP server");
       throw new AmbariLdapException("Could not connect to the LDAP server. Configuration: " + ambariLdapConfiguration);
     }
@@ -69,7 +83,6 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
    *
    * Invalid attributes are signaled by throwing an exception.
    *
-   * @param ldapConnection          connection instance used to connect to the LDAP server
    * @param testUserName            the test username
    * @param testPassword            the test password
    * @param ambariLdapConfiguration the available LDAP configuration to be validated
@@ -77,9 +90,8 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
    * @throws AmbariLdapException if an error occurs
    */
   @Override
-  public String checkUserAttributes(LdapConnection ldapConnection, String testUserName, String testPassword, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
-    String userDn = null;
-    EntryCursor entryCursor = null;
+  public String checkUserAttributes(String testUserName, String testPassword, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+    String userDn;
     try {
       LOGGER.info("Checking user attributes for user {} r ...", testUserName);
 
@@ -90,33 +102,15 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
         .toString();
 
       LOGGER.info("Searching for the user: {} using the search filter: {}", testUserName, filter);
-      entryCursor = ldapConnection.search(new Dn(ambariLdapConfiguration.userSearchBase()), filter, SearchScope.SUBTREE);
+      userDn = ldapConnectionTemplateFactory.create(ambariLdapConfiguration).searchFirst(new Dn(ambariLdapConfiguration.userSearchBase()), filter, SearchScope.SUBTREE, getUserDnNameEntryMapper(ambariLdapConfiguration));
 
-      // collecting search result entries
-      List<Entry> users = Lists.newArrayList();
-      for (Entry entry : entryCursor) {
-        users.add(entry);
-        userDn = entry.getDn().getNormName();
-      }
-
-      // there should be at least one user found
-      if (users.isEmpty()) {
-        String msg = String.format("There are no users found using the filter: [ %s ]. Try changing the attribute values", filter);
-        LOGGER.error(msg);
-        throw new Exception(msg);
-      }
-
-      LOGGER.info("Attibute validation succeeded. Filter: {}", filter);
+      LOGGER.info("Attribute validation succeeded. Filter: {}", filter);
 
     } catch (Exception e) {
 
       LOGGER.error("User attributes validation failed.", e);
       throw new AmbariLdapException(e.getMessage(), e);
 
-    } finally {
-      if (null != entryCursor) {
-        entryCursor.close();
-      }
     }
     return userDn;
   }
@@ -125,17 +119,14 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
    * Checks whether the provided group related settings are correct.
    * The algorithm implemented in this method per
    *
-   * @param ldapConnection          a connecion instance bound to an LDAP server
    * @param userDn                  a user DN to check
    * @param ambariLdapConfiguration the available LDAP configuration to be validated
    * @return
    * @throws AmbariLdapException
    */
   @Override
-  public Set<String> checkGroupAttributes(LdapConnection ldapConnection, String userDn, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
-    SearchCursor searchCursor = null;
-    Set<Response> groupResponses = Sets.newHashSet();
-
+  public Set<String> checkGroupAttributes(String userDn, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+    List<String> groups = Lists.newArrayList();
     try {
       LOGGER.info("Checking group attributes for user dn {} ...", userDn);
 
@@ -156,43 +147,42 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
       searchRequest.addAttributes(ambariLdapConfiguration.groupMemberAttribute(), ambariLdapConfiguration.groupNameAttribute());
 
       // perform the search
-      searchCursor = ldapConnection.search(searchRequest);
+      groups = ldapConnectionTemplateFactory.create(ambariLdapConfiguration).search(searchRequest, getGroupNameEntryMapper(ambariLdapConfiguration));
 
-      for (Response response : searchCursor) {
-        groupResponses.add(response);
-      }
 
     } catch (Exception e) {
 
       LOGGER.error("User attributes validation failed.", e);
       throw new AmbariLdapException(e.getMessage(), e);
 
-    } finally {
-      if (null != searchCursor) {
-        searchCursor.close();
-      }
     }
 
-    return processGroupResults(groupResponses, ambariLdapConfiguration);
+    return new HashSet<>(groups);
   }
 
 
-  /**
-   * Extracts meaningful values from the search result.
-   *
-   * @param groupResponses          the result entries returned by the search
-   * @param ambariLdapConfiguration holds the keys of the meaningful attributes
-   * @return a set with the group names the test user belongs to
-   */
-  private Set<String> processGroupResults(Set<Response> groupResponses, AmbariLdapConfiguration ambariLdapConfiguration) {
-    Set<String> groupStrSet = Sets.newHashSet();
-    for (Response response : groupResponses) {
-      Entry entry = ((SearchResultEntryDecorator) response).getEntry();
-      groupStrSet.add(entry.get(ambariLdapConfiguration.groupNameAttribute()).get().getString());
-    }
+  private EntryMapper<String> getGroupNameEntryMapper(AmbariLdapConfiguration ambariLdapConfiguration) {
+
+    EntryMapper<String> entryMapper = new EntryMapper<String>() {
+      @Override
+      public String map(Entry entry) throws LdapException {
+        return entry.get(ambariLdapConfiguration.groupNameAttribute()).get().getString();
+      }
+    };
+
+    return entryMapper;
+  }
+
+  private EntryMapper<String> getUserDnNameEntryMapper(AmbariLdapConfiguration ambariLdapConfiguration) {
+
+    EntryMapper<String> entryMapper = new EntryMapper<String>() {
+      @Override
+      public String map(Entry entry) throws LdapException {
+        return entry.getDn().getNormName();
+      }
+    };
 
-    LOGGER.debug("Extracted group names from group search responses: {}", groupStrSet);
-    return groupStrSet;
+    return entryMapper;
   }
 
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionService.java
deleted file mode 100644
index 1e9c612..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionService.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.service.ads;
-
-import javax.inject.Singleton;
-
-import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.service.LdapConnectionService;
-import org.apache.directory.ldap.client.api.LdapConnection;
-import org.apache.directory.ldap.client.api.LdapConnectionConfig;
-import org.apache.directory.ldap.client.api.LdapNetworkConnection;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Singleton
-public class DefaultLdapConnectionService implements LdapConnectionService {
-
-  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapConnectionService.class);
-
-  @Override
-  public LdapNetworkConnection createLdapConnection(AmbariLdapConfiguration ambariLdapConfiguration) {
-    LOGGER.debug("Creating ldap connection instance from: {}", ambariLdapConfiguration);
-
-    return new LdapNetworkConnection(getLdapConnectionConfig(ambariLdapConfiguration));
-  }
-
-  @Override
-  public LdapConnection getBoundLdapConnection(AmbariLdapConfiguration ambariLdapConfiguration) {
-    LOGGER.info("Creating LDAP connection instance and binding to LDAP server ...");
-
-    try {
-      LdapConnection connection = createLdapConnection(ambariLdapConfiguration);
-
-      if (!ambariLdapConfiguration.anonymousBind()) {
-
-        LOGGER.debug("Anonymous binding not supported, binding with the manager detailas...");
-        connection.bind(ambariLdapConfiguration.bindDn(), ambariLdapConfiguration.bindPassword());
-
-      } else {
-
-        LOGGER.debug("Binding anonymously ...");
-        connection.bind();
-
-      }
-
-      if (!connection.isConnected()) {
-
-        LOGGER.error("Not connected to the LDAP server. Connection instance: {}", connection);
-        throw new IllegalStateException("The connection to the LDAP server is not alive");
-
-      }
-
-      LOGGER.info("Connected / bound to LDAP server.");
-      return connection;
-
-    } catch (Exception e) {
-      LOGGER.error("Could not create or bind LdapConnection", e);
-      throw new IllegalArgumentException(e);
-    }
-
-  }
-
-  private LdapConnectionConfig getLdapConnectionConfig(AmbariLdapConfiguration ambariAmbariLdapConfiguration) {
-    LOGGER.debug("Creating a LDAP connection config instance based on the ambari configuration: {}", ambariAmbariLdapConfiguration);
-
-    LdapConnectionConfig ldapConnectionConfig = new LdapConnectionConfig();
-    ldapConnectionConfig.setLdapHost(ambariAmbariLdapConfiguration.serverHost());
-    ldapConnectionConfig.setLdapPort(ambariAmbariLdapConfiguration.serverPort());
-    ldapConnectionConfig.setUseSsl(ambariAmbariLdapConfiguration.useSSL());
-
-    return ldapConnectionConfig;
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/LdapConnectionTemplateFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/LdapConnectionTemplateFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/LdapConnectionTemplateFactory.java
new file mode 100644
index 0000000..50345bc
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/LdapConnectionTemplateFactory.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads;
+
+import javax.inject.Inject;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
+import org.apache.directory.ldap.client.api.DefaultLdapConnectionFactory;
+import org.apache.directory.ldap.client.api.LdapConnectionConfig;
+import org.apache.directory.ldap.client.api.LdapConnectionFactory;
+import org.apache.directory.ldap.client.api.LdapConnectionPool;
+import org.apache.directory.ldap.client.api.ValidatingPoolableLdapConnectionFactory;
+import org.apache.directory.ldap.client.template.LdapConnectionTemplate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Factory for creating LdapConnectionTemplate instances.
+ * Depending on the usage context, the instance can be constructed based on the provided configuration or based on the persisted settings.
+ */
+@Singleton
+public class LdapConnectionTemplateFactory {
+
+  private static final Logger LOG = LoggerFactory.getLogger(LdapConnectionTemplateFactory.class);
+
+  @Inject
+  private Provider<LdapConnectionTemplate> ldapConnectionTemplate;
+
+  @Inject
+  public LdapConnectionTemplateFactory() {
+  }
+
+  /**
+   * Creates a new instance based on the provided configuration. Use this factory method whle operating with ambari configuration not yet persisted.
+   *
+   * @param ambariLdapConfiguration ambari ldap configuration instance
+   * @return an instance of LdapConnectionTemplate
+   */
+  public LdapConnectionTemplate create(AmbariLdapConfiguration ambariLdapConfiguration) {
+    LOG.info("Constructing new instance based on the provided ambari ldap configuration: {}", ambariLdapConfiguration);
+
+    // create the connection config
+    LdapConnectionConfig ldapConnectionConfig = getLdapConnectionConfig(ambariLdapConfiguration);
+
+    // create the connection factory
+    LdapConnectionFactory ldapConnectionFactory = new DefaultLdapConnectionFactory(ldapConnectionConfig);
+
+    // create the connection pool
+    LdapConnectionPool ldapConnectionPool = new LdapConnectionPool(new ValidatingPoolableLdapConnectionFactory(ldapConnectionFactory));
+
+    LdapConnectionTemplate template = new LdapConnectionTemplate(ldapConnectionPool);
+    LOG.info("Ldap connection template instance: {}", template);
+
+    return template;
+
+  }
+
+  public LdapConnectionTemplate load() {
+    // the construction logic is implemented in the provider class
+    return ldapConnectionTemplate.get();
+  }
+
+
+  private LdapConnectionConfig getLdapConnectionConfig(AmbariLdapConfiguration ambariLdapConfiguration) {
+
+    LdapConnectionConfig config = new LdapConnectionConfig();
+    config.setLdapHost(ambariLdapConfiguration.serverHost());
+    config.setLdapPort(ambariLdapConfiguration.serverPort());
+    config.setName(ambariLdapConfiguration.bindDn());
+    config.setCredentials(ambariLdapConfiguration.bindPassword());
+
+    // todo set the other required properties here, eg.: trustmanager
+    return config;
+  }
+
+  private LdapConnectionFactory getLdapConnectionFactory(AmbariLdapConfiguration ambariLdapConfiguration) {
+    return new DefaultLdapConnectionFactory(getLdapConnectionConfig(ambariLdapConfiguration));
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java
index aa444ab..9f38357 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java
@@ -18,7 +18,7 @@ import javax.inject.Inject;
 
 import org.apache.directory.api.ldap.model.entry.Entry;
 
-public class GroupMemberAttrDetector extends OccurranceAndWeightBasedDetector {
+public class GroupMemberAttrDetector extends OccurrenceAndWeightBasedDetector {
 
   private enum GroupMemberAttr {
 
@@ -47,7 +47,7 @@ public class GroupMemberAttrDetector extends OccurranceAndWeightBasedDetector {
   @Inject
   public GroupMemberAttrDetector() {
     for (GroupMemberAttr groupMemberAttr : GroupMemberAttr.values()) {
-      occurranceMap().put(groupMemberAttr.attrName(), 0);
+      occurrenceMap().put(groupMemberAttr.attrName(), 0);
       weightsMap().put(groupMemberAttr.attrName(), groupMemberAttr.weight());
     }
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupNameAttrDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupNameAttrDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupNameAttrDetector.java
index d4dcdff..0f48348 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupNameAttrDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupNameAttrDetector.java
@@ -20,7 +20,7 @@ import org.apache.directory.api.ldap.model.entry.Entry;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class GroupNameAttrDetector extends OccurranceAndWeightBasedDetector {
+public class GroupNameAttrDetector extends OccurrenceAndWeightBasedDetector {
   private static final Logger LOGGER = LoggerFactory.getLogger(UserNameAttrDetector.class);
 
   private enum GroupNameAttr {
@@ -51,7 +51,7 @@ public class GroupNameAttrDetector extends OccurranceAndWeightBasedDetector {
   public GroupNameAttrDetector() {
 
     for (GroupNameAttr groupNameAttr : GroupNameAttr.values()) {
-      occurranceMap().put(groupNameAttr.attrName(), 0);
+      occurrenceMap().put(groupNameAttr.attrName(), 0);
       weightsMap().put(groupNameAttr.attrName(), groupNameAttr.weight());
     }
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupObjectClassDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupObjectClassDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupObjectClassDetector.java
index 88824c4..9338e70 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupObjectClassDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupObjectClassDetector.java
@@ -20,7 +20,7 @@ import org.apache.directory.api.ldap.model.entry.Entry;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class GroupObjectClassDetector extends OccurranceAndWeightBasedDetector {
+public class GroupObjectClassDetector extends OccurrenceAndWeightBasedDetector {
 
   private static final Logger LOGGER = LoggerFactory.getLogger(GroupObjectClassDetector.class);
 
@@ -55,7 +55,7 @@ public class GroupObjectClassDetector extends OccurranceAndWeightBasedDetector {
   @Inject
   public GroupObjectClassDetector() {
     for (ObjectClassValue ocVal : ObjectClassValue.values()) {
-      occurranceMap().put(ocVal.ocVal(), 0);
+      occurrenceMap().put(ocVal.ocVal(), 0);
       weightsMap().put(ocVal.ocVal(), ocVal.weight());
     }
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurranceAndWeightBasedDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurranceAndWeightBasedDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurranceAndWeightBasedDetector.java
deleted file mode 100644
index 71dfb42..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurranceAndWeightBasedDetector.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.service.ads.detectors;
-
-import java.util.Map;
-
-import org.apache.ambari.server.ldap.service.AttributeDetector;
-import org.apache.directory.api.ldap.model.entry.Entry;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.Maps;
-
-public abstract class OccurranceAndWeightBasedDetector implements AttributeDetector<Entry> {
-
-  private static final Logger LOGGER = LoggerFactory.getLogger(OccurranceAndWeightBasedDetector.class);
-
-  private Map<String, Integer> occurranceMap = Maps.newHashMap();
-  private Map<String, Integer> weightsMap = Maps.newHashMap();
-
-  protected Map<String, Integer> occurranceMap() {
-    return occurranceMap;
-  }
-
-  protected Map<String, Integer> weightsMap() {
-    return weightsMap;
-  }
-
-
-  protected abstract boolean applies(Entry entry, String value);
-
-  @Override
-  public String detect() {
-    LOGGER.info("Calculating the most probable attribute/value ...");
-    Map.Entry<String, Integer> selectedEntry = null;
-
-    for (Map.Entry<String, Integer> entry : occurranceMap().entrySet()) {
-      if (selectedEntry == null) {
-
-        selectedEntry = entry;
-        LOGGER.debug("Initial attribute / value entry: {}", selectedEntry);
-        continue;
-
-      }
-
-      if (selectedEntry.getValue() < entry.getValue()) {
-
-        LOGGER.info("Changing potential attribute / value entry from : [{}] to: [{}]", selectedEntry, entry);
-        selectedEntry = entry;
-
-      }
-    }
-
-    // check whether the selected entry is valid (has occured in the sample result set)
-    String detectedVal = "N/A";
-
-    if (selectedEntry.getValue() > 0) {
-      detectedVal = selectedEntry.getKey();
-    } else {
-      LOGGER.warn("Unable to detect attribute or attribute value");
-    }
-
-    LOGGER.info("Detected attribute or value: [{}]", detectedVal);
-    return detectedVal;
-  }
-
-  @Override
-  public void collect(Entry entry) {
-    LOGGER.info("Collecting ldap attributes/values form entry with dn: [{}]", entry.getDn());
-
-    for (String attributeValue : occurranceMap().keySet()) {
-      if (applies(entry, attributeValue)) {
-
-        Integer cnt = occurranceMap().get(attributeValue).intValue();
-        if (weightsMap().containsKey(attributeValue)) {
-          cnt = cnt + weightsMap().get(attributeValue);
-        } else {
-          cnt = cnt + 1;
-        }
-        occurranceMap().put(attributeValue, cnt);
-
-        LOGGER.info("Collected potential name attr: {}, count: {}", attributeValue, cnt);
-
-      } else {
-        LOGGER.info("The result entry doesn't contain the attribute: [{}]", attributeValue);
-      }
-    }
-  }
-
-
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurrenceAndWeightBasedDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurrenceAndWeightBasedDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurrenceAndWeightBasedDetector.java
new file mode 100644
index 0000000..2ec559b
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurrenceAndWeightBasedDetector.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads.detectors;
+
+import java.util.Map;
+
+import org.apache.ambari.server.ldap.service.AttributeDetector;
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Maps;
+
+public abstract class OccurrenceAndWeightBasedDetector implements AttributeDetector<Entry> {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(OccurrenceAndWeightBasedDetector.class);
+
+  private Map<String, Integer> occurranceMap = Maps.newHashMap();
+  private Map<String, Integer> weightsMap = Maps.newHashMap();
+
+  protected Map<String, Integer> occurrenceMap() {
+    return occurranceMap;
+  }
+
+  protected Map<String, Integer> weightsMap() {
+    return weightsMap;
+  }
+
+
+  protected abstract boolean applies(Entry entry, String value);
+
+  @Override
+  public String detect() {
+    LOGGER.info("Calculating the most probable attribute/value ...");
+    Map.Entry<String, Integer> selectedEntry = null;
+
+    for (Map.Entry<String, Integer> entry : occurrenceMap().entrySet()) {
+      if (selectedEntry == null) {
+
+        selectedEntry = entry;
+        LOGGER.debug("Initial attribute / value entry: {}", selectedEntry);
+        continue;
+
+      }
+
+      if (selectedEntry.getValue() < entry.getValue()) {
+
+        LOGGER.info("Changing potential attribute / value entry from : [{}] to: [{}]", selectedEntry, entry);
+        selectedEntry = entry;
+
+      }
+    }
+
+    // check whether the selected entry is valid (has occured in the sample result set)
+    String detectedVal = "N/A";
+
+    if (selectedEntry.getValue() > 0) {
+      detectedVal = selectedEntry.getKey();
+    } else {
+      LOGGER.warn("Unable to detect attribute or attribute value");
+    }
+
+    LOGGER.info("Detected attribute or value: [{}]", detectedVal);
+    return detectedVal;
+  }
+
+  @Override
+  public void collect(Entry entry) {
+    LOGGER.info("Collecting ldap attributes/values form entry with dn: [{}]", entry.getDn());
+
+    for (String attributeValue : occurrenceMap().keySet()) {
+      if (applies(entry, attributeValue)) {
+
+        Integer cnt = occurrenceMap().get(attributeValue).intValue();
+        if (weightsMap().containsKey(attributeValue)) {
+          cnt = cnt + weightsMap().get(attributeValue);
+        } else {
+          cnt = cnt + 1;
+        }
+        occurrenceMap().put(attributeValue, cnt);
+
+        LOGGER.info("Collected potential name attr: {}, count: {}", attributeValue, cnt);
+
+      } else {
+        LOGGER.info("The result entry doesn't contain the attribute: [{}]", attributeValue);
+      }
+    }
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java
index a7f03dd..f04201e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java
@@ -18,7 +18,7 @@ import javax.inject.Inject;
 
 import org.apache.directory.api.ldap.model.entry.Entry;
 
-public class UserGroupMemberAttrDetector extends OccurranceAndWeightBasedDetector {
+public class UserGroupMemberAttrDetector extends OccurrenceAndWeightBasedDetector {
 
   private enum UserGroupMemberAttr {
 
@@ -46,7 +46,7 @@ public class UserGroupMemberAttrDetector extends OccurranceAndWeightBasedDetecto
   @Inject
   public UserGroupMemberAttrDetector() {
     for (UserGroupMemberAttr userGroupMemberAttr : UserGroupMemberAttr.values()) {
-      occurranceMap().put(userGroupMemberAttr.attrName(), 0);
+      occurrenceMap().put(userGroupMemberAttr.attrName(), 0);
       weightsMap().put(userGroupMemberAttr.attrName(), userGroupMemberAttr.weight);
     }
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserNameAttrDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserNameAttrDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserNameAttrDetector.java
index eade3c8..2c41162 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserNameAttrDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserNameAttrDetector.java
@@ -20,7 +20,7 @@ import org.apache.directory.api.ldap.model.entry.Entry;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class UserNameAttrDetector extends OccurranceAndWeightBasedDetector {
+public class UserNameAttrDetector extends OccurrenceAndWeightBasedDetector {
   private static final Logger LOGGER = LoggerFactory.getLogger(UserNameAttrDetector.class);
 
   private enum UserNameAttrs {
@@ -49,7 +49,7 @@ public class UserNameAttrDetector extends OccurranceAndWeightBasedDetector {
   @Inject
   public UserNameAttrDetector() {
     for (UserNameAttrs nameAttr : UserNameAttrs.values()) {
-      occurranceMap().put(nameAttr.attrName(), 0);
+      occurrenceMap().put(nameAttr.attrName(), 0);
       weightsMap().put(nameAttr.attrName(), nameAttr.weight());
     }
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserObjectClassDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserObjectClassDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserObjectClassDetector.java
index 97b3c52..2b47671 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserObjectClassDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserObjectClassDetector.java
@@ -20,7 +20,7 @@ import org.apache.directory.api.ldap.model.entry.Entry;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class UserObjectClassDetector extends OccurranceAndWeightBasedDetector {
+public class UserObjectClassDetector extends OccurrenceAndWeightBasedDetector {
 
   private static final Logger LOGGER = LoggerFactory.getLogger(UserObjectClassDetector.class);
 
@@ -49,7 +49,7 @@ public class UserObjectClassDetector extends OccurranceAndWeightBasedDetector {
   @Inject
   public UserObjectClassDetector() {
     for (ObjectClassValue ocVal : ObjectClassValue.values()) {
-      occurranceMap().put(ocVal.ocVal(), 0);
+      occurrenceMap().put(ocVal.ocVal(), 0);
       weightsMap().put(ocVal.ocVal(), ocVal.weight());
     }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
new file mode 100644
index 0000000..8059723
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
@@ -0,0 +1,143 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap;
+
+import java.util.Map;
+
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfigKeys;
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.domain.TestAmbariAmbariLdapConfigurationFactory;
+import org.apache.ambari.server.ldap.service.LdapConfigurationService;
+import org.apache.ambari.server.ldap.service.LdapFacade;
+import org.apache.directory.api.ldap.model.constants.SchemaConstants;
+import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
+import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.template.ConnectionCallback;
+import org.apache.directory.ldap.client.template.LdapConnectionTemplate;
+import org.apache.directory.ldap.client.template.exception.PasswordException;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.google.common.collect.Maps;
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Module;
+import com.google.inject.util.Modules;
+
+public class LdapModuleFunctionalTest {
+
+  private static Injector injector;
+  private static Module testModule;
+  private static TestAmbariAmbariLdapConfigurationFactory ldapConfigurationFactory = new TestAmbariAmbariLdapConfigurationFactory();
+
+  @BeforeClass
+  public static void beforeClass() throws Exception {
+
+    // overriding bindings for testing purposes
+    testModule = Modules.override(new LdapModule()).with(new AbstractModule() {
+      @Override
+      protected void configure() {
+        // override the configuration instance binding not to access the database
+        bind(AmbariLdapConfiguration.class).toInstance(ldapConfigurationFactory.createLdapConfiguration(getProps()));
+      }
+    });
+
+    injector = Guice.createInjector(testModule);
+  }
+
+  @Test
+  public void shouldLdapTemplateBeInstantiated() throws LdapInvalidDnException, PasswordException {
+    // GIVEN
+    // the injector is set up
+    Assert.assertNotNull(injector);
+
+    // WHEN
+    // the ldap connection template is retrieved
+    LdapConnectionTemplate template = injector.getInstance(LdapConnectionTemplate.class);
+
+    // THEN
+    Assert.assertNotNull(template);
+    template.authenticate(new Dn("cn=read-only-admin,dc=example,dc=com"), "password".toCharArray());
+
+    Boolean success = template.execute(new ConnectionCallback<Boolean>() {
+      @Override
+      public Boolean doWithConnection(LdapConnection connection) throws LdapException {
+        connection.unBind();
+        connection.bind(new Dn("cn=read-only-admin,dc=example,dc=com"), "password");
+        return connection.isConnected() && connection.isAuthenticated();
+      }
+    });
+
+    Assert.assertTrue("Could not bind to the LDAP server", success);
+
+  }
+
+
+  @Test
+  public void testShouldConnectionCheckSucceedWhenProperConfigurationProvided() throws Exception {
+    // GIVEN
+    AmbariLdapConfiguration ambariLdapConfiguration = ldapConfigurationFactory.createLdapConfiguration(getProps());
+
+    LdapFacade ldapFacade = injector.getInstance(LdapFacade.class);
+
+
+    // WHEN
+    ldapFacade.checkConnection(ambariLdapConfiguration);
+
+    ldapFacade.detectAttributes(ambariLdapConfiguration);
+
+    // THEN
+    // no exceptions thrown
+
+  }
+
+  @Test
+  public void testShouldAttributeDetectionSucceedWhenProperConfigurationProvided() throws Exception {
+    // GIVEN
+    AmbariLdapConfiguration ambariLdapConfiguration = ldapConfigurationFactory.createLdapConfiguration(getProps());
+    LdapConfigurationService ldapConfigurationService = injector.getInstance(LdapConfigurationService.class);
+
+
+    // WHEN
+    ldapConfigurationService.checkUserAttributes("euclid", "", ambariLdapConfiguration);
+
+    // THEN
+    // no exceptions thrown
+
+  }
+
+  private static Map<String, Object> getProps() {
+    Map<String, Object> ldapPropsMap = Maps.newHashMap();
+
+    ldapPropsMap.put(AmbariLdapConfigKeys.ANONYMOUS_BIND.key(), "true");
+    ldapPropsMap.put(AmbariLdapConfigKeys.SERVER_HOST.key(), "ldap.forumsys.com");
+    ldapPropsMap.put(AmbariLdapConfigKeys.SERVER_PORT.key(), "389");
+    ldapPropsMap.put(AmbariLdapConfigKeys.BIND_DN.key(), "cn=read-only-admin,dc=example,dc=com");
+    ldapPropsMap.put(AmbariLdapConfigKeys.BIND_PASSWORD.key(), "password");
+
+    ldapPropsMap.put(AmbariLdapConfigKeys.USER_OBJECT_CLASS.key(), SchemaConstants.PERSON_OC);
+    ldapPropsMap.put(AmbariLdapConfigKeys.USER_NAME_ATTRIBUTE.key(), SchemaConstants.UID_AT);
+    ldapPropsMap.put(AmbariLdapConfigKeys.USER_SEARCH_BASE.key(), "dc=example,dc=com");
+    ldapPropsMap.put(AmbariLdapConfigKeys.DN_ATTRIBUTE.key(), SchemaConstants.UID_AT);
+
+
+    return ldapPropsMap;
+  }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigurationTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigurationTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigurationTest.java
deleted file mode 100644
index 0d02a0e..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigurationTest.java
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.domain;
-
-public class AmbariLdapConfigurationTest {
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/TestAmbariAmbariLdapConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/TestAmbariAmbariLdapConfigurationFactory.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/TestAmbariAmbariLdapConfigurationFactory.java
new file mode 100644
index 0000000..1155494
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/TestAmbariAmbariLdapConfigurationFactory.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.domain;
+
+
+import java.util.Map;
+
+/**
+ * Implementation used for testing purposes only!
+ */
+public class TestAmbariAmbariLdapConfigurationFactory implements AmbariLdapConfigurationFactory {
+
+  @Override
+  public AmbariLdapConfiguration createLdapConfiguration(Map<String, Object> configuration) {
+    return new AmbariLdapConfiguration(configuration);
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/1939f092/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/TestAmbariLdapConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/TestAmbariLdapConfigurationFactory.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/TestAmbariLdapConfigurationFactory.java
deleted file mode 100644
index ec86568..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/TestAmbariLdapConfigurationFactory.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.domain;
-
-
-import java.util.Map;
-
-/**
- * Implementation used for testing purposes only!
- */
-public class TestAmbariLdapConfigurationFactory implements LdapConfigurationFactory {
-
-  @Override
-  public AmbariLdapConfiguration createLdapConfiguration(Map<String, Object> configuration) {
-    return new AmbariLdapConfiguration(configuration);
-  }
-}


[31/46] ambari git commit: AMBARI-21307 Testing the attribute detection - fixing bugs, cleanup

Posted by lp...@apache.org.
AMBARI-21307 Testing the attribute detection - fixing bugs, cleanup


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 9b4bd20d5e3c2f0df9cfc55f66184221fc936238
Parents: 01295fe
Author: lpuskas <lp...@apache.org>
Authored: Tue Sep 12 18:58:44 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:42:00 2017 +0200

----------------------------------------------------------------------
 .../api/services/ldap/LdapConfigurationService.java  | 11 +++++++----
 .../ambari/server/ldap/AmbariLdapConfiguration.java  |  2 +-
 .../org/apache/ambari/server/ldap/LdapModule.java    |  3 +++
 .../ambari/server/ldap/service/AmbariLdapFacade.java |  6 ++++++
 .../ads/DefaultAttributeDetectionService.java        | 15 +++++++--------
 .../service/ads/DefaultLdapConfigurationService.java |  3 ---
 .../ads/detectors/GroupMemberAttrDetector.java       |  3 +++
 .../service/ads/detectors/GroupNameAttrDetector.java |  3 +++
 .../ads/detectors/GroupObjectClassDetector.java      |  3 +++
 .../ads/detectors/UserGroupMemberAttrDetector.java   |  3 +++
 .../service/ads/detectors/UserNameAttrDetector.java  |  3 +++
 .../ads/DefaultAttributeDetectionServiceTest.java    |  3 +--
 .../ads/DefaultLdapConfigurationServiceTest.java     |  4 ++--
 13 files changed, 42 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/9b4bd20d/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
index 66809c3..ae47a87 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
@@ -86,6 +86,7 @@ public class LdapConfigurationService extends AmbariConfigurationService {
     authorize();
 
     Set<String> groups = Sets.newHashSet();
+    Object responseEntity = null;
 
     Result result = new ResultImpl(new ResultStatus(ResultStatus.STATUS.OK));
     try {
@@ -108,13 +109,14 @@ public class LdapConfigurationService extends AmbariConfigurationService {
 
           LOGGER.info("Testing LDAP attributes ....");
           groups = ldapFacade.checkLdapAttributes(ldapConfigurationRequest.getRequestInfo().getParameters(), ambariLdapConfiguration);
-          setResult(groups, result);
+          responseEntity = groups;
 
           break;
         case DETECT_ATTRIBUTES:
 
           LOGGER.info("Detecting LDAP attributes ...");
-          ldapFacade.detectAttributes(ambariLdapConfiguration);
+          ambariLdapConfiguration = ldapFacade.detectAttributes(ambariLdapConfiguration);
+          responseEntity = ambariLdapConfiguration;
 
           break;
         default:
@@ -123,10 +125,11 @@ public class LdapConfigurationService extends AmbariConfigurationService {
       }
 
     } catch (Exception e) {
-      result.setResultStatus(new ResultStatus(ResultStatus.STATUS.BAD_REQUEST, e));
+      result.setResultStatus(new ResultStatus(ResultStatus.STATUS.SERVER_ERROR, e));
+      responseEntity = e.getMessage();
     }
 
-    return Response.status(result.getStatus().getStatusCode()).entity(getResultSerializer().serialize(result)).build();
+    return Response.status(result.getStatus().getStatusCode()).entity(responseEntity).build();
   }
 
   private void setResult(Set<String> groups, Result result) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/9b4bd20d/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
index ebb567d..5bdda7a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
@@ -62,7 +62,7 @@ public class AmbariLdapConfiguration {
     GROUP_OBJECT_CLASS("ambari.ldap.attributes.group.object_class"),
     GROUP_NAME_ATTRIBUTE("ambari.ldap.attributes.group.name_attr"),
     GROUP_MEMBER_ATTRIBUTE("ambari.ldap.attributes.group.member_attr"),
-    GROUP_SEARCH_BASE("ambari.ldap.attributes.user.search_base"),
+    GROUP_SEARCH_BASE("ambari.ldap.attributes.group.search_base"),
 
     USER_SEARCH_FILTER("ambari.ldap.advanced.user_search_filter"),
     USER_MEMBER_REPLACE_PATTERN("ambari.ldap.advanced.user_member_replace_pattern"),

http://git-wip-us.apache.org/repos/asf/ambari/blob/9b4bd20d/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
index 81f2a44..5d6a698 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
@@ -17,8 +17,10 @@ package org.apache.ambari.server.ldap;
 
 import org.apache.ambari.server.ldap.service.AmbariLdapConfigurationProvider;
 import org.apache.ambari.server.ldap.service.AmbariLdapFacade;
+import org.apache.ambari.server.ldap.service.LdapAttributeDetectionService;
 import org.apache.ambari.server.ldap.service.LdapConnectionService;
 import org.apache.ambari.server.ldap.service.LdapFacade;
+import org.apache.ambari.server.ldap.service.ads.DefaultAttributeDetectionService;
 import org.apache.ambari.server.ldap.service.ads.DefaultLdapConfigurationService;
 import org.apache.ambari.server.ldap.service.ads.DefaultLdapConnectionService;
 
@@ -35,6 +37,7 @@ public class LdapModule extends AbstractModule {
     bind(LdapFacade.class).to(AmbariLdapFacade.class);
     bind(LdapConfigurationService.class).to(DefaultLdapConfigurationService.class);
     bind(LdapConnectionService.class).to(DefaultLdapConnectionService.class);
+    bind(LdapAttributeDetectionService.class).to(DefaultAttributeDetectionService.class);
 
     bind(AmbariLdapConfiguration.class).toProvider(AmbariLdapConfigurationProvider.class);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/9b4bd20d/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
index d2bdef3..719bb7b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
@@ -95,13 +95,18 @@ public class AmbariLdapFacade implements LdapFacade {
     LdapConnection connection = ldapConnectionService.getBoundLdapConnection(ambariLdapConfiguration);
     try {
 
+      // decorate the configuration with detected user attributes
       ambariLdapConfiguration = ldapAttributeDetectionService.detectLdapUserAttributes(connection, ambariLdapConfiguration);
+
+      // decorate the configuration with detected group attributes
       ambariLdapConfiguration = ldapAttributeDetectionService.detectLdapGroupAttributes(connection, ambariLdapConfiguration);
       return ambariLdapConfiguration;
 
     } catch (Exception e) {
+
       LOGGER.error("Error during LDAP attribute detection", e);
       throw new AmbariLdapException(e);
+
     } finally {
       try {
         connection.unBind();
@@ -126,6 +131,7 @@ public class AmbariLdapFacade implements LdapFacade {
     LOGGER.info("Testing LDAP user attributes with test user: {}", userName);
     String userDn = ldapConfigurationService.checkUserAttributes(ldapConnection, userName, testUserPass, ldapConfiguration);
 
+    // todo handle the case where group membership is stored in the user rather than the group
     LOGGER.info("Testing LDAP group attributes with test user dn: {}", userDn);
     Set<String> groups = ldapConfigurationService.checkGroupAttributes(ldapConnection, userDn, ldapConfiguration);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/9b4bd20d/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionService.java
index b3a4fde..e5254b5 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionService.java
@@ -48,21 +48,22 @@ public class DefaultAttributeDetectionService implements LdapAttributeDetectionS
 
 
   @Inject
-  private UserNameAttrDetector userNameAttrDetector = new UserNameAttrDetector(); // todo remove instantition
+  private UserNameAttrDetector userNameAttrDetector;
 
   @Inject
-  private UserObjectClassDetector userObjectClassDetector = new UserObjectClassDetector(); // todo remove instantition
+  private UserObjectClassDetector userObjectClassDetector;
 
   @Inject
-  private UserGroupMemberAttrDetector userGroupMemberAttrDetector = new UserGroupMemberAttrDetector(); // todo remove instantition
+  private UserGroupMemberAttrDetector userGroupMemberAttrDetector;
 
   @Inject
-  private GroupNameAttrDetector groupNameAttrDetector = new GroupNameAttrDetector(); // todo remove instantition
+  private GroupNameAttrDetector groupNameAttrDetector;
 
   @Inject
-  private GroupObjectClassDetector groupObjectClassDetector = new GroupObjectClassDetector(); // todo remove instantition
+  private GroupObjectClassDetector groupObjectClassDetector;
 
-  private GroupMemberAttrDetector groupMemberAttrDetector = new GroupMemberAttrDetector(); // todo remove instantition
+  @Inject
+  private GroupMemberAttrDetector groupMemberAttrDetector;
 
   @Inject
   public DefaultAttributeDetectionService() {
@@ -81,8 +82,6 @@ public class DefaultAttributeDetectionService implements LdapAttributeDetectionS
     SearchCursor searchCursor = null;
 
     try {
-      // todo should the bind operation be done in the facade?
-      connection.bind(ambariLdapConfiguration.bindDn(), ambariLdapConfiguration.bindPassword());
 
       SearchRequest searchRequest = assembleUserSearchRequest(ambariLdapConfiguration);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/9b4bd20d/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
index 5735d7d..c90b5ac 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
@@ -49,9 +49,6 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
 
   private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapConfigurationService.class);
 
-  /**
-   * Facilitating the instantiation
-   */
   @Inject
   public DefaultLdapConfigurationService() {
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/9b4bd20d/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java
index 6931736..aa444ab 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java
@@ -14,6 +14,8 @@
 
 package org.apache.ambari.server.ldap.service.ads.detectors;
 
+import javax.inject.Inject;
+
 import org.apache.directory.api.ldap.model.entry.Entry;
 
 public class GroupMemberAttrDetector extends OccurranceAndWeightBasedDetector {
@@ -42,6 +44,7 @@ public class GroupMemberAttrDetector extends OccurranceAndWeightBasedDetector {
 
   }
 
+  @Inject
   public GroupMemberAttrDetector() {
     for (GroupMemberAttr groupMemberAttr : GroupMemberAttr.values()) {
       occurranceMap().put(groupMemberAttr.attrName(), 0);

http://git-wip-us.apache.org/repos/asf/ambari/blob/9b4bd20d/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupNameAttrDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupNameAttrDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupNameAttrDetector.java
index f868383..d4dcdff 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupNameAttrDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupNameAttrDetector.java
@@ -14,6 +14,8 @@
 
 package org.apache.ambari.server.ldap.service.ads.detectors;
 
+import javax.inject.Inject;
+
 import org.apache.directory.api.ldap.model.entry.Entry;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -45,6 +47,7 @@ public class GroupNameAttrDetector extends OccurranceAndWeightBasedDetector {
 
   }
 
+  @Inject
   public GroupNameAttrDetector() {
 
     for (GroupNameAttr groupNameAttr : GroupNameAttr.values()) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/9b4bd20d/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupObjectClassDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupObjectClassDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupObjectClassDetector.java
index fddc5a5..88824c4 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupObjectClassDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupObjectClassDetector.java
@@ -14,6 +14,8 @@
 
 package org.apache.ambari.server.ldap.service.ads.detectors;
 
+import javax.inject.Inject;
+
 import org.apache.directory.api.ldap.model.entry.Entry;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -50,6 +52,7 @@ public class GroupObjectClassDetector extends OccurranceAndWeightBasedDetector {
 
   }
 
+  @Inject
   public GroupObjectClassDetector() {
     for (ObjectClassValue ocVal : ObjectClassValue.values()) {
       occurranceMap().put(ocVal.ocVal(), 0);

http://git-wip-us.apache.org/repos/asf/ambari/blob/9b4bd20d/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java
index c3f2ab4..913c2b6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java
@@ -14,6 +14,8 @@
 
 package org.apache.ambari.server.ldap.service.ads.detectors;
 
+import javax.inject.Inject;
+
 import org.apache.directory.api.ldap.model.entry.Entry;
 
 public class UserGroupMemberAttrDetector extends OccurranceAndWeightBasedDetector {
@@ -42,6 +44,7 @@ public class UserGroupMemberAttrDetector extends OccurranceAndWeightBasedDetecto
 
   }
 
+  @Inject
   public UserGroupMemberAttrDetector() {
     for (UserGroupMemberAttr userGroupMemberAttr : UserGroupMemberAttr.values()) {
       occurranceMap().put(userGroupMemberAttr.attrName(), 0);

http://git-wip-us.apache.org/repos/asf/ambari/blob/9b4bd20d/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserNameAttrDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserNameAttrDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserNameAttrDetector.java
index 40bf09b..eade3c8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserNameAttrDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserNameAttrDetector.java
@@ -14,6 +14,8 @@
 
 package org.apache.ambari.server.ldap.service.ads.detectors;
 
+import javax.inject.Inject;
+
 import org.apache.directory.api.ldap.model.entry.Entry;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -44,6 +46,7 @@ public class UserNameAttrDetector extends OccurranceAndWeightBasedDetector {
 
   }
 
+  @Inject
   public UserNameAttrDetector() {
     for (UserNameAttrs nameAttr : UserNameAttrs.values()) {
       occurranceMap().put(nameAttr.attrName(), 0);

http://git-wip-us.apache.org/repos/asf/ambari/blob/9b4bd20d/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionServiceTest.java
index 08f2d6c..9b03b86 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionServiceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionServiceTest.java
@@ -21,7 +21,6 @@ import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
 import org.apache.ambari.server.ldap.service.LdapConnectionService;
 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
 import org.apache.directory.ldap.client.api.LdapConnection;
-import org.apache.directory.ldap.client.api.LdapNetworkConnection;
 import org.easymock.EasyMockRule;
 import org.easymock.TestSubject;
 import org.junit.Assert;
@@ -76,7 +75,7 @@ public class DefaultAttributeDetectionServiceTest {
     // GIVEN
     AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(getTestPropertiesMap());
     LdapConnectionService connectionService = new DefaultLdapConnectionService();
-    LdapNetworkConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
+    LdapConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
 
     // WHEN
     AmbariLdapConfiguration config = attributeDetectionService.detectLdapUserAttributes(ldapConnection, ambariLdapConfiguration);

http://git-wip-us.apache.org/repos/asf/ambari/blob/9b4bd20d/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
index e023c6c..1e69012 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
@@ -86,7 +86,7 @@ public class DefaultLdapConfigurationServiceTest {
 
     AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(ldapPropsMap);
     LdapConnectionService connectionService = new DefaultLdapConnectionService();
-    LdapNetworkConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
+    LdapConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
 
     ldapConfigurationService.checkUserAttributes(ldapConnection, "einstein", "", ambariLdapConfiguration);
   }
@@ -108,7 +108,7 @@ public class DefaultLdapConfigurationServiceTest {
 
     AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(ldapPropsMap);
     LdapConnectionService connectionService = new DefaultLdapConnectionService();
-    LdapNetworkConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
+    LdapConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
 
     ldapConfigurationService.checkGroupAttributes(ldapConnection, "uid=einstein,dc=example,dc=com", ambariLdapConfiguration);
   }


[19/46] ambari git commit: AMBARI-21545 Stack Advisor support for LDAP configuration (benyoka)

Posted by lp...@apache.org.
AMBARI-21545 Stack Advisor support for LDAP configuration (benyoka)


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 1d75b5429fc9eaf90fffa1c19d8f42362fd99a4b
Parents: 5790e88
Author: Balazs Bence Sari <be...@apache.org>
Authored: Tue Aug 8 20:17:14 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:41:57 2017 +0200

----------------------------------------------------------------------
 .../services/AmbariConfigurationService.java    |   4 +-
 .../stackadvisor/StackAdvisorRequest.java       |  12 ++
 .../commands/StackAdvisorCommand.java           |  54 +++++
 .../commands/StackAdvisorCommandTest.java       | 212 +++++++++++++++++++
 .../StackAdvisorResourceProviderTest.java       |  97 ++++-----
 5 files changed, 324 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/1d75b542/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java
index 0632361..927e518 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java
@@ -56,9 +56,9 @@ import io.swagger.annotations.ApiResponses;
  *            "data": [
  *                {
  *                 "authentication.ldap.primaryUrl": "localhost:33389"
-                   "authentication.ldap.secondaryUrl": "localhost:333"
+ *                 "authentication.ldap.secondaryUrl": "localhost:333"
  *                 "authentication.ldap.baseDn": "dc=ambari,dc=apache,dc=org"
-  *                 // ......
+ *                 // ......
  *         ]
  *     }
  * </pre>

http://git-wip-us.apache.org/repos/asf/ambari/blob/1d75b542/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorRequest.java
index 3a2b488..cd26c56 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorRequest.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorRequest.java
@@ -31,6 +31,8 @@ import org.apache.ambari.server.api.services.stackadvisor.recommendations.Recomm
 import org.apache.ambari.server.state.ChangedConfigInfo;
 import org.apache.commons.lang.StringUtils;
 
+import com.google.common.base.Preconditions;
+
 /**
  * Stack advisor request.
  */
@@ -48,6 +50,7 @@ public class StackAdvisorRequest {
   private List<ChangedConfigInfo> changedConfigurations = new LinkedList<>();
   private Set<RecommendationResponse.ConfigGroup> configGroups;
   private Map<String, String> userContext = new HashMap<>();
+  private Map<String, Object> ldapConfig = new HashMap<>();
 
   public String getStackName() {
     return stackName;
@@ -93,6 +96,8 @@ public class StackAdvisorRequest {
     return configurations;
   }
 
+  public Map<String, Object> getLdapConfig() { return ldapConfig; }
+
   public List<ChangedConfigInfo> getChangedConfigurations() {
     return changedConfigurations;
   }
@@ -189,6 +194,13 @@ public class StackAdvisorRequest {
       return this;
     }
 
+    public StackAdvisorRequestBuilder withLdapConfig(Map<String, Object> ldapConfig) {
+      Preconditions.checkNotNull(ldapConfig);
+      this.instance.ldapConfig = ldapConfig;
+      return this;
+    }
+
+
     public StackAdvisorRequest build() {
       return this.instance;
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/1d75b542/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/commands/StackAdvisorCommand.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/commands/StackAdvisorCommand.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/commands/StackAdvisorCommand.java
index 356754d..2dc45de 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/commands/StackAdvisorCommand.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/commands/StackAdvisorCommand.java
@@ -84,6 +84,7 @@ public abstract class StackAdvisorCommand<T extends StackAdvisorResponse> extend
       + ",services/configurations/dependencies/StackConfigurationDependency/dependency_name"
       + ",services/configurations/dependencies/StackConfigurationDependency/dependency_type,services/configurations/StackConfigurations/type"
       + "&services/StackServices/service_name.in(%s)";
+  private static final String GET_LDAP_CONFIG_URI = "/api/v1/configurations?AmbariConfiguration/type=ldap&fields=AmbariConfiguration/*";
   private static final String SERVICES_PROPERTY = "services";
   private static final String SERVICES_COMPONENTS_PROPERTY = "components";
   private static final String CONFIG_GROUPS_PROPERTY = "config-groups";
@@ -95,6 +96,7 @@ public abstract class StackAdvisorCommand<T extends StackAdvisorResponse> extend
   private static final String CHANGED_CONFIGURATIONS_PROPERTY = "changed-configurations";
   private static final String USER_CONTEXT_PROPERTY = "user-context";
   private static final String AMBARI_SERVER_CONFIGURATIONS_PROPERTY = "ambari-server-properties";
+  protected static final String LDAP_CONFIGURATION_PROPERTY = "ldap-configuration";
 
   private File recommendationsDir;
   private String recommendationsArtifactsLifetime;
@@ -160,6 +162,7 @@ public abstract class StackAdvisorCommand<T extends StackAdvisorResponse> extend
       populateConfigurations(root, request);
       populateConfigGroups(root, request);
       populateAmbariServerInfo(root);
+      populateLdapConfiguration(root);
       data.servicesJSON = mapper.writeValueAsString(root);
     } catch (Exception e) {
       // should not happen
@@ -171,6 +174,52 @@ public abstract class StackAdvisorCommand<T extends StackAdvisorResponse> extend
     return data;
   }
 
+  /**
+   * Retrieves the LDAP configuration if exists and adds it to services.json
+   * @param root The JSON document that will become service.json when passed to the stack advisor engine
+   * @throws StackAdvisorException
+   * @throws IOException
+   */
+  protected void populateLdapConfiguration(ObjectNode root) throws StackAdvisorException, IOException {
+    Response response = handleRequest(null, null, new LocalUriInfo(GET_LDAP_CONFIG_URI), Request.Type.GET,
+        createConfigResource());
+
+    if (response.getStatus() != Status.OK.getStatusCode()) {
+      String message = String.format(
+          "Error occured during retrieving ldap configuration, status=%s, response=%s",
+          response.getStatus(), (String) response.getEntity());
+      LOG.warn(message);
+      throw new StackAdvisorException(message);
+    }
+
+    String ldapConfigJSON = (String) response.getEntity();
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("LDAP configuration: {}", ldapConfigJSON);
+    }
+
+    JsonNode ldapConfigRoot = mapper.readTree(ldapConfigJSON);
+    ArrayNode ldapConfigs = ((ArrayNode)ldapConfigRoot.get("items"));
+    int numConfigs = ldapConfigs.size();
+    // Zero or one config may exist
+    switch (numConfigs) {
+      case 0:
+        LOG.debug("No LDAP config is stored in the DB");
+        break;
+      case 1:
+        ArrayNode ldapConfigData = (ArrayNode)ldapConfigs.get(0).get("AmbariConfiguration").get("data");
+        if (ldapConfigData.size() == 0) {
+          throw new StackAdvisorException("No configuration data for LDAP configuration.");
+        }
+        if (ldapConfigData.size() > 1) {
+          throw new StackAdvisorException("Ambigous configuration data for LDAP configuration.");
+        }
+        root.put(LDAP_CONFIGURATION_PROPERTY, ldapConfigData.get(0));
+        break;
+      default:
+        throw new StackAdvisorException(String.format("Multiple (%s) LDAP configs are found in the DB.", numConfigs));
+    }
+  }
+
   protected void populateAmbariServerInfo(ObjectNode root) throws StackAdvisorException {
     Map<String, String> serverProperties = metaInfo.getAmbariServerProperties();
 
@@ -437,6 +486,11 @@ public abstract class StackAdvisorCommand<T extends StackAdvisorResponse> extend
     return createResource(Resource.Type.Host, mapIds);
   }
 
+  protected ResourceInstance createConfigResource() {
+    return createResource(Resource.Type.AmbariConfiguration, new HashMap<>());
+  }
+
+
   private ResourceInstance createStackVersionResource(String stackName, String stackVersion) {
     Map<Resource.Type, String> mapIds = new HashMap<>();
     mapIds.put(Resource.Type.Stack, stackName);

http://git-wip-us.apache.org/repos/asf/ambari/blob/1d75b542/ambari-server/src/test/java/org/apache/ambari/server/api/services/stackadvisor/commands/StackAdvisorCommandTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/stackadvisor/commands/StackAdvisorCommandTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/services/stackadvisor/commands/StackAdvisorCommandTest.java
index eaa4716..959db15 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/services/stackadvisor/commands/StackAdvisorCommandTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/services/stackadvisor/commands/StackAdvisorCommandTest.java
@@ -18,6 +18,7 @@
 
 package org.apache.ambari.server.api.services.stackadvisor.commands;
 
+import static org.apache.ambari.server.api.services.stackadvisor.commands.StackAdvisorCommand.LDAP_CONFIGURATION_PROPERTY;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
@@ -33,12 +34,21 @@ import java.io.File;
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
 
+import org.apache.ambari.server.api.resources.ResourceInstance;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.ResultStatus;
 import org.apache.ambari.server.api.services.stackadvisor.StackAdvisorException;
 import org.apache.ambari.server.api.services.stackadvisor.StackAdvisorRequest;
 import org.apache.ambari.server.api.services.stackadvisor.StackAdvisorRequest.StackAdvisorRequestBuilder;
@@ -50,6 +60,7 @@ import org.apache.ambari.server.state.ServiceInfo;
 import org.apache.commons.io.FileUtils;
 import org.codehaus.jackson.JsonNode;
 import org.codehaus.jackson.annotate.JsonProperty;
+import org.codehaus.jackson.map.ObjectMapper;
 import org.codehaus.jackson.node.ArrayNode;
 import org.codehaus.jackson.node.ObjectNode;
 import org.junit.After;
@@ -59,6 +70,8 @@ import org.junit.rules.TemporaryFolder;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 
+import com.google.common.collect.Lists;
+
 /**
  * StackAdvisorCommand unit tests.
  */
@@ -265,6 +278,197 @@ public class StackAdvisorCommandTest {
     assertEquals(0, stackVersions.size());
   }
 
+  @Test
+  public void testPopulateLdapConfig() throws Exception {
+    File recommendationsDir = temp.newFolder("recommendationDir");
+    String recommendationsArtifactsLifetime = "1w";
+    int requestId = 0;
+    StackAdvisorRunner saRunner = mock(StackAdvisorRunner.class);
+    AmbariMetaInfo metaInfo = mock(AmbariMetaInfo.class);
+    doReturn(Collections.emptyList()).when(metaInfo).getStackParentVersions(anyString(), anyString());
+    TestStackAdvisorCommand command = spy(new TestStackAdvisorCommand(recommendationsDir, recommendationsArtifactsLifetime,
+      ServiceInfo.ServiceAdvisorType.PYTHON, requestId, saRunner, metaInfo));
+
+    StackAdvisorRequest request = StackAdvisorRequestBuilder.forStack("stackName", "stackVersion").build();
+
+    Map<String, Object> ldapConfigData = map(
+      "authentication.ldap.primaryUrl", "localhost:33389",
+      "authentication.ldap.secondaryUrl", "localhost:333",
+      "authentication.ldap.baseDn", "c=ambari,dc=apache,dc=org"
+    );
+
+    Map<String, Object> storedLdapConfigResult =  map(
+      "items",
+      list(
+        map(
+          "AmbariConfiguration",
+          map(
+            "data", list(ldapConfigData)
+          )
+        )
+      )
+    );
+
+    Response response =
+      Response.status(ResultStatus.STATUS.OK.getStatus()).entity(jsonString(storedLdapConfigResult)).build();
+
+    doReturn(response).when(command).handleRequest(any(), any(), any(), any(), any(), any());
+
+    JsonNode servicesRootNode = json("{}");
+    command.populateLdapConfiguration((ObjectNode)servicesRootNode);
+
+    JsonNode expectedLdapConfig = json(
+      map(LDAP_CONFIGURATION_PROPERTY, ldapConfigData)
+    );
+
+    assertEquals(expectedLdapConfig, servicesRootNode);
+  }
+
+  @Test
+  public void testPopulateLdapConfig_NoConfigs() throws Exception {
+    File recommendationsDir = temp.newFolder("recommendationDir");
+    String recommendationsArtifactsLifetime = "1w";
+    int requestId = 0;
+    StackAdvisorRunner saRunner = mock(StackAdvisorRunner.class);
+    AmbariMetaInfo metaInfo = mock(AmbariMetaInfo.class);
+    doReturn(Collections.emptyList()).when(metaInfo).getStackParentVersions(anyString(), anyString());
+    TestStackAdvisorCommand command = spy(new TestStackAdvisorCommand(recommendationsDir, recommendationsArtifactsLifetime,
+      ServiceInfo.ServiceAdvisorType.PYTHON, requestId, saRunner, metaInfo));
+
+    StackAdvisorRequest request = StackAdvisorRequestBuilder.forStack("stackName", "stackVersion").build();
+
+    Map<String, Object> storedLdapConfigResult =  map(
+      "items", list()
+    );
+
+    Response response =
+      Response.status(ResultStatus.STATUS.OK.getStatus()).entity(jsonString(storedLdapConfigResult)).build();
+
+    doReturn(response).when(command).handleRequest(any(), any(), any(), any(), any(), any());
+
+    JsonNode servicesRootNode = json("{}");
+    command.populateLdapConfiguration((ObjectNode)servicesRootNode);
+
+    JsonNode expectedLdapConfig = json("{}");
+
+    assertEquals(expectedLdapConfig, servicesRootNode);
+  }
+
+  /**
+   * An ambigous ldap config that has two items in its data[] array should result in exception
+   */
+  @Test(expected = StackAdvisorException.class)
+  public void testPopulateLdapConfig_multipleConfigs() throws Exception {
+    File recommendationsDir = temp.newFolder("recommendationDir");
+    String recommendationsArtifactsLifetime = "1w";
+    int requestId = 0;
+    StackAdvisorRunner saRunner = mock(StackAdvisorRunner.class);
+    AmbariMetaInfo metaInfo = mock(AmbariMetaInfo.class);
+    doReturn(Collections.emptyList()).when(metaInfo).getStackParentVersions(anyString(), anyString());
+    TestStackAdvisorCommand command = spy(new TestStackAdvisorCommand(recommendationsDir, recommendationsArtifactsLifetime,
+        ServiceInfo.ServiceAdvisorType.PYTHON, requestId, saRunner, metaInfo));
+
+    StackAdvisorRequest request = StackAdvisorRequestBuilder.forStack("stackName", "stackVersion").build();
+
+    Map<String, Object> ldapConfigData = map(
+      "authentication.ldap.primaryUrl", "localhost:33389",
+      "authentication.ldap.secondaryUrl", "localhost:333",
+      "authentication.ldap.baseDn", "c=ambari,dc=apache,dc=org"
+    );
+
+    Map<String, Object> storedLdapConfigResult =  map(
+      "items",
+      list(
+        map(
+          "AmbariConfiguration",
+          map(
+            "data",
+            list(ldapConfigData, ldapConfigData)
+          )
+        )
+      )
+    );
+
+    Response response =
+     Response.status(ResultStatus.STATUS.OK.getStatus()).entity(jsonString(storedLdapConfigResult)).build();
+
+    doReturn(response).when(command).handleRequest(any(), any(), any(), any(), any(), any());
+
+    JsonNode servicesRootNode = json("{}");
+    command.populateLdapConfiguration((ObjectNode)servicesRootNode);
+  }
+
+  /**
+   * An if multiple ambari configurations are stored with 'ldap-config' type, an
+   * exception should be thrown
+   */
+  @Test(expected = StackAdvisorException.class)
+  public void testPopulateLdapConfig_multipleResults() throws Exception {
+    File recommendationsDir = temp.newFolder("recommendationDir");
+    String recommendationsArtifactsLifetime = "1w";
+    int requestId = 0;
+    StackAdvisorRunner saRunner = mock(StackAdvisorRunner.class);
+    AmbariMetaInfo metaInfo = mock(AmbariMetaInfo.class);
+    doReturn(Collections.emptyList()).when(metaInfo).getStackParentVersions(anyString(), anyString());
+    TestStackAdvisorCommand command = spy(new TestStackAdvisorCommand(recommendationsDir, recommendationsArtifactsLifetime,
+      ServiceInfo.ServiceAdvisorType.PYTHON, requestId, saRunner, metaInfo));
+
+    StackAdvisorRequest request = StackAdvisorRequestBuilder.forStack("stackName", "stackVersion")
+      .build();
+
+    Map<String, Object> ldapConfig = map(
+      "AmbariConfiguration",
+      map(
+        "data",
+        list(
+          map(
+            "authentication.ldap.primaryUrl", "localhost:33389",
+            "authentication.ldap.secondaryUrl", "localhost:333",
+            "authentication.ldap.baseDn", "c=ambari,dc=apache,dc=org"
+          )
+        )
+      )
+    );
+
+    Map<String, Object> storedLdapConfigResult = map(
+      "items",
+      list(ldapConfig, ldapConfig)
+    );
+
+    Response response =
+      Response.status(ResultStatus.STATUS.OK.getStatus()).entity(jsonString(storedLdapConfigResult)).build();
+
+    doReturn(response).when(command).handleRequest(any(), any(), any(), any(), any(), any());
+
+    JsonNode servicesRootNode = json("{}");
+    command.populateLdapConfiguration((ObjectNode)servicesRootNode);
+  }
+
+  private static String jsonString(Object obj) throws IOException {
+    return new ObjectMapper().writeValueAsString(obj);
+  }
+
+  private static JsonNode json(Object obj) throws IOException {
+    return new ObjectMapper().convertValue(obj, JsonNode.class);
+  }
+
+  private static JsonNode json(String jsonString) throws IOException {
+    return new ObjectMapper().readTree(jsonString);
+  }
+
+  private static List<Object> list(Object... items) {
+    return Lists.newArrayList(items);
+  }
+
+  private static Map<String, Object> map(Object... keysAndValues) {
+    Map<String, Object> map = new HashMap<>();
+    Iterator<Object> iterator = Arrays.asList(keysAndValues).iterator();
+    while (iterator.hasNext()) {
+      map.put(iterator.next().toString(), iterator.next());
+    }
+    return map;
+  }
+
   class TestStackAdvisorCommand extends StackAdvisorCommand<TestResource> {
     public TestStackAdvisorCommand(File recommendationsDir, String recommendationsArtifactsLifetime, ServiceInfo.ServiceAdvisorType serviceAdvisorType,
                                    int requestId, StackAdvisorRunner saRunner, AmbariMetaInfo metaInfo) {
@@ -290,6 +494,14 @@ public class StackAdvisorCommandTest {
     protected TestResource updateResponse(StackAdvisorRequest request, TestResource response) {
       return response;
     }
+
+    // Overridden to ensure visiblity in tests
+    @Override
+    public javax.ws.rs.core.Response handleRequest(HttpHeaders headers, String body,
+                                                                  UriInfo uriInfo, Request.Type requestType,
+                                                                  MediaType mediaType, ResourceInstance resource) {
+      return super.handleRequest(headers, body, uriInfo, requestType, mediaType, resource);
+    }
   }
 
   public static class TestResource extends StackAdvisorResponse {

http://git-wip-us.apache.org/repos/asf/ambari/blob/1d75b542/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackAdvisorResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackAdvisorResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackAdvisorResourceProviderTest.java
index ab60948..05232ea 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackAdvisorResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackAdvisorResourceProviderTest.java
@@ -27,43 +27,35 @@ import static org.junit.Assert.assertNotNull;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 
-import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.LinkedHashSet;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import javax.annotation.Nonnull;
+
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.spi.Request;
 import org.apache.ambari.server.controller.spi.Resource;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 
+import com.google.common.collect.Lists;
+
 public class StackAdvisorResourceProviderTest {
 
+  private RecommendationResourceProvider provider;
+
   @Test
   public void testCalculateConfigurations() throws Exception {
-
-    Map<Resource.Type, String> keyPropertyIds = Collections.emptyMap();
-    Set<String> propertyIds = Collections.emptySet();
-    AmbariManagementController ambariManagementController = mock(AmbariManagementController.class);
-    RecommendationResourceProvider provider = new RecommendationResourceProvider(propertyIds,
-        keyPropertyIds, ambariManagementController);
-
-    Request request = mock(Request.class);
-    Set<Map<String, Object>> propertiesSet = new HashSet<>();
-    Map<String, Object> propertiesMap = new HashMap<>();
-    propertiesMap.put(CONFIGURATIONS_PROPERTY_ID + "site/properties/string_prop", "string");
-    List<Object> array = new ArrayList<>();
-    array.add("array1");
-    array.add("array2");
-    propertiesMap.put(CONFIGURATIONS_PROPERTY_ID + "site/properties/array_prop", array);
-    propertiesSet.add(propertiesMap);
-
-    doReturn(propertiesSet).when(request).getProperties();
+    Request request = createMockRequest(
+        CONFIGURATIONS_PROPERTY_ID + "site/properties/string_prop", "string",
+        CONFIGURATIONS_PROPERTY_ID + "site/properties/array_prop", Lists.newArrayList("array1", "array2"));
 
     Map<String, Map<String, Map<String, String>>> calculatedConfigurations = provider.calculateConfigurations(request);
 
@@ -79,27 +71,37 @@ public class StackAdvisorResourceProviderTest {
     assertEquals("[array1, array2]", properties.get("array_prop"));
   }
 
-  @Test
-  public void testReadUserContext() throws Exception {
-
+  @Nonnull
+  private RecommendationResourceProvider createRecommendationResourceProvider() {
     Map<Resource.Type, String> keyPropertyIds = Collections.emptyMap();
     Set<String> propertyIds = Collections.emptySet();
     AmbariManagementController ambariManagementController = mock(AmbariManagementController.class);
-    RecommendationResourceProvider provider = new RecommendationResourceProvider(propertyIds,
-                                                                                 keyPropertyIds, ambariManagementController);
+    return new RecommendationResourceProvider(propertyIds,
+        keyPropertyIds, ambariManagementController);
+  }
 
+  @Nonnull
+  private Request createMockRequest(Object... propertyKeysAndValues) {
     Request request = mock(Request.class);
     Set<Map<String, Object>> propertiesSet = new HashSet<>();
     Map<String, Object> propertiesMap = new HashMap<>();
-    propertiesMap.put(CONFIGURATIONS_PROPERTY_ID + "site/properties/string_prop", "string");
-    List<Object> array = new ArrayList<>();
-    array.add("array1");
-    array.add("array2");
-    propertiesMap.put(USER_CONTEXT_OPERATION_PROPERTY, "op1");
-    propertiesMap.put(USER_CONTEXT_OPERATION_DETAILS_PROPERTY, "op_det");
+    Iterator<Object> it = Arrays.asList(propertyKeysAndValues).iterator();
+    while(it.hasNext()) {
+      String key = (String)it.next();
+      Object value = it.next();
+      propertiesMap.put(key, value);
+    }
     propertiesSet.add(propertiesMap);
-
     doReturn(propertiesSet).when(request).getProperties();
+    return request;
+  }
+
+  @Test
+  public void testReadUserContext() throws Exception {
+    Request request = createMockRequest(
+        CONFIGURATIONS_PROPERTY_ID + "site/properties/string_prop", "string",
+        USER_CONTEXT_OPERATION_PROPERTY, "op1",
+        USER_CONTEXT_OPERATION_DETAILS_PROPERTY, "op_det");
 
     Map<String, String> userContext = provider.readUserContext(request);
 
@@ -111,24 +113,9 @@ public class StackAdvisorResourceProviderTest {
 
   @Test
   public void testCalculateConfigurationsWithNullPropertyValues() throws Exception {
-
-    Map<Resource.Type, String> keyPropertyIds = Collections.emptyMap();
-    Set<String> propertyIds = Collections.emptySet();
-    AmbariManagementController ambariManagementController = mock(AmbariManagementController.class);
-    RecommendationResourceProvider provider = new RecommendationResourceProvider(propertyIds,
-      keyPropertyIds, ambariManagementController);
-
-    Request request = mock(Request.class);
-    Set<Map<String, Object>> propertiesSet = new HashSet<>();
-    Map<String, Object> propertiesMap = new HashMap<>();
-    propertiesMap.put(CONFIGURATIONS_PROPERTY_ID + "site/properties/string_prop", null); //null value means no value specified for the property
-    List<Object> array = new ArrayList<>();
-    array.add("array1");
-    array.add("array2");
-    propertiesMap.put(CONFIGURATIONS_PROPERTY_ID + "site/properties/array_prop", array);
-    propertiesSet.add(propertiesMap);
-
-    doReturn(propertiesSet).when(request).getProperties();
+    Request request = createMockRequest(
+        CONFIGURATIONS_PROPERTY_ID + "site/properties/string_prop", null,
+        CONFIGURATIONS_PROPERTY_ID + "site/properties/array_prop", Lists.newArrayList("array1", "array2"));
 
     Map<String, Map<String, Map<String, String>>> calculatedConfigurations = provider.calculateConfigurations(request);
 
@@ -142,19 +129,18 @@ public class StackAdvisorResourceProviderTest {
 
     assertEquals("[array1, array2]", properties.get("array_prop"));
 
-
     // config properties with null values should be ignored
     assertFalse(properties.containsKey("string_prop"));
-
   }
 
+ 
   @Test
   public void testStackAdvisorWithEmptyHosts() {
     Map<Resource.Type, String> keyPropertyIds = Collections.emptyMap();
     Set<String> propertyIds = Collections.emptySet();
     AmbariManagementController ambariManagementController = mock(AmbariManagementController.class);
     RecommendationResourceProvider provider = new RecommendationResourceProvider(propertyIds,
-      keyPropertyIds, ambariManagementController);
+            keyPropertyIds, ambariManagementController);
 
     Request request = mock(Request.class);
     Set<Map<String, Object>> propertiesSet = new HashSet<>();
@@ -170,4 +156,9 @@ public class StackAdvisorResourceProviderTest {
     } catch (Exception e) {
     }
   }
+
+  @Before
+  public void init() {
+    provider = createRecommendationResourceProvider();
+  }
 }


[18/46] ambari git commit: AMBARI-21307 Implemented PUT operation, added unit tests

Posted by lp...@apache.org.
AMBARI-21307 Implemented PUT operation, added unit tests


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 5f35e4d9771f9df23b7317d0bed037189b0b2131
Parents: afc57b7
Author: lpuskas <lp...@apache.org>
Authored: Thu Jul 13 16:20:58 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:41:56 2017 +0200

----------------------------------------------------------------------
 .../services/AmbariConfigurationService.java    |  89 ++++---
 .../server/controller/ControllerModule.java     |   2 +
 .../controller/ResourceProviderFactory.java     |  24 +-
 .../AbstractControllerResourceProvider.java     |   2 +
 .../AmbariConfigurationResourceProvider.java    |  88 +++++--
 .../internal/DefaultProviderModule.java         |   2 -
 .../server/orm/dao/AmbariConfigurationDAO.java  |   4 +
 ...AmbariConfigurationResourceProviderTest.java | 231 +++++++++++++++++++
 8 files changed, 364 insertions(+), 78 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/5f35e4d9/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java
index 0c159b9..0632361 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java
@@ -56,16 +56,10 @@ import io.swagger.annotations.ApiResponses;
  *            "data": [
  *                {
  *                 "authentication.ldap.primaryUrl": "localhost:33389"
- *                },
- *                {
- *                "authentication.ldap.secondaryUrl": "localhost:333"
- *                 },
- *                 {
+                   "authentication.ldap.secondaryUrl": "localhost:333"
  *                 "authentication.ldap.baseDn": "dc=ambari,dc=apache,dc=org"
- *                 }
- *                 // ......
- *             ]
- *         }
+  *                 // ......
+ *         ]
  *     }
  * </pre>
  */
@@ -74,7 +68,7 @@ import io.swagger.annotations.ApiResponses;
 public class AmbariConfigurationService extends BaseService {
 
   private static final String AMBARI_CONFIGURATION_REQUEST_TYPE =
-      "org.apache.ambari.server.api.services.AmbariConfigurationRequestSwagger";
+    "org.apache.ambari.server.api.services.AmbariConfigurationRequestSwagger";
 
   /**
    * Creates an ambari configuration resource.
@@ -87,9 +81,9 @@ public class AmbariConfigurationService extends BaseService {
   @POST
   @Produces(MediaType.TEXT_PLAIN)
   @ApiOperation(value = "Creates an ambari configuration resource",
-      nickname = "AmbariConfigurationService#createAmbariConfiguration")
+    nickname = "AmbariConfigurationService#createAmbariConfiguration")
   @ApiImplicitParams({
-      @ApiImplicitParam(dataType = AMBARI_CONFIGURATION_REQUEST_TYPE, paramType = PARAM_TYPE_BODY)
+    @ApiImplicitParam(dataType = AMBARI_CONFIGURATION_REQUEST_TYPE, paramType = PARAM_TYPE_BODY)
   })
   @ApiResponses({
     @ApiResponse(code = HttpStatus.SC_CREATED, message = MSG_SUCCESSFUL_OPERATION),
@@ -108,24 +102,24 @@ public class AmbariConfigurationService extends BaseService {
   @GET
   @Produces(MediaType.TEXT_PLAIN)
   @ApiOperation(value = "Retrieve all ambari configuration resources",
-      nickname = "AmbariConfigurationService#getAmbariConfigurations",
-      notes = "Returns all Ambari configurations.",
-      response = AmbariConfigurationResponseSwagger.class,
-      responseContainer = RESPONSE_CONTAINER_LIST)
+    nickname = "AmbariConfigurationService#getAmbariConfigurations",
+    notes = "Returns all Ambari configurations.",
+    response = AmbariConfigurationResponseSwagger.class,
+    responseContainer = RESPONSE_CONTAINER_LIST)
   @ApiImplicitParams({
-      @ApiImplicitParam(name = QUERY_FIELDS, value = QUERY_FILTER_DESCRIPTION,
-          defaultValue = "AmbariConfiguration/data, AmbariConfiguration/id, AmbariConfiguration/type",
-          dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY),
-      @ApiImplicitParam(name = QUERY_SORT, value = QUERY_SORT_DESCRIPTION,
-          defaultValue = "AmbariConfiguration/id",
-          dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY),
-      @ApiImplicitParam(name = QUERY_PAGE_SIZE, value = QUERY_PAGE_SIZE_DESCRIPTION, defaultValue = DEFAULT_PAGE_SIZE, dataType = DATA_TYPE_INT, paramType = PARAM_TYPE_QUERY),
-      @ApiImplicitParam(name = QUERY_FROM, value = QUERY_FROM_DESCRIPTION, defaultValue = DEFAULT_FROM, dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY),
-      @ApiImplicitParam(name = QUERY_TO, value = QUERY_TO_DESCRIPTION, dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY)
+    @ApiImplicitParam(name = QUERY_FIELDS, value = QUERY_FILTER_DESCRIPTION,
+      defaultValue = "AmbariConfiguration/data, AmbariConfiguration/id, AmbariConfiguration/type",
+      dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY),
+    @ApiImplicitParam(name = QUERY_SORT, value = QUERY_SORT_DESCRIPTION,
+      defaultValue = "AmbariConfiguration/id",
+      dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY),
+    @ApiImplicitParam(name = QUERY_PAGE_SIZE, value = QUERY_PAGE_SIZE_DESCRIPTION, defaultValue = DEFAULT_PAGE_SIZE, dataType = DATA_TYPE_INT, paramType = PARAM_TYPE_QUERY),
+    @ApiImplicitParam(name = QUERY_FROM, value = QUERY_FROM_DESCRIPTION, defaultValue = DEFAULT_FROM, dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY),
+    @ApiImplicitParam(name = QUERY_TO, value = QUERY_TO_DESCRIPTION, dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY)
   })
   @ApiResponses(value = {
-      @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION),
-      @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR)
+    @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION),
+    @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR)
   })
   public Response getAmbariConfigurations(String body, @Context HttpHeaders headers, @Context UriInfo uri) {
     return handleRequest(headers, body, uri, Request.Type.GET, createResource(Resource.Type.AmbariConfiguration,
@@ -136,16 +130,16 @@ public class AmbariConfigurationService extends BaseService {
   @Path("{configurationId}")
   @Produces(MediaType.TEXT_PLAIN)
   @ApiOperation(value = "Retrieve the details of an ambari configuration resource",
-      nickname = "AmbariConfigurationService#getAmbariConfiguration",
-      response = AmbariConfigurationResponseSwagger.class)
+    nickname = "AmbariConfigurationService#getAmbariConfiguration",
+    response = AmbariConfigurationResponseSwagger.class)
   @ApiImplicitParams({
-      @ApiImplicitParam(name = QUERY_FIELDS, value = QUERY_FILTER_DESCRIPTION, defaultValue = "AmbariConfiguration/*",
-          dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY)
+    @ApiImplicitParam(name = QUERY_FIELDS, value = QUERY_FILTER_DESCRIPTION, defaultValue = "AmbariConfiguration/*",
+      dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY)
   })
   @ApiResponses(value = {
-      @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION),
-      @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND),
-      @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR)
+    @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION),
+    @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND),
+    @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR)
   })
   public Response getAmbariConfiguration(String body, @Context HttpHeaders headers, @Context UriInfo uri,
                                          @PathParam("configurationId") String configurationId) {
@@ -154,30 +148,35 @@ public class AmbariConfigurationService extends BaseService {
   }
 
   @PUT
+  @Path("{configurationId}")
   @Produces(MediaType.TEXT_PLAIN)
   @ApiOperation(value = "Updates ambari configuration resources - Not implemented yet",
     nickname = "AmbariConfigurationService#updateAmbariConfiguration")
   @ApiImplicitParams({
-      @ApiImplicitParam(dataType = AMBARI_CONFIGURATION_REQUEST_TYPE, paramType = PARAM_TYPE_BODY)
+    @ApiImplicitParam(dataType = AMBARI_CONFIGURATION_REQUEST_TYPE, paramType = PARAM_TYPE_BODY),
+    @ApiImplicitParam(name = QUERY_FIELDS, value = QUERY_FILTER_DESCRIPTION, defaultValue = "AmbariConfiguration/*",
+      dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY)
   })
   @ApiResponses({
-      @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION),
-      @ApiResponse(code = HttpStatus.SC_ACCEPTED, message = MSG_REQUEST_ACCEPTED),
-      @ApiResponse(code = HttpStatus.SC_BAD_REQUEST, message = MSG_INVALID_ARGUMENTS),
-      @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND),
-      @ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = MSG_NOT_AUTHENTICATED),
-      @ApiResponse(code = HttpStatus.SC_FORBIDDEN, message = MSG_PERMISSION_DENIED),
-      @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR),
+    @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION),
+    @ApiResponse(code = HttpStatus.SC_ACCEPTED, message = MSG_REQUEST_ACCEPTED),
+    @ApiResponse(code = HttpStatus.SC_BAD_REQUEST, message = MSG_INVALID_ARGUMENTS),
+    @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND),
+    @ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = MSG_NOT_AUTHENTICATED),
+    @ApiResponse(code = HttpStatus.SC_FORBIDDEN, message = MSG_PERMISSION_DENIED),
+    @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR),
   })
-  public Response updateAmbariConfiguration() {
-    throw new UnsupportedOperationException("Not yet implemented");
+  public Response updateAmbariConfiguration(String body, @Context HttpHeaders headers, @Context UriInfo uri,
+                                            @PathParam("configurationId") String configurationId) {
+    return handleRequest(headers, body, uri, Request.Type.PUT, createResource(Resource.Type.AmbariConfiguration,
+      Collections.singletonMap(Resource.Type.AmbariConfiguration, configurationId)));
   }
 
   @DELETE
   @Path("{configurationId}")
   @Produces(MediaType.TEXT_PLAIN)
   @ApiOperation(value = "Deletes an ambari configuration resource",
-      nickname = "AmbariConfigurationService#deleteAmbariConfiguration")
+    nickname = "AmbariConfigurationService#deleteAmbariConfiguration")
   @ApiResponses({
     @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION),
     @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND),

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f35e4d9/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
index dc97871..b79d122 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
@@ -62,6 +62,7 @@ import org.apache.ambari.server.cleanup.ClasspathScannerUtils;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.configuration.Configuration.ConnectionPoolType;
 import org.apache.ambari.server.configuration.Configuration.DatabaseType;
+import org.apache.ambari.server.controller.internal.AmbariConfigurationResourceProvider;
 import org.apache.ambari.server.controller.internal.AlertTargetResourceProvider;
 import org.apache.ambari.server.controller.internal.ClusterStackVersionResourceProvider;
 import org.apache.ambari.server.controller.internal.ComponentResourceProvider;
@@ -470,6 +471,7 @@ public class ControllerModule extends AbstractModule {
         .implement(ResourceProvider.class, Names.named("credential"), CredentialResourceProvider.class)
         .implement(ResourceProvider.class, Names.named("kerberosDescriptor"), KerberosDescriptorResourceProvider.class)
         .implement(ResourceProvider.class, Names.named("upgrade"), UpgradeResourceProvider.class)
+        .implement(ResourceProvider.class, Names.named("ambariConfiguration"), AmbariConfigurationResourceProvider.class)
         .implement(ResourceProvider.class, Names.named("clusterStackVersion"), ClusterStackVersionResourceProvider.class)
         .implement(ResourceProvider.class, Names.named("alertTarget"), AlertTargetResourceProvider.class)
         .implement(ResourceProvider.class, Names.named("viewInstance"), ViewInstanceResourceProvider.class)

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f35e4d9/ambari-server/src/main/java/org/apache/ambari/server/controller/ResourceProviderFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ResourceProviderFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ResourceProviderFactory.java
index a198775..711ae10 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ResourceProviderFactory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ResourceProviderFactory.java
@@ -22,6 +22,8 @@ package org.apache.ambari.server.controller;
 import java.util.Map;
 import java.util.Set;
 
+import javax.inject.Named;
+
 import org.apache.ambari.server.controller.internal.AlertTargetResourceProvider;
 import org.apache.ambari.server.controller.internal.ClusterStackVersionResourceProvider;
 import org.apache.ambari.server.controller.internal.UpgradeResourceProvider;
@@ -30,18 +32,15 @@ import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.spi.Resource.Type;
 import org.apache.ambari.server.controller.spi.ResourceProvider;
 
-import com.google.inject.name.Named;
 
 public interface ResourceProviderFactory {
   @Named("host")
-  ResourceProvider getHostResourceProvider(Set<String> propertyIds,
-      Map<Type, String> keyPropertyIds,
-      AmbariManagementController managementController);
+  ResourceProvider getHostResourceProvider(Set<String> propertyIds, Map<Type, String> keyPropertyIds,
+                                           AmbariManagementController managementController);
 
   @Named("hostComponent")
-  ResourceProvider getHostComponentResourceProvider(Set<String> propertyIds,
-      Map<Type, String> keyPropertyIds,
-      AmbariManagementController managementController);
+  ResourceProvider getHostComponentResourceProvider(Set<String> propertyIds, Map<Type, String> keyPropertyIds,
+                                                    AmbariManagementController managementController);
 
   @Named("service")
   ResourceProvider getServiceResourceProvider(AmbariManagementController managementController);
@@ -50,9 +49,8 @@ public interface ResourceProviderFactory {
   ResourceProvider getComponentResourceProvider(AmbariManagementController managementController);
 
   @Named("member")
-  ResourceProvider getMemberResourceProvider(Set<String> propertyIds,
-      Map<Type, String> keyPropertyIds,
-      AmbariManagementController managementController);
+  ResourceProvider getMemberResourceProvider(Set<String> propertyIds, Map<Type, String> keyPropertyIds,
+                                             AmbariManagementController managementController);
 
   @Named("hostKerberosIdentity")
   ResourceProvider getHostKerberosIdentityResourceProvider(AmbariManagementController managementController);
@@ -64,13 +62,15 @@ public interface ResourceProviderFactory {
   ResourceProvider getRepositoryVersionResourceProvider();
 
   @Named("kerberosDescriptor")
-  ResourceProvider getKerberosDescriptorResourceProvider(AmbariManagementController managementController,
-                                                         Set<String> propertyIds,
+  ResourceProvider getKerberosDescriptorResourceProvider(AmbariManagementController managementController, Set<String> propertyIds,
                                                          Map<Resource.Type, String> keyPropertyIds);
 
   @Named("upgrade")
   UpgradeResourceProvider getUpgradeResourceProvider(AmbariManagementController managementController);
 
+  @Named("ambariConfiguration")
+  ResourceProvider getAmbariConfigurationResourceProvider();
+
   @Named("clusterStackVersion")
   ClusterStackVersionResourceProvider getClusterStackVersionResourceProvider(AmbariManagementController managementController);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f35e4d9/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
index a98ad46..1dc0841 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
@@ -254,6 +254,8 @@ public abstract class AbstractControllerResourceProvider extends AbstractAuthori
         return new ClusterKerberosDescriptorResourceProvider(managementController);
       case LoggingQuery:
         return new LoggingResourceProvider(propertyIds, keyPropertyIds, managementController);
+      case AmbariConfiguration:
+        return resourceProviderFactory.getAmbariConfigurationResourceProvider();
       case AlertTarget:
         return resourceProviderFactory.getAlertTargetResourceProvider();
       case ViewInstance:

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f35e4d9/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProvider.java
index e8f186d..2302d8b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProvider.java
@@ -25,7 +25,6 @@ import java.util.Set;
 import javax.inject.Inject;
 
 import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.StaticallyInject;
 import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
 import org.apache.ambari.server.controller.spi.NoSuchResourceException;
 import org.apache.ambari.server.controller.spi.Predicate;
@@ -46,11 +45,11 @@ import org.slf4j.LoggerFactory;
 import com.google.common.collect.Sets;
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
+import com.google.inject.assistedinject.AssistedInject;
 
 /**
  * Resource provider for AmbariConfiguration resources.
  */
-@StaticallyInject
 public class AmbariConfigurationResourceProvider extends AbstractAuthorizedResourceProvider {
 
   private static final Logger LOGGER = LoggerFactory.getLogger(AmbariConfigurationResourceProvider.class);
@@ -60,7 +59,7 @@ public class AmbariConfigurationResourceProvider extends AbstractAuthorizedResou
   /**
    * Resource property id constants.
    */
-  private enum ResourcePropertyId {
+  public enum ResourcePropertyId {
 
     ID("AmbariConfiguration/id"),
     TYPE("AmbariConfiguration/type"),
@@ -112,11 +111,12 @@ public class AmbariConfigurationResourceProvider extends AbstractAuthorizedResou
 
 
   @Inject
-  private static AmbariConfigurationDAO ambariConfigurationDAO;
+  private AmbariConfigurationDAO ambariConfigurationDAO;
 
   private Gson gson;
 
-  protected AmbariConfigurationResourceProvider() {
+  @AssistedInject
+  public AmbariConfigurationResourceProvider() {
     super(PROPERTIES, PK_PROPERTY_MAP);
     setRequiredCreateAuthorizations(EnumSet.of(RoleAuthorization.AMBARI_MANAGE_CONFIGURATION));
     setRequiredDeleteAuthorizations(EnumSet.of(RoleAuthorization.AMBARI_MANAGE_CONFIGURATION));
@@ -134,7 +134,12 @@ public class AmbariConfigurationResourceProvider extends AbstractAuthorizedResou
     ResourceAlreadyExistsException, NoSuchParentResourceException {
 
     LOGGER.info("Creating new ambari configuration resource ...");
-    AmbariConfigurationEntity ambariConfigurationEntity = getEntityFromRequest(request);
+    AmbariConfigurationEntity ambariConfigurationEntity = null;
+    try {
+      ambariConfigurationEntity = getEntityFromRequest(request);
+    } catch (AmbariException e) {
+      throw new NoSuchParentResourceException(e.getMessage());
+    }
 
     LOGGER.info("Persisting new ambari configuration: {} ", ambariConfigurationEntity);
     ambariConfigurationDAO.create(ambariConfigurationEntity);
@@ -148,6 +153,7 @@ public class AmbariConfigurationResourceProvider extends AbstractAuthorizedResou
     UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
     Set<Resource> resources = Sets.newHashSet();
 
+    // retrieves allconfigurations, filtering is done at a higher level
     List<AmbariConfigurationEntity> ambariConfigurationEntities = ambariConfigurationDAO.findAll();
     for (AmbariConfigurationEntity ambariConfigurationEntity : ambariConfigurationEntities) {
       try {
@@ -181,40 +187,86 @@ public class AmbariConfigurationResourceProvider extends AbstractAuthorizedResou
 
   }
 
+  @Override
+  protected RequestStatus updateResourcesAuthorized(Request request, Predicate predicate) throws SystemException,
+    UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
+    Long idFromRequest = Long.valueOf((String) PredicateHelper.getProperties(predicate).get(ResourcePropertyId.ID.getPropertyId()));
+
+    AmbariConfigurationEntity persistedEntity = ambariConfigurationDAO.findByPK(idFromRequest);
+    if (persistedEntity == null) {
+      String errorMsg = String.format("Entity with primary key [ %s ] not found in the database.", idFromRequest);
+      LOGGER.error(errorMsg);
+      throw new NoSuchResourceException(errorMsg);
+    }
+
+    try {
+
+      AmbariConfigurationEntity entityFromRequest = getEntityFromRequest(request);
+      persistedEntity.getConfigurationBaseEntity().setVersionTag(entityFromRequest.getConfigurationBaseEntity().getVersionTag());
+      persistedEntity.getConfigurationBaseEntity().setVersion(entityFromRequest.getConfigurationBaseEntity().getVersion());
+      persistedEntity.getConfigurationBaseEntity().setType(entityFromRequest.getConfigurationBaseEntity().getType());
+      persistedEntity.getConfigurationBaseEntity().setConfigurationData(entityFromRequest.getConfigurationBaseEntity().getConfigurationData());
+      persistedEntity.getConfigurationBaseEntity().setConfigurationAttributes(entityFromRequest.getConfigurationBaseEntity().getConfigurationAttributes());
+
+
+      ambariConfigurationDAO.create(persistedEntity);
+    } catch (AmbariException e) {
+      throw new NoSuchParentResourceException(e.getMessage());
+    }
+
+    return getRequestStatus(null);
+
+  }
+
   private Resource toResource(AmbariConfigurationEntity entity, Set<String> requestedIds) throws AmbariException {
+
+    if (null == entity) {
+      throw new IllegalArgumentException("Null entity can't be transformed into a resource");
+    }
+
+    if (null == entity.getConfigurationBaseEntity()) {
+      throw new IllegalArgumentException("Invalid configuration entity can't be transformed into a resource");
+    }
     Resource resource = new ResourceImpl(Resource.Type.AmbariConfiguration);
     Set<Map<String, String>> configurationSet = gson.fromJson(entity.getConfigurationBaseEntity().getConfigurationData(), Set.class);
 
     setResourceProperty(resource, ResourcePropertyId.ID.getPropertyId(), entity.getId(), requestedIds);
     setResourceProperty(resource, ResourcePropertyId.TYPE.getPropertyId(), entity.getConfigurationBaseEntity().getType(), requestedIds);
     setResourceProperty(resource, ResourcePropertyId.DATA.getPropertyId(), configurationSet, requestedIds);
+    setResourceProperty(resource, ResourcePropertyId.VERSION.getPropertyId(), entity.getConfigurationBaseEntity().getVersion(), requestedIds);
+    setResourceProperty(resource, ResourcePropertyId.VERSION_TAG.getPropertyId(), entity.getConfigurationBaseEntity().getVersionTag(), requestedIds);
 
     return resource;
   }
 
-  private AmbariConfigurationEntity getEntityFromRequest(Request request) {
+  private AmbariConfigurationEntity getEntityFromRequest(Request request) throws AmbariException {
 
     AmbariConfigurationEntity ambariConfigurationEntity = new AmbariConfigurationEntity();
     ambariConfigurationEntity.setConfigurationBaseEntity(new ConfigurationBaseEntity());
 
+    // set of resource properties (eache entry in the set belongs to a different resource)
+    Set<Map<String, Object>> resourcePropertiesSet = request.getProperties();
+
+    if (resourcePropertiesSet.size() != 1) {
+      throw new AmbariException("There must be only one resource specified in the request");
+    }
+
 
     for (ResourcePropertyId resourcePropertyId : ResourcePropertyId.values()) {
-      Object requestValue = getValueFromRequest(resourcePropertyId, request);
+      Object requestValue = getValueFromResourceProperties(resourcePropertyId, resourcePropertiesSet.iterator().next());
 
       switch (resourcePropertyId) {
         case DATA:
           if (requestValue == null) {
             throw new IllegalArgumentException("No configuration data is provided in the request");
           }
-
           ambariConfigurationEntity.getConfigurationBaseEntity().setConfigurationData(gson.toJson(requestValue));
           break;
         case TYPE:
           ambariConfigurationEntity.getConfigurationBaseEntity().setType((String) requestValue);
           break;
-
         case VERSION:
-          Integer version = (requestValue == null) ? DEFAULT_VERSION : Integer.valueOf((Integer) requestValue);
+          Integer version = (requestValue == null) ? DEFAULT_VERSION : Integer.valueOf((String) requestValue);
           ambariConfigurationEntity.getConfigurationBaseEntity().setVersion((version));
           break;
         case VERSION_TAG:
@@ -231,15 +283,13 @@ public class AmbariConfigurationResourceProvider extends AbstractAuthorizedResou
 
   }
 
-  private Object getValueFromRequest(ResourcePropertyId resourcePropertyIdEnum, Request request) {
-    LOGGER.debug("Locating resource property [{}] in the request ...", resourcePropertyIdEnum);
+  private Object getValueFromResourceProperties(ResourcePropertyId resourcePropertyIdEnum, Map<String, Object> resourceProperties) {
+    LOGGER.debug("Locating resource property [{}] in the resource properties map ...", resourcePropertyIdEnum);
     Object requestValue = null;
-    for (Map<String, Object> propertyMap : request.getProperties()) {
-      if (propertyMap.containsKey(resourcePropertyIdEnum.getPropertyId())) {
-        requestValue = propertyMap.get(resourcePropertyIdEnum.getPropertyId());
-        LOGGER.debug("Found resource property {} in the request, value: {} ...", resourcePropertyIdEnum, requestValue);
-        break;
-      }
+
+    if (resourceProperties.containsKey(resourcePropertyIdEnum.getPropertyId())) {
+      requestValue = resourceProperties.get(resourcePropertyIdEnum.getPropertyId());
+      LOGGER.debug("Found resource property {} in the resource properties map, value: {}", resourcePropertyIdEnum, requestValue);
     }
     return requestValue;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f35e4d9/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
index fdf4a97..c3758b3 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
@@ -116,8 +116,6 @@ public class DefaultProviderModule extends AbstractProviderModule {
         return new ArtifactResourceProvider(managementController);
       case RemoteCluster:
         return new RemoteClusterResourceProvider();
-      case AmbariConfiguration:
-        return new AmbariConfigurationResourceProvider();
       default:
         LOGGER.debug("Delegating creation of resource provider for: {} to the AbstractControllerResourceProvider", type.getInternalType());
         return AbstractControllerResourceProvider.getResourceProvider(type, propertyIds,

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f35e4d9/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AmbariConfigurationDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AmbariConfigurationDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AmbariConfigurationDAO.java
index c29a423..5710a7f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AmbariConfigurationDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AmbariConfigurationDAO.java
@@ -19,8 +19,11 @@ import javax.inject.Singleton;
 
 import org.apache.ambari.server.orm.entities.AmbariConfigurationEntity;
 
+import com.google.inject.persist.Transactional;
+
 /**
  * DAO dealing with ambari configuration related JPA operations.
+ * Operations delegate to the JPA provider implementation of CRUD operations.
  */
 
 @Singleton
@@ -31,6 +34,7 @@ public class AmbariConfigurationDAO extends CrudDAO<AmbariConfigurationEntity, L
     super(AmbariConfigurationEntity.class);
   }
 
+  @Transactional
   public void create(AmbariConfigurationEntity entity) {
     super.create(entity);
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/5f35e4d9/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProviderTest.java
new file mode 100644
index 0000000..d974682
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProviderTest.java
@@ -0,0 +1,231 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.controller.internal;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.utilities.PredicateBuilder;
+import org.apache.ambari.server.orm.dao.AmbariConfigurationDAO;
+import org.apache.ambari.server.orm.entities.AmbariConfigurationEntity;
+import org.apache.ambari.server.orm.entities.ConfigurationBaseEntity;
+import org.easymock.Capture;
+import org.easymock.EasyMock;
+import org.easymock.EasyMockRule;
+import org.easymock.EasyMockSupport;
+import org.easymock.Mock;
+import org.easymock.TestSubject;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+public class AmbariConfigurationResourceProviderTest extends EasyMockSupport {
+
+  @Rule
+  public EasyMockRule mocks = new EasyMockRule(this);
+
+  @Mock
+  private Request requestMock;
+
+  @Mock
+  private AmbariConfigurationDAO ambariConfigurationDAO;
+
+  private Capture<AmbariConfigurationEntity> ambariConfigurationEntityCapture;
+
+  private Gson gson;
+
+  private static final String DATA_MOCK_STR = "[\n" +
+    "      {\n" +
+    "        \"authentication.ldap.baseDn\" : \"dc=ambari,dc=apache,dc=org\",\n" +
+    "        \"authentication.ldap.primaryUrl\" : \"localhost:33389\",\n" +
+    "        \"authentication.ldap.secondaryUrl\" : \"localhost:333\"\n" +
+    "      }\n" +
+    "    ]";
+
+  private static final Long PK_LONG = Long.valueOf(1);
+  private static final String PK_STRING = String.valueOf(1);
+  private static final String VERSION_TAG = "test version";
+  private static final String VERSION = "1";
+
+  @TestSubject
+  private AmbariConfigurationResourceProvider ambariConfigurationResourceProvider = new AmbariConfigurationResourceProvider();
+
+  @Before
+  public void setup() {
+    ambariConfigurationEntityCapture = Capture.newInstance();
+    gson = new GsonBuilder().create();
+  }
+
+  @Test
+  public void testCreateAmbariConfigurationRequestResultsInTheProperPersistenceCall() throws Exception {
+
+    // GIVEN
+    // configuration properties parsed from the request
+    Set<Map<String, Object>> resourcePropertiesSet = Sets.newHashSet(
+      new PropertiesMapBuilder()
+        .withId(PK_LONG)
+        .withVersion(VERSION)
+        .withVersionTag(VERSION_TAG)
+        .withData(DATA_MOCK_STR)
+        .build());
+
+    // mock the request to return the properties
+    EasyMock.expect(requestMock.getProperties()).andReturn(resourcePropertiesSet);
+
+    // capture the entity the DAO gets called with
+    ambariConfigurationDAO.create(EasyMock.capture(ambariConfigurationEntityCapture));
+    replayAll();
+
+    // WHEN
+    ambariConfigurationResourceProvider.createResourcesAuthorized(requestMock);
+
+    // THEN
+    AmbariConfigurationEntity capturedAmbariConfigurationEntity = ambariConfigurationEntityCapture.getValue();
+    Assert.assertNotNull(capturedAmbariConfigurationEntity);
+    Assert.assertNull("The entity identifier should be null", capturedAmbariConfigurationEntity.getId());
+    Assert.assertEquals("The entity version is not the expected", Integer.valueOf(VERSION),
+      capturedAmbariConfigurationEntity.getConfigurationBaseEntity().getVersion());
+    Assert.assertEquals("The entity version tag is not the expected", VERSION_TAG,
+      capturedAmbariConfigurationEntity.getConfigurationBaseEntity().getVersionTag());
+    Assert.assertEquals("The entity data is not the expected", DATA_MOCK_STR,
+      gson.fromJson(capturedAmbariConfigurationEntity.getConfigurationBaseEntity().getConfigurationData(), String.class));
+  }
+
+  @Test
+  public void testRemoveAmbariConfigurationRequestResultsInTheProperPersistenceCall() throws Exception {
+    // GIVEN
+    Predicate predicate = new PredicateBuilder().property(
+      AmbariConfigurationResourceProvider.ResourcePropertyId.ID.getPropertyId()).equals("1").toPredicate();
+
+    Capture<Long> pkCapture = Capture.newInstance();
+    ambariConfigurationDAO.removeByPK(EasyMock.capture(pkCapture));
+    replayAll();
+
+    // WHEN
+    ambariConfigurationResourceProvider.deleteResourcesAuthorized(requestMock, predicate);
+
+    // THEN
+    Assert.assertEquals("The pk of the entity to be removed doen't match the expected id", Long.valueOf(1), pkCapture.getValue());
+  }
+
+
+  @Test
+  public void testRetrieveAmbariConfigurationShouldResultsInTheProperDAOCall() throws Exception {
+    // GIVEN
+    Predicate predicate = new PredicateBuilder().property(
+      AmbariConfigurationResourceProvider.ResourcePropertyId.ID.getPropertyId()).equals("1").toPredicate();
+
+    EasyMock.expect(ambariConfigurationDAO.findAll()).andReturn(Lists.newArrayList(createDummyAmbariConfigurationEntity()));
+    replayAll();
+
+    // WHEN
+    Set<Resource> resourceSet = ambariConfigurationResourceProvider.getResourcesAuthorized(requestMock, predicate);
+
+    // THEN
+    Assert.assertNotNull(resourceSet);
+    Assert.assertFalse(resourceSet.isEmpty());
+  }
+
+  @Test
+  public void testUpdateAmbariConfigurationShouldResultInTheProperDAOCalls() throws Exception {
+    // GIVEN
+
+    Predicate predicate = new PredicateBuilder().property(
+      AmbariConfigurationResourceProvider.ResourcePropertyId.ID.getPropertyId()).equals("1").toPredicate();
+
+    // properteies in the request, representing the updated configuration
+    Set<Map<String, Object>> resourcePropertiesSet = Sets.newHashSet(new PropertiesMapBuilder()
+      .withId(PK_LONG)
+      .withVersion("2")
+      .withVersionTag("version-2")
+      .withData(DATA_MOCK_STR).build());
+
+    EasyMock.expect(requestMock.getProperties()).andReturn(resourcePropertiesSet);
+
+    AmbariConfigurationEntity persistedEntity = createDummyAmbariConfigurationEntity();
+    EasyMock.expect(ambariConfigurationDAO.findByPK(PK_LONG)).andReturn(persistedEntity);
+    ambariConfigurationDAO.create(EasyMock.capture(ambariConfigurationEntityCapture));
+
+    replayAll();
+
+    // WHEN
+    ambariConfigurationResourceProvider.updateResourcesAuthorized(requestMock, predicate);
+
+    // the captured entity should be the updated one
+    AmbariConfigurationEntity updatedEntity = ambariConfigurationEntityCapture.getValue();
+
+    // THEN
+    Assert.assertNotNull(updatedEntity);
+    Assert.assertEquals("The updated version is wrong", Integer.valueOf(2), updatedEntity.getConfigurationBaseEntity().getVersion());
+  }
+
+  private class PropertiesMapBuilder {
+
+    private Map<String, Object> resourcePropertiesMap = Maps.newHashMap();
+
+    private PropertiesMapBuilder() {
+    }
+
+    public PropertiesMapBuilder withId(Long id) {
+      resourcePropertiesMap.put(AmbariConfigurationResourceProvider.ResourcePropertyId.ID.getPropertyId(), id);
+      return this;
+    }
+
+    private PropertiesMapBuilder withVersion(String version) {
+      resourcePropertiesMap.put(AmbariConfigurationResourceProvider.ResourcePropertyId.VERSION.getPropertyId(), version);
+      return this;
+    }
+
+    private PropertiesMapBuilder withVersionTag(String versionTag) {
+      resourcePropertiesMap.put(AmbariConfigurationResourceProvider.ResourcePropertyId.VERSION_TAG.getPropertyId(), versionTag);
+      return this;
+    }
+
+    private PropertiesMapBuilder withData(String dataJson) {
+      resourcePropertiesMap.put(AmbariConfigurationResourceProvider.ResourcePropertyId.DATA.getPropertyId(), dataJson);
+      return this;
+    }
+
+    public Map<String, Object> build() {
+      return this.resourcePropertiesMap;
+    }
+
+  }
+
+  private AmbariConfigurationEntity createDummyAmbariConfigurationEntity() {
+    AmbariConfigurationEntity acEntity = new AmbariConfigurationEntity();
+    ConfigurationBaseEntity configurationBaseEntity = new ConfigurationBaseEntity();
+    acEntity.setConfigurationBaseEntity(configurationBaseEntity);
+    acEntity.setId(PK_LONG);
+    acEntity.getConfigurationBaseEntity().setConfigurationData(DATA_MOCK_STR);
+    acEntity.getConfigurationBaseEntity().setVersion(Integer.valueOf(VERSION));
+    acEntity.getConfigurationBaseEntity().setVersionTag(VERSION_TAG);
+    acEntity.getConfigurationBaseEntity().setType("ldap-config");
+
+    return acEntity;
+  }
+
+
+}
\ No newline at end of file


[29/46] ambari git commit: AMBARI-21307 Add all known LDAP properties to AmbariConfigurationEnum (benyoka)

Posted by lp...@apache.org.
AMBARI-21307 Add all known LDAP properties to AmbariConfigurationEnum (benyoka)


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: d4b9215f6991599920aec886a8f79efd6e52ad0c
Parents: 38c2785
Author: Balazs Bence Sari <be...@apache.org>
Authored: Mon Sep 4 12:45:07 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:41:59 2017 +0200

----------------------------------------------------------------------
 .../ambari/server/ldap/AmbariLdapConfiguration.java  | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/d4b9215f/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
index b1cbced..e913e77 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
@@ -40,22 +40,35 @@ public class AmbariLdapConfiguration {
     USE_SSL("ambari.ldap.usessl"),
     LDAP_SERVER_HOST("ambari.ldap.server.host"),
     LDAP_SERVER_PORT("ambari.ldap.server.port"),
+    LDAP_TRUSTSTORE("ambari.ldap.truststore"),
     LDAP_TRUSTSTORE_TYPE("ambari.ldap.truststore.type"),
     LDAP_TRUSTSTORE_PATH("ambari.ldap.truststore.path"),
+    LDAP_TRUSTSTORE_PASSWORD("ambari.ldap.truststore.password"),
     BASE_DN("ambari.ldap.bind.dn"),
+    REFERRAL("ambari.ldap.referral"),
+    PAGINATION_ENABLED("ambari.ldap.pagination.enabled"),
 
     BIND_ANONIMOUSLY("ambari.ldap.bindanonymously"),
     MANAGER_DN("ambari.ldap.managerdn"),
     MANAGER_PASSWORD("ambari.ldap.managerpassword"),
     USER_OBJECT_CLASS("ambari.ldap.user.object.class"),
     USER_NAME_ATTRIBUTE("ambari.ldap.user.name.attribute"),
+    USER_NAME_FORCE_LOWERCASE("ambari.ldap.username.force.lowercase"),
     USER_SEARCH_BASE("ambari.ldap.user.search.base"),
+    SYNC_USER_MEMBER_REPLACE_PATTERN("ambari.ldap.sync.user.member.replacepattern"),
+    SYNC_USER_MEMBER_FILTER("ambari.ldap.sync.user.member_filter"),
 
+    ADMIN_GROUP_MAPPING_RULES ("ambari.ldap.admin.group.mappingrules"),
     GROUP_OBJECT_CLASS("ambari.ldap.group.object.class"),
     GROUP_NAME_ATTRIBUTE("ambari.ldap.group.name.attribute"),
     GROUP_MEMBER_ATTRIBUTE("ambari.ldap.group.member.attribute"),
     GROUP_SEARCH_BASE("ambari.ldap.group.search.base"),
-    DN_ATTRIBUTE("authentication.ldap.dnAttribute");
+    SYNC_GROUP_MEMBER_REPLACE_PATTERN("ambari.ldap.sync.group.member.replacepattern"),
+    SYNC_GROUP_MEMBER_FILTER("ambari.ldap.sync.group.member_filter"),
+    DN_ATTRIBUTE("authentication.ldap.dnAttribute"),
+
+    TEST_USER_NAME("ambari.ldap.test.user.name"),
+    TEST_USER_PASSWORD("ambari.ldap.test.user.password");
 
     private String propertyName;
 


[09/46] ambari git commit: Updated team page. (yusaku)

Posted by lp...@apache.org.
Updated team page. (yusaku)


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: c9c96cdb881e59d8a3dfe19e32069adf05fdf445
Parents: 29d1139
Author: Yusaku Sako <yu...@hortonworks.com>
Authored: Wed Oct 18 11:08:50 2017 -0700
Committer: Yusaku Sako <yu...@hortonworks.com>
Committed: Wed Oct 18 11:08:50 2017 -0700

----------------------------------------------------------------------
 docs/pom.xml | 12 ++++++++++++
 1 file changed, 12 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c9c96cdb/docs/pom.xml
----------------------------------------------------------------------
diff --git a/docs/pom.xml b/docs/pom.xml
index a75e093..8af497e 100644
--- a/docs/pom.xml
+++ b/docs/pom.xml
@@ -186,6 +186,18 @@
             </organization>
         </developer>
         <developer>
+            <id>amruta</id>
+            <name>Amruta R Borkar</name>
+            <email>amruta@apache.org</email>
+            <timezone></timezone>
+            <roles>
+                <role>Committer</role>
+            </roles>
+            <organization>
+                IBM
+            </organization>
+        </developer>
+        <developer>
             <id>aonishuk</id>
             <name>Andrew Onischuk</name>
             <email>aonishuk@apache.org</email>


[46/46] ambari git commit: AMBARI-21307 Added unit tests, doumented the code

Posted by lp...@apache.org.
AMBARI-21307 Added unit tests, doumented the code


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: d3120b009c73281034e89d521bdfabdebd292b38
Parents: 3f64c09
Author: lpuskas <lp...@apache.org>
Authored: Thu Oct 19 14:41:33 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:42:04 2017 +0200

----------------------------------------------------------------------
 .../ads/detectors/ChainedAttributeDetector.java |   9 +-
 .../ads/detectors/GroupMemberAttrDetector.java  |   2 +-
 .../ads/detectors/UserObjectClassDetector.java  |   1 -
 .../server/ldap/LdapModuleFunctionalTest.java   | 105 +++++++-----------
 .../detectors/GroupMemberAttrDetectorTest.java  | 107 +++++++++++++++++++
 5 files changed, 153 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/d3120b00/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/ChainedAttributeDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/ChainedAttributeDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/ChainedAttributeDetector.java
index 1fb7a4c..094922b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/ChainedAttributeDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/ChainedAttributeDetector.java
@@ -39,7 +39,7 @@ public class ChainedAttributeDetector implements AttributeDetector<Entry> {
   /**
    * The set of detectors this instance delegates to
    */
-  private Set<AttributeDetector> detectors;
+  private final Set<AttributeDetector> detectors;
 
   @Inject
   public ChainedAttributeDetector(Set<AttributeDetector> detectors) {
@@ -63,4 +63,11 @@ public class ChainedAttributeDetector implements AttributeDetector<Entry> {
     }
     return detectedAttributes;
   }
+
+  @Override
+  public String toString() {
+    return "ChainedAttributeDetector{" +
+      "detectors=" + detectors +
+      '}';
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/d3120b00/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java
index ffe4027..8c34ef8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java
@@ -21,7 +21,7 @@ import org.apache.directory.api.ldap.model.entry.Entry;
 
 public class GroupMemberAttrDetector extends OccurrenceAndWeightBasedDetector {
 
-  private enum GroupMemberAttr {
+  enum GroupMemberAttr {
 
     MEMBER("member", 1),
     MEMBER_UID("memberUid", 1),

http://git-wip-us.apache.org/repos/asf/ambari/blob/d3120b00/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserObjectClassDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserObjectClassDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserObjectClassDetector.java
index 53aad8b..bf2f5b8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserObjectClassDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserObjectClassDetector.java
@@ -53,7 +53,6 @@ public class UserObjectClassDetector extends OccurrenceAndWeightBasedDetector {
       occurrenceMap().put(ocVal.ocVal(), 0);
       weightsMap().put(ocVal.ocVal(), ocVal.weight());
     }
-
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/d3120b00/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
index 875ce97..eff9869 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
@@ -18,23 +18,22 @@ import java.util.Map;
 
 import org.apache.ambari.server.ldap.domain.AmbariLdapConfigKeys;
 import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfigurationFactory;
 import org.apache.ambari.server.ldap.domain.TestAmbariLdapConfigurationFactory;
-import org.apache.ambari.server.ldap.service.LdapConfigurationService;
-import org.apache.ambari.server.ldap.service.LdapFacade;
 import org.apache.ambari.server.ldap.service.ads.LdapConnectionTemplateFactory;
 import org.apache.ambari.server.ldap.service.ads.detectors.AttributeDetectorFactory;
 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
 import org.apache.directory.api.ldap.model.exception.LdapException;
-import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
 import org.apache.directory.api.ldap.model.name.Dn;
 import org.apache.directory.ldap.client.api.LdapConnection;
 import org.apache.directory.ldap.client.template.ConnectionCallback;
 import org.apache.directory.ldap.client.template.LdapConnectionTemplate;
-import org.apache.directory.ldap.client.template.exception.PasswordException;
 import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.Maps;
 import com.google.inject.AbstractModule;
@@ -43,37 +42,50 @@ import com.google.inject.Injector;
 import com.google.inject.Module;
 import com.google.inject.util.Modules;
 
+/**
+ * Test for the GUICE LdapModule setup
+ *
+ * - checks the module's bindings (can the GUICE context be created properely)
+ * - checks for specific instances in the GUICE context (re they constructed properly, what is the instance' scope)
+ *
+ * It's named functional test as it creates a GUICE context. ("Real" unit tests only mock a class' collaborators, and
+ * are more lightweight)
+ *
+ * By default the test is ignored, as it connects to external LDAP instances, thus in different environments may fail
+ */
 @Ignore
 public class LdapModuleFunctionalTest {
 
+  private static final Logger LOG = LoggerFactory.getLogger(LdapModuleFunctionalTest.class);
   private static Injector injector;
-  private static Module testModule;
-  private static TestAmbariLdapConfigurationFactory ldapConfigurationFactory = new TestAmbariLdapConfigurationFactory();
+
 
   @BeforeClass
   public static void beforeClass() throws Exception {
 
     // overriding bindings for testing purposes
-    testModule = Modules.override(new LdapModule()).with(new AbstractModule() {
+    Module testModule = Modules.override(new LdapModule()).with(new AbstractModule() {
       @Override
       protected void configure() {
         // override the configuration instance binding not to access the database
-        bind(AmbariLdapConfiguration.class).toInstance(ldapConfigurationFactory.createLdapConfiguration(getProps()));
+        bind(AmbariLdapConfiguration.class).toInstance(new TestAmbariLdapConfigurationFactory().createLdapConfiguration(getProps()));
       }
     });
 
     injector = Guice.createInjector(testModule);
   }
 
-  @Test()
-  public void shouldLdapTemplateBeInstantiated() throws LdapInvalidDnException, PasswordException {
+  @Test
+  public void shouldLdapTemplateBeInstantiated() throws Exception {
     // GIVEN
     // the injector is set up
     Assert.assertNotNull(injector);
 
     // WHEN
-    // the ldap connection template is retrieved
-    LdapConnectionTemplate template = injector.getInstance(LdapConnectionTemplate.class);
+    LdapConnectionTemplateFactory ldapConnectionTemplateFactory = injector.getInstance(LdapConnectionTemplateFactory.class);
+    AmbariLdapConfigurationFactory ambariLdapConfigurationFactory = injector.getInstance(AmbariLdapConfigurationFactory.class);
+    AmbariLdapConfiguration ldapConfiguration = ambariLdapConfigurationFactory.createLdapConfiguration(getProps());
+    LdapConnectionTemplate template = ldapConnectionTemplateFactory.create(ldapConfiguration);
 
     // THEN
     Assert.assertNotNull(template);
@@ -93,39 +105,6 @@ public class LdapModuleFunctionalTest {
   }
 
 
-  @Test
-  public void testShouldConnectionCheckSucceedWhenProperConfigurationProvided() throws Exception {
-    // GIVEN
-    AmbariLdapConfiguration ambariLdapConfiguration = ldapConfigurationFactory.createLdapConfiguration(getProps());
-
-    LdapFacade ldapFacade = injector.getInstance(LdapFacade.class);
-
-
-    // WHEN
-    ldapFacade.checkConnection(ambariLdapConfiguration);
-
-    ldapFacade.detectAttributes(ambariLdapConfiguration);
-
-    // THEN
-    // no exceptions thrown
-
-  }
-
-  @Test
-  public void testShouldAttributeDetectionSucceedWhenProperConfigurationProvided() throws Exception {
-    // GIVEN
-    AmbariLdapConfiguration ambariLdapConfiguration = ldapConfigurationFactory.createLdapConfiguration(getProps());
-    LdapConfigurationService ldapConfigurationService = injector.getInstance(LdapConfigurationService.class);
-
-
-    // WHEN
-    ldapConfigurationService.checkUserAttributes("euclid", "", ambariLdapConfiguration);
-
-    // THEN
-    // no exceptions thrown
-
-  }
-
   private static Map<String, Object> getProps() {
     Map<String, Object> ldapPropsMap = Maps.newHashMap();
 
@@ -134,45 +113,33 @@ public class LdapModuleFunctionalTest {
     ldapPropsMap.put(AmbariLdapConfigKeys.SERVER_PORT.key(), "389");
     ldapPropsMap.put(AmbariLdapConfigKeys.BIND_DN.key(), "cn=read-only-admin,dc=example,dc=com");
     ldapPropsMap.put(AmbariLdapConfigKeys.BIND_PASSWORD.key(), "password");
-    ldapPropsMap.put(AmbariLdapConfigKeys.USE_SSL.key(), "true");
+//    ldapPropsMap.put(AmbariLdapConfigKeys.USE_SSL.key(), "true");
 
     ldapPropsMap.put(AmbariLdapConfigKeys.USER_OBJECT_CLASS.key(), SchemaConstants.PERSON_OC);
     ldapPropsMap.put(AmbariLdapConfigKeys.USER_NAME_ATTRIBUTE.key(), SchemaConstants.UID_AT);
     ldapPropsMap.put(AmbariLdapConfigKeys.USER_SEARCH_BASE.key(), "dc=example,dc=com");
     ldapPropsMap.put(AmbariLdapConfigKeys.DN_ATTRIBUTE.key(), SchemaConstants.UID_AT);
-    ldapPropsMap.put(AmbariLdapConfigKeys.TRUST_STORE.key(), "custom");
+//    ldapPropsMap.put(AmbariLdapConfigKeys.TRUST_STORE.key(), "custom");
     ldapPropsMap.put(AmbariLdapConfigKeys.TRUST_STORE_TYPE.key(), "JKS");
-    ldapPropsMap.put(AmbariLdapConfigKeys.TRUST_STORE_PATH.key(), "/Users/lpuskas/my_truststore/KeyStore.jks");
+//    ldapPropsMap.put(AmbariLdapConfigKeys.TRUST_STORE_PATH.key(), "/Users/lpuskas/my_truststore/KeyStore.jks");
     ldapPropsMap.put(AmbariLdapConfigKeys.TRUST_STORE_PASSWORD.key(), "lofasz");
 
 
     return ldapPropsMap;
   }
 
+  private static Map<String, Object> getADProps() {
+    Map<String, Object> ldapPropsMap = Maps.newHashMap();
 
-  @Test
-  public void testShouldCustomTrustManagersBeSetForLdapConnection() throws Exception {
-    // GIVEN
-    AmbariLdapConfiguration ambariLdapConfiguration = ldapConfigurationFactory.createLdapConfiguration(getProps());
-
-    LdapFacade ldapFacade = injector.getInstance(LdapFacade.class);
-
-    LdapConnectionTemplateFactory lctFactory = injector.getInstance(LdapConnectionTemplateFactory.class);
-
-    LdapConnectionTemplate template1 = lctFactory.load();
-    LdapConnectionTemplate template2 = lctFactory.create(ambariLdapConfiguration);
-
-
-    // WHEN
-    ldapFacade.checkConnection(ambariLdapConfiguration);
-
-    ldapFacade.detectAttributes(ambariLdapConfiguration);
+    ldapPropsMap.put(AmbariLdapConfigKeys.ANONYMOUS_BIND.key(), "true");
+    ldapPropsMap.put(AmbariLdapConfigKeys.SERVER_HOST.key(), "172.22.112.167");
+    ldapPropsMap.put(AmbariLdapConfigKeys.SERVER_PORT.key(), "389");
+    ldapPropsMap.put(AmbariLdapConfigKeys.BIND_DN.key(), "CN=Robert Levas,CN=Users,DC=HWQE,DC=HORTONWORKS,DC=COM");
+    ldapPropsMap.put(AmbariLdapConfigKeys.BIND_PASSWORD.key(), "Hadoop1234");
 
-    // THEN
-    // no exceptions thrown
+    return ldapPropsMap;
   }
 
-
   @Test
   public void testShouldDetectorsBeBound() throws Exception {
     // GIVEN
@@ -182,6 +149,8 @@ public class LdapModuleFunctionalTest {
 
     // THEN
     Assert.assertNotNull(f);
+    LOG.info(f.groupAttributeDetector().toString());
+    LOG.info(f.userAttributDetector().toString());
 
   }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/d3120b00/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetectorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetectorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetectorTest.java
new file mode 100644
index 0000000..79af467
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetectorTest.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads.detectors;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.directory.api.ldap.model.entry.DefaultAttribute;
+import org.apache.directory.api.ldap.model.entry.DefaultEntry;
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.apache.directory.api.ldap.model.entry.StringValue;
+import org.easymock.TestSubject;
+import org.junit.Assert;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Lists;
+
+/**
+ * Test suite for the attribute detector implementation
+ */
+public class GroupMemberAttrDetectorTest {
+
+  private static final Logger LOG = LoggerFactory.getLogger(GroupMemberAttrDetector.class);
+
+  @TestSubject
+  GroupMemberAttrDetector groupMemberAttrDetector = new GroupMemberAttrDetector();
+
+  @Test
+  public void testShouldDetectAttributeBasedOnOccurrence() throws Exception {
+    // GIVEN
+    // Mimic a sample set of entries where group membership attributes  are different
+    List<Entry> sampleEntryList = Lists.newArrayList();
+
+    sampleEntryList.addAll(getSampleEntryList(GroupMemberAttrDetector.GroupMemberAttr.MEMBER_UID, 2));
+
+    // this is the expected property to be detected as in the sample set the most entries have it
+    sampleEntryList.addAll(getSampleEntryList(GroupMemberAttrDetector.GroupMemberAttr.UNIQUE_MEMBER, 7));
+    sampleEntryList.addAll(getSampleEntryList(GroupMemberAttrDetector.GroupMemberAttr.MEMBER, 5));
+
+    // WHEN
+    for (Entry entry : sampleEntryList) {
+      groupMemberAttrDetector.collect(entry);
+    }
+
+    // The most frequently encountered attribute will be selected
+    Map<String, String> detectedAttributeMap = groupMemberAttrDetector.detect();
+
+    // THEN
+    Assert.assertEquals(1, detectedAttributeMap.size());
+    Map.Entry<String, String> selectedEntry = detectedAttributeMap.entrySet().iterator().next();
+
+    Assert.assertEquals("The selected configuration property is not the expected one", groupMemberAttrDetector.detectedProperty(), selectedEntry.getKey());
+    Assert.assertEquals("The selected configuration property value is not the expected one", GroupMemberAttrDetector.GroupMemberAttr.UNIQUE_MEMBER.attrName(), selectedEntry.getValue());
+
+
+  }
+
+  @Test
+  public void testShouldDetectorPassWhenEmptySampleSetProvided() throws Exception {
+    // GIVEN
+    List<Entry> sampleEntryList = Lists.newArrayList();
+
+    // WHEN
+    // WHEN
+    for (Entry entry : sampleEntryList) {
+      groupMemberAttrDetector.collect(entry);
+    }
+
+    Map<String, String> detectedAttributeMap = groupMemberAttrDetector.detect();
+    // THEN
+    Assert.assertEquals(1, detectedAttributeMap.size());
+    Map.Entry<String, String> selectedEntry = detectedAttributeMap.entrySet().iterator().next();
+
+    Assert.assertEquals("The selected configuration property is not the expected one", groupMemberAttrDetector.detectedProperty(), selectedEntry.getKey());
+    Assert.assertEquals("The selected configuration property value is not the expected one", "N/A", selectedEntry.getValue());
+
+  }
+
+  private List<Entry> getSampleEntryList(GroupMemberAttrDetector.GroupMemberAttr member, int count) {
+    List<Entry> entryList = Lists.newArrayList();
+    for (int i = 0; i < count; i++) {
+      Entry entry = new DefaultEntry();
+      try {
+        entry.setDn("dn=" + member.name() + "-" + i);
+        entry.add(new DefaultAttribute(member.attrName(), new StringValue("xxx")));
+        entryList.add(entry);
+      } catch (Exception e) {
+        LOG.error(e.getMessage());
+      }
+    }
+    return entryList;
+  }
+}
\ No newline at end of file


[30/46] ambari git commit: AMBARI-2130 ldap connections handled in thefacade. Code cleanup

Posted by lp...@apache.org.
AMBARI-2130 ldap connections handled in thefacade. Code cleanup


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 01295fe17d9b2f4017e113ec1014065cc7cff545
Parents: 92f2cc5
Author: lpuskas <lp...@apache.org>
Authored: Tue Sep 12 15:38:25 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:42:00 2017 +0200

----------------------------------------------------------------------
 .../server/ldap/service/AmbariLdapFacade.java   | 51 +++++++++----
 .../ldap/service/LdapConnectionService.java     | 12 ++-
 .../ambari/server/ldap/service/LdapFacade.java  |  2 +-
 .../ads/DefaultLdapConfigurationService.java    | 77 ++++----------------
 .../ads/DefaultLdapConnectionService.java       | 41 ++++++++++-
 .../OccurranceAndWeightBasedDetector.java       |  2 +-
 6 files changed, 103 insertions(+), 82 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/01295fe1/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
index f159418..d2bdef3 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
@@ -19,7 +19,6 @@ import java.util.Map;
 import java.util.Set;
 
 import javax.inject.Inject;
-import javax.inject.Provider;
 import javax.inject.Singleton;
 
 import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
@@ -58,35 +57,59 @@ public class AmbariLdapFacade implements LdapFacade {
   @Inject
   private LdapAttributeDetectionService ldapAttributeDetectionService;
 
-  //todo remove this, added for testing purposes only
-  @Inject
-  private Provider<AmbariLdapConfiguration> ambariLdapConfigurationProvider;
-
   @Inject
   public AmbariLdapFacade() {
   }
 
   @Override
   public void checkConnection(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+    LdapConnection connection = null;
     try {
+
       LOGGER.info("Validating LDAP connection related configuration based on: {}", ambariLdapConfiguration);
-      LdapConnection connection = ldapConnectionService.createLdapConnection(ambariLdapConfiguration);
+      connection = ldapConnectionService.getBoundLdapConnection(ambariLdapConfiguration);
       ldapConfigurationService.checkConnection(connection, ambariLdapConfiguration);
-    } catch (AmbariLdapException e) {
+      LOGGER.info("Validating LDAP connection related configuration: SUCCESS");
+
+    } catch (Exception e) {
+
       LOGGER.error("Validating LDAP connection configuration failed", e);
-      throw e;
+      throw new AmbariLdapException(e);
+
+    } finally {
+      try {
+        connection.unBind();
+        connection.close();
+      } catch (Exception e) {
+        throw new AmbariLdapException(e);
+      }
     }
-    LOGGER.info("Validating LDAP connection related configuration: SUCCESS");
+
   }
 
 
   @Override
-  public AmbariLdapConfiguration detectAttributes(AmbariLdapConfiguration ambariLdapConfiguration) {
+  public AmbariLdapConfiguration detectAttributes(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
     LOGGER.info("Detecting LDAP configuration attributes ...");
 
-    LdapConnection connection = ldapConnectionService.createLdapConnection(ambariLdapConfiguration);
-    ambariLdapConfiguration = ldapAttributeDetectionService.detectLdapUserAttributes(connection, ambariLdapConfiguration);
-    return ambariLdapConfiguration;
+    LdapConnection connection = ldapConnectionService.getBoundLdapConnection(ambariLdapConfiguration);
+    try {
+
+      ambariLdapConfiguration = ldapAttributeDetectionService.detectLdapUserAttributes(connection, ambariLdapConfiguration);
+      ambariLdapConfiguration = ldapAttributeDetectionService.detectLdapGroupAttributes(connection, ambariLdapConfiguration);
+      return ambariLdapConfiguration;
+
+    } catch (Exception e) {
+      LOGGER.error("Error during LDAP attribute detection", e);
+      throw new AmbariLdapException(e);
+    } finally {
+      try {
+        connection.unBind();
+        connection.close();
+      } catch (Exception e) {
+        throw new AmbariLdapException(e);
+      }
+    }
   }
 
   @Override
@@ -98,7 +121,7 @@ public class AmbariLdapFacade implements LdapFacade {
       throw new IllegalArgumentException("No test user available for testing LDAP attributes");
     }
 
-    LdapConnection ldapConnection = ldapConnectionService.createLdapConnection(ldapConfiguration);
+    LdapConnection ldapConnection = ldapConnectionService.getBoundLdapConnection(ldapConfiguration);
 
     LOGGER.info("Testing LDAP user attributes with test user: {}", userName);
     String userDn = ldapConfigurationService.checkUserAttributes(ldapConnection, userName, testUserPass, ldapConfiguration);

http://git-wip-us.apache.org/repos/asf/ambari/blob/01295fe1/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionService.java
index 50ee8ed..b4daeaa 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionService.java
@@ -15,7 +15,7 @@
 package org.apache.ambari.server.ldap.service;
 
 import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
-import org.apache.directory.ldap.client.api.LdapNetworkConnection;
+import org.apache.directory.ldap.client.api.LdapConnection;
 
 /**
  * Contract defining factory methods for creating LDAP connection instances.
@@ -29,7 +29,15 @@ public interface LdapConnectionService {
    * @param ambariLdapConfiguration configuration instance with information for creating the connection instance
    * @return a set up LdapConnection instance
    */
-  LdapNetworkConnection createLdapConnection(AmbariLdapConfiguration ambariLdapConfiguration);
+  LdapConnection createLdapConnection(AmbariLdapConfiguration ambariLdapConfiguration);
+
+  /**
+   * Creates an LdapConnection instance and binds to the LDAP server based on the provided configuration entries
+   *
+   * @param ambariLdapConfiguration ambari configuration instance
+   * @return
+   */
+  LdapConnection getBoundLdapConnection(AmbariLdapConfiguration ambariLdapConfiguration);
 
 
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/01295fe1/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
index 7cd25da..6060d7f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
@@ -39,7 +39,7 @@ public interface LdapFacade {
    *
    * @param ambariLdapConfiguration
    */
-  AmbariLdapConfiguration detectAttributes(AmbariLdapConfiguration ambariLdapConfiguration);
+  AmbariLdapConfiguration detectAttributes(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException;
 
   /**
    * Checks user and group related LDAP configuration attributes in the configuration object with the help of the provided parameters

http://git-wip-us.apache.org/repos/asf/ambari/blob/01295fe1/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
index fa2e44b..5735d7d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
@@ -14,24 +14,20 @@
 
 package org.apache.ambari.server.ldap.service.ads;
 
-import java.io.IOException;
 import java.util.List;
 import java.util.Set;
 
 import javax.inject.Inject;
 import javax.inject.Singleton;
 
-import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
 import org.apache.ambari.server.ldap.LdapConfigurationService;
 import org.apache.ambari.server.ldap.service.AmbariLdapException;
-import org.apache.ambari.server.ldap.service.LdapConnectionService;
 import org.apache.directory.api.ldap.codec.decorators.SearchResultEntryDecorator;
 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
 import org.apache.directory.api.ldap.model.cursor.EntryCursor;
 import org.apache.directory.api.ldap.model.cursor.SearchCursor;
 import org.apache.directory.api.ldap.model.entry.Entry;
-import org.apache.directory.api.ldap.model.exception.LdapException;
 import org.apache.directory.api.ldap.model.message.Response;
 import org.apache.directory.api.ldap.model.message.SearchRequest;
 import org.apache.directory.api.ldap.model.message.SearchRequestImpl;
@@ -53,9 +49,6 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
 
   private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapConfigurationService.class);
 
-  @Inject
-  private LdapConnectionService ldapConnectionService;
-
   /**
    * Facilitating the instantiation
    */
@@ -65,12 +58,12 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
 
   @Override
   public void checkConnection(LdapConnection ldapConnection, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
-    try {
-      bind(ambariLdapConfiguration, ldapConnection);
-    } catch (LdapException e) {
-      LOGGER.error("Could not connect to the LDAP server", e);
-      throw new AmbariLdapException(e);
+
+    if (!ldapConnection.isConnected()) {
+      LOGGER.error("Could not connect to the LDAP server");
+      throw new AmbariLdapException("Could not connect to the LDAP server. Configuration: " + ambariLdapConfiguration);
     }
+
   }
 
 
@@ -80,22 +73,20 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
    *
    * Invalid attributes are signaled by throwing an exception.
    *
+   * @param ldapConnection          connection instance used to connect to the LDAP server
    * @param testUserName            the test username
    * @param testPassword            the test password
    * @param ambariLdapConfiguration configuration instance holding ldap configuration details
    * @return the DN of the test user
-   * @throws AmbariException if the attributes are not valid or any errors occurs
+   * @throws AmbariLdapException if an error occurs
    */
   @Override
   public String checkUserAttributes(LdapConnection ldapConnection, String testUserName, String testPassword, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
-    SearchCursor searchCursor = null;
     String userDn = null;
+    EntryCursor entryCursor = null;
     try {
       LOGGER.info("Checking user attributes for user {} r ...", testUserName);
 
-      // bind anonimously or with manager data
-      bind(ambariLdapConfiguration, ldapConnection);
-
       // set up a filter based on the provided attributes
       String filter = FilterBuilder.and(
         FilterBuilder.equal(SchemaConstants.OBJECT_CLASS_AT, ambariLdapConfiguration.userObjectClass()),
@@ -103,7 +94,7 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
         .toString();
 
       LOGGER.info("Searching for the user: {} using the search filter: {}", testUserName, filter);
-      EntryCursor entryCursor = ldapConnection.search(new Dn(ambariLdapConfiguration.userSearchBase()), filter, SearchScope.SUBTREE);
+      entryCursor = ldapConnection.search(new Dn(ambariLdapConfiguration.userSearchBase()), filter, SearchScope.SUBTREE);
 
       // collecting search result entries
       List<Entry> users = Lists.newArrayList();
@@ -127,7 +118,9 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
       throw new AmbariLdapException(e.getMessage(), e);
 
     } finally {
-      closeResources(ldapConnection, searchCursor);
+      if (null != entryCursor) {
+        entryCursor.close();
+      }
     }
     return userDn;
   }
@@ -141,8 +134,6 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
     try {
       LOGGER.info("Checking group attributes for user dn {} ...", userDn);
 
-      bind(ambariLdapConfiguration, ldapConnection);
-
       // set up a filter based on the provided attributes
       String filter = FilterBuilder.and(
         FilterBuilder.equal(SchemaConstants.OBJECT_CLASS_AT, ambariLdapConfiguration.groupObjectClass()),
@@ -171,36 +162,14 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
       throw new AmbariLdapException(e.getMessage(), e);
 
     } finally {
-      closeResources(ldapConnection, searchCursor);
+      if (null != searchCursor) {
+        searchCursor.close();
+      }
     }
 
     return processGroupResults(groupResponses, ambariLdapConfiguration);
   }
 
-  /**
-   * Binds to the LDAP server (anonimously or wit manager credentials)
-   *
-   * @param ambariLdapConfiguration configuration instance
-   * @param connection              connection instance
-   * @throws LdapException if the bind operation fails
-   */
-  private void bind(AmbariLdapConfiguration ambariLdapConfiguration, LdapConnection connection) throws LdapException {
-    LOGGER.info("Connecting to LDAP ....");
-    if (!ambariLdapConfiguration.anonymousBind()) {
-      LOGGER.debug("Anonimous binding not supported, binding with the manager detailas...");
-      connection.bind(ambariLdapConfiguration.bindDn(), ambariLdapConfiguration.bindPassword());
-    } else {
-      LOGGER.debug("Binding anonymously ...");
-      connection.bind();
-    }
-
-    if (!connection.isConnected()) {
-      LOGGER.error("Not connected to the LDAP server. Connection instance: {}", connection);
-      throw new IllegalStateException("The connection to the LDAP server is not alive");
-    }
-    LOGGER.info("Connected to LDAP.");
-  }
-
 
   /**
    * Extracts meaningful values from the search result.
@@ -220,22 +189,6 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
     return groupStrSet;
   }
 
-  private void closeResources(LdapConnection connection, SearchCursor searchCursor) {
-    LOGGER.debug("Housekeeping: closing the connection and the search cursor ...");
-
-    if (null != searchCursor) {
-      // this method is idempotent
-      searchCursor.close();
-    }
-
-    if (null != connection) {
-      try {
-        connection.close();
-      } catch (IOException e) {
-        LOGGER.error("Exception occurred while closing the connection", e);
-      }
-    }
-  }
 
 }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/01295fe1/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionService.java
index f39df54..457e23e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionService.java
@@ -32,6 +32,7 @@ import javax.inject.Singleton;
 
 import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
 import org.apache.ambari.server.ldap.service.LdapConnectionService;
+import org.apache.directory.ldap.client.api.LdapConnection;
 import org.apache.directory.ldap.client.api.LdapConnectionConfig;
 import org.apache.directory.ldap.client.api.LdapNetworkConnection;
 import org.slf4j.Logger;
@@ -45,18 +46,54 @@ public class DefaultLdapConnectionService implements LdapConnectionService {
   @Override
   public LdapNetworkConnection createLdapConnection(AmbariLdapConfiguration ambariLdapConfiguration) {
     LOGGER.debug("Creating ldap connection instance from: {}", ambariLdapConfiguration);
+
     return new LdapNetworkConnection(getLdapConnectionConfig(ambariLdapConfiguration));
   }
 
+  @Override
+  public LdapConnection getBoundLdapConnection(AmbariLdapConfiguration ambariLdapConfiguration) {
+    LOGGER.info("Creating LDAP connection instance and binding to LDAP server ...");
+
+    try {
+      LdapConnection connection = createLdapConnection(ambariLdapConfiguration);
+
+      if (!ambariLdapConfiguration.anonymousBind()) {
+
+        LOGGER.debug("Anonymous binding not supported, binding with the manager detailas...");
+        connection.bind(ambariLdapConfiguration.bindDn(), ambariLdapConfiguration.bindPassword());
+
+      } else {
+
+        LOGGER.debug("Binding anonymously ...");
+        connection.bind();
+
+      }
+
+      if (!connection.isConnected()) {
+
+        LOGGER.error("Not connected to the LDAP server. Connection instance: {}", connection);
+        throw new IllegalStateException("The connection to the LDAP server is not alive");
+
+      }
+
+      LOGGER.info("Connected / bound to LDAP server.");
+      return connection;
+
+    } catch (Exception e) {
+      LOGGER.error("Could not create or bind LdapConnection", e);
+      throw new IllegalArgumentException(e);
+    }
+
+  }
+
   private LdapConnectionConfig getLdapConnectionConfig(AmbariLdapConfiguration ambariAmbariLdapConfiguration) {
-    LOGGER.debug("Creating a configuration instance based on the ambari configuration: {}", ambariAmbariLdapConfiguration);
+    LOGGER.debug("Creating a LDAP connection config instance based on the ambari configuration: {}", ambariAmbariLdapConfiguration);
 
     LdapConnectionConfig ldapConnectionConfig = new LdapConnectionConfig();
     ldapConnectionConfig.setLdapHost(ambariAmbariLdapConfiguration.serverHost());
     ldapConnectionConfig.setLdapPort(ambariAmbariLdapConfiguration.serverPort());
     ldapConnectionConfig.setUseSsl(ambariAmbariLdapConfiguration.useSSL());
 
-    // todo set the other values as required
     return ldapConnectionConfig;
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/01295fe1/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurranceAndWeightBasedDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurranceAndWeightBasedDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurranceAndWeightBasedDetector.java
index 8aaf6c1..71dfb42 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurranceAndWeightBasedDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurranceAndWeightBasedDetector.java
@@ -78,7 +78,7 @@ public abstract class OccurranceAndWeightBasedDetector implements AttributeDetec
 
   @Override
   public void collect(Entry entry) {
-    LOGGER.info("Collecting ldap attributes/values form entry with dn: [{]]", entry.getDn());
+    LOGGER.info("Collecting ldap attributes/values form entry with dn: [{}]", entry.getDn());
 
     for (String attributeValue : occurranceMap().keySet()) {
       if (applies(entry, attributeValue)) {


[43/46] ambari git commit: AMBARI-21307 Added unit tests, fixed logging, typos and code issues

Posted by lp...@apache.org.
AMBARI-21307 Added unit tests, fixed logging, typos and code issues


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: e3676a77996c5f4c93d130e2984d78b6e383f091
Parents: 468fdc3
Author: lpuskas <lp...@apache.org>
Authored: Tue Oct 17 11:33:52 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:42:03 2017 +0200

----------------------------------------------------------------------
 .../DefaultLdapAttributeDetectionService.java   | 58 +++++++++++---------
 .../ads/DefaultLdapConnectionConfigService.java |  5 +-
 .../ads/detectors/AttributeDetectorFactory.java | 26 +++++++++
 .../ads/detectors/ChainedAttributeDetector.java |  7 +++
 .../ads/detectors/GroupMemberAttrDetector.java  |  6 +-
 .../ads/detectors/GroupNameAttrDetector.java    |  4 +-
 .../ads/detectors/GroupObjectClassDetector.java |  4 +-
 .../OccurrenceAndWeightBasedDetector.java       | 42 ++++++++++++--
 .../detectors/UserGroupMemberAttrDetector.java  |  4 +-
 .../ads/detectors/UserNameAttrDetector.java     |  6 +-
 .../ads/detectors/UserObjectClassDetector.java  |  6 +-
 .../server/ldap/LdapModuleFunctionalTest.java   | 10 +---
 12 files changed, 122 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/e3676a77/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
index ea6e278..25abce7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
@@ -37,10 +37,18 @@ import org.apache.directory.ldap.client.template.LdapConnectionTemplate;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * Service implementation that performs user and group attribute detection based on a sample set of entries returned by
+ * an ldap search operation. A accuracy of detected values may depend on the size of the sample result set
+ */
 @Singleton
 public class DefaultLdapAttributeDetectionService implements LdapAttributeDetectionService {
 
-  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapAttributeDetectionService.class);
+  private static final Logger LOG = LoggerFactory.getLogger(DefaultLdapAttributeDetectionService.class);
+
+  /**
+   * The maximum size of the entry set the detection is performed on
+   */
   private static final int SAMPLE_RESULT_SIZE = 50;
 
   @Inject
@@ -49,46 +57,46 @@ public class DefaultLdapAttributeDetectionService implements LdapAttributeDetect
   @Inject
   private LdapConnectionTemplateFactory ldapConnectionTemplateFactory;
 
-
   @Inject
   public DefaultLdapAttributeDetectionService() {
   }
 
   @Override
   public AmbariLdapConfiguration detectLdapUserAttributes(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
-    LOGGER.info("Detecting LDAP user attributes ...");
-    LdapConnectionTemplate ldapConnectionTemplate = ldapConnectionTemplateFactory.create(ambariLdapConfiguration);
-    AttributeDetector<Entry> userAttributDetector = attributeDetectorFactory.userAttributDetector();
+    LOG.info("Detecting LDAP user attributes ...");
 
     // perform a search using the user search base
     if (Strings.isEmpty(ambariLdapConfiguration.userSearchBase())) {
-      LOGGER.warn("No user search base provided");
+      LOG.warn("No user search base provided");
       return ambariLdapConfiguration;
     }
 
     try {
 
+      LdapConnectionTemplate ldapConnectionTemplate = ldapConnectionTemplateFactory.create(ambariLdapConfiguration);
+      AttributeDetector<Entry> userAttributeDetector = attributeDetectorFactory.userAttributDetector();
+
       SearchRequest searchRequest = assembleUserSearchRequest(ldapConnectionTemplate, ambariLdapConfiguration);
 
       // do the search
       List<Entry> entries = ldapConnectionTemplate.search(searchRequest, getEntryMapper());
 
       for (Entry entry : entries) {
-        LOGGER.info("Processing sample entry with dn: [{}]", entry.getDn());
-        userAttributDetector.collect(entry);
+        LOG.info("Collecting user attribute information from the sample entry with dn: [{}]", entry.getDn());
+        userAttributeDetector.collect(entry);
       }
 
       // select attributes based on the collected information
-      Map<String, String> detectedUserAttributes = userAttributDetector.detect();
+      Map<String, String> detectedUserAttributes = userAttributeDetector.detect();
 
       // setting the attributes into the configuration
       setDetectedAttributes(ambariLdapConfiguration, detectedUserAttributes);
 
-      LOGGER.info("Decorated ambari ldap config : [{}]", ambariLdapConfiguration);
+      LOG.info("Decorated ambari ldap config : [{}]", ambariLdapConfiguration);
 
     } catch (Exception e) {
 
-      LOGGER.error("Ldap operation failed", e);
+      LOG.error("Ldap operation failed while detecting user attributes", e);
       throw new AmbariLdapException(e);
 
     }
@@ -99,19 +107,19 @@ public class DefaultLdapAttributeDetectionService implements LdapAttributeDetect
 
   @Override
   public AmbariLdapConfiguration detectLdapGroupAttributes(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
-    LOGGER.info("Detecting LDAP group attributes ...");
+    LOG.info("Detecting LDAP group attributes ...");
 
     // perform a search using the user search base
     if (Strings.isEmpty(ambariLdapConfiguration.groupSearchBase())) {
-      LOGGER.warn("No group search base provided");
+      LOG.warn("No group search base provided");
       return ambariLdapConfiguration;
     }
 
-    LdapConnectionTemplate ldapConnectionTemplate = ldapConnectionTemplateFactory.create(ambariLdapConfiguration);
-    AttributeDetector<Entry> groupAttributDetector = attributeDetectorFactory.groupAttributDetector();
-
     try {
 
+      LdapConnectionTemplate ldapConnectionTemplate = ldapConnectionTemplateFactory.create(ambariLdapConfiguration);
+      AttributeDetector<Entry> groupAttributeDetector = attributeDetectorFactory.groupAttributDetector();
+
       SearchRequest searchRequest = assembleGroupSearchRequest(ldapConnectionTemplate, ambariLdapConfiguration);
 
       // do the search
@@ -119,22 +127,22 @@ public class DefaultLdapAttributeDetectionService implements LdapAttributeDetect
 
       for (Entry groupEntry : groupEntries) {
 
-        LOGGER.info("Processing sample entry with dn: [{}]", groupEntry.getDn());
-        groupAttributDetector.collect(groupEntry);
+        LOG.info("Collecting group attribute information from the sample entry with dn: [{}]", groupEntry.getDn());
+        groupAttributeDetector.collect(groupEntry);
 
       }
 
       // select attributes based on the collected information
-      Map<String, String> detectedGroupAttributes = groupAttributDetector.detect();
+      Map<String, String> detectedGroupAttributes = groupAttributeDetector.detect();
 
       // setting the attributes into the configuration
       setDetectedAttributes(ambariLdapConfiguration, detectedGroupAttributes);
 
-      LOGGER.info("Decorated ambari ldap config : [{}]", ambariLdapConfiguration);
+      LOG.info("Decorated ambari ldap config : [{}]", ambariLdapConfiguration);
 
     } catch (Exception e) {
 
-      LOGGER.error("Ldap operation failed", e);
+      LOG.error("Ldap operation failed while detecting group attributes", e);
       throw new AmbariLdapException(e);
 
     }
@@ -143,8 +151,9 @@ public class DefaultLdapAttributeDetectionService implements LdapAttributeDetect
   }
 
   private void setDetectedAttributes(AmbariLdapConfiguration ambariLdapConfiguration, Map<String, String> detectedAttributes) {
+
     for (Map.Entry<String, String> detecteMapEntry : detectedAttributes.entrySet()) {
-      LOGGER.info("Setting detected configuration value: [{}] - > [{}]", detecteMapEntry.getKey(), detecteMapEntry.getValue());
+      LOG.info("Setting detected configuration value: [{}] - > [{}]", detecteMapEntry.getKey(), detecteMapEntry.getValue());
       ambariLdapConfiguration.setValueFor(AmbariLdapConfigKeys.fromKeyStr(detecteMapEntry.getKey()), detecteMapEntry.getValue());
     }
 
@@ -160,7 +169,7 @@ public class DefaultLdapAttributeDetectionService implements LdapAttributeDetect
       return req;
 
     } catch (Exception e) {
-      LOGGER.error("Could not assemble ldap search request", e);
+      LOG.error("Could not assemble ldap search request", e);
       throw new AmbariLdapException(e);
     }
   }
@@ -175,12 +184,11 @@ public class DefaultLdapAttributeDetectionService implements LdapAttributeDetect
       return req;
 
     } catch (Exception e) {
-      LOGGER.error("Could not assemble ldap search request", e);
+      LOG.error("Could not assemble ldap search request", e);
       throw new AmbariLdapException(e);
     }
   }
 
-
   public EntryMapper<Entry> getEntryMapper() {
     return new EntryMapper<Entry>() {
       @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/e3676a77/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionConfigService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionConfigService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionConfigService.java
index 9bc2daf..9afcf51 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionConfigService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionConfigService.java
@@ -53,20 +53,17 @@ public class DefaultLdapConnectionConfigService implements LdapConnectionConfigS
     config.setCredentials(ambariLdapConfiguration.bindPassword());
     config.setUseSsl(ambariLdapConfiguration.useSSL());
 
-    // todo implement proper validation logic here: identify optional/mandatory settings
-    // todo suggest proper naming
     if ("custom".equals(ambariLdapConfiguration.trustStore())) {
       LOG.info("Using custom trust manager configuration");
       config.setTrustManagers(trustManagers(ambariLdapConfiguration));
     }
 
-
     return config;
   }
 
 
   /**
-   * Configure the trustmanagers to use the custom keystore.
+   * Configure the trust managers to use the custom keystore.
    *
    * @param ambariLdapConfiguration congiguration instance holding current values
    * @return the array of trust managers

http://git-wip-us.apache.org/repos/asf/ambari/blob/e3676a77/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/AttributeDetectorFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/AttributeDetectorFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/AttributeDetectorFactory.java
index 08e3625..8155461 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/AttributeDetectorFactory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/AttributeDetectorFactory.java
@@ -21,30 +21,56 @@ import javax.inject.Named;
 import javax.inject.Singleton;
 
 import org.apache.ambari.server.ldap.service.AttributeDetector;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
+/**
+ * Factory for attribute detector chains.
+ */
 @Singleton
 public class AttributeDetectorFactory {
 
+  private static final Logger LOG = LoggerFactory.getLogger(AttributeDetectorFactory.class);
   private static final String USER_ATTRIBUTES_DETECTORS = "UserAttributesDetectors";
   private static final String GROUP_ATTRIBUTES_DETECTORS = "GroupAttributesDetectors";
 
 
+  /**
+   * The set of user attribute detectors, configured by GUICE (check the relevant guice module implementation)
+   */
   @Inject
   @Named(USER_ATTRIBUTES_DETECTORS)
   private Set<AttributeDetector> userAttributeDetectors;
 
+  /**
+   * The set of group attribute detectors, configured by GUICE (check the relevant guice module implementation)
+   */
   @Inject
   @Named(GROUP_ATTRIBUTES_DETECTORS)
   Set<AttributeDetector> groupAttributeDetectors;
 
+  @Inject
   public AttributeDetectorFactory() {
   }
 
+  /**
+   * Creates a chained attribute detector instance with user attribute detectors
+   *
+   * @return the constructed ChainedAttributeDetector instance
+   */
   public ChainedAttributeDetector userAttributDetector() {
+    LOG.info("Creating instance with user attribute detectors: [{}]", userAttributDetector());
     return new ChainedAttributeDetector(userAttributeDetectors);
   }
 
+  /**
+   * Creates a chained attribute detector instance with user attribute detectors
+   *
+   * @return the constructed ChainedAttributeDetector instance
+   */
+
   public ChainedAttributeDetector groupAttributDetector() {
+    LOG.info("Creating instance with group attribute detectors: [{}]", groupAttributDetector());
     return new ChainedAttributeDetector(groupAttributeDetectors);
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/e3676a77/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/ChainedAttributeDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/ChainedAttributeDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/ChainedAttributeDetector.java
index ad70d0b..1fb7a4c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/ChainedAttributeDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/ChainedAttributeDetector.java
@@ -27,11 +27,18 @@ import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.Maps;
 
+/**
+ * Attribute detector implementation that performs the attribute detection on a configured set of attribute detectors.
+ * (it implements the composite design pattern)
+ */
 @Singleton
 public class ChainedAttributeDetector implements AttributeDetector<Entry> {
 
   private static final Logger LOG = LoggerFactory.getLogger(ChainedAttributeDetector.class);
 
+  /**
+   * The set of detectors this instance delegates to
+   */
   private Set<AttributeDetector> detectors;
 
   @Inject

http://git-wip-us.apache.org/repos/asf/ambari/blob/e3676a77/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java
index 72e753b..ffe4027 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java
@@ -54,12 +54,12 @@ public class GroupMemberAttrDetector extends OccurrenceAndWeightBasedDetector {
   }
 
   @Override
-  protected boolean applies(Entry entry, String value) {
-    return entry.containsAttribute(value);
+  protected boolean applies(Entry entry, String attribute) {
+    return entry.containsAttribute(attribute);
   }
 
   @Override
   public String detectedProperty() {
-    return AmbariLdapConfigKeys.USER_GROUP_MEMBER_ATTRIBUTE.key();
+    return AmbariLdapConfigKeys.GROUP_MEMBER_ATTRIBUTE.key();
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/e3676a77/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupNameAttrDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupNameAttrDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupNameAttrDetector.java
index ca54dad..0315ef2 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupNameAttrDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupNameAttrDetector.java
@@ -59,8 +59,8 @@ public class GroupNameAttrDetector extends OccurrenceAndWeightBasedDetector {
 
 
   @Override
-  protected boolean applies(Entry entry, String value) {
-    return entry.containsAttribute(value);
+  protected boolean applies(Entry entry, String attribute) {
+    return entry.containsAttribute(attribute);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/e3676a77/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupObjectClassDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupObjectClassDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupObjectClassDetector.java
index 8f342f1..b681134 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupObjectClassDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupObjectClassDetector.java
@@ -62,8 +62,8 @@ public class GroupObjectClassDetector extends OccurrenceAndWeightBasedDetector {
   }
 
   @Override
-  protected boolean applies(Entry entry, String value) {
-    return entry.hasObjectClass(value);
+  protected boolean applies(Entry entry, String attribute) {
+    return entry.hasObjectClass(attribute);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/e3676a77/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurrenceAndWeightBasedDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurrenceAndWeightBasedDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurrenceAndWeightBasedDetector.java
index cb78d25..6ce7ca6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurrenceAndWeightBasedDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurrenceAndWeightBasedDetector.java
@@ -23,15 +23,27 @@ import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.Maps;
 
+/**
+ * Attribute detector implementation that detects attributes considering their count of occurrence in a sample set of entries.
+ * When multiple values are checked these values can be assigned a weight, that represents it's importance.
+ */
 public abstract class OccurrenceAndWeightBasedDetector implements AttributeDetector<Entry> {
 
   private static final Logger LOGGER = LoggerFactory.getLogger(OccurrenceAndWeightBasedDetector.class);
 
-  private Map<String, Integer> occurranceMap = Maps.newHashMap();
+  /**
+   * A map in which the keys are the attributes that are checked in an entry and the values are the number the key occurs
+   * in the sample entry set.
+   */
+  private Map<String, Integer> occurrenceMap = Maps.newHashMap();
+
+  /**
+   * A map in which the keys are the attributes that are checked in an entry and the values are the weight of the attribute.
+   */
   private Map<String, Integer> weightsMap = Maps.newHashMap();
 
   protected Map<String, Integer> occurrenceMap() {
-    return occurranceMap;
+    return occurrenceMap;
   }
 
   protected Map<String, Integer> weightsMap() {
@@ -39,10 +51,27 @@ public abstract class OccurrenceAndWeightBasedDetector implements AttributeDetec
   }
 
 
-  protected abstract boolean applies(Entry entry, String value);
-
+  /**
+   * Checks whether the provided atribute is present in the entry.s
+   *
+   * @param entry     the entry being procesed
+   * @param attribute the attribute being detected
+   * @return true if the attribute is present, false otherwise
+   */
+  protected abstract boolean applies(Entry entry, String attribute);
+
+  /**
+   * The configuration key being detected.
+   *
+   * @return the key as a string
+   */
   public abstract String detectedProperty();
 
+  /**
+   * Calculates the attribute value based on the two maps.
+   *
+   * @return a map with a single element, the key is the configuration key, the value is the detected attribute value
+   */
   @Override
   public Map<String, String> detect() {
     LOGGER.info("Calculating the most probable attribute/value ...");
@@ -82,6 +111,11 @@ public abstract class OccurrenceAndWeightBasedDetector implements AttributeDetec
   }
 
 
+  /**
+   * Collects the information about the attribute to be detected from the provided entry.
+   *
+   * @param entry a result entry returned by a search operation
+   */
   @Override
   public void collect(Entry entry) {
     LOGGER.info("Collecting ldap attributes/values form entry with dn: [{}]", entry.getDn());

http://git-wip-us.apache.org/repos/asf/ambari/blob/e3676a77/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java
index 63ad8ba..b34a2b2 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java
@@ -53,8 +53,8 @@ public class UserGroupMemberAttrDetector extends OccurrenceAndWeightBasedDetecto
   }
 
   @Override
-  protected boolean applies(Entry entry, String value) {
-    return entry.containsAttribute(value);
+  protected boolean applies(Entry entry, String attribute) {
+    return entry.containsAttribute(attribute);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/e3676a77/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserNameAttrDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserNameAttrDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserNameAttrDetector.java
index 8f46d72..dec4459 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserNameAttrDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserNameAttrDetector.java
@@ -58,9 +58,9 @@ public class UserNameAttrDetector extends OccurrenceAndWeightBasedDetector {
   }
 
   @Override
-  protected boolean applies(Entry entry, String value) {
-    LOGGER.info("Checking for attribute  [{}] in entry [{}]", value, entry.getDn());
-    return entry.containsAttribute(value);
+  protected boolean applies(Entry entry, String attribute) {
+    LOGGER.info("Checking for attribute  [{}] in entry [{}]", attribute, entry.getDn());
+    return entry.containsAttribute(attribute);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/e3676a77/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserObjectClassDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserObjectClassDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserObjectClassDetector.java
index 902dff9..53aad8b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserObjectClassDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserObjectClassDetector.java
@@ -57,9 +57,9 @@ public class UserObjectClassDetector extends OccurrenceAndWeightBasedDetector {
   }
 
   @Override
-  protected boolean applies(Entry entry, String value) {
-    LOGGER.info("Checking for object class [{}] in entry [{}]", value, entry.getDn());
-    return entry.hasObjectClass(value);
+  protected boolean applies(Entry entry, String attribute) {
+    LOGGER.info("Checking for object class [{}] in entry [{}]", attribute, entry.getDn());
+    return entry.hasObjectClass(attribute);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/e3676a77/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
index e77f816..875ce97 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
@@ -15,12 +15,10 @@
 package org.apache.ambari.server.ldap;
 
 import java.util.Map;
-import java.util.Set;
 
 import org.apache.ambari.server.ldap.domain.AmbariLdapConfigKeys;
 import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
 import org.apache.ambari.server.ldap.domain.TestAmbariLdapConfigurationFactory;
-import org.apache.ambari.server.ldap.service.AttributeDetector;
 import org.apache.ambari.server.ldap.service.LdapConfigurationService;
 import org.apache.ambari.server.ldap.service.LdapFacade;
 import org.apache.ambari.server.ldap.service.ads.LdapConnectionTemplateFactory;
@@ -39,7 +37,6 @@ import org.junit.Ignore;
 import org.junit.Test;
 
 import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
 import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
@@ -180,14 +177,11 @@ public class LdapModuleFunctionalTest {
   public void testShouldDetectorsBeBound() throws Exception {
     // GIVEN
 
-    Set<AttributeDetector> adSet = Sets.newHashSet();
-//    ChainedAttributeDetector ad = injector.getInstance(ChainedAttributeDetector.class);
-
-    AttributeDetectorFactory f = injector.getInstance(AttributeDetectorFactory.class);
     // WHEN
-    Assert.assertNotNull(f);
+    AttributeDetectorFactory f = injector.getInstance(AttributeDetectorFactory.class);
 
     // THEN
+    Assert.assertNotNull(f);
 
   }
 }
\ No newline at end of file


[33/46] ambari git commit: AMBARI-21307 added javadocs, organized and cleaned the code

Posted by lp...@apache.org.
AMBARI-21307 added javadocs, organized and cleaned the code


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 25d6edf9ca4aafec3e8a1eee94443fc2ffd245e0
Parents: 9b4bd20
Author: lpuskas <lp...@apache.org>
Authored: Wed Sep 13 15:27:39 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:42:00 2017 +0200

----------------------------------------------------------------------
 .../server/ldap/LdapConfigurationFactory.java   |  13 +
 .../server/ldap/LdapConfigurationService.java   |  60 -----
 .../apache/ambari/server/ldap/LdapModule.java   |   6 +-
 .../server/ldap/service/AmbariLdapFacade.java   |   9 +-
 .../server/ldap/service/AttributeDetector.java  |   3 +-
 .../ldap/service/LdapConfigurationService.java  |  60 +++++
 .../ambari/server/ldap/service/LdapFacade.java  |  10 +-
 .../ads/DefaultAttributeDetectionService.java   | 238 -------------------
 .../DefaultLdapAttributeDetectionService.java   | 238 +++++++++++++++++++
 .../ads/DefaultLdapConfigurationService.java    |  17 +-
 .../detectors/UserGroupMemberAttrDetector.java  |   1 -
 .../DefaultAttributeDetectionServiceTest.java   | 108 ---------
 ...efaultLdapAttributeDetectionServiceTest.java | 108 +++++++++
 .../DefaultLdapConfigurationServiceTest.java    |   2 +-
 14 files changed, 453 insertions(+), 420 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/25d6edf9/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationFactory.java
index 57cdf6e..67ac092 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationFactory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationFactory.java
@@ -16,6 +16,19 @@ package org.apache.ambari.server.ldap;
 
 import java.util.Map;
 
+/**
+ * Factory interface for AmbariLdapConfiguration instances.
+ * It's registered as a factory in the GUICE context ( so no implementations required)
+ *
+ * To be extended with other factory methods upon needs.
+ */
 public interface LdapConfigurationFactory {
+
+  /**
+   * Creates an AmbariLdapConfiguration instance with the provided map of configuration settings.
+   *
+   * @param configuration a map where keys are the configuration properties and values are the configuration values
+   * @return an AmbariLdapConfiguration instance
+   */
   AmbariLdapConfiguration createLdapConfiguration(Map<String, Object> configuration);
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/25d6edf9/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationService.java
deleted file mode 100644
index 69a641f..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationService.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap;
-
-import java.util.Set;
-
-import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.ldap.service.AmbariLdapException;
-import org.apache.directory.ldap.client.api.LdapConnection;
-
-/**
- * Collection of operations for validating ldap configuration.
- * It's intended to decouple implementations using different libraries.
- */
-public interface LdapConfigurationService {
-
-  /**
-   * Tests the connection based on the provided configuration.
-   *
-   * @param ldapConnection connection instance
-   * @param configuration  the ambari ldap configuration instance
-   * @throws AmbariLdapException if the connection is not possible
-   */
-  void checkConnection(LdapConnection ldapConnection, AmbariLdapConfiguration configuration) throws AmbariLdapException;
-
-
-  /**
-   * Implements LDAP user related configuration settings validation logic.
-   * Implementers communicate with the LDAP server (search, bind) to validate attributes in the provided configuration
-   * instance
-   *
-   * @param ldapConnection connection instance used to connect to the LDAP server
-   * @param testUserName   the test username
-   * @param testPassword   the test password
-   * @param configuration  the available ldap configuration
-   * @return The DN of the found user entry
-   * @throws AmbariException if the connection couldn't be estabilisheds
-   */
-  String checkUserAttributes(LdapConnection ldapConnection, String testUserName, String testPassword, AmbariLdapConfiguration configuration) throws AmbariLdapException;
-
-  /**
-   * Checks whether the group related LDAP attributes in the configuration are correct.
-   *
-   * @throws AmbariException if the attributes are not valid
-   */
-  Set<String> checkGroupAttributes(LdapConnection ldapConnection, String userDn, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException;
-
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/25d6edf9/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
index 5d6a698..0be69d4 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
@@ -18,9 +18,10 @@ package org.apache.ambari.server.ldap;
 import org.apache.ambari.server.ldap.service.AmbariLdapConfigurationProvider;
 import org.apache.ambari.server.ldap.service.AmbariLdapFacade;
 import org.apache.ambari.server.ldap.service.LdapAttributeDetectionService;
+import org.apache.ambari.server.ldap.service.LdapConfigurationService;
 import org.apache.ambari.server.ldap.service.LdapConnectionService;
 import org.apache.ambari.server.ldap.service.LdapFacade;
-import org.apache.ambari.server.ldap.service.ads.DefaultAttributeDetectionService;
+import org.apache.ambari.server.ldap.service.ads.DefaultLdapAttributeDetectionService;
 import org.apache.ambari.server.ldap.service.ads.DefaultLdapConfigurationService;
 import org.apache.ambari.server.ldap.service.ads.DefaultLdapConnectionService;
 
@@ -37,8 +38,9 @@ public class LdapModule extends AbstractModule {
     bind(LdapFacade.class).to(AmbariLdapFacade.class);
     bind(LdapConfigurationService.class).to(DefaultLdapConfigurationService.class);
     bind(LdapConnectionService.class).to(DefaultLdapConnectionService.class);
-    bind(LdapAttributeDetectionService.class).to(DefaultAttributeDetectionService.class);
+    bind(LdapAttributeDetectionService.class).to(DefaultLdapAttributeDetectionService.class);
 
+    // this binding requires the JPA module!
     bind(AmbariLdapConfiguration.class).toProvider(AmbariLdapConfigurationProvider.class);
 
     install(new FactoryModuleBuilder().build(LdapConfigurationFactory.class));

http://git-wip-us.apache.org/repos/asf/ambari/blob/25d6edf9/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
index 719bb7b..689a072 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
@@ -22,7 +22,6 @@ import javax.inject.Inject;
 import javax.inject.Singleton;
 
 import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.LdapConfigurationService;
 import org.apache.directory.ldap.client.api.LdapConnection;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -32,9 +31,12 @@ public class AmbariLdapFacade implements LdapFacade {
 
   private static final Logger LOGGER = LoggerFactory.getLogger(AmbariLdapFacade.class);
 
+  /**
+   * Additional parameters expected to be provided along with the configuration
+   */
   private enum Parameters {
-    TEST_USER_NAME("ldap.test.user.name"),
-    TEST_USER_PASSWORD("ldap.test.user.password");
+    TEST_USER_NAME("ambari.ldap.test.user.name"),
+    TEST_USER_PASSWORD("ambari.ldap.test.user.password");
 
     private String parameterKey;
 
@@ -68,6 +70,7 @@ public class AmbariLdapFacade implements LdapFacade {
 
       LOGGER.info("Validating LDAP connection related configuration based on: {}", ambariLdapConfiguration);
       connection = ldapConnectionService.getBoundLdapConnection(ambariLdapConfiguration);
+
       ldapConfigurationService.checkConnection(connection, ambariLdapConfiguration);
       LOGGER.info("Validating LDAP connection related configuration: SUCCESS");
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/25d6edf9/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AttributeDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AttributeDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AttributeDetector.java
index 3e20a6a..1b28148 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AttributeDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AttributeDetector.java
@@ -16,7 +16,8 @@ package org.apache.ambari.server.ldap.service;
 
 /**
  * Operations for detecting LDAP related settings.
- * Attributes and values are detected based on a sample set of results returned from a search
+ * The basis for the attribute or value detection is a set of entries returned by a search operation.
+ * Individual attribute detector implementations are responsible for detecting a specific set of attributes or values
  */
 public interface AttributeDetector<T> {
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/25d6edf9/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConfigurationService.java
new file mode 100644
index 0000000..06566cc
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConfigurationService.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service;
+
+import java.util.Set;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.directory.ldap.client.api.LdapConnection;
+
+/**
+ * Collection of operations for validating ldap configuration.
+ * It's intended to decouple implementations using different libraries.
+ */
+public interface LdapConfigurationService {
+
+  /**
+   * Tests the connection based on the provided configuration.
+   *
+   * @param ldapConnection connection instance
+   * @param configuration  the ambari ldap configuration instance
+   * @throws AmbariLdapException if the connection is not possible
+   */
+  void checkConnection(LdapConnection ldapConnection, AmbariLdapConfiguration configuration) throws AmbariLdapException;
+
+
+  /**
+   * Implements LDAP user related configuration settings validation logic.
+   * Implementers communicate with the LDAP server (search, bind) to validate attributes in the provided configuration
+   * instance
+   *
+   * @param ldapConnection connection instance used to connect to the LDAP server
+   * @param testUserName   the test username
+   * @param testPassword   the test password
+   * @param configuration  the available ldap configuration
+   * @return The DN of the found user entry
+   * @throws AmbariException if the connection couldn't be estabilisheds
+   */
+  String checkUserAttributes(LdapConnection ldapConnection, String testUserName, String testPassword, AmbariLdapConfiguration configuration) throws AmbariLdapException;
+
+  /**
+   * Checks whether the group related LDAP attributes in the configuration are correct.
+   *
+   * @throws AmbariException if the attributes are not valid
+   */
+  Set<String> checkGroupAttributes(LdapConnection ldapConnection, String userDn, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException;
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/25d6edf9/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
index 6060d7f..3ae913c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
@@ -22,6 +22,9 @@ import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
 /**
  * The contract defining all the operations required by the application when communicating with an arbitrary LDAP server.
  * This interface is intended to decouple LDAP specific details from the application.
+ *
+ * Any operation that requires interaction with an LDAP server from within Ambari should go through this interface.
+ * (LDAP)
  */
 public interface LdapFacade {
 
@@ -35,9 +38,12 @@ public interface LdapFacade {
 
 
   /**
-   * Runs the user and group attribute detection algorithms
+   * Runs the user and group attribute detection algorithms.
+   * The method is not intended to be used as a coniguration factory, the returned instance may not be suitable for use.
    *
-   * @param ambariLdapConfiguration
+   * @param ambariLdapConfiguration partially filled configuration instance to be extended with detected properties
+   * @return a configuration instance, with properties filled with potentially correct values
+   * @throws AmbariLdapException
    */
   AmbariLdapConfiguration detectAttributes(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException;
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/25d6edf9/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionService.java
deleted file mode 100644
index e5254b5..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionService.java
+++ /dev/null
@@ -1,238 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.service.ads;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.service.AmbariLdapException;
-import org.apache.ambari.server.ldap.service.LdapAttributeDetectionService;
-import org.apache.ambari.server.ldap.service.ads.detectors.GroupMemberAttrDetector;
-import org.apache.ambari.server.ldap.service.ads.detectors.GroupNameAttrDetector;
-import org.apache.ambari.server.ldap.service.ads.detectors.GroupObjectClassDetector;
-import org.apache.ambari.server.ldap.service.ads.detectors.UserGroupMemberAttrDetector;
-import org.apache.ambari.server.ldap.service.ads.detectors.UserNameAttrDetector;
-import org.apache.ambari.server.ldap.service.ads.detectors.UserObjectClassDetector;
-import org.apache.directory.api.ldap.model.cursor.SearchCursor;
-import org.apache.directory.api.ldap.model.entry.Entry;
-import org.apache.directory.api.ldap.model.message.Response;
-import org.apache.directory.api.ldap.model.message.SearchRequest;
-import org.apache.directory.api.ldap.model.message.SearchRequestImpl;
-import org.apache.directory.api.ldap.model.message.SearchResultEntry;
-import org.apache.directory.api.ldap.model.message.SearchScope;
-import org.apache.directory.api.ldap.model.name.Dn;
-import org.apache.directory.api.util.Strings;
-import org.apache.directory.ldap.client.api.LdapConnection;
-import org.apache.directory.ldap.client.api.search.FilterBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Singleton
-public class DefaultAttributeDetectionService implements LdapAttributeDetectionService<LdapConnection> {
-
-  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultAttributeDetectionService.class);
-  private static final int SAMPLE_RESULT_SIZE = 50;
-
-
-  @Inject
-  private UserNameAttrDetector userNameAttrDetector;
-
-  @Inject
-  private UserObjectClassDetector userObjectClassDetector;
-
-  @Inject
-  private UserGroupMemberAttrDetector userGroupMemberAttrDetector;
-
-  @Inject
-  private GroupNameAttrDetector groupNameAttrDetector;
-
-  @Inject
-  private GroupObjectClassDetector groupObjectClassDetector;
-
-  @Inject
-  private GroupMemberAttrDetector groupMemberAttrDetector;
-
-  @Inject
-  public DefaultAttributeDetectionService() {
-  }
-
-  @Override
-  public AmbariLdapConfiguration detectLdapUserAttributes(LdapConnection connection, AmbariLdapConfiguration ambariLdapConfiguration) {
-    LOGGER.info("Detecting LDAP user attributes ...");
-
-    // perform a search using the user search base
-    if (Strings.isEmpty(ambariLdapConfiguration.userSearchBase())) {
-      LOGGER.warn("No user search base provided");
-      return ambariLdapConfiguration;
-    }
-
-    SearchCursor searchCursor = null;
-
-    try {
-
-      SearchRequest searchRequest = assembleUserSearchRequest(ambariLdapConfiguration);
-
-      // do the search
-      searchCursor = connection.search(searchRequest);
-
-      int processedUserCnt = 0;
-
-      while (searchCursor.next()) {
-
-        if (processedUserCnt >= SAMPLE_RESULT_SIZE) {
-          LOGGER.debug("The maximum count of results for attribute detection has exceeded. Quit user attribute detection.");
-          break;
-        }
-
-        Response response = searchCursor.get();
-        // process the SearchResultEntry
-
-        if (response instanceof SearchResultEntry) {
-          Entry resultEntry = ((SearchResultEntry) response).getEntry();
-          LOGGER.info("Processing sample entry with dn: [{}]", resultEntry.getDn());
-
-          userNameAttrDetector.collect(resultEntry);
-          userObjectClassDetector.collect(resultEntry);
-          userGroupMemberAttrDetector.collect(resultEntry);
-
-          processedUserCnt++;
-        }
-      }
-
-      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.USER_NAME_ATTRIBUTE, userNameAttrDetector.detect());
-      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.USER_OBJECT_CLASS, userObjectClassDetector.detect());
-      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.USER_GROUP_MEMBER_ATTRIBUTE, userGroupMemberAttrDetector.detect());
-
-      LOGGER.info("Decorated ambari ldap config : [{}]", ambariLdapConfiguration);
-
-    } catch (Exception e) {
-
-      LOGGER.error("Ldap operation failed", e);
-    } finally {
-      // housekeeping
-      if (null != searchCursor) {
-        searchCursor.close();
-      }
-    }
-
-    return ambariLdapConfiguration;
-  }
-
-
-  @Override
-  public AmbariLdapConfiguration detectLdapGroupAttributes(LdapConnection connection, AmbariLdapConfiguration ambariLdapConfiguration) {
-    LOGGER.info("Detecting LDAP group attributes ...");
-
-    // perform a search using the user search base
-    if (Strings.isEmpty(ambariLdapConfiguration.groupSearchBase())) {
-      LOGGER.warn("No group search base provided");
-      return ambariLdapConfiguration;
-    }
-
-    SearchCursor searchCursor = null;
-
-    try {
-      // todo should the bind operation be done in the facade?
-      connection.bind(ambariLdapConfiguration.bindDn(), ambariLdapConfiguration.bindPassword());
-
-      SearchRequest searchRequest = assembleGroupSearchRequest(ambariLdapConfiguration);
-
-      // do the search
-      searchCursor = connection.search(searchRequest);
-
-      int processedGroupCnt = 0;
-
-      while (searchCursor.next()) {
-
-        if (processedGroupCnt >= SAMPLE_RESULT_SIZE) {
-          LOGGER.debug("The maximum number of results for attribute detection has exceeded. Quit  detection.");
-          break;
-        }
-
-        Response response = searchCursor.get();
-        // process the SearchResultEntry
-
-        if (response instanceof SearchResultEntry) {
-          Entry resultEntry = ((SearchResultEntry) response).getEntry();
-          LOGGER.info("Processing sample entry with dn: [{}]", resultEntry.getDn());
-
-          groupNameAttrDetector.collect(resultEntry);
-          groupObjectClassDetector.collect(resultEntry);
-          groupMemberAttrDetector.collect(resultEntry);
-
-          processedGroupCnt++;
-        }
-      }
-
-      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.GROUP_NAME_ATTRIBUTE, groupNameAttrDetector.detect());
-      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.GROUP_OBJECT_CLASS, groupObjectClassDetector.detect());
-      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.GROUP_MEMBER_ATTRIBUTE, groupMemberAttrDetector.detect());
-
-      LOGGER.info("Decorated ambari ldap config : [{}]", ambariLdapConfiguration);
-
-    } catch (Exception e) {
-
-      LOGGER.error("Ldap operation failed", e);
-    } finally {
-      // housekeeping
-      if (null != searchCursor) {
-        searchCursor.close();
-      }
-    }
-
-    return ambariLdapConfiguration;
-  }
-
-  private SearchRequest assembleUserSearchRequest(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
-    try {
-
-      SearchRequest req = new SearchRequestImpl();
-      req.setScope(SearchScope.SUBTREE);
-      req.addAttributes("*");
-      req.setTimeLimit(0);
-      req.setBase(new Dn(ambariLdapConfiguration.userSearchBase()));
-      // the filter must be set!
-      req.setFilter(FilterBuilder.present(ambariLdapConfiguration.dnAttribute()).toString());
-
-      return req;
-
-    } catch (Exception e) {
-      LOGGER.error("Could not assemble ldap search request", e);
-      throw new AmbariLdapException(e);
-    }
-  }
-
-  private SearchRequest assembleGroupSearchRequest(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
-    try {
-
-      SearchRequest req = new SearchRequestImpl();
-      req.setScope(SearchScope.SUBTREE);
-      req.addAttributes("*");
-      req.setTimeLimit(0);
-      req.setBase(new Dn(ambariLdapConfiguration.groupSearchBase()));
-      // the filter must be set!
-      req.setFilter(FilterBuilder.present(ambariLdapConfiguration.dnAttribute()).toString());
-
-      return req;
-
-    } catch (Exception e) {
-      LOGGER.error("Could not assemble ldap search request", e);
-      throw new AmbariLdapException(e);
-    }
-  }
-
-
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/25d6edf9/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
new file mode 100644
index 0000000..b499b65
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
@@ -0,0 +1,238 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.service.AmbariLdapException;
+import org.apache.ambari.server.ldap.service.LdapAttributeDetectionService;
+import org.apache.ambari.server.ldap.service.ads.detectors.GroupMemberAttrDetector;
+import org.apache.ambari.server.ldap.service.ads.detectors.GroupNameAttrDetector;
+import org.apache.ambari.server.ldap.service.ads.detectors.GroupObjectClassDetector;
+import org.apache.ambari.server.ldap.service.ads.detectors.UserGroupMemberAttrDetector;
+import org.apache.ambari.server.ldap.service.ads.detectors.UserNameAttrDetector;
+import org.apache.ambari.server.ldap.service.ads.detectors.UserObjectClassDetector;
+import org.apache.directory.api.ldap.model.cursor.SearchCursor;
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.apache.directory.api.ldap.model.message.Response;
+import org.apache.directory.api.ldap.model.message.SearchRequest;
+import org.apache.directory.api.ldap.model.message.SearchRequestImpl;
+import org.apache.directory.api.ldap.model.message.SearchResultEntry;
+import org.apache.directory.api.ldap.model.message.SearchScope;
+import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.api.util.Strings;
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.search.FilterBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Singleton
+public class DefaultLdapAttributeDetectionService implements LdapAttributeDetectionService<LdapConnection> {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapAttributeDetectionService.class);
+  private static final int SAMPLE_RESULT_SIZE = 50;
+
+
+  @Inject
+  private UserNameAttrDetector userNameAttrDetector;
+
+  @Inject
+  private UserObjectClassDetector userObjectClassDetector;
+
+  @Inject
+  private UserGroupMemberAttrDetector userGroupMemberAttrDetector;
+
+  @Inject
+  private GroupNameAttrDetector groupNameAttrDetector;
+
+  @Inject
+  private GroupObjectClassDetector groupObjectClassDetector;
+
+  @Inject
+  private GroupMemberAttrDetector groupMemberAttrDetector;
+
+  @Inject
+  public DefaultLdapAttributeDetectionService() {
+  }
+
+  @Override
+  public AmbariLdapConfiguration detectLdapUserAttributes(LdapConnection connection, AmbariLdapConfiguration ambariLdapConfiguration) {
+    LOGGER.info("Detecting LDAP user attributes ...");
+
+    // perform a search using the user search base
+    if (Strings.isEmpty(ambariLdapConfiguration.userSearchBase())) {
+      LOGGER.warn("No user search base provided");
+      return ambariLdapConfiguration;
+    }
+
+    SearchCursor searchCursor = null;
+
+    try {
+
+      SearchRequest searchRequest = assembleUserSearchRequest(ambariLdapConfiguration);
+
+      // do the search
+      searchCursor = connection.search(searchRequest);
+
+      int processedUserCnt = 0;
+
+      while (searchCursor.next()) {
+
+        if (processedUserCnt >= SAMPLE_RESULT_SIZE) {
+          LOGGER.debug("The maximum count of results for attribute detection has exceeded. Quit user attribute detection.");
+          break;
+        }
+
+        Response response = searchCursor.get();
+        // process the SearchResultEntry
+
+        if (response instanceof SearchResultEntry) {
+          Entry resultEntry = ((SearchResultEntry) response).getEntry();
+          LOGGER.info("Processing sample entry with dn: [{}]", resultEntry.getDn());
+
+          userNameAttrDetector.collect(resultEntry);
+          userObjectClassDetector.collect(resultEntry);
+          userGroupMemberAttrDetector.collect(resultEntry);
+
+          processedUserCnt++;
+        }
+      }
+
+      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.USER_NAME_ATTRIBUTE, userNameAttrDetector.detect());
+      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.USER_OBJECT_CLASS, userObjectClassDetector.detect());
+      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.USER_GROUP_MEMBER_ATTRIBUTE, userGroupMemberAttrDetector.detect());
+
+      LOGGER.info("Decorated ambari ldap config : [{}]", ambariLdapConfiguration);
+
+    } catch (Exception e) {
+
+      LOGGER.error("Ldap operation failed", e);
+    } finally {
+      // housekeeping
+      if (null != searchCursor) {
+        searchCursor.close();
+      }
+    }
+
+    return ambariLdapConfiguration;
+  }
+
+
+  @Override
+  public AmbariLdapConfiguration detectLdapGroupAttributes(LdapConnection connection, AmbariLdapConfiguration ambariLdapConfiguration) {
+    LOGGER.info("Detecting LDAP group attributes ...");
+
+    // perform a search using the user search base
+    if (Strings.isEmpty(ambariLdapConfiguration.groupSearchBase())) {
+      LOGGER.warn("No group search base provided");
+      return ambariLdapConfiguration;
+    }
+
+    SearchCursor searchCursor = null;
+
+    try {
+      // todo should the bind operation be done in the facade?
+      connection.bind(ambariLdapConfiguration.bindDn(), ambariLdapConfiguration.bindPassword());
+
+      SearchRequest searchRequest = assembleGroupSearchRequest(ambariLdapConfiguration);
+
+      // do the search
+      searchCursor = connection.search(searchRequest);
+
+      int processedGroupCnt = 0;
+
+      while (searchCursor.next()) {
+
+        if (processedGroupCnt >= SAMPLE_RESULT_SIZE) {
+          LOGGER.debug("The maximum number of results for attribute detection has exceeded. Quit  detection.");
+          break;
+        }
+
+        Response response = searchCursor.get();
+        // process the SearchResultEntry
+
+        if (response instanceof SearchResultEntry) {
+          Entry resultEntry = ((SearchResultEntry) response).getEntry();
+          LOGGER.info("Processing sample entry with dn: [{}]", resultEntry.getDn());
+
+          groupNameAttrDetector.collect(resultEntry);
+          groupObjectClassDetector.collect(resultEntry);
+          groupMemberAttrDetector.collect(resultEntry);
+
+          processedGroupCnt++;
+        }
+      }
+
+      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.GROUP_NAME_ATTRIBUTE, groupNameAttrDetector.detect());
+      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.GROUP_OBJECT_CLASS, groupObjectClassDetector.detect());
+      ambariLdapConfiguration.setValueFor(AmbariLdapConfiguration.AmbariLdapConfig.GROUP_MEMBER_ATTRIBUTE, groupMemberAttrDetector.detect());
+
+      LOGGER.info("Decorated ambari ldap config : [{}]", ambariLdapConfiguration);
+
+    } catch (Exception e) {
+
+      LOGGER.error("Ldap operation failed", e);
+    } finally {
+      // housekeeping
+      if (null != searchCursor) {
+        searchCursor.close();
+      }
+    }
+
+    return ambariLdapConfiguration;
+  }
+
+  private SearchRequest assembleUserSearchRequest(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+    try {
+
+      SearchRequest req = new SearchRequestImpl();
+      req.setScope(SearchScope.SUBTREE);
+      req.addAttributes("*");
+      req.setTimeLimit(0);
+      req.setBase(new Dn(ambariLdapConfiguration.userSearchBase()));
+      // the filter must be set!
+      req.setFilter(FilterBuilder.present(ambariLdapConfiguration.dnAttribute()).toString());
+
+      return req;
+
+    } catch (Exception e) {
+      LOGGER.error("Could not assemble ldap search request", e);
+      throw new AmbariLdapException(e);
+    }
+  }
+
+  private SearchRequest assembleGroupSearchRequest(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+    try {
+
+      SearchRequest req = new SearchRequestImpl();
+      req.setScope(SearchScope.SUBTREE);
+      req.addAttributes("*");
+      req.setTimeLimit(0);
+      req.setBase(new Dn(ambariLdapConfiguration.groupSearchBase()));
+      // the filter must be set!
+      req.setFilter(FilterBuilder.present(ambariLdapConfiguration.dnAttribute()).toString());
+
+      return req;
+
+    } catch (Exception e) {
+      LOGGER.error("Could not assemble ldap search request", e);
+      throw new AmbariLdapException(e);
+    }
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/25d6edf9/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
index c90b5ac..0a309cd 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
@@ -21,8 +21,8 @@ import javax.inject.Inject;
 import javax.inject.Singleton;
 
 import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.LdapConfigurationService;
 import org.apache.ambari.server.ldap.service.AmbariLdapException;
+import org.apache.ambari.server.ldap.service.LdapConfigurationService;
 import org.apache.directory.api.ldap.codec.decorators.SearchResultEntryDecorator;
 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
 import org.apache.directory.api.ldap.model.cursor.EntryCursor;
@@ -63,7 +63,6 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
 
   }
 
-
   /**
    * Checks the user attributes provided in the configuration instance by issuing a search for a (known) test user in the LDAP.
    * Attributes are considered correct if there is at least one entry found.
@@ -73,7 +72,7 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
    * @param ldapConnection          connection instance used to connect to the LDAP server
    * @param testUserName            the test username
    * @param testPassword            the test password
-   * @param ambariLdapConfiguration configuration instance holding ldap configuration details
+   * @param ambariLdapConfiguration the available LDAP configuration to be validated
    * @return the DN of the test user
    * @throws AmbariLdapException if an error occurs
    */
@@ -122,7 +121,16 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
     return userDn;
   }
 
-
+  /**
+   * Checks whether the provided group related settings are correct.
+   * The algorithm implemented in this method per
+   *
+   * @param ldapConnection          a connecion instance bound to an LDAP server
+   * @param userDn                  a user DN to check
+   * @param ambariLdapConfiguration the available LDAP configuration to be validated
+   * @return
+   * @throws AmbariLdapException
+   */
   @Override
   public Set<String> checkGroupAttributes(LdapConnection ldapConnection, String userDn, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
     SearchCursor searchCursor = null;
@@ -144,6 +152,7 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
       searchRequest.setFilter(filter);
       searchRequest.setBase(new Dn(ambariLdapConfiguration.groupSearchBase()));
       searchRequest.setScope(SearchScope.SUBTREE);
+      // attributes to be returned
       searchRequest.addAttributes(ambariLdapConfiguration.groupMemberAttribute(), ambariLdapConfiguration.groupNameAttribute());
 
       // perform the search

http://git-wip-us.apache.org/repos/asf/ambari/blob/25d6edf9/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java
index 913c2b6..a7f03dd 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java
@@ -19,7 +19,6 @@ import javax.inject.Inject;
 import org.apache.directory.api.ldap.model.entry.Entry;
 
 public class UserGroupMemberAttrDetector extends OccurranceAndWeightBasedDetector {
-  private static String[] userGroupMemAttrValues = {"memberOf", "ismemberOf"};
 
   private enum UserGroupMemberAttr {
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/25d6edf9/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionServiceTest.java
deleted file mode 100644
index 9b03b86..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionServiceTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.service.ads;
-
-
-import java.util.Map;
-
-import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.service.LdapConnectionService;
-import org.apache.directory.api.ldap.model.constants.SchemaConstants;
-import org.apache.directory.ldap.client.api.LdapConnection;
-import org.easymock.EasyMockRule;
-import org.easymock.TestSubject;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.Maps;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-
-public class DefaultAttributeDetectionServiceTest {
-
-  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultAttributeDetectionServiceTest.class);
-
-  @Rule
-  public EasyMockRule mocks = new EasyMockRule(this);
-
-  private AmbariLdapConfiguration testLdapConfiguration;
-  private LdapConnection connection;
-
-  @TestSubject
-  private DefaultAttributeDetectionService attributeDetectionService = new DefaultAttributeDetectionService();
-
-  @Before
-  public void before() {
-
-    Map<String, Object> initialProps = Maps.newHashMap();
-    initialProps.put(AmbariLdapConfiguration.AmbariLdapConfig.BIND_DN.key(), "");
-    testLdapConfiguration = new AmbariLdapConfiguration(initialProps);
-  }
-
-  @Test
-  public void testShouldUserNameAttributeBeDetectedWhenSearchReturnsValidUsers() throws Exception {
-    // GIVEN
-// a set of entries returned from the LDAP search
-
-    // WHEN
-    AmbariLdapConfiguration ambariLdapConfiguration = attributeDetectionService.detectLdapUserAttributes(connection, testLdapConfiguration);
-
-    // THEN
-    Assert.assertNotNull(ambariLdapConfiguration);
-    Assert.assertEquals("The username attribute is not the expected", "uid", ambariLdapConfiguration.userNameAttribute());
-
-  }
-
-
-  @Test
-  public void functionalTest() throws Exception {
-    // GIVEN
-    AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(getTestPropertiesMap());
-    LdapConnectionService connectionService = new DefaultLdapConnectionService();
-    LdapConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
-
-    // WHEN
-    AmbariLdapConfiguration config = attributeDetectionService.detectLdapUserAttributes(ldapConnection, ambariLdapConfiguration);
-    config = attributeDetectionService.detectLdapGroupAttributes(ldapConnection, ambariLdapConfiguration);
-
-    Gson gson = new GsonBuilder().create();
-    LOGGER.info(gson.toJson(config));
-
-    // THEN
-    ldapConnection.close();
-
-  }
-
-  private Map<String, Object> getTestPropertiesMap() {
-    Map<String, Object> ldapPropsMap = Maps.newHashMap();
-
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.ANONYMOUS_BIND.key(), "true");
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.SERVER_HOST.key(), "ldap.forumsys.com");
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.SERVER_PORT.key(), "389");
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.BIND_DN.key(), "cn=read-only-admin,dc=example,dc=com");
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.BIND_PASSWORD.key(), "password");
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.DN_ATTRIBUTE.key(), SchemaConstants.CN_AT);
-
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.USER_SEARCH_BASE.key(), "dc=example,dc=com");
-    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.GROUP_SEARCH_BASE.key(), "dc=example,dc=com");
-
-    return ldapPropsMap;
-
-  }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/25d6edf9/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java
new file mode 100644
index 0000000..3d335bf
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java
@@ -0,0 +1,108 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads;
+
+
+import java.util.Map;
+
+import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.service.LdapConnectionService;
+import org.apache.directory.api.ldap.model.constants.SchemaConstants;
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.easymock.EasyMockRule;
+import org.easymock.TestSubject;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Maps;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+public class DefaultLdapAttributeDetectionServiceTest {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapAttributeDetectionServiceTest.class);
+
+  @Rule
+  public EasyMockRule mocks = new EasyMockRule(this);
+
+  private AmbariLdapConfiguration testLdapConfiguration;
+  private LdapConnection connection;
+
+  @TestSubject
+  private DefaultLdapAttributeDetectionService attributeDetectionService = new DefaultLdapAttributeDetectionService();
+
+  @Before
+  public void before() {
+
+    Map<String, Object> initialProps = Maps.newHashMap();
+    initialProps.put(AmbariLdapConfiguration.AmbariLdapConfig.BIND_DN.key(), "");
+    testLdapConfiguration = new AmbariLdapConfiguration(initialProps);
+  }
+
+  @Test
+  public void testShouldUserNameAttributeBeDetectedWhenSearchReturnsValidUsers() throws Exception {
+    // GIVEN
+// a set of entries returned from the LDAP search
+
+    // WHEN
+    AmbariLdapConfiguration ambariLdapConfiguration = attributeDetectionService.detectLdapUserAttributes(connection, testLdapConfiguration);
+
+    // THEN
+    Assert.assertNotNull(ambariLdapConfiguration);
+    Assert.assertEquals("The username attribute is not the expected", "uid", ambariLdapConfiguration.userNameAttribute());
+
+  }
+
+
+  @Test
+  public void functionalTest() throws Exception {
+    // GIVEN
+    AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(getTestPropertiesMap());
+    LdapConnectionService connectionService = new DefaultLdapConnectionService();
+    LdapConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
+
+    // WHEN
+    AmbariLdapConfiguration config = attributeDetectionService.detectLdapUserAttributes(ldapConnection, ambariLdapConfiguration);
+    config = attributeDetectionService.detectLdapGroupAttributes(ldapConnection, ambariLdapConfiguration);
+
+    Gson gson = new GsonBuilder().create();
+    LOGGER.info(gson.toJson(config));
+
+    // THEN
+    ldapConnection.close();
+
+  }
+
+  private Map<String, Object> getTestPropertiesMap() {
+    Map<String, Object> ldapPropsMap = Maps.newHashMap();
+
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.ANONYMOUS_BIND.key(), "true");
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.SERVER_HOST.key(), "ldap.forumsys.com");
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.SERVER_PORT.key(), "389");
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.BIND_DN.key(), "cn=read-only-admin,dc=example,dc=com");
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.BIND_PASSWORD.key(), "password");
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.DN_ATTRIBUTE.key(), SchemaConstants.CN_AT);
+
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.USER_SEARCH_BASE.key(), "dc=example,dc=com");
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.GROUP_SEARCH_BASE.key(), "dc=example,dc=com");
+
+    return ldapPropsMap;
+
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/25d6edf9/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
index 1e69012..1ba6110 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
@@ -19,7 +19,7 @@ import static org.junit.Assert.assertNotNull;
 import java.util.Map;
 
 import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.LdapConfigurationService;
+import org.apache.ambari.server.ldap.service.LdapConfigurationService;
 import org.apache.ambari.server.ldap.service.LdapConnectionService;
 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
 import org.apache.directory.api.ldap.model.cursor.EntryCursor;


[07/46] ambari git commit: AMBARI-22263. Disable Actions menu while Wizard in progress instead of hide (alexantonenko)

Posted by lp...@apache.org.
AMBARI-22263. Disable Actions menu while Wizard in progress instead of hide (alexantonenko)


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 84342f6a851daa12ef612a96e0076ea893fd12f2
Parents: ee509e0
Author: Alex Antonenko <aa...@hortonworks.com>
Authored: Wed Oct 18 18:26:08 2017 +0300
Committer: Alex Antonenko <aa...@hortonworks.com>
Committed: Wed Oct 18 18:26:08 2017 +0300

----------------------------------------------------------------------
 ambari-web/app/app.js                           |  24 ++-
 .../models/configs/service_config_version.js    |   9 +-
 ambari-web/app/models/host_stack_version.js     |   4 +-
 .../common/configs/config_history_flow.hbs      |   8 +-
 .../common/configs/service_version_box.hbs      |   8 +-
 .../templates/common/host_progress_popup.hbs    |   6 +-
 .../modal_popups/widget_browser_popup.hbs       |   6 +-
 ambari-web/app/templates/experimental.hbs       |   6 +-
 .../main/admin/stack_upgrade/versions.hbs       |   6 +-
 ambari-web/app/templates/main/host.hbs          |   4 +-
 .../templates/main/host/bulk_operation_menu.hbs |   4 +-
 .../main/host/details/host_component.hbs        | 176 ++++++++++---------
 .../app/templates/main/host/stack_versions.hbs  |   4 +-
 ambari-web/app/templates/main/host/summary.hbs  | 120 +++++++------
 ambari-web/app/utils/helper.js                  |  23 +++
 ambari-web/app/views/main/service/item.js       |   2 +-
 ambari-web/test/views/main/service/item_test.js |   6 +-
 17 files changed, 224 insertions(+), 192 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/app.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/app.js b/ambari-web/app/app.js
index 2c638e4..6432849 100644
--- a/ambari-web/app/app.js
+++ b/ambari-web/app/app.js
@@ -131,27 +131,18 @@ module.exports = Em.Application.create({
   }.property('upgradeIsRunning', 'upgradeAborted', 'router.wizardWatcherController.isNonWizardUser', 'upgradeSuspended'),
 
   /**
-   * Options:
-   *  - ignoreWizard: ignore when some wizard is running by another user (default `false`)
-   *
    * @param {string} authRoles
-   * @param {object} options
    * @returns {boolean}
    */
-  isAuthorized: function (authRoles, options) {
-    options = $.extend({ignoreWizard: false}, options);
+  havePermissions: function (authRoles) {
     var result = false;
     authRoles = $.map(authRoles.split(","), $.trim);
 
     // When Upgrade running(not suspended) only operations related to upgrade should be allowed
     if ((!this.get('upgradeSuspended') && !authRoles.contains('CLUSTER.UPGRADE_DOWNGRADE_STACK')) &&
-        !App.get('supports.opsDuringRollingUpgrade') &&
-        !['NOT_REQUIRED', 'COMPLETED'].contains(this.get('upgradeState')) ||
-        !App.auth){
-      return false;
-    }
-
-    if (!options.ignoreWizard && App.router.get('wizardWatcherController.isNonWizardUser')) {
+      !App.get('supports.opsDuringRollingUpgrade') &&
+      !['NOT_REQUIRED', 'COMPLETED'].contains(this.get('upgradeState')) ||
+      !App.auth){
       return false;
     }
 
@@ -161,6 +152,13 @@ module.exports = Em.Application.create({
 
     return result;
   },
+  /**
+   * @param {string} authRoles
+   * @returns {boolean}
+   */
+  isAuthorized: function (authRoles) {
+    return this.havePermissions(authRoles) && !App.router.get('wizardWatcherController.isNonWizardUser');
+  },
 
   isStackServicesLoaded: false,
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/models/configs/service_config_version.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/configs/service_config_version.js b/ambari-web/app/models/configs/service_config_version.js
index 4120681..7645377 100644
--- a/ambari-web/app/models/configs/service_config_version.js
+++ b/ambari-web/app/models/configs/service_config_version.js
@@ -141,12 +141,13 @@ App.ServiceConfigVersion = DS.Model.extend({
    * {{view: (string|boolean), compare: (string|boolean), revert: (string|boolean)}} disabledActionAttr
    */
   disabledActionAttr: function () {
+    var isNonWizardUser = App.router.get('wizardWatcherController.isNonWizardUser');
     return {
-      view: (this.get('isDisplayed')) ? 'disabled' : false,
-      compare: (this.get('isDisabled') || this.get('isDisplayed')) ? 'disabled' : false,
-      revert: (this.get('isDisabled') || this.get('isCurrent')) ? 'disabled' : false
+      view: (this.get('isDisplayed') || isNonWizardUser) ? 'disabled' : false,
+      compare: (this.get('isDisabled') || isNonWizardUser || this.get('isDisplayed')) ? 'disabled' : false,
+      revert: (this.get('isDisabled') || isNonWizardUser || this.get('isCurrent')) ? 'disabled' : false
     }
-  }.property('isDisplayed', 'isCurrent', 'isDisabled')
+  }.property('isDisplayed', 'isCurrent', 'isDisabled', 'App.router.wizardWatcherController.isNonWizardUser')
 });
 
 App.ServiceConfigVersion.FIXTURES = [];

http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/models/host_stack_version.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/host_stack_version.js b/ambari-web/app/models/host_stack_version.js
index 7e6d0a0..15e62f4 100644
--- a/ambari-web/app/models/host_stack_version.js
+++ b/ambari-web/app/models/host_stack_version.js
@@ -61,7 +61,9 @@ App.HostStackVersion = DS.Model.extend({
    */
   installEnabled: Em.computed.existsIn('status', ['OUT_OF_SYNC', 'INSTALL_FAILED']),
 
-  installDisabled: Em.computed.not('installEnabled')
+  installDisabled: function(){
+    return !this.get('installEnabled') || App.router.get('wizardWatcherController.isNonWizardUser');
+  }.property('installEnabled', 'App.routerwizardWatcherController.isNonWizardUser')
 });
 
 App.HostStackVersion.FIXTURES = [];

http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/templates/common/configs/config_history_flow.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/common/configs/config_history_flow.hbs b/ambari-web/app/templates/common/configs/config_history_flow.hbs
index f063406..99cd140 100644
--- a/ambari-web/app/templates/common/configs/config_history_flow.hbs
+++ b/ambari-web/app/templates/common/configs/config_history_flow.hbs
@@ -70,12 +70,12 @@
         </div>
         <div class="version-operations-buttons">
           <button {{bindAttr disabled="view.parentView.hoveredServiceVersion.disabledActionAttr.view" class=":btn :btn-default view.parentView.hoveredServiceVersion.isDisplayed:not-allowed-cursor" title="view.parentView.hoveredServiceVersion.disabledActionMessages.view"}} {{action doAction undefined view.parentView.actionTypes.SWITCH target="view.parentView"}}><i class="glyphicon glyphicon-search"></i>&nbsp;{{t common.view}}</button>
-          {{#isAuthorized "SERVICE.COMPARE_CONFIGS"}}
+          {{#havePermissions "SERVICE.COMPARE_CONFIGS"}}
             <button {{bindAttr disabled="view.parentView.hoveredServiceVersion.disabledActionAttr.compare" class=":btn :btn-default view.parentView.hoveredServiceVersion.isDisplayed:not-allowed-cursor" title="view.parentView.hoveredServiceVersion.disabledActionMessages.compare"}} {{action doAction undefined view.parentView.actionTypes.COMPARE target="view.parentView"}}><i class="glyphicon glyphicon-copy"></i>&nbsp;{{t common.compare}}</button>
-          {{/isAuthorized}}
-          {{#isAuthorized "SERVICE.MODIFY_CONFIGS"}}
+          {{/havePermissions}}
+          {{#havePermissions "SERVICE.MODIFY_CONFIGS"}}
             <button {{bindAttr disabled="view.parentView.hoveredServiceVersion.disabledActionAttr.revert" class=":btn :btn-default view.parentView.hoveredServiceVersion.isCurrent:not-allowed-cursor view.parentView.hoveredServiceVersion.isCompatible::hidden" title="view.parentView.hoveredServiceVersion.disabledActionMessages.revert"}} {{action doAction undefined view.parentView.actionTypes.REVERT target="view.parentView"}}>{{t dashboard.configHistory.info-bar.revert.button}}</button>
-          {{/isAuthorized}}
+          {{/havePermissions}}
         </div>
       {{/if}}
     {{/view}}

http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/templates/common/configs/service_version_box.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/common/configs/service_version_box.hbs b/ambari-web/app/templates/common/configs/service_version_box.hbs
index aaa4520..738b83d 100644
--- a/ambari-web/app/templates/common/configs/service_version_box.hbs
+++ b/ambari-web/app/templates/common/configs/service_version_box.hbs
@@ -46,16 +46,16 @@
         <button {{bindAttr disabled="view.disabledActionAttr.view" class=":btn :btn-default view.serviceVersion.isDisplayed:not-allowed-cursor" title="view.disabledActionMessages.view"}} {{action doAction view.serviceVersion view.actionTypes.SWITCH target="view.parentView"}}>
           <i class="glyphicon glyphicon-search"></i>&nbsp;{{t common.view}}
         </button>
-        {{#isAuthorized "SERVICE.COMPARE_CONFIGS"}}
+        {{#havePermissions "SERVICE.COMPARE_CONFIGS"}}
           <button {{bindAttr disabled="view.disabledActionAttr.compare" class=":btn :btn-default view.serviceVersion.isDisplayed:not-allowed-cursor" title="view.disabledActionMessages.compare"}} {{action doAction view.serviceVersion view.actionTypes.COMPARE target="view.parentView"}}>
             <i class="glyphicon glyphicon-copy"></i>&nbsp;{{t common.compare}}
           </button>
-        {{/isAuthorized}}
-        {{#isAuthorized "SERVICE.MODIFY_CONFIGS"}}
+        {{/havePermissions}}
+        {{#havePermissions "SERVICE.MODIFY_CONFIGS"}}
           <button {{bindAttr disabled="view.disabledActionAttr.revert" class=":btn :btn-default view.serviceVersion.isCurrent:not-allowed-cursor view.serviceVersion.isCompatible::hidden" title="view.disabledActionMessages.revert"}} {{action doAction view.serviceVersion view.actionTypes.REVERT target="view.parentView"}}>
             {{t dashboard.configHistory.info-bar.revert.button}}
           </button>
-        {{/isAuthorized}}
+        {{/havePermissions}}
       </div>
     </div>
   </div>

http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/templates/common/host_progress_popup.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/common/host_progress_popup.hbs b/ambari-web/app/templates/common/host_progress_popup.hbs
index f5b1c73..31358e4 100644
--- a/ambari-web/app/templates/common/host_progress_popup.hbs
+++ b/ambari-web/app/templates/common/host_progress_popup.hbs
@@ -256,11 +256,11 @@
           <div class="col-sm-12">
             {{#if App.supports.logSearch}}
               {{#if view.isLogSearchInstalled}}
-                {{#isAuthorized "SERVICE.VIEW_OPERATIONAL_LOGS"}}
-                  <button type="button" class="btn btn-link pull-right" {{action navigateToHostLogs target="view"}} {{bindAttr class="view.isLogsLinkVisible::hidden"}}>
+                {{#havePermissions "SERVICE.VIEW_OPERATIONAL_LOGS"}}
+                  <button type="button" class="btn btn-link pull-right" {{action navigateToHostLogs target="view"}} {{bindAttr class="view.isLogsLinkVisible::hidden" disabled="App.router.wizardWatcherController.isNonWizardUser"}}>
                     <i class="glyphicon glyphicon-file"></i>&nbsp;{{t common.host}} {{t common.logs}}
                   </button>
-                {{/isAuthorized}}
+                {{/havePermissions}}
               {{/if}}
             {{/if}}
             <button type="button" class="btn btn-link pull-right" {{translateAttr title="common.openNewWindow"}} {{action openTaskLogInDialog}}>

http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/templates/common/modal_popups/widget_browser_popup.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/common/modal_popups/widget_browser_popup.hbs b/ambari-web/app/templates/common/modal_popups/widget_browser_popup.hbs
index 2cc40c2..9910d07 100644
--- a/ambari-web/app/templates/common/modal_popups/widget_browser_popup.hbs
+++ b/ambari-web/app/templates/common/modal_popups/widget_browser_popup.hbs
@@ -26,13 +26,13 @@
           <li {{bindAttr class="service.isActive:active"}}>
             <a {{action "filterByService" service.value target="view"}}>{{service.label}}</a></li>
         {{/each}}
-        {{#isAuthorized "SERVICE.MODIFY_CONFIGS"}}
+        {{#havePermissions "SERVICE.MODIFY_CONFIGS"}}
           <li class="pull-right">
-            <button type="button" class="btn btn-primary" {{action "createWidget" target="view"}} >
+            <button type="button" class="btn btn-primary" {{bindAttr disabled="App.router.wizardWatcherController.isNonWizardUser"}} {{action "createWidget" target="view"}} >
               <i class="glyphicon glyphicon-plus"></i> &nbsp; {{t dashboard.widgets.create}}
             </button>
           </li>
-        {{/isAuthorized}}
+        {{/havePermissions}}
       </ul>
 
       <!--Widgets table two column-->

http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/templates/experimental.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/experimental.hbs b/ambari-web/app/templates/experimental.hbs
index c3d9eba..80d9e3d 100644
--- a/ambari-web/app/templates/experimental.hbs
+++ b/ambari-web/app/templates/experimental.hbs
@@ -56,14 +56,14 @@
   </div>
     <hr>
     <div class="control-group" style="margin-bottom: 100px;">
-      {{#isAuthorized "CLUSTER.MANAGE_USER_PERSISTED_DATA"}}
+      {{#havePermissions "CLUSTER.MANAGE_USER_PERSISTED_DATA"}}
         <div class="pull-left" style="margin-bottom: 100px;">
-          <button class="btn btn-danger" {{action doResetUIStates target="controller"}}>{{t reset.ui.states}}</button>
+          <button class="btn btn-danger" {{bindAttr disabled="App.router.wizardWatcherController.isNonWizardUser"}} {{action doResetUIStates target="controller"}}>{{t reset.ui.states}}</button>
           <p class="pull-right" style="margin-left: 10px; padding-top: 5px;">
               Reset UI state locally and on the server
           </p>
         </div>
-      {{/isAuthorized}}
+      {{/havePermissions}}
     </div>
   {{else}}
     <div class="alert alert-danger">

http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/templates/main/admin/stack_upgrade/versions.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/admin/stack_upgrade/versions.hbs b/ambari-web/app/templates/main/admin/stack_upgrade/versions.hbs
index edcb37c..47f9a2d 100644
--- a/ambari-web/app/templates/main/admin/stack_upgrade/versions.hbs
+++ b/ambari-web/app/templates/main/admin/stack_upgrade/versions.hbs
@@ -17,11 +17,11 @@
 }}
 
 <div id="versions-filter-section" class="btn-toolbar">
-  {{#isAuthorized "AMBARI.MANAGE_STACK_VERSIONS"}}
-    <button class="btn btn-primary" {{action goToVersions target="view"}} id="manage-versions-link">
+  {{#havePermissions "AMBARI.MANAGE_STACK_VERSIONS"}}
+    <button class="btn btn-primary" {{action goToVersions target="view"}}  {{bindAttr disabled="App.router.wizardWatcherController.isNonWizardUser"}} id="manage-versions-link">
         <i class="icon-external-link"></i>&nbsp;{{t admin.stackVersions.manageVersions}}
     </button>
-  {{/isAuthorized}}
+  {{/havePermissions}}
   <div class="btn-group display-inline-block">
     <button class="btn btn-default dropdown-toggle" data-toggle="dropdown" href="#">
       <span class="filters-label">{{t common.filter}}: </span>

http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/templates/main/host.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/host.hbs b/ambari-web/app/templates/main/host.hbs
index b373c40..07a9e7f 100644
--- a/ambari-web/app/templates/main/host.hbs
+++ b/ambari-web/app/templates/main/host.hbs
@@ -22,9 +22,9 @@
     <h2 class="table-title col-sm-1">{{t common.hosts}}</h2>
     <div class="table-controls row col-sm-10 pull-right">
       <div class="col-sm-12">
-        {{#isAuthorized "HOST.ADD_DELETE_COMPONENTS, HOST.TOGGLE_MAINTENANCE, HOST.ADD_DELETE_HOSTS"}}
+        {{#havePermissions "HOST.ADD_DELETE_COMPONENTS, HOST.TOGGLE_MAINTENANCE, HOST.ADD_DELETE_HOSTS"}}
           {{view App.HostTableMenuView}}
-        {{/isAuthorized}}
+        {{/havePermissions}}
         <div class="col-sm-10 pull-right">
           {{outlet}}
         </div>

http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/templates/main/host/bulk_operation_menu.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/host/bulk_operation_menu.hbs b/ambari-web/app/templates/main/host/bulk_operation_menu.hbs
index 89551ca..d7bf8bd 100644
--- a/ambari-web/app/templates/main/host/bulk_operation_menu.hbs
+++ b/ambari-web/app/templates/main/host/bulk_operation_menu.hbs
@@ -16,7 +16,8 @@
 * limitations under the License.
 }}
 
-<button class="btn btn-success dropdown-toggle" data-toggle="dropdown" href="#">{{t common.actions}} <span class="caret"></span></button>
+<button class="btn btn-success dropdown-toggle" data-toggle="dropdown" href="#" {{bindAttr disabled="App.router.wizardWatcherController.isNonWizardUser"}}>{{t common.actions}} <span class="caret"></span></button>
+{{#unless App.router.wizardWatcherController.isNonWizardUser}}
 <ul class="dropdown-menu">
   {{#isAuthorized "HOST.ADD_DELETE_HOSTS"}}
     <li><a href="#" {{action addHost}}><i class="glyphicon glyphicon-plus glyphicon-white"></i> {{t hosts.host.add}}</a></li>
@@ -151,3 +152,4 @@
     </div>
   </li>
 </ul>
+{{/unless}}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/templates/main/host/details/host_component.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/host/details/host_component.hbs b/ambari-web/app/templates/main/host/details/host_component.hbs
index d94dd3b..28d2acf 100644
--- a/ambari-web/app/templates/main/host/details/host_component.hbs
+++ b/ambari-web/app/templates/main/host/details/host_component.hbs
@@ -54,112 +54,114 @@
   </span>
 </div>
 <div class="col-md-5 col-lg-4">
-  {{#isAuthorized "SERVICE.DECOMMISSION_RECOMMISSION"}}
+  {{#havePermissions "SERVICE.DECOMMISSION_RECOMMISSION"}}
     <div class="dropdown">
-      <button {{ bindAttr class="view.disabled :btn :btn-default :btn-block :dropdown-toggle"}} data-toggle="dropdown">
+      <button {{ bindAttr class="view.disabled :btn :btn-default :btn-block :dropdown-toggle" disabled="App.router.wizardWatcherController.isNonWizardUser"}} data-toggle="dropdown">
         {{view.componentTextStatus}}
         <span class="caret pull-right button-caret-margin"></span>
       </button>
-      <ul class="dropdown-menu">
-        {{#if view.isComponentDecommissionAvailable}}
-          {{view view.decommissionView}}
-        {{/if}}
-        {{#if view.isComponentRecommissionAvailable}}
-          {{view view.decommissionView}}
-        {{/if}}
-        {{#if view.isRestartableComponent}}
-          <li {{bindAttr class="view.isRestartComponentDisabled:hidden"}}>
-            <a href="javascript:void(null)" data-toggle="modal" {{action "restartComponent" view.content target="controller"}}>
-              {{t common.restart}}
-            </a>
-          </li>
-        {{/if}}
-        {{#unless view.isInstalling}}
-          {{#isAuthorized "SERVICE.START_STOP"}}
-            {{#if view.isStart}}
-              <li {{bindAttr class="view.isComponentDecommissioning:hidden view.noActionAvailable"}}>
-                <a href="javascript:void(null)" data-toggle="modal" {{action "stopComponent" view.content target="controller"}}>
-                  {{t common.stop}}
+      {{#unless App.router.wizardWatcherController.isNonWizardUser}}
+        <ul class="dropdown-menu">
+          {{#if view.isComponentDecommissionAvailable}}
+            {{view view.decommissionView}}
+          {{/if}}
+          {{#if view.isComponentRecommissionAvailable}}
+            {{view view.decommissionView}}
+          {{/if}}
+          {{#if view.isRestartableComponent}}
+            <li {{bindAttr class="view.isRestartComponentDisabled:hidden"}}>
+              <a href="javascript:void(null)" data-toggle="modal" {{action "restartComponent" view.content target="controller"}}>
+                {{t common.restart}}
+              </a>
+            </li>
+          {{/if}}
+          {{#unless view.isInstalling}}
+            {{#isAuthorized "SERVICE.START_STOP"}}
+              {{#if view.isStart}}
+                <li {{bindAttr class="view.isComponentDecommissioning:hidden view.noActionAvailable"}}>
+                  <a href="javascript:void(null)" data-toggle="modal" {{action "stopComponent" view.content target="controller"}}>
+                    {{t common.stop}}
+                  </a>
+                </li>
+              {{/if}}
+              {{#unless view.isStart}}
+                {{#unless view.isInit}}
+                  <li {{bindAttr class="view.isUpgradeFailed:hidden view.isInstallFailed:hidden view.isDecommissioning:hidden view.noActionAvailable"}}>
+                    <a href="javascript:void(null)" data-toggle="modal" {{action "startComponent" view.content target="controller"}}>
+                      {{t common.start}}
+                    </a>
+                  </li>
+                {{/unless}}
+              {{/unless}}
+            {{/isAuthorized}}
+            {{#if view.isUpgradeFailed}}
+              <li {{bindAttr class="view.noActionAvailable"}}>
+                <a href="javascript:void(null)" data-toggle="modal" {{action "upgradeComponent" view.content target="controller"}}>
+                  {{t common.reUpgrade}}
+                </a>
+              </li>
+            {{/if}}
+            {{#if view.isInstallFailed}}
+              <li {{bindAttr class="view.noActionAvailable"}}>
+                <a href="javascript:void(null)" data-toggle="modal" {{action "installComponent" view.content target="controller"}}>
+                  {{t common.reinstall}}
                 </a>
               </li>
             {{/if}}
-            {{#unless view.isStart}}
-              {{#unless view.isInit}}
-                <li {{bindAttr class="view.isUpgradeFailed:hidden view.isInstallFailed:hidden view.isDecommissioning:hidden view.noActionAvailable"}}>
-                  <a href="javascript:void(null)" data-toggle="modal" {{action "startComponent" view.content target="controller"}}>
-                    {{t common.start}}
+            {{#if view.isReassignable}}
+              {{#isAuthorized "SERVICE.MOVE"}}
+                <li {{bindAttr class="view.noActionAvailable view.isMoveComponentDisabled:disabled"}}>
+                  <a href="javascript:void(null)" data-toggle="modal" {{action "moveComponent" view.content target="controller"}}>
+                    {{t common.move}}
                   </a>
                 </li>
-              {{/unless}}
-            {{/unless}}
-          {{/isAuthorized}}
-          {{#if view.isUpgradeFailed}}
-            <li {{bindAttr class="view.noActionAvailable"}}>
-              <a href="javascript:void(null)" data-toggle="modal" {{action "upgradeComponent" view.content target="controller"}}>
-                {{t common.reUpgrade}}
+              {{/isAuthorized}}
+            {{/if}}
+            {{#isAuthorized "HOST.TOGGLE_MAINTENANCE"}}
+              <li {{bindAttr class="view.noActionAvailable view.content.isImpliedState:disabled :allow-tooltip"}}
+                {{bindAttr data-original-title="view.maintenanceTooltip"}} rel="passiveTooltip" >
+              <a href="javascript:void(null)"
+                 data-toggle="modal" {{action "toggleMaintenanceMode" view.content target="controller"}}>
+                {{#if view.isActive}}
+                  {{t passiveState.turnOn}}
+                {{else}}
+                  {{t passiveState.turnOff}}
+                {{/if}}
               </a>
             </li>
-          {{/if}}
-          {{#if view.isInstallFailed}}
-            <li {{bindAttr class="view.noActionAvailable"}}>
+            {{/isAuthorized}}
+          {{/unless}}
+          {{#if view.isInit}}
+            <li>
               <a href="javascript:void(null)" data-toggle="modal" {{action "installComponent" view.content target="controller"}}>
                 {{t common.reinstall}}
               </a>
             </li>
           {{/if}}
-          {{#if view.isReassignable}}
-            {{#isAuthorized "SERVICE.MOVE"}}
-              <li {{bindAttr class="view.noActionAvailable view.isMoveComponentDisabled:disabled"}}>
-                <a href="javascript:void(null)" data-toggle="modal" {{action "moveComponent" view.content target="controller"}}>
-                  {{t common.move}}
-                </a>
+          {{#if view.isDeletableComponent}}
+            {{#isAuthorized "HOST.ADD_DELETE_COMPONENTS"}}
+              <li {{bindAttr class="view.isDeleteComponentDisabled:disabled"}}>
+                  <a href="javascript:void(null)" data-toggle="modal" {{action "deleteComponent" view.content target="controller"}}>
+                    {{t common.delete}}
+                  </a>
               </li>
             {{/isAuthorized}}
           {{/if}}
-          {{#isAuthorized "HOST.TOGGLE_MAINTENANCE"}}
-            <li {{bindAttr class="view.noActionAvailable view.content.isImpliedState:disabled :allow-tooltip"}}
-              {{bindAttr data-original-title="view.maintenanceTooltip"}} rel="passiveTooltip" >
-            <a href="javascript:void(null)"
-               data-toggle="modal" {{action "toggleMaintenanceMode" view.content target="controller"}}>
-              {{#if view.isActive}}
-                {{t passiveState.turnOn}}
-              {{else}}
-                {{t passiveState.turnOff}}
-              {{/if}}
-            </a>
-          </li>
-          {{/isAuthorized}}
-        {{/unless}}
-        {{#if view.isInit}}
-          <li>
-            <a href="javascript:void(null)" data-toggle="modal" {{action "installComponent" view.content target="controller"}}>
-              {{t common.reinstall}}
-            </a>
-          </li>
-        {{/if}}
-        {{#if view.isDeletableComponent}}
-          {{#isAuthorized "HOST.ADD_DELETE_COMPONENTS"}}
-            <li {{bindAttr class="view.isDeleteComponentDisabled:disabled"}}>
-                <a href="javascript:void(null)" data-toggle="modal" {{action "deleteComponent" view.content target="controller"}}>
-                  {{t common.delete}}
-                </a>
-            </li>
-          {{/isAuthorized}}
-        {{/if}}
-        {{#if view.isRefreshConfigsAllowed}}
-            <li>
-                <a href="javascript:void(null)" data-toggle="modal" {{action "refreshComponentConfigs" view.content target="controller"}}>
-                  {{t hosts.host.details.refreshConfigs}}
-                </a>
-            </li>
-        {{/if}}
+          {{#if view.isRefreshConfigsAllowed}}
+              <li>
+                  <a href="javascript:void(null)" data-toggle="modal" {{action "refreshComponentConfigs" view.content target="controller"}}>
+                    {{t hosts.host.details.refreshConfigs}}
+                  </a>
+              </li>
+          {{/if}}
 
-      {{#each command in view.customCommands}}
-        <li {{bindAttr class="command.disabled:disabled"}}>
-          <a href="javascript:void(null)" {{action "executeCustomCommand" command target="controller" href=true}}>{{command.label}}</a>
-        </li>
-      {{/each}}
-      </ul>
+        {{#each command in view.customCommands}}
+          <li {{bindAttr class="command.disabled:disabled"}}>
+            <a href="javascript:void(null)" {{action "executeCustomCommand" command target="controller" href=true}}>{{command.label}}</a>
+          </li>
+        {{/each}}
+        </ul>
+      {{/unless}}
     </div>
-  {{/isAuthorized}}
+  {{/havePermissions}}
 </div>

http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/templates/main/host/stack_versions.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/host/stack_versions.hbs b/ambari-web/app/templates/main/host/stack_versions.hbs
index 60e6571..cf167a4 100644
--- a/ambari-web/app/templates/main/host/stack_versions.hbs
+++ b/ambari-web/app/templates/main/host/stack_versions.hbs
@@ -54,9 +54,9 @@
           {{/if}}
         </td>
         <td class="install-repo-version align-center">
-          {{#isAuthorized "AMBARI.MANAGE_STACK_VERSIONS"}}
+          {{#havePermissions "AMBARI.MANAGE_STACK_VERSIONS"}}
             <button class="btn btn-default" {{action installVersionConfirmation version target="controller"}} {{bindAttr disabled="version.installDisabled"}}><i class="glyphicon glyphicon-off"></i>&nbsp;{{t common.install}}</button>
-          {{/isAuthorized}}
+          {{/havePermissions}}
         </td>
       </tr>
     {{/each}}

http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/templates/main/host/summary.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/host/summary.hbs b/ambari-web/app/templates/main/host/summary.hbs
index 84a1c5e..3ceb92f 100644
--- a/ambari-web/app/templates/main/host/summary.hbs
+++ b/ambari-web/app/templates/main/host/summary.hbs
@@ -26,38 +26,40 @@
             <h4 class="panel-title">{{t common.components}}</h4>
           </div>
           <div class="col-md-6">
-            {{#isAuthorized "HOST.ADD_DELETE_COMPONENTS"}}
+            {{#havePermissions "HOST.ADD_DELETE_COMPONENTS"}}
               <div class="dropdown pull-right">
-                <button id="add_component" data-toggle="dropdown" {{bindAttr class="view.addComponentDisabled:disabled :btn :btn-default :dropdown-toggle"}}>
+                <button id="add_component" data-toggle="dropdown" {{bindAttr class="view.addComponentDisabled:disabled :btn :btn-default :dropdown-toggle" disabled="App.router.wizardWatcherController.isNonWizardUser"}}>
                   <span class="glyphicon glyphicon-plus"></span>&nbsp;{{t add}}
                 </button>
-                <ul class="dropdown-menu">
-                  {{#each component in view.addableComponents}}
-                    <li>
-                      <a href="javascript:void(null)" data-toggle="modal" {{action addComponentWithCheck component target="controller"}}>
-                        {{component.displayName}}
-                      </a>
-                    </li>
-                  {{/each}}
-                </ul>
+                {{#unless App.router.wizardWatcherController.isNonWizardUser}}
+                  <ul class="dropdown-menu">
+                    {{#each component in view.addableComponents}}
+                      <li>
+                        <a href="javascript:void(null)" data-toggle="modal" {{action addComponentWithCheck component target="controller"}}>
+                          {{component.displayName}}
+                        </a>
+                      </li>
+                    {{/each}}
+                  </ul>
+                {{/unless}}
               </div>
-            {{/isAuthorized}}
+            {{/havePermissions}}
           </div>
         </div>
       </div>
       <div class="host-components panel-body">
           {{#if view.sortedComponents.length}}
 
-              {{#isAuthorized "SERVICE.MODIFY_CONFIGS, SERVICE.START_STOP, HOST.ADD_DELETE_COMPONENTS, HOST.TOGGLE_MAINTENANCE"}}
+              {{#havePermissions "SERVICE.MODIFY_CONFIGS, SERVICE.START_STOP, HOST.ADD_DELETE_COMPONENTS, HOST.TOGGLE_MAINTENANCE"}}
                   {{#if view.content.componentsWithStaleConfigsCount}}
                     <div class="alert alert-warning clearfix restart-required">
                       <i class="glyphicon glyphicon-refresh"></i> {{view.needToRestartMessage}}
-                      <button {{bindAttr class=":btn :restart-components :pull-right :btn-warning"}} {{action restartAllStaleConfigComponents target="controller"}}>
+                      <button {{bindAttr class=":btn :restart-components :pull-right :btn-warning" disabled="App.router.wizardWatcherController.isNonWizardUser"}} {{action restartAllStaleConfigComponents target="controller"}}>
                           {{t hosts.host.details.needToRestart.button}}
                       </button>
                     </div>
                   {{/if}}
-              {{/isAuthorized}}
+              {{/havePermissions}}
 
               {{#each component in view.sortedComponents}}
                 {{view component.viewClass classNames="row row-no-pad" contentBinding="component"}}
@@ -89,58 +91,60 @@
               {{/if}}
           </div>
           <div class="col-md-5 col-lg-4 pull-right">
-              {{#isAuthorized "SERVICE.MODIFY_CONFIGS, SERVICE.START_STOP, HOST.ADD_DELETE_COMPONENTS, HOST.TOGGLE_MAINTENANCE"}}
+              {{#havePermissions "SERVICE.MODIFY_CONFIGS, SERVICE.START_STOP, HOST.ADD_DELETE_COMPONENTS, HOST.TOGGLE_MAINTENANCE"}}
                   {{#if view.clients.length}}
                     <div class="dropdown">
                       <button id="add_component"
-                              data-toggle="dropdown" {{bindAttr class=":btn :btn-default :btn-block :dropdown-toggle controller.content.isNotHeartBeating:disabled"}}>
+                              data-toggle="dropdown" {{bindAttr disabled="App.router.wizardWatcherController.isNonWizardUser" class=":btn :btn-default :btn-block :dropdown-toggle controller.content.isNotHeartBeating:disabled"}}>
                           {{t common.installed}}
                         <span class="caret pull-right button-caret-margin"></span>
                       </button>
-                      <ul class="dropdown-menu">
-                        <li>
-                          <a href="javascript:void(null)"
-                             data-toggle="modal" {{action refreshConfigs view.clients target="controller"}}>
-                              {{t hosts.host.details.refreshConfigs}}
-                          </a>
-                        </li>
-                        <li>
-                          <a href="javascript:void(null)" {{bindAttr class="view.areClientsNotInstalled::disabled" }}
-                             data-toggle="modal" {{action installClients target="view"}}>
-                              {{t host.host.details.installClients}}
-                          </a>
-                        </li>
-                          {{#if view.anyClientFailedToInstall}}
-                            <li>
-                              <a href="javascript:void(null)" {{action reinstallClients target="view"}}>
-                                  {{t host.host.details.reinstallClients}}
-                              </a>
-                            </li>
-                          {{/if}}
-                          {{#each option in view.clientsWithCustomCommands}}
-                            <li class="dropdown-submenu submenu-left">
-                              <a href="javascript:void(null)">
-                                <i class="glyphicon glyphicon-play-circle"></i>
-                                  {{option.label}}
-                              </a>
+                      {{#unless App.router.wizardWatcherController.isNonWizardUser}}
+                        <ul class="dropdown-menu">
+                          <li>
+                            <a href="javascript:void(null)"
+                               data-toggle="modal" {{action refreshConfigs view.clients target="controller"}}>
+                                {{t hosts.host.details.refreshConfigs}}
+                            </a>
+                          </li>
+                          <li>
+                            <a href="javascript:void(null)" {{bindAttr class="view.areClientsNotInstalled::disabled" }}
+                               data-toggle="modal" {{action installClients target="view"}}>
+                                {{t host.host.details.installClients}}
+                            </a>
+                          </li>
+                            {{#if view.anyClientFailedToInstall}}
+                              <li>
+                                <a href="javascript:void(null)" {{action reinstallClients target="view"}}>
+                                    {{t host.host.details.reinstallClients}}
+                                </a>
+                              </li>
+                            {{/if}}
+                            {{#each option in view.clientsWithCustomCommands}}
+                              <li class="dropdown-submenu submenu-left">
+                                <a href="javascript:void(null)">
+                                  <i class="glyphicon glyphicon-play-circle"></i>
+                                    {{option.label}}
+                                </a>
 
-                              <div class="dropdown-menu-wrap">
-                                <ul class="dropdown-menu">
-                                    {{#each command in option.commands}}
-                                      <li>
-                                        <a href="javascript:void(null)" {{action "executeCustomCommand" command target="controller" href=true}}>
-                                          {{command.label}}
-                                        </a>
-                                      </li>
-                                    {{/each}}
-                                </ul>
-                              </div>
-                            </li>
-                          {{/each}}
-                      </ul>
+                                <div class="dropdown-menu-wrap">
+                                  <ul class="dropdown-menu">
+                                      {{#each command in option.commands}}
+                                        <li>
+                                          <a href="javascript:void(null)" {{action "executeCustomCommand" command target="controller" href=true}}>
+                                            {{command.label}}
+                                          </a>
+                                        </li>
+                                      {{/each}}
+                                  </ul>
+                                </div>
+                              </li>
+                            {{/each}}
+                        </ul>
+                      {{/unless}}
                     </div>
                   {{/if}}
-              {{/isAuthorized}}
+              {{/havePermissions}}
           </div>
         </div>
       </div>

http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/utils/helper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/helper.js b/ambari-web/app/utils/helper.js
index 3bc247c..baacdf3 100644
--- a/ambari-web/app/utils/helper.js
+++ b/ambari-web/app/utils/helper.js
@@ -445,6 +445,29 @@ Em.Handlebars.registerHelper('isAuthorized', function (property, options) {
 });
 
 /**
+ * Usage:
+ *
+ * <pre>
+ *   {{#havePermissions "SERVICE.TOGGLE_ALERTS"}}
+ *     {{! some truly code }}
+ *   {{else}}
+ *     {{! some falsy code }}
+ *   {{/havePermissions}}
+ * </pre>
+ */
+Em.Handlebars.registerHelper('havePermissions', function (property, options) {
+  var permission = Ember.Object.create({
+    havePermissions: function() {
+      return App.havePermissions(property);
+    }.property()
+  });
+
+  // wipe out contexts so boundIf uses `this` (the permission) as the context
+  options.contexts = null;
+  return Ember.Handlebars.helpers.boundIf.call(permission, "havePermissions", options);
+});
+
+/**
  * @namespace App
  */
 App = require('app');

http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/app/views/main/service/item.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/service/item.js b/ambari-web/app/views/main/service/item.js
index 45c783b..945dc8f 100644
--- a/ambari-web/app/views/main/service/item.js
+++ b/ambari-web/app/views/main/service/item.js
@@ -319,7 +319,7 @@ App.MainServiceItemView = Em.View.extend({
   }.property('maintenance'),
 
   hasConfigTab: function() {
-    return App.isAuthorized('CLUSTER.VIEW_CONFIGS', {ignoreWizard: true}) && !App.get('services.noConfigTypes').contains(this.get('controller.content.serviceName'));
+    return App.havePermissions('CLUSTER.VIEW_CONFIGS') && !App.get('services.noConfigTypes').contains(this.get('controller.content.serviceName'));
   }.property('controller.content.serviceName','App.services.noConfigTypes'),
 
   hasHeatmapTab: function() {

http://git-wip-us.apache.org/repos/asf/ambari/blob/84342f6a/ambari-web/test/views/main/service/item_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/main/service/item_test.js b/ambari-web/test/views/main/service/item_test.js
index e4a1940..b86d021 100644
--- a/ambari-web/test/views/main/service/item_test.js
+++ b/ambari-web/test/views/main/service/item_test.js
@@ -614,7 +614,7 @@ describe('App.MainServiceItemView', function () {
 
   describe('#hasConfigTab', function() {
     beforeEach(function() {
-      this.mockAuthorized = sinon.stub(App, 'isAuthorized');
+      this.mockAuthorized = sinon.stub(App, 'havePermissions');
       this.mockGet = sinon.stub(App, 'get').returns(['S2']);
     });
     afterEach(function() {
@@ -622,7 +622,7 @@ describe('App.MainServiceItemView', function () {
       this.mockGet.restore();
     });
 
-    it('should return false when not authorized', function() {
+    it('should return false when have not permissions', function() {
       this.mockAuthorized.returns(false);
       view.set('controller.content.serviceName', 'S1');
       expect(view.get('hasConfigTab')).to.be.false;
@@ -634,7 +634,7 @@ describe('App.MainServiceItemView', function () {
       expect(view.get('hasConfigTab')).to.be.false;
     });
 
-    it('should return true when authorized', function() {
+    it('should return true when have permissions', function() {
       this.mockAuthorized.returns(true);
       view.set('controller.content.serviceName', 'S1');
       expect(view.get('hasConfigTab')).to.be.true;


[34/46] ambari git commit: AMBARI-21307 Ldapconnection template optimization, basic support for custom trust store

Posted by lp...@apache.org.
AMBARI-21307 Ldapconnection template optimization, basic support for custom trust store


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 71292fb1c7ed2fe3e1368ec22ab5b1dbf952d724
Parents: 1939f09
Author: lpuskas <lp...@apache.org>
Authored: Mon Oct 9 17:20:38 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:42:01 2017 +0200

----------------------------------------------------------------------
 .../apache/ambari/server/ldap/LdapModule.java   |   8 +-
 .../service/LdapAttributeDetectionService.java  |   4 +-
 .../service/LdapConnectionConfigService.java    |  34 ++++++
 .../service/LdapConnectionTemplateProvider.java |  56 ---------
 .../DefaultLdapAttributeDetectionService.java   |   4 +-
 .../ads/DefaultLdapConfigurationService.java    |  11 +-
 .../ads/LdapConnectionTemplateFactory.java      |  56 +++++----
 .../DefaultLdapConnectionConfigService.java     | 116 +++++++++++++++++++
 .../server/ldap/LdapModuleFunctionalTest.java   |  28 +++++
 9 files changed, 224 insertions(+), 93 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/71292fb1/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
index d59264a..4abf4e7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
@@ -21,11 +21,11 @@ import org.apache.ambari.server.ldap.service.AmbariLdapConfigurationProvider;
 import org.apache.ambari.server.ldap.service.AmbariLdapFacade;
 import org.apache.ambari.server.ldap.service.LdapAttributeDetectionService;
 import org.apache.ambari.server.ldap.service.LdapConfigurationService;
-import org.apache.ambari.server.ldap.service.LdapConnectionTemplateProvider;
+import org.apache.ambari.server.ldap.service.LdapConnectionConfigService;
 import org.apache.ambari.server.ldap.service.LdapFacade;
 import org.apache.ambari.server.ldap.service.ads.DefaultLdapAttributeDetectionService;
 import org.apache.ambari.server.ldap.service.ads.DefaultLdapConfigurationService;
-import org.apache.directory.ldap.client.template.LdapConnectionTemplate;
+import org.apache.ambari.server.ldap.service.ads.detectors.DefaultLdapConnectionConfigService;
 
 import com.google.inject.AbstractModule;
 import com.google.inject.assistedinject.FactoryModuleBuilder;
@@ -40,13 +40,11 @@ public class LdapModule extends AbstractModule {
     bind(LdapFacade.class).to(AmbariLdapFacade.class);
     bind(LdapConfigurationService.class).to(DefaultLdapConfigurationService.class);
     bind(LdapAttributeDetectionService.class).to(DefaultLdapAttributeDetectionService.class);
+    bind(LdapConnectionConfigService.class).to(DefaultLdapConnectionConfigService.class);
 
     // this binding requires the JPA module!
     bind(AmbariLdapConfiguration.class).toProvider(AmbariLdapConfigurationProvider.class);
 
-    // bind to the provider implementation (let GUICE deal with instantiating 3rd party instances)
-    bind(LdapConnectionTemplate.class).toProvider(LdapConnectionTemplateProvider.class);
-
     install(new FactoryModuleBuilder().build(AmbariLdapConfigurationFactory.class));
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/71292fb1/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapAttributeDetectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapAttributeDetectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapAttributeDetectionService.java
index 6cd369b..c08a2e0 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapAttributeDetectionService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapAttributeDetectionService.java
@@ -27,7 +27,7 @@ public interface LdapAttributeDetectionService {
    * @param ambariLdapConfiguration configuration instance holding connection details
    * @return the configuration decorated with user related attributes
    */
-  AmbariLdapConfiguration detectLdapUserAttributes(AmbariLdapConfiguration ambariLdapConfiguration);
+  AmbariLdapConfiguration detectLdapUserAttributes(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException;
 
   /**
    * Decorates the passed in configuration with the detected ldap group attribute values
@@ -35,6 +35,6 @@ public interface LdapAttributeDetectionService {
    * @param ambariLdapConfiguration configuration instance holding connection details
    * @return the configuration decorated with group related attributes
    */
-  AmbariLdapConfiguration detectLdapGroupAttributes(AmbariLdapConfiguration ambariLdapConfiguration);
+  AmbariLdapConfiguration detectLdapGroupAttributes(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException;
 }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/71292fb1/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionConfigService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionConfigService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionConfigService.java
new file mode 100644
index 0000000..e2055bb
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionConfigService.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service;
+
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
+import org.apache.directory.ldap.client.api.LdapConnectionConfig;
+
+/**
+ * Contract for creating connection configuration instances
+ */
+public interface LdapConnectionConfigService {
+
+  /**
+   * Creates and sets up an ldap connection configuration instance based on the provided ambari ldap configuration instance.
+   *
+   * @param ambariLdapConfiguration instance holding configuration values
+   * @return a set up ldap connection configuration instance
+   * @throws AmbariLdapException if an error occurs while setting up the connection configuration
+   */
+  LdapConnectionConfig createLdapConnectionConfig(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException;
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/71292fb1/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionTemplateProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionTemplateProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionTemplateProvider.java
deleted file mode 100644
index 5ed06e3..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionTemplateProvider.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.service;
-
-
-import javax.inject.Inject;
-import javax.inject.Provider;
-
-import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
-import org.apache.directory.ldap.client.api.DefaultLdapConnectionFactory;
-import org.apache.directory.ldap.client.api.LdapConnectionConfig;
-import org.apache.directory.ldap.client.api.LdapConnectionFactory;
-import org.apache.directory.ldap.client.api.LdapConnectionPool;
-import org.apache.directory.ldap.client.api.ValidatingPoolableLdapConnectionFactory;
-import org.apache.directory.ldap.client.template.LdapConnectionTemplate;
-
-public class LdapConnectionTemplateProvider implements Provider<LdapConnectionTemplate> {
-
-  // Inject the persisted configuration (when available) check the provider implementation for details.
-  @Inject
-  private Provider<AmbariLdapConfiguration> ambariLdapConfigurationProvider;
-
-  @Override
-  public LdapConnectionTemplate get() {
-    return new LdapConnectionTemplate(new LdapConnectionPool(
-      new ValidatingPoolableLdapConnectionFactory(getLdapConnectionFactory())));
-  }
-
-  private LdapConnectionConfig getLdapConnectionConfig() {
-    LdapConnectionConfig config = new LdapConnectionConfig();
-    config.setLdapHost(ambariLdapConfigurationProvider.get().serverHost());
-    config.setLdapPort(ambariLdapConfigurationProvider.get().serverPort());
-    config.setName(ambariLdapConfigurationProvider.get().bindDn());
-    config.setCredentials(ambariLdapConfigurationProvider.get().bindPassword());
-
-    return config;
-  }
-
-  private LdapConnectionFactory getLdapConnectionFactory() {
-    return new DefaultLdapConnectionFactory(getLdapConnectionConfig());
-  }
-
-
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/71292fb1/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
index 639d48d..204c46a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
@@ -73,7 +73,7 @@ public class DefaultLdapAttributeDetectionService implements LdapAttributeDetect
   }
 
   @Override
-  public AmbariLdapConfiguration detectLdapUserAttributes(AmbariLdapConfiguration ambariLdapConfiguration) {
+  public AmbariLdapConfiguration detectLdapUserAttributes(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
     LOGGER.info("Detecting LDAP user attributes ...");
     LdapConnectionTemplate ldapConnectionTemplate = ldapConnectionTemplateFactory.create(ambariLdapConfiguration);
 
@@ -116,7 +116,7 @@ public class DefaultLdapAttributeDetectionService implements LdapAttributeDetect
 
 
   @Override
-  public AmbariLdapConfiguration detectLdapGroupAttributes(AmbariLdapConfiguration ambariLdapConfiguration) {
+  public AmbariLdapConfiguration detectLdapGroupAttributes(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
     LOGGER.info("Detecting LDAP group attributes ...");
 
     // perform a search using the user search base

http://git-wip-us.apache.org/repos/asf/ambari/blob/71292fb1/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
index bbe4d0a..60c1272 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
@@ -28,7 +28,6 @@ import org.apache.directory.api.ldap.model.constants.SchemaConstants;
 import org.apache.directory.api.ldap.model.entry.Entry;
 import org.apache.directory.api.ldap.model.exception.LdapException;
 import org.apache.directory.api.ldap.model.message.SearchRequest;
-import org.apache.directory.api.ldap.model.message.SearchRequestImpl;
 import org.apache.directory.api.ldap.model.message.SearchScope;
 import org.apache.directory.api.ldap.model.name.Dn;
 import org.apache.directory.ldap.client.api.LdapConnection;
@@ -117,7 +116,6 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
 
   /**
    * Checks whether the provided group related settings are correct.
-   * The algorithm implemented in this method per
    *
    * @param userDn                  a user DN to check
    * @param ambariLdapConfiguration the available LDAP configuration to be validated
@@ -137,18 +135,15 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
       ).toString();
 
       LOGGER.info("Searching for the groups the user dn: {} is member of using the search filter: {}", userDn, filter);
+      LdapConnectionTemplate ldapConnectionTemplate = ldapConnectionTemplateFactory.create(ambariLdapConfiguration);
 
       // assemble a search request
-      SearchRequest searchRequest = new SearchRequestImpl();
-      searchRequest.setFilter(filter);
-      searchRequest.setBase(new Dn(ambariLdapConfiguration.groupSearchBase()));
-      searchRequest.setScope(SearchScope.SUBTREE);
+      SearchRequest searchRequest = ldapConnectionTemplate.newSearchRequest(new Dn(ambariLdapConfiguration.groupSearchBase()), filter, SearchScope.SUBTREE);
       // attributes to be returned
       searchRequest.addAttributes(ambariLdapConfiguration.groupMemberAttribute(), ambariLdapConfiguration.groupNameAttribute());
 
       // perform the search
-      groups = ldapConnectionTemplateFactory.create(ambariLdapConfiguration).search(searchRequest, getGroupNameEntryMapper(ambariLdapConfiguration));
-
+      groups = ldapConnectionTemplate.search(searchRequest, getGroupNameEntryMapper(ambariLdapConfiguration));
 
     } catch (Exception e) {
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/71292fb1/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/LdapConnectionTemplateFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/LdapConnectionTemplateFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/LdapConnectionTemplateFactory.java
index 50345bc..8467af0 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/LdapConnectionTemplateFactory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/LdapConnectionTemplateFactory.java
@@ -18,7 +18,10 @@ import javax.inject.Inject;
 import javax.inject.Provider;
 import javax.inject.Singleton;
 
+import org.apache.ambari.server.events.AmbariLdapConfigChangedEvent;
 import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.service.AmbariLdapException;
+import org.apache.ambari.server.ldap.service.LdapConnectionConfigService;
 import org.apache.directory.ldap.client.api.DefaultLdapConnectionFactory;
 import org.apache.directory.ldap.client.api.LdapConnectionConfig;
 import org.apache.directory.ldap.client.api.LdapConnectionFactory;
@@ -28,6 +31,8 @@ import org.apache.directory.ldap.client.template.LdapConnectionTemplate;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.eventbus.Subscribe;
+
 /**
  * Factory for creating LdapConnectionTemplate instances.
  * Depending on the usage context, the instance can be constructed based on the provided configuration or based on the persisted settings.
@@ -37,8 +42,17 @@ public class LdapConnectionTemplateFactory {
 
   private static final Logger LOG = LoggerFactory.getLogger(LdapConnectionTemplateFactory.class);
 
+  // Inject the persisted configuration (when available) check the provider implementation for details.
+  @Inject
+  private Provider<AmbariLdapConfiguration> ambariLdapConfigurationProvider;
+
+
   @Inject
-  private Provider<LdapConnectionTemplate> ldapConnectionTemplate;
+  private LdapConnectionConfigService ldapConnectionConfigService;
+
+  // cached instance that only changes when the underlying configuration changes.
+  private LdapConnectionTemplate ldapConnectionTemplateInstance;
+
 
   @Inject
   public LdapConnectionTemplateFactory() {
@@ -50,11 +64,11 @@ public class LdapConnectionTemplateFactory {
    * @param ambariLdapConfiguration ambari ldap configuration instance
    * @return an instance of LdapConnectionTemplate
    */
-  public LdapConnectionTemplate create(AmbariLdapConfiguration ambariLdapConfiguration) {
+  public LdapConnectionTemplate create(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
     LOG.info("Constructing new instance based on the provided ambari ldap configuration: {}", ambariLdapConfiguration);
 
     // create the connection config
-    LdapConnectionConfig ldapConnectionConfig = getLdapConnectionConfig(ambariLdapConfiguration);
+    LdapConnectionConfig ldapConnectionConfig = ldapConnectionConfigService.createLdapConnectionConfig(ambariLdapConfiguration);
 
     // create the connection factory
     LdapConnectionFactory ldapConnectionFactory = new DefaultLdapConnectionFactory(ldapConnectionConfig);
@@ -69,26 +83,28 @@ public class LdapConnectionTemplateFactory {
 
   }
 
-  public LdapConnectionTemplate load() {
-    // the construction logic is implemented in the provider class
-    return ldapConnectionTemplate.get();
-  }
-
-
-  private LdapConnectionConfig getLdapConnectionConfig(AmbariLdapConfiguration ambariLdapConfiguration) {
-
-    LdapConnectionConfig config = new LdapConnectionConfig();
-    config.setLdapHost(ambariLdapConfiguration.serverHost());
-    config.setLdapPort(ambariLdapConfiguration.serverPort());
-    config.setName(ambariLdapConfiguration.bindDn());
-    config.setCredentials(ambariLdapConfiguration.bindPassword());
+  /**
+   * Loads the persisted LDAP configuration.
+   *
+   * @return theh persisted
+   */
+  public LdapConnectionTemplate load() throws AmbariLdapException {
 
-    // todo set the other required properties here, eg.: trustmanager
-    return config;
+    if (null == ldapConnectionTemplateInstance) {
+      ldapConnectionTemplateInstance = create(ambariLdapConfigurationProvider.get());
+    }
+    return ldapConnectionTemplateInstance;
   }
 
-  private LdapConnectionFactory getLdapConnectionFactory(AmbariLdapConfiguration ambariLdapConfiguration) {
-    return new DefaultLdapConnectionFactory(getLdapConnectionConfig(ambariLdapConfiguration));
+  /**
+   * The returned connection template instance is recreated whenever the ambari ldap configuration changes
+   *
+   * @param event
+   * @throws AmbariLdapException
+   */
+  @Subscribe
+  public void onConfigChange(AmbariLdapConfigChangedEvent event) throws AmbariLdapException {
+    ldapConnectionTemplateInstance = create(ambariLdapConfigurationProvider.get());
   }
 
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/71292fb1/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/DefaultLdapConnectionConfigService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/DefaultLdapConnectionConfigService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/DefaultLdapConnectionConfigService.java
new file mode 100644
index 0000000..b12cc85
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/DefaultLdapConnectionConfigService.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads.detectors;
+
+import static javax.net.ssl.TrustManagerFactory.getDefaultAlgorithm;
+
+import java.io.FileInputStream;
+import java.security.KeyStore;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
+
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.service.AmbariLdapException;
+import org.apache.ambari.server.ldap.service.LdapConnectionConfigService;
+import org.apache.directory.api.util.Strings;
+import org.apache.directory.ldap.client.api.LdapConnectionConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Singleton
+public class DefaultLdapConnectionConfigService implements LdapConnectionConfigService {
+
+  private static Logger LOG = LoggerFactory.getLogger(DefaultLdapConnectionConfigService.class);
+
+  @Inject
+  public DefaultLdapConnectionConfigService() {
+  }
+
+  @Override
+  public LdapConnectionConfig createLdapConnectionConfig(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+
+    LOG.debug("Assembling ldap connection config based on: {}", ambariLdapConfiguration);
+
+    LdapConnectionConfig config = new LdapConnectionConfig();
+    config.setLdapHost(ambariLdapConfiguration.serverHost());
+    config.setLdapPort(ambariLdapConfiguration.serverPort());
+    config.setName(ambariLdapConfiguration.bindDn());
+    config.setCredentials(ambariLdapConfiguration.bindPassword());
+    config.setUseSsl(ambariLdapConfiguration.useSSL());
+
+    // todo implement proper validation logic here: identify optional/mandatory settings
+    // todo suggest proper naming
+    if ("custom".equals(ambariLdapConfiguration.trustStore())) {
+      LOG.info("Using custom trust manager configuration");
+      config.setTrustManagers(trustManagers(ambariLdapConfiguration));
+    }
+
+
+    return config;
+  }
+
+
+  /**
+   * Configure the trustmanagers to use the custom keystore.
+   *
+   * @param ambariLdapConfiguration congiguration instance holding current values
+   * @return the array of trust managers
+   * @throws AmbariLdapException if an error occurs while setting up the connection
+   */
+  private TrustManager[] trustManagers(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+    try {
+
+      TrustManagerFactory tmFactory = TrustManagerFactory.getInstance(getDefaultAlgorithm());
+      tmFactory.init(keyStore(ambariLdapConfiguration));
+      return tmFactory.getTrustManagers();
+
+    } catch (Exception e) {
+
+      LOG.error("Failed to initialize trust managers", e);
+      throw new AmbariLdapException(e);
+
+    }
+
+  }
+
+  private KeyStore keyStore(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+
+    // validating configuration settings
+    if (Strings.isEmpty(ambariLdapConfiguration.trustStoreType())) {
+      throw new AmbariLdapException("Key Store Type must be specified");
+    }
+
+    if (Strings.isEmpty(ambariLdapConfiguration.trustStorePath())) {
+      throw new AmbariLdapException("Key Store Path must be specified");
+    }
+
+    try {
+
+      KeyStore ks = KeyStore.getInstance(ambariLdapConfiguration.trustStoreType());
+      FileInputStream fis = new FileInputStream(ambariLdapConfiguration.trustStorePath());
+      ks.load(fis, ambariLdapConfiguration.trustStorePassword().toCharArray());
+      return ks;
+
+    } catch (Exception e) {
+
+      LOG.error("Failed to create keystore", e);
+      throw new AmbariLdapException(e);
+
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/71292fb1/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
index 8059723..b9f140e 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
@@ -21,6 +21,7 @@ import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
 import org.apache.ambari.server.ldap.domain.TestAmbariAmbariLdapConfigurationFactory;
 import org.apache.ambari.server.ldap.service.LdapConfigurationService;
 import org.apache.ambari.server.ldap.service.LdapFacade;
+import org.apache.ambari.server.ldap.service.ads.LdapConnectionTemplateFactory;
 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
 import org.apache.directory.api.ldap.model.exception.LdapException;
 import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
@@ -130,14 +131,41 @@ public class LdapModuleFunctionalTest {
     ldapPropsMap.put(AmbariLdapConfigKeys.SERVER_PORT.key(), "389");
     ldapPropsMap.put(AmbariLdapConfigKeys.BIND_DN.key(), "cn=read-only-admin,dc=example,dc=com");
     ldapPropsMap.put(AmbariLdapConfigKeys.BIND_PASSWORD.key(), "password");
+    ldapPropsMap.put(AmbariLdapConfigKeys.USE_SSL.key(), "true");
 
     ldapPropsMap.put(AmbariLdapConfigKeys.USER_OBJECT_CLASS.key(), SchemaConstants.PERSON_OC);
     ldapPropsMap.put(AmbariLdapConfigKeys.USER_NAME_ATTRIBUTE.key(), SchemaConstants.UID_AT);
     ldapPropsMap.put(AmbariLdapConfigKeys.USER_SEARCH_BASE.key(), "dc=example,dc=com");
     ldapPropsMap.put(AmbariLdapConfigKeys.DN_ATTRIBUTE.key(), SchemaConstants.UID_AT);
+    ldapPropsMap.put(AmbariLdapConfigKeys.TRUST_STORE.key(), "custom");
+    ldapPropsMap.put(AmbariLdapConfigKeys.TRUST_STORE_TYPE.key(), "JKS");
+    ldapPropsMap.put(AmbariLdapConfigKeys.TRUST_STORE_PATH.key(), "/Users/lpuskas/my_truststore/KeyStore.jks");
+    ldapPropsMap.put(AmbariLdapConfigKeys.TRUST_STORE_PASSWORD.key(), "lofasz");
 
 
     return ldapPropsMap;
   }
 
+
+  @Test
+  public void testShouldCustomTrustManagersBeSetForLdapConnection() throws Exception {
+    // GIVEN
+    AmbariLdapConfiguration ambariLdapConfiguration = ldapConfigurationFactory.createLdapConfiguration(getProps());
+
+    LdapFacade ldapFacade = injector.getInstance(LdapFacade.class);
+
+    LdapConnectionTemplateFactory lctFactory = injector.getInstance(LdapConnectionTemplateFactory.class);
+
+    LdapConnectionTemplate template1 = lctFactory.load();
+    LdapConnectionTemplate template2 = lctFactory.create(ambariLdapConfiguration);
+
+
+    // WHEN
+    ldapFacade.checkConnection(ambariLdapConfiguration);
+
+    ldapFacade.detectAttributes(ambariLdapConfiguration);
+
+    // THEN
+    // no exceptions thrown
+  }
 }
\ No newline at end of file


[36/46] ambari git commit: AMBARI-21307 organized code, fixed build failures

Posted by lp...@apache.org.
AMBARI-21307 organized code, fixed build failures


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 1de16c84be4ae6fecb07604535e6850e872c8464
Parents: 6fc9fad
Author: lpuskas <lp...@apache.org>
Authored: Thu Sep 14 17:58:59 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:42:01 2017 +0200

----------------------------------------------------------------------
 .../ldap/domain/AmbariLdapConfigKeys.java       | 72 ++++++++++++++++++++
 .../ldap/domain/AmbariLdapConfiguration.java    |  3 -
 .../ldap/domain/LdapConfigurationFactory.java   |  2 +-
 .../ldap/service/AmbariLdapConfigKeys.java      | 72 --------------------
 .../DefaultLdapAttributeDetectionService.java   |  2 +-
 .../domain/AmbariLdapConfigurationTest.java     | 19 ++++++
 .../TestAmbariLdapConfigurationFactory.java     | 29 ++++++++
 ...efaultLdapAttributeDetectionServiceTest.java |  9 ++-
 .../DefaultLdapConfigurationServiceTest.java    | 19 +++++-
 9 files changed, 144 insertions(+), 83 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/1de16c84/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigKeys.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigKeys.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigKeys.java
new file mode 100644
index 0000000..b7b41a3
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigKeys.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.domain;
+
+/**
+ * Constants representing supported LDAP related property names
+ * // todo extend this with validation information, description, defaults maybe
+ */
+public enum AmbariLdapConfigKeys {
+
+  LDAP_ENABLED("ambari.ldap.authentication.enabled"),
+  SERVER_HOST("ambari.ldap.connectivity.server.host"),
+  SERVER_PORT("ambari.ldap.connectivity.server.port"),
+  USE_SSL("ambari.ldap.connectivity.use_ssl"),
+
+  TRUST_STORE("ambari.ldap.connectivity.trust_store"),
+  TRUST_STORE_TYPE("ambari.ldap.connectivity.trust_store.type"),
+  TRUST_STORE_PATH("ambari.ldap.connectivity.trust_store.path"),
+  TRUST_STORE_PASSWORD("ambari.ldap.connectivity.trust_store.password"),
+  ANONYMOUS_BIND("ambari.ldap.connectivity.anonymous_bind"),
+
+  BIND_DN("ambari.ldap.connectivity.bind_dn"),
+  BIND_PASSWORD("ambari.ldap.connectivity.bind_password"),
+
+  ATTR_DETECTION("ambari.ldap.attributes.detection"), // manual | auto
+
+  DN_ATTRIBUTE("ambari.ldap.attributes.dn_attr"),
+
+  USER_OBJECT_CLASS("ambari.ldap.attributes.user.object_class"),
+  USER_NAME_ATTRIBUTE("ambari.ldap.attributes.user.name_attr"),
+  USER_GROUP_MEMBER_ATTRIBUTE("ambari.ldap.attributes.user.group_member_attr"),
+  USER_SEARCH_BASE("ambari.ldap.attributes.user.search_base"),
+
+  GROUP_OBJECT_CLASS("ambari.ldap.attributes.group.object_class"),
+  GROUP_NAME_ATTRIBUTE("ambari.ldap.attributes.group.name_attr"),
+  GROUP_MEMBER_ATTRIBUTE("ambari.ldap.attributes.group.member_attr"),
+  GROUP_SEARCH_BASE("ambari.ldap.attributes.group.search_base"),
+
+  USER_SEARCH_FILTER("ambari.ldap.advanced.user_search_filter"),
+  USER_MEMBER_REPLACE_PATTERN("ambari.ldap.advanced.user_member_replace_pattern"),
+  USER_MEMBER_FILTER("ambari.ldap.advanced.user_member_filter"),
+
+  GROUP_SEARCH_FILTER("ambari.ldap.advanced.group_search_filter"),
+  GROUP_MEMBER_REPLACE_PATTERN("ambari.ldap.advanced.group_member_replace_pattern"),
+  GROUP_MEMBER_FILTER("ambari.ldap.advanced.group_member_filter"),
+
+  FORCE_LOWERCASE_USERNAMES("ambari.ldap.advanced.force_lowercase_usernames"),
+  REFERRAL_HANDLING("ambari.ldap.advanced.referrals"), // folow
+  PAGINATION_ENABLED("ambari.ldap.advanced.pagination_enabled"); // true | false
+
+  private String propertyName;
+
+  AmbariLdapConfigKeys(String propName) {
+    this.propertyName = propName;
+  }
+
+  public String key() {
+    return this.propertyName;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/1de16c84/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfiguration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfiguration.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfiguration.java
index 072393a..d071ebe 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfiguration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfiguration.java
@@ -18,9 +18,7 @@ package org.apache.ambari.server.ldap.domain;
 import java.util.Map;
 
 import javax.inject.Inject;
-import javax.inject.Singleton;
 
-import org.apache.ambari.server.ldap.service.AmbariLdapConfigKeys;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -29,7 +27,6 @@ import com.google.inject.assistedinject.Assisted;
 /**
  * This class is an immutable representation of all the LDAP related configurationMap entries.
  */
-@Singleton
 public class AmbariLdapConfiguration {
 
   private static final Logger LOGGER = LoggerFactory.getLogger(AmbariLdapConfiguration.class);

http://git-wip-us.apache.org/repos/asf/ambari/blob/1de16c84/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/LdapConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/LdapConfigurationFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/LdapConfigurationFactory.java
index f9a74da..bf8f825 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/LdapConfigurationFactory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/LdapConfigurationFactory.java
@@ -18,7 +18,7 @@ import java.util.Map;
 
 /**
  * Factory interface for AmbariLdapConfiguration instances.
- * It's registered as a factory in the GUICE context ( so no implementations required)
+ * It's registered as a factory in the GUICE context (so no implementations required)
  *
  * To be extended with other factory methods upon needs.
  */

http://git-wip-us.apache.org/repos/asf/ambari/blob/1de16c84/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigKeys.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigKeys.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigKeys.java
deleted file mode 100644
index 9cf4e56..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigKeys.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.service;
-
-/**
- * Constants representing supported LDAP related property names
- * // todo extend this with validation information, description, defaults maybe
- */
-public enum AmbariLdapConfigKeys {
-
-  LDAP_ENABLED("ambari.ldap.authentication.enabled"),
-  SERVER_HOST("ambari.ldap.connectivity.server.host"),
-  SERVER_PORT("ambari.ldap.connectivity.server.port"),
-  USE_SSL("ambari.ldap.connectivity.use_ssl"),
-
-  TRUST_STORE("ambari.ldap.connectivity.trust_store"),
-  TRUST_STORE_TYPE("ambari.ldap.connectivity.trust_store.type"),
-  TRUST_STORE_PATH("ambari.ldap.connectivity.trust_store.path"),
-  TRUST_STORE_PASSWORD("ambari.ldap.connectivity.trust_store.password"),
-  ANONYMOUS_BIND("ambari.ldap.connectivity.anonymous_bind"),
-
-  BIND_DN("ambari.ldap.connectivity.bind_dn"),
-  BIND_PASSWORD("ambari.ldap.connectivity.bind_password"),
-
-  ATTR_DETECTION("ambari.ldap.attributes.detection"), // manual | auto
-
-  DN_ATTRIBUTE("ambari.ldap.attributes.dn_attr"),
-
-  USER_OBJECT_CLASS("ambari.ldap.attributes.user.object_class"),
-  USER_NAME_ATTRIBUTE("ambari.ldap.attributes.user.name_attr"),
-  USER_GROUP_MEMBER_ATTRIBUTE("ambari.ldap.attributes.user.group_member_attr"),
-  USER_SEARCH_BASE("ambari.ldap.attributes.user.search_base"),
-
-  GROUP_OBJECT_CLASS("ambari.ldap.attributes.group.object_class"),
-  GROUP_NAME_ATTRIBUTE("ambari.ldap.attributes.group.name_attr"),
-  GROUP_MEMBER_ATTRIBUTE("ambari.ldap.attributes.group.member_attr"),
-  GROUP_SEARCH_BASE("ambari.ldap.attributes.group.search_base"),
-
-  USER_SEARCH_FILTER("ambari.ldap.advanced.user_search_filter"),
-  USER_MEMBER_REPLACE_PATTERN("ambari.ldap.advanced.user_member_replace_pattern"),
-  USER_MEMBER_FILTER("ambari.ldap.advanced.user_member_filter"),
-
-  GROUP_SEARCH_FILTER("ambari.ldap.advanced.group_search_filter"),
-  GROUP_MEMBER_REPLACE_PATTERN("ambari.ldap.advanced.group_member_replace_pattern"),
-  GROUP_MEMBER_FILTER("ambari.ldap.advanced.group_member_filter"),
-
-  FORCE_LOWERCASE_USERNAMES("ambari.ldap.advanced.force_lowercase_usernames"),
-  REFERRAL_HANDLING("ambari.ldap.advanced.referrals"), // folow
-  PAGINATION_ENABLED("ambari.ldap.advanced.pagination_enabled"); // true | false
-
-  private String propertyName;
-
-  AmbariLdapConfigKeys(String propName) {
-    this.propertyName = propName;
-  }
-
-  public String key() {
-    return this.propertyName;
-  }
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/1de16c84/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
index ed24015..cddb952 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
@@ -17,8 +17,8 @@ package org.apache.ambari.server.ldap.service.ads;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfigKeys;
 import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.service.AmbariLdapConfigKeys;
 import org.apache.ambari.server.ldap.service.AmbariLdapException;
 import org.apache.ambari.server.ldap.service.LdapAttributeDetectionService;
 import org.apache.ambari.server.ldap.service.ads.detectors.GroupMemberAttrDetector;

http://git-wip-us.apache.org/repos/asf/ambari/blob/1de16c84/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigurationTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigurationTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigurationTest.java
new file mode 100644
index 0000000..0d02a0e
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigurationTest.java
@@ -0,0 +1,19 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.domain;
+
+public class AmbariLdapConfigurationTest {
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/1de16c84/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/TestAmbariLdapConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/TestAmbariLdapConfigurationFactory.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/TestAmbariLdapConfigurationFactory.java
new file mode 100644
index 0000000..ec86568
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/domain/TestAmbariLdapConfigurationFactory.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.domain;
+
+
+import java.util.Map;
+
+/**
+ * Implementation used for testing purposes only!
+ */
+public class TestAmbariLdapConfigurationFactory implements LdapConfigurationFactory {
+
+  @Override
+  public AmbariLdapConfiguration createLdapConfiguration(Map<String, Object> configuration) {
+    return new AmbariLdapConfiguration(configuration);
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/1de16c84/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java
index 2920588..878d1f0 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java
@@ -17,8 +17,9 @@ package org.apache.ambari.server.ldap.service.ads;
 
 import java.util.Map;
 
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfigKeys;
 import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.service.AmbariLdapConfigKeys;
+import org.apache.ambari.server.ldap.domain.TestAmbariLdapConfigurationFactory;
 import org.apache.ambari.server.ldap.service.LdapConnectionService;
 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
 import org.apache.directory.ldap.client.api.LdapConnection;
@@ -43,6 +44,8 @@ public class DefaultLdapAttributeDetectionServiceTest {
   public EasyMockRule mocks = new EasyMockRule(this);
 
   private AmbariLdapConfiguration testLdapConfiguration;
+  private TestAmbariLdapConfigurationFactory ldapConfigurationFactory = new TestAmbariLdapConfigurationFactory();
+
   private LdapConnection connection;
 
   @TestSubject
@@ -53,7 +56,7 @@ public class DefaultLdapAttributeDetectionServiceTest {
 
     Map<String, Object> initialProps = Maps.newHashMap();
     initialProps.put(AmbariLdapConfigKeys.BIND_DN.key(), "");
-    testLdapConfiguration = new AmbariLdapConfiguration(initialProps);
+    testLdapConfiguration = ldapConfigurationFactory.createLdapConfiguration(initialProps);
   }
 
   @Test
@@ -74,7 +77,7 @@ public class DefaultLdapAttributeDetectionServiceTest {
   @Test
   public void functionalTest() throws Exception {
     // GIVEN
-    AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(getTestPropertiesMap());
+    AmbariLdapConfiguration ambariLdapConfiguration = ldapConfigurationFactory.createLdapConfiguration(getTestPropertiesMap());
     LdapConnectionService connectionService = new DefaultLdapConnectionService();
     LdapConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/1de16c84/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
index 449d003..2844054 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
@@ -18,8 +18,9 @@ import static org.junit.Assert.assertNotNull;
 
 import java.util.Map;
 
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfigKeys;
 import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.service.AmbariLdapConfigKeys;
+import org.apache.ambari.server.ldap.domain.TestAmbariLdapConfigurationFactory;
 import org.apache.ambari.server.ldap.service.LdapConfigurationService;
 import org.apache.ambari.server.ldap.service.LdapConnectionService;
 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
@@ -40,6 +41,8 @@ public class DefaultLdapConfigurationServiceTest {
   private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapConfigurationService.class);
   private static final String TEST_USER = "einstein";
 
+  private TestAmbariLdapConfigurationFactory ldapConfigurationFactory = new TestAmbariLdapConfigurationFactory();
+
   LdapConfigurationService ldapConfigurationService = new DefaultLdapConfigurationService();
 
 
@@ -85,7 +88,7 @@ public class DefaultLdapConfigurationServiceTest {
     ldapPropsMap.put(AmbariLdapConfigKeys.USER_SEARCH_BASE.key(), "dc=example,dc=com");
 
 
-    AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(ldapPropsMap);
+    AmbariLdapConfiguration ambariLdapConfiguration = ldapConfigurationFactory.createLdapConfiguration(ldapPropsMap);
     LdapConnectionService connectionService = new DefaultLdapConnectionService();
     LdapConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
 
@@ -107,10 +110,20 @@ public class DefaultLdapConfigurationServiceTest {
     ldapPropsMap.put(AmbariLdapConfigKeys.USER_SEARCH_BASE.key(), "dc=example,dc=com");
 
 
-    AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(ldapPropsMap);
+    AmbariLdapConfiguration ambariLdapConfiguration = ldapConfigurationFactory.createLdapConfiguration(ldapPropsMap);
     LdapConnectionService connectionService = new DefaultLdapConnectionService();
     LdapConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
 
     ldapConfigurationService.checkGroupAttributes(ldapConnection, "uid=einstein,dc=example,dc=com", ambariLdapConfiguration);
   }
+
+  @Test
+  public void testListSupportedProperties(){
+    StringBuilder sb = new StringBuilder().append(System.lineSeparator());
+    for (AmbariLdapConfigKeys configKey : AmbariLdapConfigKeys.values()) {
+      sb.append(configKey.key()).append(System.lineSeparator());
+    }
+    LOGGER.info(sb.toString());
+
+  }
 }
\ No newline at end of file


[40/46] ambari git commit: AMBARI-21307 Fixed failing unit tests (in most cases the new guice module was needed)

Posted by lp...@apache.org.
AMBARI-21307 Fixed failing unit tests (in most cases the new guice module was needed)


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 010ff383af5e1e7a7de9ebf67bf76fc0274dc90a
Parents: 32c292c
Author: lpuskas <lp...@apache.org>
Authored: Thu Oct 12 19:25:24 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:42:02 2017 +0200

----------------------------------------------------------------------
 .../main/resources/Ambari-DDL-Derby-CREATE.sql  |  2 +-
 .../main/resources/Ambari-DDL-MySQL-CREATE.sql  |  2 +-
 .../main/resources/Ambari-DDL-Oracle-CREATE.sql |  2 +-
 .../resources/Ambari-DDL-Postgres-CREATE.sql    |  2 +-
 .../resources/Ambari-DDL-SQLAnywhere-CREATE.sql |  2 +-
 .../resources/Ambari-DDL-SQLServer-CREATE.sql   |  2 +-
 .../api/services/ldap/LDAPServiceTest.java      | 85 --------------------
 .../server/checks/UpgradeCheckOrderTest.java    |  3 +-
 ...AmbariConfigurationResourceProviderTest.java | 24 +++++-
 .../server/ldap/LdapModuleFunctionalTest.java   |  4 +-
 .../notifications/DispatchFactoryTest.java      |  3 +-
 .../server/orm/InMemoryDefaultTestModule.java   |  2 +
 .../ambari/server/orm/JdbcPropertyTest.java     |  5 +-
 ...uthenticationProviderForDNWithSpaceTest.java | 35 ++++----
 .../AmbariLdapAuthenticationProviderTest.java   |  3 +-
 .../AmbariLocalUserProviderTest.java            |  3 +-
 .../authorization/LdapServerPropertiesTest.java |  5 +-
 17 files changed, 65 insertions(+), 119 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/010ff383/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
index cebd33e..20d64de 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
@@ -98,7 +98,7 @@ CREATE TABLE configuration_base (
 CREATE TABLE ambari_configuration (
   id BIGINT NOT NULL,
   CONSTRAINT PK_ambari_configuration PRIMARY KEY (id),
-  CONSTRAINT FK_ambari_configuration_configuration_base FOREIGN KEY (id) REFERENCES configuration_base (id)
+  CONSTRAINT FK_ambari_conf_conf_base FOREIGN KEY (id) REFERENCES configuration_base (id)
 );
 
 CREATE TABLE serviceconfig (

http://git-wip-us.apache.org/repos/asf/ambari/blob/010ff383/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
index b8b506a..dc1dea9 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -118,7 +118,7 @@ CREATE TABLE configuration_base (
 CREATE TABLE ambari_configuration (
   id BIGINT NOT NULL,
   CONSTRAINT PK_ambari_configuration PRIMARY KEY (id),
-  CONSTRAINT FK_ambari_configuration_configuration_base FOREIGN KEY (id) REFERENCES configuration_base (id)
+  CONSTRAINT FK_ambari_conf_conf_base FOREIGN KEY (id) REFERENCES configuration_base (id)
 );
 
 CREATE TABLE serviceconfig (

http://git-wip-us.apache.org/repos/asf/ambari/blob/010ff383/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
index 1e90426..7c34304 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -98,7 +98,7 @@ CREATE TABLE configuration_base (
 CREATE TABLE ambari_configuration (
   id NUMBER(19) NOT NULL,
   CONSTRAINT PK_ambari_configuration PRIMARY KEY (id),
-  CONSTRAINT FK_ambari_configuration_configuration_base FOREIGN KEY (id) REFERENCES configuration_base (id)
+  CONSTRAINT FK_ambari_conf_conf_base FOREIGN KEY (id) REFERENCES configuration_base (id)
 );
 
 CREATE TABLE serviceconfig (

http://git-wip-us.apache.org/repos/asf/ambari/blob/010ff383/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
index 583a51b..9270522 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -80,7 +80,7 @@ CREATE TABLE configuration_base (
 CREATE TABLE ambari_configuration (
   id BIGINT NOT NULL,
   CONSTRAINT PK_ambari_configuration PRIMARY KEY (id),
-  CONSTRAINT FK_ambari_configuration_configuration_base FOREIGN KEY (id) REFERENCES configuration_base (id)
+  CONSTRAINT FK_ambari_conf_conf_base FOREIGN KEY (id) REFERENCES configuration_base (id)
 );
 
 CREATE TABLE clusterconfig (

http://git-wip-us.apache.org/repos/asf/ambari/blob/010ff383/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
index 2104b2d..bf6cd4a 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
@@ -97,7 +97,7 @@ CREATE TABLE configuration_base (
 CREATE TABLE ambari_configuration (
   id NUMERIC(19) NOT NULL,
   CONSTRAINT PK_ambari_configuration PRIMARY KEY (id),
-  CONSTRAINT FK_ambari_configuration_configuration_base FOREIGN KEY (id) REFERENCES configuration_base (id)
+  CONSTRAINT FK_ambari_conf_conf_base FOREIGN KEY (id) REFERENCES configuration_base (id)
 );
 
 CREATE TABLE serviceconfig (

http://git-wip-us.apache.org/repos/asf/ambari/blob/010ff383/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
index 7d248b6..fc93600 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
@@ -111,7 +111,7 @@ CREATE TABLE configuration_base (
 CREATE TABLE ambari_configuration (
   id BIGINT NOT NULL,
   CONSTRAINT PK_ambari_configuration PRIMARY KEY (id),
-  CONSTRAINT FK_ambari_configuration_configuration_base FOREIGN KEY (id) REFERENCES configuration_base (id)
+  CONSTRAINT FK_ambari_conf_conf_base FOREIGN KEY (id) REFERENCES configuration_base (id)
 );
 
 CREATE TABLE serviceconfig (

http://git-wip-us.apache.org/repos/asf/ambari/blob/010ff383/ambari-server/src/test/java/org/apache/ambari/server/api/services/ldap/LDAPServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/ldap/LDAPServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/services/ldap/LDAPServiceTest.java
deleted file mode 100644
index 5e8eac6..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/services/ldap/LDAPServiceTest.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.api.services.ldap;
-
-import org.apache.directory.ldap.client.api.LdapConnection;
-import org.apache.directory.ldap.client.api.LdapConnectionConfig;
-import org.apache.directory.ldap.client.api.LdapNetworkConnection;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.junit.Assert;
-import org.junit.Test;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-
-public class LDAPServiceTest {
-
-  private static String JSON_STRING = "{\n" +
-    "  \"AmbariConfiguration\": {\n" +
-    "    \"type\": \"ldap-config\",\n" +
-    "    \"data\": [{\n" +
-    "        \"authentication.ldap.primaryUrl\": \"localhost:33389\",\n" +
-    "        \"authentication.ldap.secondaryUrl\": \"localhost:333\",\n" +
-    "        \"authentication.ldap.baseDn\": \"dc=ambari,dc=apache,dc=org\"\n" +
-    "      }]\n" +
-    "  }\n" +
-    "}";
-
-  @Test
-  public void testJaxRsJsonTransformation() throws Exception {
-    // GIVEN
-    ObjectMapper objectMapper = new ObjectMapper();
-
-    Gson gsonJsonProvider = new GsonBuilder().create();
-
-
-    // WHEN
-    LdapConfigurationRequest ldapConfigurationRequest = gsonJsonProvider.fromJson(JSON_STRING, LdapConfigurationRequest.class);
-    // LdapConfigurationRequest ldapConfigurationRequest = objectMapper.readValue(JSON_STRING, LdapConfigurationRequest.class);
-
-    // THEN
-    Assert.assertNotNull(ldapConfigurationRequest);
-
-  }
-
-
-  @Test
-  public void testLdapConnection() throws Exception {
-    // GIVEN
-    LdapConnection connection = new LdapNetworkConnection("localhost", 389);
-
-    // WHEN
-    connection.bind();
-    // THEN
-
-  }
-
-
-  @Test
-  public void testLdapConnectionConfigs() throws Exception {
-    // GIVEN
-    LdapConnectionConfig config = new LdapConnectionConfig();
-    config.setLdapHost("localhost");
-    config.setLdapPort(389);
-
-    // WHEN
-    LdapConnection connection = new LdapNetworkConnection(config);
-
-    // THEN
-    connection.anonymousBind();
-
-    Assert.assertNotNull(connection);
-  }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/010ff383/ambari-server/src/test/java/org/apache/ambari/server/checks/UpgradeCheckOrderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/UpgradeCheckOrderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/UpgradeCheckOrderTest.java
index aa975e2..0bc1584 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/UpgradeCheckOrderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/UpgradeCheckOrderTest.java
@@ -25,6 +25,7 @@ import java.util.Set;
 import org.apache.ambari.server.audit.AuditLoggerModule;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.ControllerModule;
+import org.apache.ambari.server.ldap.LdapModule;
 import org.junit.Assert;
 import org.junit.Test;
 import org.springframework.beans.factory.config.BeanDefinition;
@@ -54,7 +55,7 @@ public class UpgradeCheckOrderTest {
     properties.setProperty(Configuration.OS_VERSION.getKey(), "centos6");
     properties.setProperty(Configuration.SHARED_RESOURCES_DIR.getKey(), sourceResourceDirectory);
 
-    Injector injector = Guice.createInjector(new ControllerModule(properties), new AuditLoggerModule());
+    Injector injector = Guice.createInjector(new ControllerModule(properties), new AuditLoggerModule(), new LdapModule());
     UpgradeCheckRegistry registry = injector.getInstance(UpgradeCheckRegistry.class);
     UpgradeCheckRegistry registry2 = injector.getInstance(UpgradeCheckRegistry.class);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/010ff383/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProviderTest.java
index d974682..c2a1421 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProviderTest.java
@@ -21,6 +21,8 @@ import org.apache.ambari.server.controller.spi.Predicate;
 import org.apache.ambari.server.controller.spi.Request;
 import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.utilities.PredicateBuilder;
+import org.apache.ambari.server.events.AmbariLdapConfigChangedEvent;
+import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
 import org.apache.ambari.server.orm.dao.AmbariConfigurationDAO;
 import org.apache.ambari.server.orm.entities.AmbariConfigurationEntity;
 import org.apache.ambari.server.orm.entities.ConfigurationBaseEntity;
@@ -52,6 +54,9 @@ public class AmbariConfigurationResourceProviderTest extends EasyMockSupport {
   @Mock
   private AmbariConfigurationDAO ambariConfigurationDAO;
 
+  @Mock
+  private AmbariEventPublisher publisher;
+
   private Capture<AmbariConfigurationEntity> ambariConfigurationEntityCapture;
 
   private Gson gson;
@@ -68,6 +73,7 @@ public class AmbariConfigurationResourceProviderTest extends EasyMockSupport {
   private static final String PK_STRING = String.valueOf(1);
   private static final String VERSION_TAG = "test version";
   private static final String VERSION = "1";
+  private static final String TYPE = "AmbariConfiguration";
 
   @TestSubject
   private AmbariConfigurationResourceProvider ambariConfigurationResourceProvider = new AmbariConfigurationResourceProvider();
@@ -89,6 +95,7 @@ public class AmbariConfigurationResourceProviderTest extends EasyMockSupport {
         .withVersion(VERSION)
         .withVersionTag(VERSION_TAG)
         .withData(DATA_MOCK_STR)
+        .withType(TYPE)
         .build());
 
     // mock the request to return the properties
@@ -96,6 +103,8 @@ public class AmbariConfigurationResourceProviderTest extends EasyMockSupport {
 
     // capture the entity the DAO gets called with
     ambariConfigurationDAO.create(EasyMock.capture(ambariConfigurationEntityCapture));
+    publisher.publish(EasyMock.anyObject(AmbariLdapConfigChangedEvent.class));
+
     replayAll();
 
     // WHEN
@@ -121,6 +130,8 @@ public class AmbariConfigurationResourceProviderTest extends EasyMockSupport {
 
     Capture<Long> pkCapture = Capture.newInstance();
     ambariConfigurationDAO.removeByPK(EasyMock.capture(pkCapture));
+    publisher.publish(EasyMock.anyObject(AmbariLdapConfigChangedEvent.class));
+
     replayAll();
 
     // WHEN
@@ -160,13 +171,16 @@ public class AmbariConfigurationResourceProviderTest extends EasyMockSupport {
       .withId(PK_LONG)
       .withVersion("2")
       .withVersionTag("version-2")
-      .withData(DATA_MOCK_STR).build());
+      .withData(DATA_MOCK_STR)
+      .withType(TYPE)
+      .build());
 
     EasyMock.expect(requestMock.getProperties()).andReturn(resourcePropertiesSet);
 
     AmbariConfigurationEntity persistedEntity = createDummyAmbariConfigurationEntity();
     EasyMock.expect(ambariConfigurationDAO.findByPK(PK_LONG)).andReturn(persistedEntity);
-    ambariConfigurationDAO.create(EasyMock.capture(ambariConfigurationEntityCapture));
+    ambariConfigurationDAO.update(EasyMock.capture(ambariConfigurationEntityCapture));
+    publisher.publish(EasyMock.anyObject(AmbariLdapConfigChangedEvent.class));
 
     replayAll();
 
@@ -208,6 +222,12 @@ public class AmbariConfigurationResourceProviderTest extends EasyMockSupport {
       return this;
     }
 
+    private PropertiesMapBuilder withType(String type) {
+      resourcePropertiesMap.put(AmbariConfigurationResourceProvider.ResourcePropertyId.TYPE.getPropertyId(), type);
+      return this;
+    }
+
+
     public Map<String, Object> build() {
       return this.resourcePropertiesMap;
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/010ff383/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
index b9f140e..f3f0644 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
@@ -32,6 +32,7 @@ import org.apache.directory.ldap.client.template.LdapConnectionTemplate;
 import org.apache.directory.ldap.client.template.exception.PasswordException;
 import org.junit.Assert;
 import org.junit.BeforeClass;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import com.google.common.collect.Maps;
@@ -41,6 +42,7 @@ import com.google.inject.Injector;
 import com.google.inject.Module;
 import com.google.inject.util.Modules;
 
+@Ignore
 public class LdapModuleFunctionalTest {
 
   private static Injector injector;
@@ -62,7 +64,7 @@ public class LdapModuleFunctionalTest {
     injector = Guice.createInjector(testModule);
   }
 
-  @Test
+  @Test()
   public void shouldLdapTemplateBeInstantiated() throws LdapInvalidDnException, PasswordException {
     // GIVEN
     // the injector is set up

http://git-wip-us.apache.org/repos/asf/ambari/blob/010ff383/ambari-server/src/test/java/org/apache/ambari/server/notifications/DispatchFactoryTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/notifications/DispatchFactoryTest.java b/ambari-server/src/test/java/org/apache/ambari/server/notifications/DispatchFactoryTest.java
index 382799c..d34d732 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/notifications/DispatchFactoryTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/notifications/DispatchFactoryTest.java
@@ -23,6 +23,7 @@ import java.util.Properties;
 import org.apache.ambari.server.audit.AuditLoggerModule;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.ControllerModule;
+import org.apache.ambari.server.ldap.LdapModule;
 import org.apache.ambari.server.notifications.dispatchers.EmailDispatcher;
 import org.apache.ambari.server.notifications.dispatchers.SNMPDispatcher;
 import org.junit.Assert;
@@ -55,7 +56,7 @@ public class DispatchFactoryTest {
     properties.setProperty(Configuration.SHARED_RESOURCES_DIR.getKey(),sourceResourceDirectory);
     properties.setProperty(Configuration.ALERTS_SNMP_DISPATCH_UDP_PORT.getKey(),snmpPort.toString());
 
-    Injector injector = Guice.createInjector(new AuditLoggerModule(), new ControllerModule(properties));
+    Injector injector = Guice.createInjector(new AuditLoggerModule(), new ControllerModule(properties), new LdapModule());
     DispatchFactory dispatchFactory = injector.getInstance(DispatchFactory.class);
     DispatchFactory dispatchFactory2 = injector.getInstance(DispatchFactory.class);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/010ff383/ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java
index 434a2a1..ebc2596 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java
@@ -26,6 +26,7 @@ import java.util.concurrent.atomic.AtomicReference;
 import org.apache.ambari.server.audit.AuditLogger;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.ControllerModule;
+import org.apache.ambari.server.ldap.LdapModule;
 import org.apache.ambari.server.stack.StackManager;
 import org.apache.ambari.server.stack.StackManagerFactory;
 import org.apache.ambari.server.stack.StackManagerMock;
@@ -122,6 +123,7 @@ public class InMemoryDefaultTestModule extends AbstractModule {
     }
 
     try {
+      install(new LdapModule());
       install(Modules.override(new BeanDefinitionsCachingTestControllerModule(properties)).with(new AbstractModule() {
         @Override
         protected void configure() {

http://git-wip-us.apache.org/repos/asf/ambari/blob/010ff383/ambari-server/src/test/java/org/apache/ambari/server/orm/JdbcPropertyTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/JdbcPropertyTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/JdbcPropertyTest.java
index 427cede..14c5dd6 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/JdbcPropertyTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/JdbcPropertyTest.java
@@ -23,6 +23,7 @@ import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.audit.AuditLoggerModule;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.ControllerModule;
+import org.apache.ambari.server.ldap.LdapModule;
 import org.apache.ambari.server.state.Clusters;
 import org.junit.After;
 import org.junit.Assert;
@@ -53,7 +54,7 @@ public class JdbcPropertyTest {
 
   @Test
   public void testNormal() throws Exception {
-    injector = Guice.createInjector(new AuditLoggerModule(), new ControllerModule(properties));
+    injector = Guice.createInjector(new AuditLoggerModule(), new ControllerModule(properties), new LdapModule());
     injector.getInstance(GuiceJpaInitializer.class);
 
     injector.getInstance(Clusters.class);
@@ -62,7 +63,7 @@ public class JdbcPropertyTest {
   @Test
   public void testJdbcProperty() throws Exception {
     properties.setProperty(Configuration.SERVER_JDBC_PROPERTIES_PREFIX + "shutdown", "true");
-    injector = Guice.createInjector(new AuditLoggerModule(), new ControllerModule(properties));
+    injector = Guice.createInjector(new AuditLoggerModule(), new ControllerModule(properties), new LdapModule());
     injector.getInstance(GuiceJpaInitializer.class);
     try {
       injector.getInstance(Clusters.class);

http://git-wip-us.apache.org/repos/asf/ambari/blob/010ff383/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthenticationProviderForDNWithSpaceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthenticationProviderForDNWithSpaceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthenticationProviderForDNWithSpaceTest.java
index 442414f..566d6b7 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthenticationProviderForDNWithSpaceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthenticationProviderForDNWithSpaceTest.java
@@ -26,6 +26,7 @@ import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.audit.AuditLoggerModule;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.ControllerModule;
+import org.apache.ambari.server.ldap.LdapModule;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.dao.UserDAO;
 import org.apache.ambari.server.security.ClientSecurityType;
@@ -49,23 +50,23 @@ import com.google.inject.Injector;
 
 @RunWith(FrameworkRunner.class)
 @CreateDS(allowAnonAccess = true,
-    name = "AmbariLdapAuthenticationProviderForDNWithSpaceTest",
-    partitions = {
-        @CreatePartition(name = "Root",
-            suffix = "dc=the apache,dc=org",
-            contextEntry = @ContextEntry(
-                entryLdif =
-                    "dn: dc=the apache,dc=org\n" +
-                        "dc: the apache\n" +
-                        "objectClass: top\n" +
-                        "objectClass: domain\n\n" +
-                        "dn: dc=ambari,dc=the apache,dc=org\n" +
-                        "dc: ambari\n" +
-                        "objectClass: top\n" +
-                        "objectClass: domain\n\n"))
-    })
+  name = "AmbariLdapAuthenticationProviderForDNWithSpaceTest",
+  partitions = {
+    @CreatePartition(name = "Root",
+      suffix = "dc=the apache,dc=org",
+      contextEntry = @ContextEntry(
+        entryLdif =
+          "dn: dc=the apache,dc=org\n" +
+            "dc: the apache\n" +
+            "objectClass: top\n" +
+            "objectClass: domain\n\n" +
+            "dn: dc=ambari,dc=the apache,dc=org\n" +
+            "dc: ambari\n" +
+            "objectClass: top\n" +
+            "objectClass: domain\n\n"))
+  })
 @CreateLdapServer(allowAnonymousAccess = true,
-    transports = {@CreateTransport(protocol = "LDAP")})
+  transports = {@CreateTransport(protocol = "LDAP")})
 @ApplyLdifFiles("users_for_dn_with_space.ldif")
 public class AmbariLdapAuthenticationProviderForDNWithSpaceTest extends AmbariLdapAuthenticationProviderBaseTest {
 
@@ -83,7 +84,7 @@ public class AmbariLdapAuthenticationProviderForDNWithSpaceTest extends AmbariLd
 
   @Before
   public void setUp() throws Exception {
-    injector = Guice.createInjector(new ControllerModule(getTestProperties()), new AuditLoggerModule());
+    injector = Guice.createInjector(new ControllerModule(getTestProperties()), new AuditLoggerModule(), new LdapModule());
     injector.getInstance(GuiceJpaInitializer.class);
     injector.injectMembers(this);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/010ff383/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthenticationProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthenticationProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthenticationProviderTest.java
index 4941bc7..d8be809 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthenticationProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthenticationProviderTest.java
@@ -29,6 +29,7 @@ import static org.junit.Assert.fail;
 import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.audit.AuditLoggerModule;
 import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.ldap.LdapModule;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.dao.UserDAO;
 import org.apache.ambari.server.orm.entities.UserEntity;
@@ -90,7 +91,7 @@ public class AmbariLdapAuthenticationProviderTest extends AmbariLdapAuthenticati
 
   @Before
   public void setUp() {
-    injector = Guice.createInjector(new AuditLoggerModule(), new AuthorizationTestModule());
+    injector = Guice.createInjector(new AuditLoggerModule(), new AuthorizationTestModule(), new LdapModule());
     injector.injectMembers(this);
     injector.getInstance(GuiceJpaInitializer.class);
     configuration.setClientSecurityType(ClientSecurityType.LDAP);

http://git-wip-us.apache.org/repos/asf/ambari/blob/010ff383/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLocalUserProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLocalUserProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLocalUserProviderTest.java
index 2362823..d889372 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLocalUserProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLocalUserProviderTest.java
@@ -27,6 +27,7 @@ import static org.junit.Assert.assertTrue;
 
 import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.audit.AuditLoggerModule;
+import org.apache.ambari.server.ldap.LdapModule;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.OrmTestHelper;
 import org.apache.ambari.server.orm.dao.UserDAO;
@@ -56,7 +57,7 @@ public class AmbariLocalUserProviderTest {
 
   @BeforeClass
   public static void prepareData() {
-    injector = Guice.createInjector(new AuditLoggerModule(), new AuthorizationTestModule());
+    injector = Guice.createInjector(new AuditLoggerModule(), new AuthorizationTestModule(), new LdapModule());
     injector.getInstance(GuiceJpaInitializer.class);
     injector.getInstance(OrmTestHelper.class).createTestUsers();
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/010ff383/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/LdapServerPropertiesTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/LdapServerPropertiesTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/LdapServerPropertiesTest.java
index 5747408..0e1515b 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/LdapServerPropertiesTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/LdapServerPropertiesTest.java
@@ -25,6 +25,7 @@ import java.util.List;
 
 import org.apache.ambari.server.audit.AuditLoggerModule;
 import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.ldap.LdapModule;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -45,13 +46,13 @@ public class LdapServerPropertiesTest {
   Configuration configuration;
 
   public LdapServerPropertiesTest() {
-    injector = Guice.createInjector(new AuditLoggerModule(), new AuthorizationTestModule());
+    injector = Guice.createInjector(new AuditLoggerModule(), new AuthorizationTestModule(), new LdapModule());
     injector.injectMembers(this);
   }
 
   @Before
   public void setUp() throws Exception {
-    ldapServerProperties =  new LdapServerProperties();
+    ldapServerProperties = new LdapServerProperties();
     ldapServerProperties.setAnonymousBind(true);
     ldapServerProperties.setBaseDN("dc=ambari,dc=apache,dc=org");
     ldapServerProperties.setManagerDn("uid=manager," + ldapServerProperties.getBaseDN());


[28/46] ambari git commit: AMBARI-21307 Added the supported ldap properties to the code. Refactored existing code relying on these properties

Posted by lp...@apache.org.
AMBARI-21307 Added the supported ldap properties to the code. Refactored existing code relying on these properties


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 4afe98147ba4be03e1280a35530bd5e35d048d14
Parents: d4b9215
Author: lpuskas <lp...@apache.org>
Authored: Fri Sep 8 13:57:25 2017 +0300
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:41:59 2017 +0200

----------------------------------------------------------------------
 .../server/ldap/AmbariLdapConfiguration.java    | 189 ++++++++++++-------
 .../AmbariLdapConfigurationProvider.java        |   6 +-
 .../server/ldap/service/AmbariLdapFacade.java   |  10 +-
 .../service/LdapAttributeDetectionService.java  |  43 +++++
 .../ambari/server/ldap/service/LdapFacade.java  |   2 +-
 .../ads/DefaultAttributeDetectionService.java   |  47 +++++
 .../ads/DefaultLdapConfigurationService.java    |   4 +-
 .../ads/DefaultLdapConnectionService.java       |   4 +-
 .../DefaultAttributeDetectionServiceTest.java   | 102 ++++++++++
 .../DefaultLdapConfigurationServiceTest.java    |  30 ++-
 10 files changed, 348 insertions(+), 89 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/4afe9814/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
index e913e77..76faeed 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
@@ -34,63 +34,67 @@ public class AmbariLdapConfiguration {
   /**
    * Constants representing supported LDAP related property names
    */
-  public enum LdapConfigProperty {
-    LDAP_CONFIGURED("ambari.ldap.configured"),
-    AUTOMATIC_ATTRIBUTE_DETECTION("ambari.ldap.automatic.attribute.detection"),
-    USE_SSL("ambari.ldap.usessl"),
-    LDAP_SERVER_HOST("ambari.ldap.server.host"),
-    LDAP_SERVER_PORT("ambari.ldap.server.port"),
-    LDAP_TRUSTSTORE("ambari.ldap.truststore"),
-    LDAP_TRUSTSTORE_TYPE("ambari.ldap.truststore.type"),
-    LDAP_TRUSTSTORE_PATH("ambari.ldap.truststore.path"),
-    LDAP_TRUSTSTORE_PASSWORD("ambari.ldap.truststore.password"),
-    BASE_DN("ambari.ldap.bind.dn"),
-    REFERRAL("ambari.ldap.referral"),
-    PAGINATION_ENABLED("ambari.ldap.pagination.enabled"),
-
-    BIND_ANONIMOUSLY("ambari.ldap.bindanonymously"),
-    MANAGER_DN("ambari.ldap.managerdn"),
-    MANAGER_PASSWORD("ambari.ldap.managerpassword"),
-    USER_OBJECT_CLASS("ambari.ldap.user.object.class"),
-    USER_NAME_ATTRIBUTE("ambari.ldap.user.name.attribute"),
-    USER_NAME_FORCE_LOWERCASE("ambari.ldap.username.force.lowercase"),
-    USER_SEARCH_BASE("ambari.ldap.user.search.base"),
-    SYNC_USER_MEMBER_REPLACE_PATTERN("ambari.ldap.sync.user.member.replacepattern"),
-    SYNC_USER_MEMBER_FILTER("ambari.ldap.sync.user.member_filter"),
-
-    ADMIN_GROUP_MAPPING_RULES ("ambari.ldap.admin.group.mappingrules"),
-    GROUP_OBJECT_CLASS("ambari.ldap.group.object.class"),
-    GROUP_NAME_ATTRIBUTE("ambari.ldap.group.name.attribute"),
-    GROUP_MEMBER_ATTRIBUTE("ambari.ldap.group.member.attribute"),
-    GROUP_SEARCH_BASE("ambari.ldap.group.search.base"),
-    SYNC_GROUP_MEMBER_REPLACE_PATTERN("ambari.ldap.sync.group.member.replacepattern"),
-    SYNC_GROUP_MEMBER_FILTER("ambari.ldap.sync.group.member_filter"),
-    DN_ATTRIBUTE("authentication.ldap.dnAttribute"),
-
-    TEST_USER_NAME("ambari.ldap.test.user.name"),
-    TEST_USER_PASSWORD("ambari.ldap.test.user.password");
+  public enum AmbariLdapConfig {
+
+    LDAP_ENABLED("ambari.ldap.authentication.enabled"),
+    SERVER_HOST("ambari.ldap.connectivity.server.host"),
+    SERVER_PORT("ambari.ldap.connectivity.server.port"),
+    USE_SSL("ambari.ldap.connectivity.use_ssl"),
+
+    TRUST_STORE("ambari.ldap.connectivity.trust_store"),
+    TRUST_STORE_TYPE("ambari.ldap.connectivity.trust_store.type"),
+    TRUST_STORE_PATH("ambari.ldap.connectivity.trust_store.path"),
+    TRUST_STORE_PASSWORD("ambari.ldap.connectivity.trust_store.password"),
+    ANONYMOUS_BIND("ambari.ldap.connectivity.anonymous_bind"),
+
+    BIND_DN("ambari.ldap.connectivity.bind_dn"),
+    BIND_PASSWORD("ambari.ldap.connectivity.bind_password"),
+
+    ATTR_DETECTION("ambari.ldap.attributes.detection"), // manual | auto
+
+    DN_ATTRIBUTE("ambari.ldap.attributes.dn_attr"),
+
+    USER_OBJECT_CLASS("ambari.ldap.attributes.user.object_class"),
+    USER_NAME_ATTRIBUTE("ambari.ldap.attributes.user.name_attr"),
+    USER_SEARCH_BASE("ambari.ldap.attributes.user.search_base"),
+
+    GROUP_OBJECT_CLASS("ambari.ldap.attributes.group.object_class"),
+    GROUP_NAME_ATTRIBUTE("ambari.ldap.attributes.group.name_attr"),
+    GROUP_MEMBER_ATTRIBUTE("ambari.ldap.attributes.group.member_attr"),
+    GROUP_SEARCH_BASE("ambari.ldap.attributes.user.search_base"),
+
+    USER_SEARCH_FILTER("ambari.ldap.advanced.user_search_filter"),
+    USER_MEMBER_REPLACE_PATTERN("ambari.ldap.advanced.user_member_replace_pattern"),
+    USER_MEMBER_FILTER("ambari.ldap.advanced.user_member_filter"),
+
+    GROUP_SEARCH_FILTER("ambari.ldap.advanced.group_search_filter"),
+    GROUP_MEMBER_REPLACE_PATTERN("ambari.ldap.advanced.group_member_replace_pattern"),
+    GROUP_MEMBER_FILTER("ambari.ldap.advanced.group_member_filter"),
+
+    FORCE_LOWERCASE_USERNAMES("ambari.ldap.advanced.force_lowercase_usernames"),
+    REFERRAL_HANDLING("ambari.ldap.advanced.referrals"), // folow
+    PAGINATION_ENABLED("ambari.ldap.advanced.pagination_enabled"); // true | false
 
     private String propertyName;
 
-    LdapConfigProperty(String propertyName) {
-      this.propertyName = propertyName;
+    AmbariLdapConfig(String propName) {
+      this.propertyName = propName;
     }
 
-    public String propertyName() {
+    public String key() {
       return this.propertyName;
     }
   }
 
   private final Map<String, Object> configurationMap;
 
-  private Object configurationValue(LdapConfigProperty ldapConfigProperty) {
+  private Object configValue(AmbariLdapConfig ambariLdapConfig) {
     Object value = null;
-    if (configurationMap.containsKey(ldapConfigProperty.propertyName)) {
-      value = configurationMap.get(ldapConfigProperty.propertyName);
+    if (configurationMap.containsKey(ambariLdapConfig.key())) {
+      value = configurationMap.get(ambariLdapConfig.key());
     } else {
-      LOGGER.warn("Ldap configuration property [{}] hasn't been set", ldapConfigProperty.propertyName());
+      LOGGER.warn("Ldap configuration property [{}] hasn't been set", ambariLdapConfig.key());
     }
-
     return value;
   }
 
@@ -99,65 +103,120 @@ public class AmbariLdapConfiguration {
     this.configurationMap = configuration;
   }
 
+  public boolean ldapEnabled() {
+    return Boolean.valueOf((String) configValue(AmbariLdapConfig.LDAP_ENABLED));
+  }
 
-  public String ldapServerHost() {
-    return (String) configurationValue(LdapConfigProperty.LDAP_SERVER_HOST);
+  public String serverHost() {
+    return (String) configValue(AmbariLdapConfig.SERVER_HOST);
   }
 
-  public int ldapServerPort() {
-    return Integer.valueOf((String) configurationValue(LdapConfigProperty.LDAP_SERVER_PORT));
+  public int serverPort() {
+    return Integer.valueOf((String) configValue(AmbariLdapConfig.SERVER_PORT));
   }
 
   public boolean useSSL() {
-    return Boolean.valueOf((String) configurationValue(LdapConfigProperty.USE_SSL));
+    return Boolean.valueOf((String) configValue(AmbariLdapConfig.USE_SSL));
+  }
+
+  public String trustStore() {
+    return (String) configValue(AmbariLdapConfig.TRUST_STORE);
+  }
+
+  public String trustStoreType() {
+    return (String) configValue(AmbariLdapConfig.TRUST_STORE_TYPE);
+  }
+
+  public String trustStorePath() {
+    return (String) configValue(AmbariLdapConfig.TRUST_STORE_PATH);
+  }
+
+  public String trustStorePassword() {
+    return (String) configValue(AmbariLdapConfig.TRUST_STORE_PASSWORD);
   }
 
-  public boolean bindAnonimously() {
-    return Boolean.valueOf((String) configurationValue(LdapConfigProperty.BIND_ANONIMOUSLY));
+  public boolean anonymousBind() {
+    return Boolean.valueOf((String) configValue(AmbariLdapConfig.ANONYMOUS_BIND));
   }
 
-  public String managerDn() {
-    return (String) configurationValue(LdapConfigProperty.MANAGER_DN);
+  public String bindDn() {
+    return (String) configValue(AmbariLdapConfig.BIND_DN);
   }
 
-  public String managerPassword() {
-    return (String) configurationValue(LdapConfigProperty.MANAGER_PASSWORD);
+  public String bindPassword() {
+    return (String) configValue(AmbariLdapConfig.BIND_PASSWORD);
   }
 
-  public boolean automaticAttributeDetection() {
-    return Boolean.valueOf((String) configurationValue(LdapConfigProperty.AUTOMATIC_ATTRIBUTE_DETECTION));
+  public String attributeDetection() {
+    return (String) configValue(AmbariLdapConfig.ATTR_DETECTION);
   }
 
-  public String baseDn() {
-    return (String) configurationValue(LdapConfigProperty.BASE_DN);
+  public String dnAttribute() {
+    return (String) configValue(AmbariLdapConfig.DN_ATTRIBUTE);
   }
 
   public String userObjectClass() {
-    return (String) configurationValue(LdapConfigProperty.USER_OBJECT_CLASS);
+    return (String) configValue(AmbariLdapConfig.USER_OBJECT_CLASS);
   }
 
   public String userNameAttribute() {
-    return (String) configurationValue(LdapConfigProperty.USER_NAME_ATTRIBUTE);
+    return (String) configValue(AmbariLdapConfig.USER_NAME_ATTRIBUTE);
   }
 
   public String userSearchBase() {
-    return (String) configurationValue(LdapConfigProperty.USER_SEARCH_BASE);
+    return (String) configValue(AmbariLdapConfig.USER_SEARCH_BASE);
   }
 
   public String groupObjectClass() {
-    return (String) configurationValue(LdapConfigProperty.GROUP_OBJECT_CLASS);
+    return (String) configValue(AmbariLdapConfig.GROUP_OBJECT_CLASS);
   }
 
   public String groupNameAttribute() {
-    return (String) configurationValue(LdapConfigProperty.GROUP_NAME_ATTRIBUTE);
+    return (String) configValue(AmbariLdapConfig.GROUP_NAME_ATTRIBUTE);
   }
 
   public String groupMemberAttribute() {
-    return (String) configurationValue(LdapConfigProperty.GROUP_MEMBER_ATTRIBUTE);
+    return (String) configValue(AmbariLdapConfig.GROUP_MEMBER_ATTRIBUTE);
   }
 
   public String groupSearchBase() {
-    return (String) configurationValue(LdapConfigProperty.GROUP_SEARCH_BASE);
+    return (String) configValue(AmbariLdapConfig.GROUP_SEARCH_BASE);
+  }
+
+  public String userSearchFilter() {
+    return (String) configValue(AmbariLdapConfig.USER_SEARCH_FILTER);
+  }
+
+  public String userMemberReplacePattern() {
+    return (String) configValue(AmbariLdapConfig.USER_MEMBER_REPLACE_PATTERN);
+  }
+
+  public String userMemberFilter() {
+    return (String) configValue(AmbariLdapConfig.USER_MEMBER_FILTER);
+  }
+
+  public String groupSearchFilter() {
+    return (String) configValue(AmbariLdapConfig.GROUP_SEARCH_FILTER);
+  }
+
+  public String groupMemberReplacePattern() {
+    return (String) configValue(AmbariLdapConfig.GROUP_MEMBER_REPLACE_PATTERN);
+  }
+
+  public String groupMemberFilter() {
+    return (String) configValue(AmbariLdapConfig.GROUP_MEMBER_FILTER);
+  }
+
+  public boolean forceLowerCaseUserNames() {
+    return Boolean.valueOf((String) configValue(AmbariLdapConfig.FORCE_LOWERCASE_USERNAMES));
+  }
+
+  public boolean paginationEnabled() {
+    return Boolean.valueOf((String) configValue(AmbariLdapConfig.PAGINATION_ENABLED));
+  }
+
+  public String referralHandling() {
+    return (String) configValue(AmbariLdapConfig.REFERRAL_HANDLING);
   }
 
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/4afe9814/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java
index 7f3e8a9..80ed828 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java
@@ -24,6 +24,7 @@ import javax.inject.Singleton;
 import org.apache.ambari.server.events.AmbariLdapConfigChangedEvent;
 import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
 import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.LdapConfigurationFactory;
 import org.apache.ambari.server.orm.dao.AmbariConfigurationDAO;
 import org.apache.ambari.server.orm.entities.AmbariConfigurationEntity;
 import org.apache.ambari.server.security.authorization.AmbariLdapAuthenticationProvider;
@@ -55,6 +56,9 @@ public class AmbariLdapConfigurationProvider implements Provider<AmbariLdapConfi
   @Inject
   private Provider<AmbariConfigurationDAO> ambariConfigurationDAOProvider;
 
+  @Inject
+  private LdapConfigurationFactory ldapConfigurationFactory;
+
   private Gson gson = new GsonBuilder().create();
 
   @Inject
@@ -95,7 +99,7 @@ public class AmbariLdapConfigurationProvider implements Provider<AmbariLdapConfi
 
     if (configEntity != null) {
       Set propertyMaps = gson.fromJson(configEntity.getConfigurationBaseEntity().getConfigurationData(), Set.class);
-      instance = new AmbariLdapConfiguration((Map<String, Object>) propertyMaps.iterator().next());
+      instance = ldapConfigurationFactory.createLdapConfiguration((Map<String, Object>) propertyMaps.iterator().next());
     }
 
     LOGGER.info("Loaded LDAP configuration instance: [ {} ]", instance);

http://git-wip-us.apache.org/repos/asf/ambari/blob/4afe9814/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
index 90a5ba7..16bf6b7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
@@ -55,6 +55,9 @@ public class AmbariLdapFacade implements LdapFacade {
   @Inject
   private LdapConnectionService ldapConnectionService;
 
+  @Inject
+  private LdapAttributeDetectionService ldapAttributeDetectionService;
+
   //todo remove this, added for testing purposes only
   @Inject
   private Provider<AmbariLdapConfiguration> ambariLdapConfigurationProvider;
@@ -78,9 +81,12 @@ public class AmbariLdapFacade implements LdapFacade {
 
 
   @Override
-  public void detectAttributes(AmbariLdapConfiguration ambariLdapConfiguration) {
+  public AmbariLdapConfiguration detectAttributes(AmbariLdapConfiguration ambariLdapConfiguration) {
     LOGGER.info("Detecting LDAP configuration attributes ...");
-    LOGGER.info("LDAP config: {}", ambariLdapConfigurationProvider.get());
+
+    LdapConnection connection = ldapConnectionService.createLdapConnection(ambariLdapConfiguration);
+    ambariLdapConfiguration = ldapAttributeDetectionService.detectLdapUserAttributes(connection, ambariLdapConfiguration);
+    return ambariLdapConfiguration;
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/4afe9814/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapAttributeDetectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapAttributeDetectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapAttributeDetectionService.java
new file mode 100644
index 0000000..70a8977
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapAttributeDetectionService.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service;
+
+import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.directory.ldap.client.api.LdapConnection;
+
+/**
+ * Contract defining operations to detect user and group attributes.
+ */
+public interface LdapAttributeDetectionService {
+
+  /**
+   * Decorates the passed in configuration with the detected ldap user attribute values
+   *
+   * @param ldapConnection          the connection instance to LDAP
+   * @param ambariLdapConfiguration configuration instance holding connection details
+   * @return the configuration decorated with user related attributes
+   */
+  AmbariLdapConfiguration detectLdapUserAttributes(LdapConnection ldapConnection, AmbariLdapConfiguration ambariLdapConfiguration);
+
+  /**
+   * Decorates the passed in configuration with the detected ldap group attribute values
+   *
+   * @param ldapConnection          the connection instance to LDAP
+   * @param ambariLdapConfiguration configuration instance holding connection details
+   * @return the configuration decorated with group related attributes
+   */
+  AmbariLdapConfiguration detectLdapGroupAttributes(LdapConnection ldapConnection, AmbariLdapConfiguration ambariLdapConfiguration);
+}
+

http://git-wip-us.apache.org/repos/asf/ambari/blob/4afe9814/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
index eadff7d..76b16c4 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
@@ -39,7 +39,7 @@ public interface LdapFacade {
    *
    * @param ambariLdapConfiguration
    */
-  void detectAttributes(AmbariLdapConfiguration ambariLdapConfiguration);
+  AmbariLdapConfiguration detectAttributes(AmbariLdapConfiguration ambariLdapConfiguration);
 
   /**
    * Checks user and group related LDAP configuration attributes in the configuration object with the help of the provided parameters

http://git-wip-us.apache.org/repos/asf/ambari/blob/4afe9814/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionService.java
new file mode 100644
index 0000000..55d0765
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionService.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.service.LdapAttributeDetectionService;
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Singleton
+public class DefaultAttributeDetectionService implements LdapAttributeDetectionService {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultAttributeDetectionService.class);
+
+  @Inject
+  public DefaultAttributeDetectionService() {
+  }
+
+  @Override
+  public AmbariLdapConfiguration detectLdapUserAttributes(LdapConnection connection, AmbariLdapConfiguration ambariLdapConfiguration) {
+    LOGGER.info("Detecting LDAP user attributes ...");
+
+    return null;
+  }
+
+  @Override
+  public AmbariLdapConfiguration detectLdapGroupAttributes(LdapConnection connection, AmbariLdapConfiguration ambariLdapConfiguration) {
+    LOGGER.info("Detecting LDAP group attributes ...");
+    return null;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/4afe9814/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
index abc9201..db8c77f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationService.java
@@ -186,9 +186,9 @@ public class DefaultLdapConfigurationService implements LdapConfigurationService
    */
   private void bind(AmbariLdapConfiguration ambariLdapConfiguration, LdapConnection connection) throws LdapException {
     LOGGER.info("Connecting to LDAP ....");
-    if (!ambariLdapConfiguration.bindAnonimously()) {
+    if (!ambariLdapConfiguration.anonymousBind()) {
       LOGGER.debug("Anonimous binding not supported, binding with the manager detailas...");
-      connection.bind(ambariLdapConfiguration.managerDn(), ambariLdapConfiguration.managerPassword());
+      connection.bind(ambariLdapConfiguration.bindDn(), ambariLdapConfiguration.bindPassword());
     } else {
       LOGGER.debug("Binding anonimously ...");
       connection.bind();

http://git-wip-us.apache.org/repos/asf/ambari/blob/4afe9814/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionService.java
index ced52fc..f39df54 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionService.java
@@ -52,8 +52,8 @@ public class DefaultLdapConnectionService implements LdapConnectionService {
     LOGGER.debug("Creating a configuration instance based on the ambari configuration: {}", ambariAmbariLdapConfiguration);
 
     LdapConnectionConfig ldapConnectionConfig = new LdapConnectionConfig();
-    ldapConnectionConfig.setLdapHost(ambariAmbariLdapConfiguration.ldapServerHost());
-    ldapConnectionConfig.setLdapPort(ambariAmbariLdapConfiguration.ldapServerPort());
+    ldapConnectionConfig.setLdapHost(ambariAmbariLdapConfiguration.serverHost());
+    ldapConnectionConfig.setLdapPort(ambariAmbariLdapConfiguration.serverPort());
     ldapConnectionConfig.setUseSsl(ambariAmbariLdapConfiguration.useSSL());
 
     // todo set the other values as required

http://git-wip-us.apache.org/repos/asf/ambari/blob/4afe9814/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionServiceTest.java
new file mode 100644
index 0000000..5b3ac20
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultAttributeDetectionServiceTest.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads;
+
+
+import java.util.Map;
+
+import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.service.LdapConnectionService;
+import org.apache.directory.api.ldap.model.constants.SchemaConstants;
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.LdapNetworkConnection;
+import org.easymock.EasyMockRule;
+import org.easymock.TestSubject;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Maps;
+
+public class DefaultAttributeDetectionServiceTest {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultAttributeDetectionServiceTest.class);
+
+  @Rule
+  public EasyMockRule mocks = new EasyMockRule(this);
+
+  private AmbariLdapConfiguration testLdapConfiguration;
+  private LdapConnection connection;
+
+  @TestSubject
+  private DefaultAttributeDetectionService attributeDetectionService = new DefaultAttributeDetectionService();
+
+  @Before
+  public void before() {
+
+    Map<String, Object> initialProps = Maps.newHashMap();
+    initialProps.put(AmbariLdapConfiguration.AmbariLdapConfig.BIND_DN.key(), "");
+    testLdapConfiguration = new AmbariLdapConfiguration(initialProps);
+  }
+
+  @Test
+  public void testShouldUserNameAttributeBeDetectedWhenSearchReturnsValidUsers() throws Exception {
+    // GIVEN
+// a set of entries returned from the LDAP search
+
+    // WHEN
+    AmbariLdapConfiguration ambariLdapConfiguration = attributeDetectionService.detectLdapUserAttributes(connection, testLdapConfiguration);
+
+    // THEN
+    Assert.assertNotNull(ambariLdapConfiguration);
+    Assert.assertEquals("The username attribute is not the expected", "uid", ambariLdapConfiguration.userNameAttribute());
+
+  }
+
+
+  private Map<String, Object> getTestPropertiesMap() {
+    Map<String, Object> ldapPropsMap = Maps.newHashMap();
+
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.ANONYMOUS_BIND.key(), "true");
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.SERVER_HOST.key(), "ldap.forumsys.com");
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.SERVER_PORT.key(), "389");
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.BIND_DN.key(), "dc=example,dc=com");
+
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.USER_OBJECT_CLASS.key(), SchemaConstants.PERSON_OC);
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.USER_NAME_ATTRIBUTE.key(), SchemaConstants.UID_AT);
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.USER_SEARCH_BASE.key(), "dc=example,dc=com");
+
+    return ldapPropsMap;
+
+  }
+
+  @Test
+  public void functionalTest() throws Exception {
+    // GIVEN
+    AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(getTestPropertiesMap());
+    LdapConnectionService connectionService = new DefaultLdapConnectionService();
+    LdapNetworkConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
+
+
+    // WHEN
+    AmbariLdapConfiguration config = attributeDetectionService.detectLdapUserAttributes(ldapConnection, ambariLdapConfiguration);
+
+    // THEN
+
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/4afe9814/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
index b5978a5..e023c6c 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
@@ -74,14 +74,14 @@ public class DefaultLdapConfigurationServiceTest {
     // GIVEN
     Map<String, Object> ldapPropsMap = Maps.newHashMap();
 
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BIND_ANONIMOUSLY.propertyName(), "true");
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_HOST.propertyName(), "ldap.forumsys.com");
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_PORT.propertyName(), "389");
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BASE_DN.propertyName(), "dc=example,dc=com");
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.ANONYMOUS_BIND.key(), "true");
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.SERVER_HOST.key(), "ldap.forumsys.com");
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.SERVER_PORT.key(), "389");
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.BIND_DN.key(), "dc=example,dc=com");
 
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_OBJECT_CLASS.propertyName(), SchemaConstants.PERSON_OC);
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_NAME_ATTRIBUTE.propertyName(), SchemaConstants.UID_AT);
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_SEARCH_BASE.propertyName(), "dc=example,dc=com");
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.USER_OBJECT_CLASS.key(), SchemaConstants.PERSON_OC);
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.USER_NAME_ATTRIBUTE.key(), SchemaConstants.UID_AT);
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.USER_SEARCH_BASE.key(), "dc=example,dc=com");
 
 
     AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(ldapPropsMap);
@@ -96,16 +96,14 @@ public class DefaultLdapConfigurationServiceTest {
     // GIVEN
     Map<String, Object> ldapPropsMap = Maps.newHashMap();
 
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BIND_ANONIMOUSLY.propertyName(), "true");
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_HOST.propertyName(), "ldap.forumsys.com");
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_PORT.propertyName(), "389");
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BASE_DN.propertyName(), "dc=example,dc=com");
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.ANONYMOUS_BIND.key(), "true");
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.SERVER_HOST.key(), "ldap.forumsys.com");
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.SERVER_PORT.key(), "389");
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.BIND_DN.key(), "dc=example,dc=com");
 
-
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_OBJECT_CLASS.propertyName(), SchemaConstants.GROUP_OF_UNIQUE_NAMES_OC);
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_NAME_ATTRIBUTE.propertyName(), SchemaConstants.CN_AT);
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_MEMBER_ATTRIBUTE.propertyName(), SchemaConstants.UNIQUE_MEMBER_AT);
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_SEARCH_BASE.propertyName(), "dc=example,dc=com");
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.USER_OBJECT_CLASS.key(), SchemaConstants.PERSON_OC);
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.USER_NAME_ATTRIBUTE.key(), SchemaConstants.UID_AT);
+    ldapPropsMap.put(AmbariLdapConfiguration.AmbariLdapConfig.USER_SEARCH_BASE.key(), "dc=example,dc=com");
 
 
     AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(ldapPropsMap);


[25/46] ambari git commit: AMBARI-21307 LDAP config rest service implementation extends the ambari config rest implementaiton

Posted by lp...@apache.org.
AMBARI-21307 LDAP config rest  service implementation extends the ambari config rest implementaiton


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 2e8d7b14875caf8d3d0c2a64a713b2be9226fb8e
Parents: 6c3dcc7
Author: lpuskas <lp...@apache.org>
Authored: Mon Aug 21 15:53:45 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:41:58 2017 +0200

----------------------------------------------------------------------
 .../services/ldap/LdapConfigurationService.java | 208 +++++++++++++++++++
 .../api/services/ldap/LdapRestService.java      | 149 -------------
 2 files changed, 208 insertions(+), 149 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/2e8d7b14/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
new file mode 100644
index 0000000..52244bc
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
@@ -0,0 +1,208 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.api.services.ldap;
+
+import java.util.Set;
+
+import javax.inject.Inject;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.ambari.annotations.ApiIgnore;
+import org.apache.ambari.server.StaticallyInject;
+import org.apache.ambari.server.api.services.AmbariConfigurationService;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultImpl;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.controller.internal.ResourceImpl;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.LdapConfigurationFactory;
+import org.apache.ambari.server.ldap.service.LdapFacade;
+import org.apache.ambari.server.security.authorization.AuthorizationException;
+import org.apache.ambari.server.security.authorization.AuthorizationHelper;
+import org.apache.ambari.server.security.authorization.ResourceType;
+import org.apache.ambari.server.security.authorization.RoleAuthorization;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.security.core.Authentication;
+
+import com.google.common.collect.Sets;
+
+/**
+ * Endpoint designated to LDAP specific operations.
+ */
+@StaticallyInject
+@Path("/ldapconfigs/")
+public class LdapConfigurationService extends AmbariConfigurationService {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(LdapConfigurationService.class);
+
+  @Inject
+  private static LdapFacade ldapFacade;
+
+  @Inject
+  private static LdapConfigurationFactory ldapConfigurationFactory;
+
+  /**
+   * Actions supported by this endpoint
+   */
+  private enum LdapAction {
+    TEST_CONNECTION("test-connection"),
+    TEST_ATTRIBUTES("test-attributes"),
+    DETECT_ATTRIBUTES("detect-attributes");
+
+    private String actionStr;
+
+    LdapAction(String actionStr) {
+      this.actionStr = actionStr;
+    }
+
+    public static LdapAction fromAction(String action) {
+      for (LdapAction val : LdapAction.values()) {
+        if (val.action().equals(action)) {
+          return val;
+        }
+      }
+      throw new IllegalStateException("Action [ " + action + " ] is not supported");
+    }
+
+    public String action() {
+      return this.actionStr;
+    }
+  }
+
+  @POST
+  @ApiIgnore // until documented
+  @Path("/validate")
+  @Consumes(MediaType.APPLICATION_JSON)
+  @Produces(MediaType.APPLICATION_JSON)
+  public Response validateConfiguration(LdapCheckConfigurationRequest ldapCheckConfigurationRequest) {
+
+    authorize();
+
+    Set<String> groups = Sets.newHashSet();
+
+    Result result = new ResultImpl(new ResultStatus(ResultStatus.STATUS.OK));
+    try {
+
+      validateRequest(ldapCheckConfigurationRequest);
+
+      AmbariLdapConfiguration ambariLdapConfiguration = ldapConfigurationFactory.createLdapConfiguration(
+        ldapCheckConfigurationRequest.getAmbariConfiguration().getData().iterator().next());
+
+      LdapAction action = LdapAction.fromAction(ldapCheckConfigurationRequest.getRequestInfo().getAction());
+      switch (action) {
+
+        case TEST_CONNECTION:
+
+          LOGGER.info("Testing connection to the LDAP server ...");
+          ldapFacade.checkConnection(ambariLdapConfiguration);
+
+          break;
+        case TEST_ATTRIBUTES:
+
+          LOGGER.info("Testing LDAP attributes ....");
+          groups = ldapFacade.checkLdapAttibutes(ldapCheckConfigurationRequest.getRequestInfo().getParameters(), ambariLdapConfiguration);
+          setResult(groups, result);
+
+          break;
+        case DETECT_ATTRIBUTES:
+
+          LOGGER.info("Detecting LDAP attributes ...");
+          ldapFacade.detectAttributes(ambariLdapConfiguration);
+
+          break;
+        default:
+          LOGGER.warn("No action provided ...");
+          throw new IllegalArgumentException("No request action provided");
+      }
+
+    } catch (Exception e) {
+      result.setResultStatus(new ResultStatus(ResultStatus.STATUS.BAD_REQUEST, e));
+    }
+
+    return Response.status(result.getStatus().getStatusCode()).entity(getResultSerializer().serialize(result)).build();
+  }
+
+  private void setResult(Set<String> groups, Result result) {
+    Resource resource = new ResourceImpl(Resource.Type.AmbariConfiguration);
+    resource.setProperty("groups", groups);
+    result.getResultTree().addChild(resource, "payload");
+  }
+
+  private void validateRequest(LdapCheckConfigurationRequest ldapCheckConfigurationRequest) {
+    String errMsg;
+
+    if (null == ldapCheckConfigurationRequest) {
+      errMsg = "No ldap configuraiton request provided";
+      LOGGER.error(errMsg);
+      throw new IllegalArgumentException(errMsg);
+    }
+
+    if (null == ldapCheckConfigurationRequest.getRequestInfo()) {
+      errMsg = String.format("No request information provided. Request: [%s]", ldapCheckConfigurationRequest);
+      LOGGER.error(errMsg);
+      throw new IllegalArgumentException(errMsg);
+    }
+
+    if (null == ldapCheckConfigurationRequest.getAmbariConfiguration()
+      || ldapCheckConfigurationRequest.getAmbariConfiguration().getData().size() != 1) {
+      errMsg = String.format("No / Invalid configuration data provided. Request: [%s]", ldapCheckConfigurationRequest);
+      LOGGER.error(errMsg);
+      throw new IllegalArgumentException(errMsg);
+    }
+  }
+
+  private void authorize() {
+    try {
+      Authentication authentication = AuthorizationHelper.getAuthentication();
+
+      if (authentication == null || !authentication.isAuthenticated()) {
+        throw new AuthorizationException("Authentication data is not available, authorization to perform the requested operation is not granted");
+      }
+
+      if (!AuthorizationHelper.isAuthorized(authentication, ResourceType.AMBARI, null, requiredAuthorizations())) {
+        throw new AuthorizationException("The authenticated user does not have the appropriate authorizations to create the requested resource(s)");
+      }
+    } catch (AuthorizationException e) {
+      LOGGER.error("Unauthorized operation.", e);
+      throw new IllegalArgumentException("User is not authorized to perform the operation", e);
+    }
+
+  }
+
+  Set<RoleAuthorization> requiredAuthorizations() {
+    return Sets.newHashSet(RoleAuthorization.AMBARI_MANAGE_CONFIGURATION);
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/2e8d7b14/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapRestService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapRestService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapRestService.java
deleted file mode 100644
index 4e654dc..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapRestService.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.api.services.ldap;
-
-import java.util.Set;
-
-import javax.inject.Inject;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-import org.apache.ambari.annotations.ApiIgnore;
-import org.apache.ambari.server.StaticallyInject;
-import org.apache.ambari.server.api.services.BaseService;
-import org.apache.ambari.server.api.services.Result;
-import org.apache.ambari.server.api.services.ResultImpl;
-import org.apache.ambari.server.api.services.ResultStatus;
-import org.apache.ambari.server.controller.internal.ResourceImpl;
-import org.apache.ambari.server.controller.spi.Resource;
-import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.LdapConfigurationFactory;
-import org.apache.ambari.server.ldap.service.LdapFacade;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.Sets;
-
-/**
- * Endpoint designated to LDAP specific operations.
- */
-@StaticallyInject
-@Path("/ldap")
-public class LdapRestService extends BaseService {
-
-  private static final Logger LOGGER = LoggerFactory.getLogger(LdapRestService.class);
-
-  @Inject
-  private static LdapFacade ldapFacade;
-
-  @Inject
-  private static LdapConfigurationFactory ldapConfigurationFactory;
-
-  @POST
-  @ApiIgnore // until documented
-  @Path("/validate") // todo this needs to be moved under the resource
-  @Consumes(MediaType.APPLICATION_JSON)
-  @Produces(MediaType.APPLICATION_JSON)
-  public Response validateConfiguration(LdapCheckConfigurationRequest ldapCheckConfigurationRequest) {
-
-    Set<String> groups = Sets.newHashSet();
-
-    Result result = new ResultImpl(new ResultStatus(ResultStatus.STATUS.OK));
-    try {
-
-      validateRequest(ldapCheckConfigurationRequest);
-
-      AmbariLdapConfiguration ambariLdapConfiguration = ldapConfigurationFactory.createLdapConfiguration(
-        ldapCheckConfigurationRequest.getAmbariConfiguration().getData().iterator().next());
-
-      switch (ldapCheckConfigurationRequest.getRequestInfo().getAction()) {
-        case "test-connection":
-
-          LOGGER.info("Testing connection to the LDAP server ...");
-          ldapFacade.checkConnection(ambariLdapConfiguration);
-
-          break;
-        case "test-attributes":
-
-          LOGGER.info("Testing LDAP attributes ....");
-          groups = ldapFacade.checkLdapAttibutes(ldapCheckConfigurationRequest.getRequestInfo().getParameters(), ambariLdapConfiguration);
-          setResult(groups, result);
-
-          break;
-        case "detect-attributes":
-
-          LOGGER.info("Detecting LDAP attributes ...");
-          ldapFacade.detectAttributes(ambariLdapConfiguration);
-
-          break;
-        default:
-          LOGGER.warn("No action provided ...");
-          throw new IllegalArgumentException("No request action provided");
-      }
-
-    } catch (Exception e) {
-      result.setResultStatus(new ResultStatus(ResultStatus.STATUS.BAD_REQUEST, e));
-    }
-
-    return Response.status(result.getStatus().getStatusCode()).entity(getResultSerializer().serialize(result)).build();
-  }
-
-  private void setResult(Set<String> groups, Result result) {
-    Resource resource = new ResourceImpl(Resource.Type.AmbariConfiguration);
-    resource.setProperty("groups", groups);
-    result.getResultTree().addChild(resource, "payload");
-  }
-
-  private void validateRequest(LdapCheckConfigurationRequest ldapCheckConfigurationRequest) {
-    String errMsg;
-
-    if (null == ldapCheckConfigurationRequest) {
-      errMsg = "No ldap configuraiton request provided";
-      LOGGER.error(errMsg);
-      throw new IllegalArgumentException(errMsg);
-    }
-
-    if (null == ldapCheckConfigurationRequest.getRequestInfo()) {
-      errMsg = String.format("No request information provided. Request: [%s]", ldapCheckConfigurationRequest);
-      LOGGER.error(errMsg);
-      throw new IllegalArgumentException(errMsg);
-    }
-
-    if (null == ldapCheckConfigurationRequest.getAmbariConfiguration()
-      || ldapCheckConfigurationRequest.getAmbariConfiguration().getData().size() != 1) {
-      errMsg = String.format("No / Invalid configuration data provided. Request: [%s]", ldapCheckConfigurationRequest);
-      LOGGER.error(errMsg);
-      throw new IllegalArgumentException(errMsg);
-    }
-  }
-}


[45/46] ambari git commit: AMBARI-21307 Improved the attribute detection implementation (using detector chains, added logging, improved guice setup).

Posted by lp...@apache.org.
AMBARI-21307 Improved the attribute detection implementation (using detector chains, added logging, improved guice setup).


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 468fdc3f2d250567fc3c6329dd43c48cbdf4e6ba
Parents: 3bb03e9
Author: lpuskas <lp...@apache.org>
Authored: Mon Oct 16 18:24:32 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:42:03 2017 +0200

----------------------------------------------------------------------
 .../apache/ambari/server/ldap/LdapModule.java   | 32 +++++++++
 .../ldap/domain/AmbariLdapConfigKeys.java       | 11 +++
 .../server/ldap/service/AttributeDetector.java  |  6 +-
 .../DefaultLdapAttributeDetectionService.java   | 70 +++++++++-----------
 .../ads/detectors/AttributeDetectorFactory.java | 52 +++++++++++++++
 .../ads/detectors/ChainedAttributeDetector.java | 59 +++++++++++++++++
 .../ads/detectors/GroupMemberAttrDetector.java  |  6 ++
 .../ads/detectors/GroupNameAttrDetector.java    |  6 ++
 .../ads/detectors/GroupObjectClassDetector.java |  6 ++
 .../OccurrenceAndWeightBasedDetector.java       | 10 ++-
 .../detectors/UserGroupMemberAttrDetector.java  |  6 ++
 .../ads/detectors/UserNameAttrDetector.java     |  8 +++
 .../ads/detectors/UserObjectClassDetector.java  |  6 ++
 .../server/ldap/LdapModuleFunctionalTest.java   | 20 ++++++
 14 files changed, 255 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/468fdc3f/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
index 67e84dc..089da1d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
@@ -19,6 +19,7 @@ import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
 import org.apache.ambari.server.ldap.domain.AmbariLdapConfigurationFactory;
 import org.apache.ambari.server.ldap.service.AmbariLdapConfigurationProvider;
 import org.apache.ambari.server.ldap.service.AmbariLdapFacade;
+import org.apache.ambari.server.ldap.service.AttributeDetector;
 import org.apache.ambari.server.ldap.service.LdapAttributeDetectionService;
 import org.apache.ambari.server.ldap.service.LdapConfigurationService;
 import org.apache.ambari.server.ldap.service.LdapConnectionConfigService;
@@ -26,15 +27,27 @@ import org.apache.ambari.server.ldap.service.LdapFacade;
 import org.apache.ambari.server.ldap.service.ads.DefaultLdapAttributeDetectionService;
 import org.apache.ambari.server.ldap.service.ads.DefaultLdapConfigurationService;
 import org.apache.ambari.server.ldap.service.ads.DefaultLdapConnectionConfigService;
+import org.apache.ambari.server.ldap.service.ads.detectors.AttributeDetectorFactory;
+import org.apache.ambari.server.ldap.service.ads.detectors.GroupMemberAttrDetector;
+import org.apache.ambari.server.ldap.service.ads.detectors.GroupNameAttrDetector;
+import org.apache.ambari.server.ldap.service.ads.detectors.GroupObjectClassDetector;
+import org.apache.ambari.server.ldap.service.ads.detectors.UserGroupMemberAttrDetector;
+import org.apache.ambari.server.ldap.service.ads.detectors.UserNameAttrDetector;
+import org.apache.ambari.server.ldap.service.ads.detectors.UserObjectClassDetector;
 
 import com.google.inject.AbstractModule;
 import com.google.inject.assistedinject.FactoryModuleBuilder;
+import com.google.inject.multibindings.Multibinder;
+import com.google.inject.name.Names;
 
 /**
  * GUICE configuration module for setting up LDAP related infrastructure.
  */
 public class LdapModule extends AbstractModule {
 
+  public static final String USER_ATTRIBUTES_DETECTORS = "UserAttributesDetectors";
+  public static final String GROUP_ATTRIBUTES_DETECTORS = "GroupAttributesDetectors";
+
   @Override
   protected void configure() {
     bind(LdapFacade.class).to(AmbariLdapFacade.class);
@@ -45,6 +58,25 @@ public class LdapModule extends AbstractModule {
     // this binding requires the JPA module!
     bind(AmbariLdapConfiguration.class).toProvider(AmbariLdapConfigurationProvider.class);
 
+    bind(AttributeDetectorFactory.class);
+
     install(new FactoryModuleBuilder().build(AmbariLdapConfigurationFactory.class));
+
+    // binding the set of user attributes detector
+    Multibinder<AttributeDetector> userAttributeDetectorBinder = Multibinder.newSetBinder(binder(), AttributeDetector.class,
+      Names.named(USER_ATTRIBUTES_DETECTORS));
+    userAttributeDetectorBinder.addBinding().to(UserObjectClassDetector.class);
+    userAttributeDetectorBinder.addBinding().to(UserNameAttrDetector.class);
+    userAttributeDetectorBinder.addBinding().to(UserGroupMemberAttrDetector.class);
+
+
+    // binding the set of group attributes detector
+    Multibinder<AttributeDetector> groupAttributeDetectorBinder = Multibinder.newSetBinder(binder(), AttributeDetector.class,
+      Names.named(GROUP_ATTRIBUTES_DETECTORS));
+    groupAttributeDetectorBinder.addBinding().to(GroupObjectClassDetector.class);
+    groupAttributeDetectorBinder.addBinding().to(GroupNameAttrDetector.class);
+    groupAttributeDetectorBinder.addBinding().to(GroupMemberAttrDetector.class);
+
   }
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/468fdc3f/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigKeys.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigKeys.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigKeys.java
index b7b41a3..da655ad 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigKeys.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigKeys.java
@@ -69,4 +69,15 @@ public enum AmbariLdapConfigKeys {
   public String key() {
     return this.propertyName;
   }
+
+  public static AmbariLdapConfigKeys fromKeyStr(String keyStr) {
+    for (AmbariLdapConfigKeys key : values()) {
+      if (key.key().equals(keyStr)) {
+        return key;
+      }
+    }
+
+    throw new IllegalStateException("invalid konfiguration key found!");
+
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/468fdc3f/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AttributeDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AttributeDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AttributeDetector.java
index c694b17..f39a1fd 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AttributeDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AttributeDetector.java
@@ -14,6 +14,8 @@
 
 package org.apache.ambari.server.ldap.service;
 
+import java.util.Map;
+
 /**
  * Operations for detecting LDAP related settings.
  * The basis for the attribute or value detection is a set of entries returned by a search operation.
@@ -31,9 +33,9 @@ public interface AttributeDetector<T> {
   /**
    * Implements the decision based on which the "best" possible attribute or value is selected.
    *
-   * @return the most probable attribute name or value (based on the logic in the implementer)
+   * @return a map of the form <property-key, detected-value>
    */
-  String detect();
+  Map<String, String> detect();
 
 
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/468fdc3f/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
index 204c46a..ea6e278 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
@@ -15,6 +15,7 @@
 package org.apache.ambari.server.ldap.service.ads;
 
 import java.util.List;
+import java.util.Map;
 
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -22,13 +23,9 @@ import javax.inject.Singleton;
 import org.apache.ambari.server.ldap.domain.AmbariLdapConfigKeys;
 import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
 import org.apache.ambari.server.ldap.service.AmbariLdapException;
+import org.apache.ambari.server.ldap.service.AttributeDetector;
 import org.apache.ambari.server.ldap.service.LdapAttributeDetectionService;
-import org.apache.ambari.server.ldap.service.ads.detectors.GroupMemberAttrDetector;
-import org.apache.ambari.server.ldap.service.ads.detectors.GroupNameAttrDetector;
-import org.apache.ambari.server.ldap.service.ads.detectors.GroupObjectClassDetector;
-import org.apache.ambari.server.ldap.service.ads.detectors.UserGroupMemberAttrDetector;
-import org.apache.ambari.server.ldap.service.ads.detectors.UserNameAttrDetector;
-import org.apache.ambari.server.ldap.service.ads.detectors.UserObjectClassDetector;
+import org.apache.ambari.server.ldap.service.ads.detectors.AttributeDetectorFactory;
 import org.apache.directory.api.ldap.model.entry.Entry;
 import org.apache.directory.api.ldap.model.exception.LdapException;
 import org.apache.directory.api.ldap.model.message.SearchRequest;
@@ -47,22 +44,7 @@ public class DefaultLdapAttributeDetectionService implements LdapAttributeDetect
   private static final int SAMPLE_RESULT_SIZE = 50;
 
   @Inject
-  private UserNameAttrDetector userNameAttrDetector;
-
-  @Inject
-  private UserObjectClassDetector userObjectClassDetector;
-
-  @Inject
-  private UserGroupMemberAttrDetector userGroupMemberAttrDetector;
-
-  @Inject
-  private GroupNameAttrDetector groupNameAttrDetector;
-
-  @Inject
-  private GroupObjectClassDetector groupObjectClassDetector;
-
-  @Inject
-  private GroupMemberAttrDetector groupMemberAttrDetector;
+  private AttributeDetectorFactory attributeDetectorFactory;
 
   @Inject
   private LdapConnectionTemplateFactory ldapConnectionTemplateFactory;
@@ -76,7 +58,7 @@ public class DefaultLdapAttributeDetectionService implements LdapAttributeDetect
   public AmbariLdapConfiguration detectLdapUserAttributes(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
     LOGGER.info("Detecting LDAP user attributes ...");
     LdapConnectionTemplate ldapConnectionTemplate = ldapConnectionTemplateFactory.create(ambariLdapConfiguration);
-
+    AttributeDetector<Entry> userAttributDetector = attributeDetectorFactory.userAttributDetector();
 
     // perform a search using the user search base
     if (Strings.isEmpty(ambariLdapConfiguration.userSearchBase())) {
@@ -92,23 +74,23 @@ public class DefaultLdapAttributeDetectionService implements LdapAttributeDetect
       List<Entry> entries = ldapConnectionTemplate.search(searchRequest, getEntryMapper());
 
       for (Entry entry : entries) {
-
         LOGGER.info("Processing sample entry with dn: [{}]", entry.getDn());
-
-        userNameAttrDetector.collect(entry);
-        userObjectClassDetector.collect(entry);
-        userGroupMemberAttrDetector.collect(entry);
-
+        userAttributDetector.collect(entry);
       }
 
-      ambariLdapConfiguration.setValueFor(AmbariLdapConfigKeys.USER_NAME_ATTRIBUTE, userNameAttrDetector.detect());
-      ambariLdapConfiguration.setValueFor(AmbariLdapConfigKeys.USER_OBJECT_CLASS, userObjectClassDetector.detect());
-      ambariLdapConfiguration.setValueFor(AmbariLdapConfigKeys.USER_GROUP_MEMBER_ATTRIBUTE, userGroupMemberAttrDetector.detect());
+      // select attributes based on the collected information
+      Map<String, String> detectedUserAttributes = userAttributDetector.detect();
+
+      // setting the attributes into the configuration
+      setDetectedAttributes(ambariLdapConfiguration, detectedUserAttributes);
 
       LOGGER.info("Decorated ambari ldap config : [{}]", ambariLdapConfiguration);
 
     } catch (Exception e) {
+
       LOGGER.error("Ldap operation failed", e);
+      throw new AmbariLdapException(e);
+
     }
 
     return ambariLdapConfiguration;
@@ -126,6 +108,7 @@ public class DefaultLdapAttributeDetectionService implements LdapAttributeDetect
     }
 
     LdapConnectionTemplate ldapConnectionTemplate = ldapConnectionTemplateFactory.create(ambariLdapConfiguration);
+    AttributeDetector<Entry> groupAttributDetector = attributeDetectorFactory.groupAttributDetector();
 
     try {
 
@@ -134,30 +117,39 @@ public class DefaultLdapAttributeDetectionService implements LdapAttributeDetect
       // do the search
       List<Entry> groupEntries = ldapConnectionTemplate.search(searchRequest, getEntryMapper());
 
-
       for (Entry groupEntry : groupEntries) {
 
         LOGGER.info("Processing sample entry with dn: [{}]", groupEntry.getDn());
-        groupNameAttrDetector.collect(groupEntry);
-        groupObjectClassDetector.collect(groupEntry);
-        groupMemberAttrDetector.collect(groupEntry);
+        groupAttributDetector.collect(groupEntry);
 
       }
 
-      ambariLdapConfiguration.setValueFor(AmbariLdapConfigKeys.GROUP_NAME_ATTRIBUTE, groupNameAttrDetector.detect());
-      ambariLdapConfiguration.setValueFor(AmbariLdapConfigKeys.GROUP_OBJECT_CLASS, groupObjectClassDetector.detect());
-      ambariLdapConfiguration.setValueFor(AmbariLdapConfigKeys.GROUP_MEMBER_ATTRIBUTE, groupMemberAttrDetector.detect());
+      // select attributes based on the collected information
+      Map<String, String> detectedGroupAttributes = groupAttributDetector.detect();
+
+      // setting the attributes into the configuration
+      setDetectedAttributes(ambariLdapConfiguration, detectedGroupAttributes);
 
       LOGGER.info("Decorated ambari ldap config : [{}]", ambariLdapConfiguration);
 
     } catch (Exception e) {
 
       LOGGER.error("Ldap operation failed", e);
+      throw new AmbariLdapException(e);
+
     }
 
     return ambariLdapConfiguration;
   }
 
+  private void setDetectedAttributes(AmbariLdapConfiguration ambariLdapConfiguration, Map<String, String> detectedAttributes) {
+    for (Map.Entry<String, String> detecteMapEntry : detectedAttributes.entrySet()) {
+      LOGGER.info("Setting detected configuration value: [{}] - > [{}]", detecteMapEntry.getKey(), detecteMapEntry.getValue());
+      ambariLdapConfiguration.setValueFor(AmbariLdapConfigKeys.fromKeyStr(detecteMapEntry.getKey()), detecteMapEntry.getValue());
+    }
+
+  }
+
   private SearchRequest assembleUserSearchRequest(LdapConnectionTemplate ldapConnectionTemplate, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
     try {
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/468fdc3f/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/AttributeDetectorFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/AttributeDetectorFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/AttributeDetectorFactory.java
new file mode 100644
index 0000000..08e3625
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/AttributeDetectorFactory.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads.detectors;
+
+import java.util.Set;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.apache.ambari.server.ldap.service.AttributeDetector;
+
+@Singleton
+public class AttributeDetectorFactory {
+
+  private static final String USER_ATTRIBUTES_DETECTORS = "UserAttributesDetectors";
+  private static final String GROUP_ATTRIBUTES_DETECTORS = "GroupAttributesDetectors";
+
+
+  @Inject
+  @Named(USER_ATTRIBUTES_DETECTORS)
+  private Set<AttributeDetector> userAttributeDetectors;
+
+  @Inject
+  @Named(GROUP_ATTRIBUTES_DETECTORS)
+  Set<AttributeDetector> groupAttributeDetectors;
+
+  public AttributeDetectorFactory() {
+  }
+
+  public ChainedAttributeDetector userAttributDetector() {
+    return new ChainedAttributeDetector(userAttributeDetectors);
+  }
+
+  public ChainedAttributeDetector groupAttributDetector() {
+    return new ChainedAttributeDetector(groupAttributeDetectors);
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/468fdc3f/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/ChainedAttributeDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/ChainedAttributeDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/ChainedAttributeDetector.java
new file mode 100644
index 0000000..ad70d0b
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/ChainedAttributeDetector.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads.detectors;
+
+import java.util.Map;
+import java.util.Set;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.apache.ambari.server.ldap.service.AttributeDetector;
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Maps;
+
+@Singleton
+public class ChainedAttributeDetector implements AttributeDetector<Entry> {
+
+  private static final Logger LOG = LoggerFactory.getLogger(ChainedAttributeDetector.class);
+
+  private Set<AttributeDetector> detectors;
+
+  @Inject
+  public ChainedAttributeDetector(Set<AttributeDetector> detectors) {
+    this.detectors = detectors;
+  }
+
+  @Override
+  public void collect(Entry entry) {
+    for (AttributeDetector detector : detectors) {
+      LOG.info("Collecting information for the detector: [{}]", detector);
+      detector.collect(entry);
+    }
+  }
+
+  @Override
+  public Map<String, String> detect() {
+    Map<String, String> detectedAttributes = Maps.newHashMap();
+    for (AttributeDetector detector : detectors) {
+      LOG.info("Detecting ldap configuration value using the detector: [{}]", detector);
+      detectedAttributes.putAll(detector.detect());
+    }
+    return detectedAttributes;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/468fdc3f/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java
index 9f38357..72e753b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupMemberAttrDetector.java
@@ -16,6 +16,7 @@ package org.apache.ambari.server.ldap.service.ads.detectors;
 
 import javax.inject.Inject;
 
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfigKeys;
 import org.apache.directory.api.ldap.model.entry.Entry;
 
 public class GroupMemberAttrDetector extends OccurrenceAndWeightBasedDetector {
@@ -56,4 +57,9 @@ public class GroupMemberAttrDetector extends OccurrenceAndWeightBasedDetector {
   protected boolean applies(Entry entry, String value) {
     return entry.containsAttribute(value);
   }
+
+  @Override
+  public String detectedProperty() {
+    return AmbariLdapConfigKeys.USER_GROUP_MEMBER_ATTRIBUTE.key();
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/468fdc3f/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupNameAttrDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupNameAttrDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupNameAttrDetector.java
index 0f48348..ca54dad 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupNameAttrDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupNameAttrDetector.java
@@ -16,6 +16,7 @@ package org.apache.ambari.server.ldap.service.ads.detectors;
 
 import javax.inject.Inject;
 
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfigKeys;
 import org.apache.directory.api.ldap.model.entry.Entry;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -61,4 +62,9 @@ public class GroupNameAttrDetector extends OccurrenceAndWeightBasedDetector {
   protected boolean applies(Entry entry, String value) {
     return entry.containsAttribute(value);
   }
+
+  @Override
+  public String detectedProperty() {
+    return AmbariLdapConfigKeys.GROUP_NAME_ATTRIBUTE.key();
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/468fdc3f/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupObjectClassDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupObjectClassDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupObjectClassDetector.java
index 9338e70..8f342f1 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupObjectClassDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/GroupObjectClassDetector.java
@@ -16,6 +16,7 @@ package org.apache.ambari.server.ldap.service.ads.detectors;
 
 import javax.inject.Inject;
 
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfigKeys;
 import org.apache.directory.api.ldap.model.entry.Entry;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -64,4 +65,9 @@ public class GroupObjectClassDetector extends OccurrenceAndWeightBasedDetector {
   protected boolean applies(Entry entry, String value) {
     return entry.hasObjectClass(value);
   }
+
+  @Override
+  public String detectedProperty() {
+    return AmbariLdapConfigKeys.GROUP_OBJECT_CLASS.key();
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/468fdc3f/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurrenceAndWeightBasedDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurrenceAndWeightBasedDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurrenceAndWeightBasedDetector.java
index 2ec559b..cb78d25 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurrenceAndWeightBasedDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/OccurrenceAndWeightBasedDetector.java
@@ -41,9 +41,13 @@ public abstract class OccurrenceAndWeightBasedDetector implements AttributeDetec
 
   protected abstract boolean applies(Entry entry, String value);
 
+  public abstract String detectedProperty();
+
   @Override
-  public String detect() {
+  public Map<String, String> detect() {
     LOGGER.info("Calculating the most probable attribute/value ...");
+    Map<String, String> detectedMap = Maps.newHashMap();
+
     Map.Entry<String, Integer> selectedEntry = null;
 
     for (Map.Entry<String, Integer> entry : occurrenceMap().entrySet()) {
@@ -73,9 +77,11 @@ public abstract class OccurrenceAndWeightBasedDetector implements AttributeDetec
     }
 
     LOGGER.info("Detected attribute or value: [{}]", detectedVal);
-    return detectedVal;
+    detectedMap.put(detectedProperty(), detectedVal);
+    return detectedMap;
   }
 
+
   @Override
   public void collect(Entry entry) {
     LOGGER.info("Collecting ldap attributes/values form entry with dn: [{}]", entry.getDn());

http://git-wip-us.apache.org/repos/asf/ambari/blob/468fdc3f/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java
index f04201e..63ad8ba 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserGroupMemberAttrDetector.java
@@ -16,6 +16,7 @@ package org.apache.ambari.server.ldap.service.ads.detectors;
 
 import javax.inject.Inject;
 
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfigKeys;
 import org.apache.directory.api.ldap.model.entry.Entry;
 
 public class UserGroupMemberAttrDetector extends OccurrenceAndWeightBasedDetector {
@@ -55,4 +56,9 @@ public class UserGroupMemberAttrDetector extends OccurrenceAndWeightBasedDetecto
   protected boolean applies(Entry entry, String value) {
     return entry.containsAttribute(value);
   }
+
+  @Override
+  public String detectedProperty() {
+    return AmbariLdapConfigKeys.USER_GROUP_MEMBER_ATTRIBUTE.key();
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/468fdc3f/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserNameAttrDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserNameAttrDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserNameAttrDetector.java
index 2c41162..8f46d72 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserNameAttrDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserNameAttrDetector.java
@@ -15,11 +15,14 @@
 package org.apache.ambari.server.ldap.service.ads.detectors;
 
 import javax.inject.Inject;
+import javax.inject.Singleton;
 
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfigKeys;
 import org.apache.directory.api.ldap.model.entry.Entry;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@Singleton
 public class UserNameAttrDetector extends OccurrenceAndWeightBasedDetector {
   private static final Logger LOGGER = LoggerFactory.getLogger(UserNameAttrDetector.class);
 
@@ -60,4 +63,9 @@ public class UserNameAttrDetector extends OccurrenceAndWeightBasedDetector {
     return entry.containsAttribute(value);
   }
 
+  @Override
+  public String detectedProperty() {
+    return AmbariLdapConfigKeys.USER_NAME_ATTRIBUTE.key();
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/468fdc3f/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserObjectClassDetector.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserObjectClassDetector.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserObjectClassDetector.java
index 2b47671..902dff9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserObjectClassDetector.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/UserObjectClassDetector.java
@@ -16,6 +16,7 @@ package org.apache.ambari.server.ldap.service.ads.detectors;
 
 import javax.inject.Inject;
 
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfigKeys;
 import org.apache.directory.api.ldap.model.entry.Entry;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -61,4 +62,9 @@ public class UserObjectClassDetector extends OccurrenceAndWeightBasedDetector {
     return entry.hasObjectClass(value);
   }
 
+  @Override
+  public String detectedProperty() {
+    return AmbariLdapConfigKeys.USER_OBJECT_CLASS.key();
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/468fdc3f/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
index 91f4e10..e77f816 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/LdapModuleFunctionalTest.java
@@ -15,13 +15,16 @@
 package org.apache.ambari.server.ldap;
 
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.ambari.server.ldap.domain.AmbariLdapConfigKeys;
 import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
 import org.apache.ambari.server.ldap.domain.TestAmbariLdapConfigurationFactory;
+import org.apache.ambari.server.ldap.service.AttributeDetector;
 import org.apache.ambari.server.ldap.service.LdapConfigurationService;
 import org.apache.ambari.server.ldap.service.LdapFacade;
 import org.apache.ambari.server.ldap.service.ads.LdapConnectionTemplateFactory;
+import org.apache.ambari.server.ldap.service.ads.detectors.AttributeDetectorFactory;
 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
 import org.apache.directory.api.ldap.model.exception.LdapException;
 import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
@@ -36,6 +39,7 @@ import org.junit.Ignore;
 import org.junit.Test;
 
 import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
 import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
@@ -170,4 +174,20 @@ public class LdapModuleFunctionalTest {
     // THEN
     // no exceptions thrown
   }
+
+
+  @Test
+  public void testShouldDetectorsBeBound() throws Exception {
+    // GIVEN
+
+    Set<AttributeDetector> adSet = Sets.newHashSet();
+//    ChainedAttributeDetector ad = injector.getInstance(ChainedAttributeDetector.class);
+
+    AttributeDetectorFactory f = injector.getInstance(AttributeDetectorFactory.class);
+    // WHEN
+    Assert.assertNotNull(f);
+
+    // THEN
+
+  }
 }
\ No newline at end of file


[11/46] ambari git commit: AMBARI-22258. Use correct property attribute setter fn(). while setting 'tez.runtime.io.sort.mb' maximum value.

Posted by lp...@apache.org.
AMBARI-22258. Use correct property attribute setter fn(). while setting 'tez.runtime.io.sort.mb' maximum value.


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 3b5cbed0983ef3e47b6a948dcbeeef0ac5d6a604
Parents: 37d59f2
Author: Swapan Shridhar <ss...@hortonworks.com>
Authored: Wed Oct 18 13:05:40 2017 -0700
Committer: Swapan Shridhar <ss...@hortonworks.com>
Committed: Wed Oct 18 13:05:40 2017 -0700

----------------------------------------------------------------------
 .../resources/common-services/YARN/3.0.0.3.0/service_advisor.py | 3 ++-
 .../src/main/resources/stacks/HDP/2.5/services/stack_advisor.py | 3 ++-
 .../src/test/python/stacks/2.5/common/test_stack_advisor.py     | 5 ++++-
 3 files changed, 8 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/3b5cbed0/ambari-server/src/main/resources/common-services/YARN/3.0.0.3.0/service_advisor.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/YARN/3.0.0.3.0/service_advisor.py b/ambari-server/src/main/resources/common-services/YARN/3.0.0.3.0/service_advisor.py
index ecf245d..70eb5be 100644
--- a/ambari-server/src/main/resources/common-services/YARN/3.0.0.3.0/service_advisor.py
+++ b/ambari-server/src/main/resources/common-services/YARN/3.0.0.3.0/service_advisor.py
@@ -580,6 +580,7 @@ class YARNRecommender(service_advisor.ServiceAdvisor):
     putHiveInteractiveEnvProperty = self.putProperty(configurations, "hive-interactive-env", services)
     putHiveInteractiveEnvPropertyAttribute = self.putPropertyAttribute(configurations, "hive-interactive-env")
     putTezInteractiveSiteProperty = self.putProperty(configurations, "tez-interactive-site", services)
+    putTezInteractiveSitePropertyAttribute = self.putPropertyAttribute(configurations, "tez-interactive-site")
     llap_daemon_selected_queue_name = None
     selected_queue_is_ambari_managed_llap = None  # Queue named 'llap' at root level is Ambari managed.
     llap_selected_queue_am_percent = None
@@ -1047,7 +1048,7 @@ class YARNRecommender(service_advisor.ServiceAdvisor):
     putTezInteractiveSiteProperty('tez.runtime.io.sort.mb', tez_runtime_io_sort_mb)
     if "tez-site" in services["configurations"] and "tez.runtime.sorter.class" in services["configurations"]["tez-site"]["properties"]:
       if services["configurations"]["tez-site"]["properties"]["tez.runtime.sorter.class"] == "LEGACY":
-        putTezInteractiveSiteProperty("tez.runtime.io.sort.mb", "maximum", 1800)
+        putTezInteractiveSitePropertyAttribute("tez.runtime.io.sort.mb", "maximum", 1800)
 
     putTezInteractiveSiteProperty('tez.runtime.unordered.output.buffer.size-mb', tez_runtime_unordered_output_buffer_size)
     putHiveInteractiveSiteProperty('hive.auto.convert.join.noconditionaltask.size', hive_auto_convert_join_noconditionaltask_size)

http://git-wip-us.apache.org/repos/asf/ambari/blob/3b5cbed0/ambari-server/src/main/resources/stacks/HDP/2.5/services/stack_advisor.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.5/services/stack_advisor.py b/ambari-server/src/main/resources/stacks/HDP/2.5/services/stack_advisor.py
index 92ce9b9..b6f2478 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.5/services/stack_advisor.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.5/services/stack_advisor.py
@@ -860,6 +860,7 @@ class HDP25StackAdvisor(HDP24StackAdvisor):
     putHiveInteractiveEnvProperty = self.putProperty(configurations, "hive-interactive-env", services)
     putHiveInteractiveEnvPropertyAttribute = self.putPropertyAttribute(configurations, "hive-interactive-env")
     putTezInteractiveSiteProperty = self.putProperty(configurations, "tez-interactive-site", services)
+    putTezInteractiveSitePropertyAttribute = self.putPropertyAttribute(configurations, "tez-interactive-site")
     llap_daemon_selected_queue_name = None
     selected_queue_is_ambari_managed_llap = None  # Queue named 'llap' at root level is Ambari managed.
     llap_selected_queue_am_percent = None
@@ -1331,7 +1332,7 @@ class HDP25StackAdvisor(HDP24StackAdvisor):
     putTezInteractiveSiteProperty('tez.runtime.io.sort.mb', tez_runtime_io_sort_mb)
     if "tez-site" in services["configurations"] and "tez.runtime.sorter.class" in services["configurations"]["tez-site"]["properties"]:
       if services["configurations"]["tez-site"]["properties"]["tez.runtime.sorter.class"] == "LEGACY":
-        putTezInteractiveSiteProperty("tez.runtime.io.sort.mb", "maximum", 1800)
+        putTezInteractiveSitePropertyAttribute("tez.runtime.io.sort.mb", "maximum", 1800)
 
     putTezInteractiveSiteProperty('tez.runtime.unordered.output.buffer.size-mb', tez_runtime_unordered_output_buffer_size)
     putHiveInteractiveSiteProperty('hive.auto.convert.join.noconditionaltask.size', hive_auto_convert_join_noconditionaltask_size)

http://git-wip-us.apache.org/repos/asf/ambari/blob/3b5cbed0/ambari-server/src/test/python/stacks/2.5/common/test_stack_advisor.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.5/common/test_stack_advisor.py b/ambari-server/src/test/python/stacks/2.5/common/test_stack_advisor.py
index cf462de..407e78d 100644
--- a/ambari-server/src/test/python/stacks/2.5/common/test_stack_advisor.py
+++ b/ambari-server/src/test/python/stacks/2.5/common/test_stack_advisor.py
@@ -4446,7 +4446,8 @@ class TestHDP25StackAdvisor(TestCase):
           },
         "tez-site": {
           "properties": {
-            "tez.am.resource.memory.mb": "1024"
+            "tez.am.resource.memory.mb": "1024",
+            "tez.runtime.sorter.class": "LEGACY"
           }
         },
       }
@@ -4481,6 +4482,8 @@ class TestHDP25StackAdvisor(TestCase):
 
     self.assertEqual(configurations['hive-interactive-site']['properties']['hive.llap.io.memory.size'], '186368')
     self.assertEqual(configurations['hive-interactive-env']['properties']['llap_heap_size'], '9830')
+    self.assertEqual(configurations['tez-interactive-site']['properties']['tez.runtime.io.sort.mb'], '1092')
+    self.assertEquals(configurations['tez-interactive-site']['property_attributes']['tez.runtime.io.sort.mb'], {'maximum': '1800'})
 
 
 


[39/46] ambari git commit: AMBARI-21307 Added unit test for the LdapFacade

Posted by lp...@apache.org.
AMBARI-21307 Added unit test for the LdapFacade


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 32c292c7a9708dd74407d3a677059964144ece61
Parents: e1fe7b6
Author: lpuskas <lp...@apache.org>
Authored: Thu Oct 12 16:53:31 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:42:02 2017 +0200

----------------------------------------------------------------------
 .../services/AmbariConfigurationService.java    |   2 +-
 .../ldap/domain/AmbariLdapConfiguration.java    |  22 ++
 .../server/ldap/service/AmbariLdapFacade.java   |  10 +-
 .../ldap/service/AmbariLdapFacadeTest.java      | 215 +++++++++++++++++++
 4 files changed, 245 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/32c292c7/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java
index 492509f..38ae766 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java
@@ -150,7 +150,7 @@ public class AmbariConfigurationService extends BaseService {
   @PUT
   @Path("{configurationId}")
   @Produces(MediaType.TEXT_PLAIN)
-  @ApiOperation(value = "Updates ambari configuration resources - Not implemented yet",
+  @ApiOperation(value = "Updates ambari configuration resources ",
     nickname = "AmbariConfigurationService#updateAmbariConfiguration")
   @ApiImplicitParams({
     @ApiImplicitParam(dataType = AMBARI_CONFIGURATION_REQUEST_TYPE, paramType = PARAM_TYPE_BODY),

http://git-wip-us.apache.org/repos/asf/ambari/blob/32c292c7/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfiguration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfiguration.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfiguration.java
index d071ebe..8b26cd3 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfiguration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfiguration.java
@@ -19,6 +19,8 @@ import java.util.Map;
 
 import javax.inject.Inject;
 
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -174,4 +176,24 @@ public class AmbariLdapConfiguration {
   public String toString() {
     return configurationMap.toString();
   }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+
+    if (o == null || getClass() != o.getClass()) return false;
+
+    AmbariLdapConfiguration that = (AmbariLdapConfiguration) o;
+
+    return new EqualsBuilder()
+      .append(configurationMap, that.configurationMap)
+      .isEquals();
+  }
+
+  @Override
+  public int hashCode() {
+    return new HashCodeBuilder(17, 37)
+      .append(configurationMap)
+      .toHashCode();
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/32c292c7/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
index c75b0c4..bbfbc8e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
@@ -33,7 +33,7 @@ public class AmbariLdapFacade implements LdapFacade {
   /**
    * Additional parameters expected to be provided along with the configuration
    */
-  private enum Parameters {
+  protected enum Parameters {
     TEST_USER_NAME("ambari.ldap.test.user.name"),
     TEST_USER_PASSWORD("ambari.ldap.test.user.password");
 
@@ -43,7 +43,7 @@ public class AmbariLdapFacade implements LdapFacade {
       this.parameterKey = parameterKey;
     }
 
-    private String getParameterKey() {
+    public String getParameterKey() {
       return parameterKey;
     }
 
@@ -62,6 +62,7 @@ public class AmbariLdapFacade implements LdapFacade {
   @Override
   public void checkConnection(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
     try {
+
       ldapConfigurationService.checkConnection(ambariLdapConfiguration);
       LOGGER.info("Validating LDAP connection related configuration: SUCCESS");
 
@@ -80,12 +81,15 @@ public class AmbariLdapFacade implements LdapFacade {
     LOGGER.info("Detecting LDAP configuration attributes ...");
 
     try {
-
+      LOGGER.info("Detecting user attributes ....");
       // decorate the configuration with detected user attributes
       ambariLdapConfiguration = ldapAttributeDetectionService.detectLdapUserAttributes(ambariLdapConfiguration);
 
+      LOGGER.info("Detecting group attributes ....");
       // decorate the configuration with detected group attributes
       ambariLdapConfiguration = ldapAttributeDetectionService.detectLdapGroupAttributes(ambariLdapConfiguration);
+
+      LOGGER.info("Attribute detection finished.");
       return ambariLdapConfiguration;
 
     } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/32c292c7/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/AmbariLdapFacadeTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/AmbariLdapFacadeTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/AmbariLdapFacadeTest.java
new file mode 100644
index 0000000..8552f86
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/AmbariLdapFacadeTest.java
@@ -0,0 +1,215 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfigKeys;
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfigurationFactory;
+import org.apache.ambari.server.ldap.domain.TestAmbariAmbariLdapConfigurationFactory;
+import org.easymock.Capture;
+import org.easymock.EasyMock;
+import org.easymock.EasyMockRule;
+import org.easymock.EasyMockSupport;
+import org.easymock.Mock;
+import org.easymock.MockType;
+import org.easymock.TestSubject;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+
+/**
+ * Unit test suite for the LdapFacade operations.
+ */
+public class AmbariLdapFacadeTest extends EasyMockSupport {
+
+  @Rule
+  public EasyMockRule mocks = new EasyMockRule(this);
+
+  @Mock(type = MockType.STRICT)
+  public LdapConfigurationService ldapConfigurationServiceMock;
+
+  @Mock(type = MockType.STRICT)
+  public LdapAttributeDetectionService ldapAttributeDetectionServiceMock;
+
+  private AmbariLdapConfigurationFactory ambariLdapConfigurationFactory;
+
+
+  @TestSubject
+  private LdapFacade ldapFacade = new AmbariLdapFacade();
+
+  private AmbariLdapConfiguration ambariLdapConfiguration;
+
+
+  private Capture<AmbariLdapConfiguration> ambariLdapConfigurationCapture;
+
+  @Before
+  public void before() {
+    ambariLdapConfigurationFactory = new TestAmbariAmbariLdapConfigurationFactory();
+    ambariLdapConfiguration = ambariLdapConfigurationFactory.createLdapConfiguration(Maps.newHashMap());
+    ambariLdapConfigurationCapture = Capture.newInstance();
+
+
+    resetAll();
+  }
+
+  /**
+   * Tests whether the facade method call delegates to the proper service call.
+   * The thest is success if the same instance is passed to the service.
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testShouldConfigurationCheckDelegateToTheRightServiceCall() throws Exception {
+    // GIVEN
+    // the mocks are set up
+    ldapConfigurationServiceMock.checkConnection(EasyMock.capture(ambariLdapConfigurationCapture));
+    replayAll();
+    // WHEN
+    // the facade method is called
+    ldapFacade.checkConnection(ambariLdapConfiguration);
+
+    // THEN
+    // the captured configuration instance is the same the facade method got called with
+    Assert.assertEquals("The configuration instance souldn't change before passing it to the service",
+      ambariLdapConfiguration, ambariLdapConfigurationCapture.getValue());
+  }
+
+  @Test(expected = AmbariLdapException.class)
+  public void testShouldConfigurationCheckFailureResultInAmbariLdapException() throws Exception {
+    // GIVEN
+    ldapConfigurationServiceMock.checkConnection(EasyMock.anyObject(AmbariLdapConfiguration.class));
+    EasyMock.expectLastCall().andThrow(new AmbariLdapException("Testing ..."));
+    replayAll();
+
+    // WHEN
+    ldapFacade.checkConnection(ambariLdapConfiguration);
+
+    // THEN
+    // exception is thrown
+
+  }
+
+  @Test
+  public void testShouldLdapAttributesCheckDelegateToTheRightServiceCalls() throws Exception {
+    // GIVEN
+
+    Map<String, Object> parameters = Maps.newHashMap();
+    parameters.put(AmbariLdapFacade.Parameters.TEST_USER_NAME.getParameterKey(), "testUser");
+    parameters.put(AmbariLdapFacade.Parameters.TEST_USER_PASSWORD.getParameterKey(), "testPassword");
+
+
+    Capture<String> testUserCapture = Capture.newInstance();
+    Capture<String> testPasswordCapture = Capture.newInstance();
+    Capture<String> userDnCapture = Capture.newInstance();
+
+    EasyMock.expect(ldapConfigurationServiceMock.checkUserAttributes(EasyMock.capture(testUserCapture), EasyMock.capture(testPasswordCapture),
+      EasyMock.capture(ambariLdapConfigurationCapture))).andReturn("userDn");
+
+    EasyMock.expect(ldapConfigurationServiceMock.checkGroupAttributes(EasyMock.capture(userDnCapture),
+      EasyMock.capture(ambariLdapConfigurationCapture))).andReturn(Sets.newHashSet("userGroup"));
+
+    replayAll();
+
+    // WHEN
+    Set<String> testUserGroups = ldapFacade.checkLdapAttributes(parameters, ambariLdapConfiguration);
+
+    // THEN
+    Assert.assertEquals("testUser", testUserCapture.getValue());
+    Assert.assertEquals("testPassword", testPasswordCapture.getValue());
+    Assert.assertEquals("userDn", userDnCapture.getValue());
+
+    Assert.assertTrue(testUserGroups.contains("userGroup"));
+
+  }
+
+  @Test(expected = AmbariLdapException.class)
+  public void testShouldAttributeCheckFailuresResultInAmbariLdapException() throws Exception {
+    // GIVEN
+    Map<String, Object> parameters = Maps.newHashMap();
+    parameters.put(AmbariLdapFacade.Parameters.TEST_USER_NAME.getParameterKey(), "testUser");
+    parameters.put(AmbariLdapFacade.Parameters.TEST_USER_PASSWORD.getParameterKey(), "testPassword");
+
+    EasyMock.expect(ldapConfigurationServiceMock.checkUserAttributes(EasyMock.anyString(), EasyMock.anyString(),
+      EasyMock.anyObject(AmbariLdapConfiguration.class))).andThrow(new AmbariLdapException("Testing ..."));
+
+    replayAll();
+
+    // WHEN
+    Set<String> testUserGroups = ldapFacade.checkLdapAttributes(parameters, ambariLdapConfiguration);
+    // THEN
+    // Exception is thrown
+  }
+
+  @Test
+  public void testShouldLdapAttributeDetectionDelegateToTheRightServiceCalls() throws Exception {
+
+    // configuration map with user attributes detected
+    Map<String, Object> userConfigMap = Maps.newHashMap();
+    userConfigMap.put(AmbariLdapConfigKeys.USER_NAME_ATTRIBUTE.key(), "uid");
+    AmbariLdapConfiguration userAttrDecoratedConfig = ambariLdapConfigurationFactory.createLdapConfiguration(userConfigMap);
+
+    // configuration map with user+group attributes detected
+    Map<String, Object> groupConfigMap = Maps.newHashMap(userConfigMap);
+    groupConfigMap.put(AmbariLdapConfigKeys.GROUP_NAME_ATTRIBUTE.key(), "dn");
+    AmbariLdapConfiguration groupAttrDecoratedConfig = ambariLdapConfigurationFactory.createLdapConfiguration(groupConfigMap);
+
+    Capture<AmbariLdapConfiguration> userAttrDetectionConfigCapture = Capture.newInstance();
+    Capture<AmbariLdapConfiguration> groupAttrDetectionConfigCapture = Capture.newInstance();
+
+    // GIVEN
+    EasyMock.expect(ldapAttributeDetectionServiceMock.detectLdapUserAttributes(EasyMock.capture(userAttrDetectionConfigCapture)))
+      .andReturn(userAttrDecoratedConfig);
+
+    EasyMock.expect(ldapAttributeDetectionServiceMock.detectLdapGroupAttributes(EasyMock.capture(groupAttrDetectionConfigCapture)))
+      .andReturn(groupAttrDecoratedConfig);
+
+    replayAll();
+
+    // WHEN
+    AmbariLdapConfiguration detected = ldapFacade.detectAttributes(ambariLdapConfiguration);
+
+    // THEN
+    Assert.assertEquals("User attribute detection called with the wrong configuration", ambariLdapConfiguration,
+      userAttrDetectionConfigCapture.getValue());
+
+    Assert.assertEquals("Group attribute detection called with the wrong configuration", userAttrDecoratedConfig,
+      groupAttrDetectionConfigCapture.getValue());
+
+    Assert.assertEquals("Attribute detection returned an invalid configuration", groupAttrDecoratedConfig, detected);
+
+  }
+
+  @Test(expected = AmbariLdapException.class)
+  public void testShouldAttributeDetectionFailuresResultInAmbariLdapException() throws Exception {
+    // GIVEN
+    EasyMock.expect(ldapAttributeDetectionServiceMock.detectLdapUserAttributes(EasyMock.anyObject(AmbariLdapConfiguration.class)))
+      .andThrow(new AmbariLdapException("Testing ..."));
+
+    replayAll();
+
+    // WHEN
+    ldapFacade.detectAttributes(ambariLdapConfiguration);
+
+    // THEN
+    // Exception is thrown
+  }
+}
\ No newline at end of file


[12/46] ambari git commit: AMBARI-22228 - Remove Remote Tea Runtime library dependency from Storm binaries (Arun Mahadevan via jonathanhurley)

Posted by lp...@apache.org.
AMBARI-22228 - Remove Remote Tea Runtime library dependency from Storm binaries (Arun Mahadevan via jonathanhurley)


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 8852f33b90d4983dd9927184f0c20153eaf3b065
Parents: 3b5cbed
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Wed Oct 18 16:54:16 2017 -0400
Committer: Jonathan Hurley <jh...@hortonworks.com>
Committed: Wed Oct 18 17:27:11 2017 -0400

----------------------------------------------------------------------
 .../resources/stacks/HDP/2.3/upgrades/config-upgrade.xml  |  5 +++++
 .../stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.6.xml    |  3 +++
 .../resources/stacks/HDP/2.3/upgrades/upgrade-2.6.xml     |  1 +
 .../resources/stacks/HDP/2.4/upgrades/config-upgrade.xml  |  4 ++++
 .../stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.6.xml    |  3 +++
 .../resources/stacks/HDP/2.4/upgrades/upgrade-2.6.xml     |  1 +
 .../resources/stacks/HDP/2.5/upgrades/config-upgrade.xml  | 10 ++++++++++
 .../stacks/HDP/2.5/upgrades/nonrolling-upgrade-2.6.xml    |  3 +++
 .../resources/stacks/HDP/2.5/upgrades/upgrade-2.6.xml     |  1 +
 .../HDP/2.6/services/STORM/configuration/storm-site.xml   |  6 +++---
 .../resources/stacks/HDP/2.6/upgrades/config-upgrade.xml  |  4 ++++
 .../stacks/HDP/2.6/upgrades/nonrolling-upgrade-2.6.xml    |  4 ++++
 .../resources/stacks/HDP/2.6/upgrades/upgrade-2.6.xml     |  1 +
 13 files changed, 43 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/8852f33b/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/config-upgrade.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/config-upgrade.xml b/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/config-upgrade.xml
index ff12150..c4a5b95 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/config-upgrade.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/config-upgrade.xml
@@ -660,6 +660,11 @@
                      replace-with="${sys:workers.artifacts}/${sys:storm.id}/${sys:worker.port}/${sys:logfile.name}"/>
           </definition>
 
+          <definition xsi:type="configure" id="storm_remove_jmxetric" summary="Removing jmxetric from childopts.">
+            <type>storm-site</type>
+            <regex-replace key="content" find=" -javaagent:.*JVM" replace-with=""/>
+          </definition>
+
         </changes>
       </component>
     </service>

http://git-wip-us.apache.org/repos/asf/ambari/blob/8852f33b/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.6.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.6.xml b/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.6.xml
index 4034f4b..907626d 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.6.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.6.xml
@@ -671,6 +671,9 @@
           <summary>Update Storm log directory in storm worker log4j</summary>
         </task>
       </execute-stage>
+      <execute-stage service="STORM" component="NIMBUS" title="Removing jmxetric from childopts">
+        <task xsi:type="configure" id="storm_remove_jmxetric"/>
+      </execute-stage>
 
       <!--ATLAS-->
       <execute-stage service="ATLAS" component="ATLAS_SERVER" title="Parameterizing Atlas Log4J Properties">

http://git-wip-us.apache.org/repos/asf/ambari/blob/8852f33b/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/upgrade-2.6.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/upgrade-2.6.xml b/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/upgrade-2.6.xml
index 2e2c9c3..567e6e1 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/upgrade-2.6.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/upgrade-2.6.xml
@@ -1130,6 +1130,7 @@
           <task xsi:type="configure" id="storm_worker_log4j_parameterize" />
           <task xsi:type="configure" id="storm_cluster_log4j_parameterize" />
           <task xsi:type="configure" id="storm_worker_log4j_directory" />
+          <task xsi:type="configure" id="storm_remove_jmxetric"/>
         </pre-upgrade>
 
         <pre-downgrade>

http://git-wip-us.apache.org/repos/asf/ambari/blob/8852f33b/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/config-upgrade.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/config-upgrade.xml b/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/config-upgrade.xml
index 5c1f33f..64121a4 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/config-upgrade.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/config-upgrade.xml
@@ -481,6 +481,10 @@
             <replace key="content" find="${sys:storm.log.dir}/${sys:logfile.name}"
                      replace-with="${sys:workers.artifacts}/${sys:storm.id}/${sys:worker.port}/${sys:logfile.name}"/>
           </definition>
+          <definition xsi:type="configure" id="storm_remove_jmxetric" summary="Removing jmxetric from childopts.">
+            <type>storm-site</type>
+            <regex-replace key="content" find=" -javaagent:.*JVM" replace-with=""/>
+          </definition>
         </changes>
       </component>
     </service>

http://git-wip-us.apache.org/repos/asf/ambari/blob/8852f33b/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.6.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.6.xml b/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.6.xml
index 4703709..faf5b76 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.6.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.6.xml
@@ -591,6 +591,9 @@
           <summary>Update Storm log directory in storm worker log4j</summary>
         </task>
       </execute-stage>
+      <execute-stage service="STORM" component="NIMBUS" title="Removing jmxetric from childopts">
+        <task xsi:type="configure" id="storm_remove_jmxetric"/>
+      </execute-stage>
 
       <!-- KAFKA -->
       <execute-stage service="KAFKA" component="KAFKA_BROKER" title="Apply config changes for Kafka Broker">

http://git-wip-us.apache.org/repos/asf/ambari/blob/8852f33b/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/upgrade-2.6.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/upgrade-2.6.xml b/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/upgrade-2.6.xml
index 35187c7..572a259 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/upgrade-2.6.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/upgrade-2.6.xml
@@ -1092,6 +1092,7 @@
           <task xsi:type="configure" id="storm_worker_log4j_parameterize" />
           <task xsi:type="configure" id="storm_cluster_log4j_parameterize" />
           <task xsi:type="configure" id="storm_worker_log4j_directory" />
+          <task xsi:type="configure" id="storm_remove_jmxetric"/>
         </pre-upgrade>
 
         <pre-downgrade>

http://git-wip-us.apache.org/repos/asf/ambari/blob/8852f33b/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/config-upgrade.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/config-upgrade.xml b/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/config-upgrade.xml
index cf42e93..d138d60 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/config-upgrade.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/config-upgrade.xml
@@ -63,6 +63,16 @@
             <regex-replace key="content" find="A1&quot; immediateFlush=&quot;false&quot;&#xA;                 fileName=&quot;\$\{sys:storm.log.dir}/\$\{sys:logfile.name}&quot;&#xA;                 filePattern=&quot;\$\{sys:storm.log.dir}/\$\{sys:logfile.name}.%i.gz&quot;&gt;&#xA;        &lt;PatternLayout&gt;&#xA;            &lt;pattern&gt;\$\{pattern}&lt;/pattern&gt;&#xA;        &lt;/PatternLayout&gt;&#xA;        &lt;Policies&gt;&#xA;            &lt;SizeBasedTriggeringPolicy size=&quot;(?:[0-9]+) MB&quot;/&gt; &lt;!-- Or every 100 MB --&gt;&#xA;        &lt;/Policies&gt;&#xA;        &lt;DefaultRolloverStrategy max=&quot;([0-9]+)"
                                          replace-with="A1&quot; immediateFlush=&quot;false&quot;&#xA;                 fileName=&quot;${sys:storm.log.dir}/${sys:logfile.name}&quot;&#xA;                 filePattern=&quot;${sys:storm.log.dir}/${sys:logfile.name}.%i.gz&quot;&gt;&#xA;        &lt;PatternLayout&gt;&#xA;            &lt;pattern&gt;${pattern}&lt;/pattern&gt;&#xA;        &lt;/PatternLayout&gt;&#xA;        &lt;Policies&gt;&#xA;            &lt;SizeBasedTriggeringPolicy size=&quot;{{storm_a1_maxfilesize}} MB&quot;/&gt; &lt;!-- Or every 100 MB --&gt;&#xA;        &lt;/Policies&gt;&#xA;        &lt;DefaultRolloverStrategy max=&quot;{{storm_a1_maxbackupindex}}"/>
           </definition>
+          <definition xsi:type="configure" id="storm_nimbus_autocred_config" summary="Update Storm's Nimbus AutoCred config">
+            <type>storm-site</type>
+            <set key="nimbus.autocredential.plugins.classes" value="['org.apache.storm.hdfs.security.AutoHDFS', 'org.apache.storm.hbase.security.AutoHBase', 'org.apache.storm.hive.security.AutoHive']" if-type="streamline-common" if-key="authorizer.class.name" if-key-state="present"/>
+            <set key="nimbus.credential.renewers.classes" value="['org.apache.storm.hdfs.security.AutoHDFS', 'org.apache.storm.hbase.security.AutoHBase', 'org.apache.storm.hive.security.AutoHive']" if-type="streamline-common" if-key="authorizer.class.name" if-key-state="present"/>
+            <set key="nimbus.credential.renewers.freq.secs" value="82800" if-type="streamline-common" if-key="authorizer.class.name" if-key-state="present"/>
+          </definition>
+          <definition xsi:type="configure" id="storm_remove_jmxetric" summary="Removing jmxetric from childopts.">
+            <type>storm-site</type>
+            <regex-replace key="content" find=" -javaagent:.*JVM" replace-with=""/>
+          </definition>
         </changes>
       </component>
     </service>

http://git-wip-us.apache.org/repos/asf/ambari/blob/8852f33b/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/nonrolling-upgrade-2.6.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/nonrolling-upgrade-2.6.xml b/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/nonrolling-upgrade-2.6.xml
index cd69a9c..8012c90 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/nonrolling-upgrade-2.6.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/nonrolling-upgrade-2.6.xml
@@ -526,6 +526,9 @@
           <summary>Updating the Storm cluster Log4J properties to include parameterizations</summary>
         </task>
       </execute-stage>
+      <execute-stage service="STORM" component="NIMBUS" title="Removing jmxetric from childopts">
+        <task xsi:type="configure" id="storm_remove_jmxetric"/>
+      </execute-stage>
 
       <!-- PIG -->
       <execute-stage service="PIG" component="PIG" title="Apply config changes for Pig">

http://git-wip-us.apache.org/repos/asf/ambari/blob/8852f33b/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/upgrade-2.6.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/upgrade-2.6.xml b/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/upgrade-2.6.xml
index a6d3f29..7c43948 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/upgrade-2.6.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/upgrade-2.6.xml
@@ -1050,6 +1050,7 @@
         <pre-upgrade>
           <task xsi:type="configure" id="storm_worker_log4j_parameterize" />
           <task xsi:type="configure" id="storm_cluster_log4j_parameterize" />
+          <task xsi:type="configure" id="storm_remove_jmxetric"/>
         </pre-upgrade>
         <pre-downgrade/>
         <upgrade>

http://git-wip-us.apache.org/repos/asf/ambari/blob/8852f33b/ambari-server/src/main/resources/stacks/HDP/2.6/services/STORM/configuration/storm-site.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.6/services/STORM/configuration/storm-site.xml b/ambari-server/src/main/resources/stacks/HDP/2.6/services/STORM/configuration/storm-site.xml
index 902fdc9..74262b6 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.6/services/STORM/configuration/storm-site.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.6/services/STORM/configuration/storm-site.xml
@@ -29,7 +29,7 @@
   </property>
   <property>
     <name>nimbus.childopts</name>
-    <value>-Xmx1024m _JAAS_PLACEHOLDER -javaagent:/usr/hdp/current/storm-nimbus/contrib/storm-jmxetric/lib/jmxetric-1.0.4.jar=host=localhost,port=8649,wireformat31x=true,mode=multicast,config=/usr/hdp/current/storm-nimbus/contrib/storm-jmxetric/conf/jmxetric-conf.xml,process=Nimbus_JVM</value>
+    <value>-Xmx1024m _JAAS_PLACEHOLDER</value>
     <description>This parameter is used by the storm-deploy project to configure the jvm options for the nimbus daemon.</description>
     <value-attributes>
       <overridable>false</overridable>
@@ -38,7 +38,7 @@
   </property>
   <property>
     <name>worker.childopts</name>
-    <value>-Xmx768m _JAAS_PLACEHOLDER -javaagent:/usr/hdp/current/storm-client/contrib/storm-jmxetric/lib/jmxetric-1.0.4.jar=host=localhost,port=8650,wireformat31x=true,mode=multicast,config=/usr/hdp/current/storm-client/contrib/storm-jmxetric/conf/jmxetric-conf.xml,process=Worker_%ID%_JVM</value>
+    <value>-Xmx768m _JAAS_PLACEHOLDER</value>
     <description>The jvm opts provided to workers launched by this supervisor. All \"%ID%\" substrings are replaced with an identifier for this worker.</description>
     <value-attributes>
       <type>multiLine</type>
@@ -47,7 +47,7 @@
   </property>
   <property>
     <name>supervisor.childopts</name>
-    <value>-Xmx256m _JAAS_PLACEHOLDER -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port={{jmxremote_port}} -javaagent:/usr/hdp/current/storm-supervisor/contrib/storm-jmxetric/lib/jmxetric-1.0.4.jar=host=localhost,port=8650,wireformat31x=true,mode=multicast,config=/usr/hdp/current/storm-supervisor/contrib/storm-jmxetric/conf/jmxetric-conf.xml,process=Supervisor_JVM</value>
+    <value>-Xmx256m _JAAS_PLACEHOLDER -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port={{jmxremote_port}}</value>
     <description>This parameter is used by the storm-deploy project to configure the jvm options for the supervisor daemon.</description>
     <value-attributes>
       <overridable>false</overridable>

http://git-wip-us.apache.org/repos/asf/ambari/blob/8852f33b/ambari-server/src/main/resources/stacks/HDP/2.6/upgrades/config-upgrade.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.6/upgrades/config-upgrade.xml b/ambari-server/src/main/resources/stacks/HDP/2.6/upgrades/config-upgrade.xml
index 91044d8..647bdeb 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.6/upgrades/config-upgrade.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.6/upgrades/config-upgrade.xml
@@ -132,6 +132,10 @@
             <set key="ranger.plugin.storm.ambari.cluster.name" value="{{cluster_name}}"
               if-type="ranger-storm-plugin-properties" if-key="ranger-storm-plugin-enabled" if-key-state="present"/>
           </definition>
+          <definition xsi:type="configure" id="storm_remove_jmxetric" summary="Removing jmxetric from childopts.">
+            <type>storm-site</type>
+            <regex-replace key="content" find=" -javaagent:.*JVM" replace-with=""/>
+          </definition>
         </changes>
       </component>
     </service>

http://git-wip-us.apache.org/repos/asf/ambari/blob/8852f33b/ambari-server/src/main/resources/stacks/HDP/2.6/upgrades/nonrolling-upgrade-2.6.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.6/upgrades/nonrolling-upgrade-2.6.xml b/ambari-server/src/main/resources/stacks/HDP/2.6/upgrades/nonrolling-upgrade-2.6.xml
index 0b5e8c1..c9e90a9 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.6/upgrades/nonrolling-upgrade-2.6.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.6/upgrades/nonrolling-upgrade-2.6.xml
@@ -333,6 +333,10 @@
         <task xsi:type="configure" id="hdp_2_6_maint_ranger_storm_plugin_cluster_name"/>
       </execute-stage>
 
+      <execute-stage service="STORM" component="NIMBUS" title="Removing jmxetric from childopts">
+        <task xsi:type="configure" id="storm_remove_jmxetric"/>
+      </execute-stage>
+
       <!-- YARN -->
       <execute-stage service="YARN" component="RESOURCEMANAGER" title="Apply config changes for Ranger Yarn plugin">
         <task xsi:type="configure" id="hdp_2_6_maint_ranger_yarn_plugin_cluster_name"/>

http://git-wip-us.apache.org/repos/asf/ambari/blob/8852f33b/ambari-server/src/main/resources/stacks/HDP/2.6/upgrades/upgrade-2.6.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.6/upgrades/upgrade-2.6.xml b/ambari-server/src/main/resources/stacks/HDP/2.6/upgrades/upgrade-2.6.xml
index 00597c6..176143c 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.6/upgrades/upgrade-2.6.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.6/upgrades/upgrade-2.6.xml
@@ -979,6 +979,7 @@
       <component name="NIMBUS">
         <pre-upgrade>
           <task xsi:type="configure" id="hdp_2_6_maint_ranger_storm_plugin_cluster_name"/>
+          <task xsi:type="configure" id="storm_remove_jmxetric"/>
         </pre-upgrade>
         <pre-downgrade/> <!--  no-op to prevent config changes on downgrade -->
         <upgrade>


[10/46] ambari git commit: Revert "AMBARI-22258. Use correct property attribute setter fn(). while setting 'tez.runtime.io.sort.mb' maximum value."

Posted by lp...@apache.org.
Revert "AMBARI-22258. Use correct property attribute setter fn(). while setting 'tez.runtime.io.sort.mb' maximum value."

This reverts commit b9f26708dd19c444918ea9b21150f66236fcdf2d.


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 37d59f281e682c17e0a34aa7e6d9a09c927febca
Parents: c9c96cd
Author: Swapan Shridhar <ss...@hortonworks.com>
Authored: Wed Oct 18 11:15:12 2017 -0700
Committer: Swapan Shridhar <ss...@hortonworks.com>
Committed: Wed Oct 18 11:15:12 2017 -0700

----------------------------------------------------------------------
 .../src/main/resources/stacks/HDP/2.5/services/stack_advisor.py | 3 +--
 .../src/test/python/stacks/2.5/common/test_stack_advisor.py     | 5 +----
 2 files changed, 2 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/37d59f28/ambari-server/src/main/resources/stacks/HDP/2.5/services/stack_advisor.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.5/services/stack_advisor.py b/ambari-server/src/main/resources/stacks/HDP/2.5/services/stack_advisor.py
index b6f2478..92ce9b9 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.5/services/stack_advisor.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.5/services/stack_advisor.py
@@ -860,7 +860,6 @@ class HDP25StackAdvisor(HDP24StackAdvisor):
     putHiveInteractiveEnvProperty = self.putProperty(configurations, "hive-interactive-env", services)
     putHiveInteractiveEnvPropertyAttribute = self.putPropertyAttribute(configurations, "hive-interactive-env")
     putTezInteractiveSiteProperty = self.putProperty(configurations, "tez-interactive-site", services)
-    putTezInteractiveSitePropertyAttribute = self.putPropertyAttribute(configurations, "tez-interactive-site")
     llap_daemon_selected_queue_name = None
     selected_queue_is_ambari_managed_llap = None  # Queue named 'llap' at root level is Ambari managed.
     llap_selected_queue_am_percent = None
@@ -1332,7 +1331,7 @@ class HDP25StackAdvisor(HDP24StackAdvisor):
     putTezInteractiveSiteProperty('tez.runtime.io.sort.mb', tez_runtime_io_sort_mb)
     if "tez-site" in services["configurations"] and "tez.runtime.sorter.class" in services["configurations"]["tez-site"]["properties"]:
       if services["configurations"]["tez-site"]["properties"]["tez.runtime.sorter.class"] == "LEGACY":
-        putTezInteractiveSitePropertyAttribute("tez.runtime.io.sort.mb", "maximum", 1800)
+        putTezInteractiveSiteProperty("tez.runtime.io.sort.mb", "maximum", 1800)
 
     putTezInteractiveSiteProperty('tez.runtime.unordered.output.buffer.size-mb', tez_runtime_unordered_output_buffer_size)
     putHiveInteractiveSiteProperty('hive.auto.convert.join.noconditionaltask.size', hive_auto_convert_join_noconditionaltask_size)

http://git-wip-us.apache.org/repos/asf/ambari/blob/37d59f28/ambari-server/src/test/python/stacks/2.5/common/test_stack_advisor.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.5/common/test_stack_advisor.py b/ambari-server/src/test/python/stacks/2.5/common/test_stack_advisor.py
index 407e78d..cf462de 100644
--- a/ambari-server/src/test/python/stacks/2.5/common/test_stack_advisor.py
+++ b/ambari-server/src/test/python/stacks/2.5/common/test_stack_advisor.py
@@ -4446,8 +4446,7 @@ class TestHDP25StackAdvisor(TestCase):
           },
         "tez-site": {
           "properties": {
-            "tez.am.resource.memory.mb": "1024",
-            "tez.runtime.sorter.class": "LEGACY"
+            "tez.am.resource.memory.mb": "1024"
           }
         },
       }
@@ -4482,8 +4481,6 @@ class TestHDP25StackAdvisor(TestCase):
 
     self.assertEqual(configurations['hive-interactive-site']['properties']['hive.llap.io.memory.size'], '186368')
     self.assertEqual(configurations['hive-interactive-env']['properties']['llap_heap_size'], '9830')
-    self.assertEqual(configurations['tez-interactive-site']['properties']['tez.runtime.io.sort.mb'], '1092')
-    self.assertEquals(configurations['tez-interactive-site']['property_attributes']['tez.runtime.io.sort.mb'], {'maximum': '1800'})
 
 
 


[24/46] ambari git commit: AMBARI-21307 renamed package, minor corrections. Changed endpoint name

Posted by lp...@apache.org.
AMBARI-21307 renamed package, minor corrections. Changed endpoint name


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 6c3dcc78032680fe5999fae0f727fb659822dfde
Parents: 1d75b54
Author: lpuskas <lp...@apache.org>
Authored: Mon Aug 14 13:21:07 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:41:58 2017 +0200

----------------------------------------------------------------------
 .../services/AmbariConfigurationService.java    |   2 +-
 .../api/services/ldap/LdapRestService.java      |  15 +-
 .../server/ldap/AmbariLdapConfiguration.java    |   5 +-
 .../apache/ambari/server/ldap/LdapModule.java   |   4 +-
 ...efaultLdapConfigurationValidatorService.java | 243 -------------------
 .../ad/DefaultLdapConnectionService.java        |  63 -----
 ...efaultLdapConfigurationValidatorService.java | 243 +++++++++++++++++++
 .../ads/DefaultLdapConnectionService.java       |  63 +++++
 ...ltLdapConfigurationValidatorServiceTest.java | 113 ---------
 ...ltLdapConfigurationValidatorServiceTest.java | 113 +++++++++
 10 files changed, 435 insertions(+), 429 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/6c3dcc78/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java
index 927e518..492509f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java
@@ -63,7 +63,7 @@ import io.swagger.annotations.ApiResponses;
  *     }
  * </pre>
  */
-@Path("/configurations/")
+@Path("/ambariconfigs/")
 @Api(value = "Ambari Configurations", description = "Endpoint for Ambari configuration related operations")
 public class AmbariConfigurationService extends BaseService {
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/6c3dcc78/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapRestService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapRestService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapRestService.java
index 8578204..4e654dc 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapRestService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapRestService.java
@@ -34,6 +34,7 @@ import javax.inject.Inject;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.POST;
 import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
@@ -70,8 +71,9 @@ public class LdapRestService extends BaseService {
 
   @POST
   @ApiIgnore // until documented
-  @Path("/action") // todo this needs to be moved under the resource
+  @Path("/validate") // todo this needs to be moved under the resource
   @Consumes(MediaType.APPLICATION_JSON)
+  @Produces(MediaType.APPLICATION_JSON)
   public Response validateConfiguration(LdapCheckConfigurationRequest ldapCheckConfigurationRequest) {
 
     Set<String> groups = Sets.newHashSet();
@@ -95,10 +97,7 @@ public class LdapRestService extends BaseService {
 
           LOGGER.info("Testing LDAP attributes ....");
           groups = ldapFacade.checkLdapAttibutes(ldapCheckConfigurationRequest.getRequestInfo().getParameters(), ambariLdapConfiguration);
-          // todo factor out the resource creation, design better the structure in the response
-          Resource resource = new ResourceImpl(Resource.Type.AmbariConfiguration);
-          resource.setProperty("groups", groups);
-          result.getResultTree().addChild(resource, "payload");
+          setResult(groups, result);
 
           break;
         case "detect-attributes":
@@ -119,6 +118,12 @@ public class LdapRestService extends BaseService {
     return Response.status(result.getStatus().getStatusCode()).entity(getResultSerializer().serialize(result)).build();
   }
 
+  private void setResult(Set<String> groups, Result result) {
+    Resource resource = new ResourceImpl(Resource.Type.AmbariConfiguration);
+    resource.setProperty("groups", groups);
+    result.getResultTree().addChild(resource, "payload");
+  }
+
   private void validateRequest(LdapCheckConfigurationRequest ldapCheckConfigurationRequest) {
     String errMsg;
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/6c3dcc78/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
index 8ab587b..b1cbced 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
@@ -37,11 +37,12 @@ public class AmbariLdapConfiguration {
   public enum LdapConfigProperty {
     LDAP_CONFIGURED("ambari.ldap.configured"),
     AUTOMATIC_ATTRIBUTE_DETECTION("ambari.ldap.automatic.attribute.detection"),
-
     USE_SSL("ambari.ldap.usessl"),
     LDAP_SERVER_HOST("ambari.ldap.server.host"),
     LDAP_SERVER_PORT("ambari.ldap.server.port"),
-    BASE_DN("ambari.ldap.base.dn"),
+    LDAP_TRUSTSTORE_TYPE("ambari.ldap.truststore.type"),
+    LDAP_TRUSTSTORE_PATH("ambari.ldap.truststore.path"),
+    BASE_DN("ambari.ldap.bind.dn"),
 
     BIND_ANONIMOUSLY("ambari.ldap.bindanonymously"),
     MANAGER_DN("ambari.ldap.managerdn"),

http://git-wip-us.apache.org/repos/asf/ambari/blob/6c3dcc78/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
index 1b49159..a4ad2ee 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
@@ -18,8 +18,8 @@ package org.apache.ambari.server.ldap;
 import org.apache.ambari.server.ldap.service.AmbariLdapFacade;
 import org.apache.ambari.server.ldap.service.LdapConnectionService;
 import org.apache.ambari.server.ldap.service.LdapFacade;
-import org.apache.ambari.server.ldap.service.ad.DefaultLdapConfigurationValidatorService;
-import org.apache.ambari.server.ldap.service.ad.DefaultLdapConnectionService;
+import org.apache.ambari.server.ldap.service.ads.DefaultLdapConfigurationValidatorService;
+import org.apache.ambari.server.ldap.service.ads.DefaultLdapConnectionService;
 
 import com.google.inject.AbstractModule;
 import com.google.inject.assistedinject.FactoryModuleBuilder;

http://git-wip-us.apache.org/repos/asf/ambari/blob/6c3dcc78/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorService.java
deleted file mode 100644
index a8503ca..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorService.java
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.service.ad;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.Set;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.LdapConfigurationValidatorService;
-import org.apache.ambari.server.ldap.service.AmbariLdapException;
-import org.apache.ambari.server.ldap.service.LdapConnectionService;
-import org.apache.directory.api.ldap.codec.decorators.SearchResultEntryDecorator;
-import org.apache.directory.api.ldap.model.cursor.EntryCursor;
-import org.apache.directory.api.ldap.model.cursor.SearchCursor;
-import org.apache.directory.api.ldap.model.entry.Entry;
-import org.apache.directory.api.ldap.model.exception.LdapException;
-import org.apache.directory.api.ldap.model.message.Response;
-import org.apache.directory.api.ldap.model.message.SearchRequest;
-import org.apache.directory.api.ldap.model.message.SearchRequestImpl;
-import org.apache.directory.api.ldap.model.message.SearchScope;
-import org.apache.directory.api.ldap.model.name.Dn;
-import org.apache.directory.ldap.client.api.LdapConnection;
-import org.apache.directory.ldap.client.api.search.FilterBuilder;
-import org.apache.directory.shared.ldap.constants.SchemaConstants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-
-/**
- * Implementation of the validation logic using the Apache Directory API.
- */
-@Singleton
-public class DefaultLdapConfigurationValidatorService implements LdapConfigurationValidatorService {
-
-  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapConfigurationValidatorService.class);
-
-  @Inject
-  private LdapConnectionService ldapConnectionService;
-
-  /**
-   * Facilitating the instantiation
-   */
-  @Inject
-  public DefaultLdapConfigurationValidatorService() {
-  }
-
-  @Override
-  public void checkConnection(LdapConnection ldapConnection, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
-    try {
-      bind(ambariLdapConfiguration, ldapConnection);
-    } catch (LdapException e) {
-      LOGGER.error("Could not connect to the LDAP server", e);
-      throw new AmbariLdapException(e);
-    }
-  }
-
-
-  /**
-   * Checks the user attributes provided in the configuration instance by issuing a search for a (known) test user in the LDAP.
-   * Attributes are considered correct if there is at least one entry found.
-   *
-   * Invalid attributes are signaled by throwing an exception.
-   *
-   * @param testUserName            the test username
-   * @param testPassword            the test password
-   * @param ambariLdapConfiguration configuration instance holding ldap configuration details
-   * @return the DN of the test user
-   * @throws AmbariException if the attributes are not valid or any errors occurs
-   */
-  @Override
-  public String checkUserAttributes(LdapConnection ldapConnection, String testUserName, String testPassword, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
-    SearchCursor searchCursor = null;
-    String userDn = null;
-    try {
-      LOGGER.info("Checking user attributes for user {} r ...", testUserName);
-
-      // bind anonimously or with manager data
-      bind(ambariLdapConfiguration, ldapConnection);
-
-      // set up a filter based on the provided attributes
-      String filter = FilterBuilder.and(
-        FilterBuilder.equal(SchemaConstants.OBJECT_CLASS_AT, ambariLdapConfiguration.userObjectClass()),
-        FilterBuilder.equal(ambariLdapConfiguration.userNameAttribute(), testUserName))
-        .toString();
-
-      LOGGER.info("Searching for the user: {} using the search filter: {}", testUserName, filter);
-      EntryCursor entryCursor = ldapConnection.search(new Dn(ambariLdapConfiguration.userSearchBase()), filter, SearchScope.SUBTREE);
-
-      // collecting search result entries
-      List<Entry> users = Lists.newArrayList();
-      for (Entry entry : entryCursor) {
-        users.add(entry);
-        userDn = entry.getDn().getNormName();
-      }
-
-      // there should be at least one user found
-      if (users.isEmpty()) {
-        String msg = String.format("There are no users found using the filter: [ %s ]. Try changing the attribute values", filter);
-        LOGGER.error(msg);
-        throw new Exception(msg);
-      }
-
-      LOGGER.info("Attibute validation succeeded. Filter: {}", filter);
-
-    } catch (Exception e) {
-
-      LOGGER.error("User attributes validation failed.", e);
-      throw new AmbariLdapException(e.getMessage(), e);
-
-    } finally {
-      closeResources(ldapConnection, searchCursor);
-    }
-    return userDn;
-  }
-
-
-  @Override
-  public Set<String> checkGroupAttributes(LdapConnection ldapConnection, String userDn, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
-    SearchCursor searchCursor = null;
-    Set<Response> groupResponses = Sets.newHashSet();
-
-    try {
-      LOGGER.info("Checking group attributes for user dn {} ...", userDn);
-
-      bind(ambariLdapConfiguration, ldapConnection);
-
-      // set up a filter based on the provided attributes
-      String filter = FilterBuilder.and(
-        FilterBuilder.equal(SchemaConstants.OBJECT_CLASS_AT, ambariLdapConfiguration.groupObjectClass()),
-        FilterBuilder.equal(ambariLdapConfiguration.groupMemberAttribute(), userDn)
-      ).toString();
-
-      LOGGER.info("Searching for the groups the user dn: {} is member of using the search filter: {}", userDn, filter);
-
-      // assemble a search request
-      SearchRequest searchRequest = new SearchRequestImpl();
-      searchRequest.setFilter(filter);
-      searchRequest.setBase(new Dn(ambariLdapConfiguration.groupSearchBase()));
-      searchRequest.setScope(SearchScope.SUBTREE);
-      searchRequest.addAttributes(ambariLdapConfiguration.groupMemberAttribute(), ambariLdapConfiguration.groupNameAttribute());
-
-      // perform the search
-      searchCursor = ldapConnection.search(searchRequest);
-
-      for (Response response : searchCursor) {
-        groupResponses.add(response);
-      }
-
-    } catch (Exception e) {
-
-      LOGGER.error("User attributes validation failed.", e);
-      throw new AmbariLdapException(e.getMessage(), e);
-
-    } finally {
-      closeResources(ldapConnection, searchCursor);
-    }
-
-    return processGroupResults(groupResponses, ambariLdapConfiguration);
-  }
-
-  /**
-   * Binds to the LDAP server (anonimously or wit manager credentials)
-   *
-   * @param ambariLdapConfiguration configuration instance
-   * @param connection              connection instance
-   * @throws LdapException if the bind operation fails
-   */
-  private void bind(AmbariLdapConfiguration ambariLdapConfiguration, LdapConnection connection) throws LdapException {
-    LOGGER.info("Connecting to LDAP ....");
-    if (!ambariLdapConfiguration.bindAnonimously()) {
-      LOGGER.debug("Anonimous binding not supported, binding with the manager detailas...");
-      connection.bind(ambariLdapConfiguration.managerDn(), ambariLdapConfiguration.managerPassword());
-    } else {
-      LOGGER.debug("Binding anonimously ...");
-      connection.bind();
-    }
-
-    if (!connection.isConnected()) {
-      LOGGER.error("Not connected to the LDAP server. Connection instance: {}", connection);
-      throw new IllegalStateException("The connection to the LDAP server is not alive");
-    }
-    LOGGER.info("Connected to LDAP.");
-  }
-
-
-  /**
-   * Extracts meaningful values from the search result.
-   *
-   * @param groupResponses          the result entries returned by the search
-   * @param ambariLdapConfiguration holds the keys of the meaningful attributes
-   * @return a set with the group names the test user belongs to
-   */
-  private Set<String> processGroupResults(Set<Response> groupResponses, AmbariLdapConfiguration ambariLdapConfiguration) {
-    Set<String> groupStrSet = Sets.newHashSet();
-    for (Response response : groupResponses) {
-      Entry entry = ((SearchResultEntryDecorator) response).getEntry();
-      groupStrSet.add(entry.get(ambariLdapConfiguration.groupNameAttribute()).get().getString());
-    }
-
-    LOGGER.debug("Extracted group names from group search responses: {}", groupStrSet);
-    return groupStrSet;
-  }
-
-  private void closeResources(LdapConnection connection, SearchCursor searchCursor) {
-    LOGGER.debug("Housekeeping: closing the connection and the search cursor ...");
-
-    if (null != searchCursor) {
-      // this method is idempotent
-      searchCursor.close();
-    }
-
-    if (null != connection) {
-      try {
-        connection.close();
-      } catch (IOException e) {
-        LOGGER.error("Exception occurred while closing the connection", e);
-      }
-    }
-  }
-
-}
-
-
-

http://git-wip-us.apache.org/repos/asf/ambari/blob/6c3dcc78/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConnectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConnectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConnectionService.java
deleted file mode 100644
index 25dc1f2..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConnectionService.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.service.ad;
-
-import javax.inject.Singleton;
-
-import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.service.LdapConnectionService;
-import org.apache.directory.ldap.client.api.LdapConnectionConfig;
-import org.apache.directory.ldap.client.api.LdapNetworkConnection;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Singleton
-public class DefaultLdapConnectionService implements LdapConnectionService {
-
-  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapConnectionService.class);
-
-  @Override
-  public LdapNetworkConnection createLdapConnection(AmbariLdapConfiguration ambariLdapConfiguration) {
-    LOGGER.debug("Creating ldap connection instance from: {}", ambariLdapConfiguration);
-    return new LdapNetworkConnection(getLdapConnectionConfig(ambariLdapConfiguration));
-  }
-
-  private LdapConnectionConfig getLdapConnectionConfig(AmbariLdapConfiguration ambariAmbariLdapConfiguration) {
-    LOGGER.debug("Creating a configuration instance based on the ambari configuration: {}", ambariAmbariLdapConfiguration);
-
-    LdapConnectionConfig ldapConnectionConfig = new LdapConnectionConfig();
-    ldapConnectionConfig.setLdapHost(ambariAmbariLdapConfiguration.ldapServerHost());
-    ldapConnectionConfig.setLdapPort(ambariAmbariLdapConfiguration.ldapServerPort());
-    ldapConnectionConfig.setUseSsl(ambariAmbariLdapConfiguration.useSSL());
-
-    // todo set the other values as required
-    return ldapConnectionConfig;
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/6c3dcc78/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationValidatorService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationValidatorService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationValidatorService.java
new file mode 100644
index 0000000..040983a
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationValidatorService.java
@@ -0,0 +1,243 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Set;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.LdapConfigurationValidatorService;
+import org.apache.ambari.server.ldap.service.AmbariLdapException;
+import org.apache.ambari.server.ldap.service.LdapConnectionService;
+import org.apache.directory.api.ldap.codec.decorators.SearchResultEntryDecorator;
+import org.apache.directory.api.ldap.model.constants.SchemaConstants;
+import org.apache.directory.api.ldap.model.cursor.EntryCursor;
+import org.apache.directory.api.ldap.model.cursor.SearchCursor;
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.message.Response;
+import org.apache.directory.api.ldap.model.message.SearchRequest;
+import org.apache.directory.api.ldap.model.message.SearchRequestImpl;
+import org.apache.directory.api.ldap.model.message.SearchScope;
+import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.search.FilterBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+
+/**
+ * Implementation of the validation logic using the Apache Directory API.
+ */
+@Singleton
+public class DefaultLdapConfigurationValidatorService implements LdapConfigurationValidatorService {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapConfigurationValidatorService.class);
+
+  @Inject
+  private LdapConnectionService ldapConnectionService;
+
+  /**
+   * Facilitating the instantiation
+   */
+  @Inject
+  public DefaultLdapConfigurationValidatorService() {
+  }
+
+  @Override
+  public void checkConnection(LdapConnection ldapConnection, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+    try {
+      bind(ambariLdapConfiguration, ldapConnection);
+    } catch (LdapException e) {
+      LOGGER.error("Could not connect to the LDAP server", e);
+      throw new AmbariLdapException(e);
+    }
+  }
+
+
+  /**
+   * Checks the user attributes provided in the configuration instance by issuing a search for a (known) test user in the LDAP.
+   * Attributes are considered correct if there is at least one entry found.
+   *
+   * Invalid attributes are signaled by throwing an exception.
+   *
+   * @param testUserName            the test username
+   * @param testPassword            the test password
+   * @param ambariLdapConfiguration configuration instance holding ldap configuration details
+   * @return the DN of the test user
+   * @throws AmbariException if the attributes are not valid or any errors occurs
+   */
+  @Override
+  public String checkUserAttributes(LdapConnection ldapConnection, String testUserName, String testPassword, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+    SearchCursor searchCursor = null;
+    String userDn = null;
+    try {
+      LOGGER.info("Checking user attributes for user {} r ...", testUserName);
+
+      // bind anonimously or with manager data
+      bind(ambariLdapConfiguration, ldapConnection);
+
+      // set up a filter based on the provided attributes
+      String filter = FilterBuilder.and(
+        FilterBuilder.equal(SchemaConstants.OBJECT_CLASS_AT, ambariLdapConfiguration.userObjectClass()),
+        FilterBuilder.equal(ambariLdapConfiguration.userNameAttribute(), testUserName))
+        .toString();
+
+      LOGGER.info("Searching for the user: {} using the search filter: {}", testUserName, filter);
+      EntryCursor entryCursor = ldapConnection.search(new Dn(ambariLdapConfiguration.userSearchBase()), filter, SearchScope.SUBTREE);
+
+      // collecting search result entries
+      List<Entry> users = Lists.newArrayList();
+      for (Entry entry : entryCursor) {
+        users.add(entry);
+        userDn = entry.getDn().getNormName();
+      }
+
+      // there should be at least one user found
+      if (users.isEmpty()) {
+        String msg = String.format("There are no users found using the filter: [ %s ]. Try changing the attribute values", filter);
+        LOGGER.error(msg);
+        throw new Exception(msg);
+      }
+
+      LOGGER.info("Attibute validation succeeded. Filter: {}", filter);
+
+    } catch (Exception e) {
+
+      LOGGER.error("User attributes validation failed.", e);
+      throw new AmbariLdapException(e.getMessage(), e);
+
+    } finally {
+      closeResources(ldapConnection, searchCursor);
+    }
+    return userDn;
+  }
+
+
+  @Override
+  public Set<String> checkGroupAttributes(LdapConnection ldapConnection, String userDn, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+    SearchCursor searchCursor = null;
+    Set<Response> groupResponses = Sets.newHashSet();
+
+    try {
+      LOGGER.info("Checking group attributes for user dn {} ...", userDn);
+
+      bind(ambariLdapConfiguration, ldapConnection);
+
+      // set up a filter based on the provided attributes
+      String filter = FilterBuilder.and(
+        FilterBuilder.equal(SchemaConstants.OBJECT_CLASS_AT, ambariLdapConfiguration.groupObjectClass()),
+        FilterBuilder.equal(ambariLdapConfiguration.groupMemberAttribute(), userDn)
+      ).toString();
+
+      LOGGER.info("Searching for the groups the user dn: {} is member of using the search filter: {}", userDn, filter);
+
+      // assemble a search request
+      SearchRequest searchRequest = new SearchRequestImpl();
+      searchRequest.setFilter(filter);
+      searchRequest.setBase(new Dn(ambariLdapConfiguration.groupSearchBase()));
+      searchRequest.setScope(SearchScope.SUBTREE);
+      searchRequest.addAttributes(ambariLdapConfiguration.groupMemberAttribute(), ambariLdapConfiguration.groupNameAttribute());
+
+      // perform the search
+      searchCursor = ldapConnection.search(searchRequest);
+
+      for (Response response : searchCursor) {
+        groupResponses.add(response);
+      }
+
+    } catch (Exception e) {
+
+      LOGGER.error("User attributes validation failed.", e);
+      throw new AmbariLdapException(e.getMessage(), e);
+
+    } finally {
+      closeResources(ldapConnection, searchCursor);
+    }
+
+    return processGroupResults(groupResponses, ambariLdapConfiguration);
+  }
+
+  /**
+   * Binds to the LDAP server (anonimously or wit manager credentials)
+   *
+   * @param ambariLdapConfiguration configuration instance
+   * @param connection              connection instance
+   * @throws LdapException if the bind operation fails
+   */
+  private void bind(AmbariLdapConfiguration ambariLdapConfiguration, LdapConnection connection) throws LdapException {
+    LOGGER.info("Connecting to LDAP ....");
+    if (!ambariLdapConfiguration.bindAnonimously()) {
+      LOGGER.debug("Anonimous binding not supported, binding with the manager detailas...");
+      connection.bind(ambariLdapConfiguration.managerDn(), ambariLdapConfiguration.managerPassword());
+    } else {
+      LOGGER.debug("Binding anonimously ...");
+      connection.bind();
+    }
+
+    if (!connection.isConnected()) {
+      LOGGER.error("Not connected to the LDAP server. Connection instance: {}", connection);
+      throw new IllegalStateException("The connection to the LDAP server is not alive");
+    }
+    LOGGER.info("Connected to LDAP.");
+  }
+
+
+  /**
+   * Extracts meaningful values from the search result.
+   *
+   * @param groupResponses          the result entries returned by the search
+   * @param ambariLdapConfiguration holds the keys of the meaningful attributes
+   * @return a set with the group names the test user belongs to
+   */
+  private Set<String> processGroupResults(Set<Response> groupResponses, AmbariLdapConfiguration ambariLdapConfiguration) {
+    Set<String> groupStrSet = Sets.newHashSet();
+    for (Response response : groupResponses) {
+      Entry entry = ((SearchResultEntryDecorator) response).getEntry();
+      groupStrSet.add(entry.get(ambariLdapConfiguration.groupNameAttribute()).get().getString());
+    }
+
+    LOGGER.debug("Extracted group names from group search responses: {}", groupStrSet);
+    return groupStrSet;
+  }
+
+  private void closeResources(LdapConnection connection, SearchCursor searchCursor) {
+    LOGGER.debug("Housekeeping: closing the connection and the search cursor ...");
+
+    if (null != searchCursor) {
+      // this method is idempotent
+      searchCursor.close();
+    }
+
+    if (null != connection) {
+      try {
+        connection.close();
+      } catch (IOException e) {
+        LOGGER.error("Exception occurred while closing the connection", e);
+      }
+    }
+  }
+
+}
+
+
+

http://git-wip-us.apache.org/repos/asf/ambari/blob/6c3dcc78/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionService.java
new file mode 100644
index 0000000..ced52fc
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionService.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads;
+
+import javax.inject.Singleton;
+
+import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.service.LdapConnectionService;
+import org.apache.directory.ldap.client.api.LdapConnectionConfig;
+import org.apache.directory.ldap.client.api.LdapNetworkConnection;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Singleton
+public class DefaultLdapConnectionService implements LdapConnectionService {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapConnectionService.class);
+
+  @Override
+  public LdapNetworkConnection createLdapConnection(AmbariLdapConfiguration ambariLdapConfiguration) {
+    LOGGER.debug("Creating ldap connection instance from: {}", ambariLdapConfiguration);
+    return new LdapNetworkConnection(getLdapConnectionConfig(ambariLdapConfiguration));
+  }
+
+  private LdapConnectionConfig getLdapConnectionConfig(AmbariLdapConfiguration ambariAmbariLdapConfiguration) {
+    LOGGER.debug("Creating a configuration instance based on the ambari configuration: {}", ambariAmbariLdapConfiguration);
+
+    LdapConnectionConfig ldapConnectionConfig = new LdapConnectionConfig();
+    ldapConnectionConfig.setLdapHost(ambariAmbariLdapConfiguration.ldapServerHost());
+    ldapConnectionConfig.setLdapPort(ambariAmbariLdapConfiguration.ldapServerPort());
+    ldapConnectionConfig.setUseSsl(ambariAmbariLdapConfiguration.useSSL());
+
+    // todo set the other values as required
+    return ldapConnectionConfig;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/6c3dcc78/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorServiceTest.java
deleted file mode 100644
index 663ea12..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorServiceTest.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.service.ad;
-
-import static org.junit.Assert.assertNotNull;
-
-import java.util.Map;
-
-import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.LdapConfigurationValidatorService;
-import org.apache.ambari.server.ldap.service.LdapConnectionService;
-import org.apache.directory.api.ldap.model.cursor.EntryCursor;
-import org.apache.directory.api.ldap.model.entry.Entry;
-import org.apache.directory.api.ldap.model.message.SearchScope;
-import org.apache.directory.ldap.client.api.LdapConnection;
-import org.apache.directory.ldap.client.api.LdapConnectionConfig;
-import org.apache.directory.ldap.client.api.LdapNetworkConnection;
-import org.apache.directory.shared.ldap.constants.SchemaConstants;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.Maps;
-
-public class DefaultLdapConfigurationValidatorServiceTest {
-  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapConfigurationValidatorService.class);
-  private static final String TEST_USER = "einstein";
-
-  LdapConfigurationValidatorService ldapConfigurationValidatorService = new DefaultLdapConfigurationValidatorService();
-
-
-  @Test
-  public void testCheckAttributes() throws Exception {
-
-    // WHEN
-    LdapConnectionConfig config = new LdapConnectionConfig();
-    config.setLdapHost("localhost");
-    config.setLdapPort(389);
-    LdapConnection connection = new LdapNetworkConnection(config);
-
-    // THEN
-    connection.anonymousBind();
-
-
-    EntryCursor cursor = connection.search("dc=dev,dc=local", "(objectclass=*)", SearchScope.ONELEVEL);
-
-    for (Entry entry : cursor) {
-      assertNotNull(entry);
-      System.out.println(entry);
-    }
-
-    cursor.close();
-
-  }
-
-  @Test
-  public void testCheckUserAttributes() throws Exception {
-    // GIVEN
-    Map<String, Object> ldapPropsMap = Maps.newHashMap();
-
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BIND_ANONIMOUSLY.propertyName(), "true");
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_HOST.propertyName(), "ldap.forumsys.com");
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_PORT.propertyName(), "389");
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BASE_DN.propertyName(), "dc=example,dc=com");
-
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_OBJECT_CLASS.propertyName(), SchemaConstants.PERSON_OC);
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_NAME_ATTRIBUTE.propertyName(), SchemaConstants.UID_AT);
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_SEARCH_BASE.propertyName(), "dc=example,dc=com");
-
-
-    AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(ldapPropsMap);
-    LdapConnectionService connectionService = new DefaultLdapConnectionService();
-    LdapNetworkConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
-
-    ldapConfigurationValidatorService.checkUserAttributes(ldapConnection, "einstein", "", ambariLdapConfiguration);
-  }
-
-  @Test
-  public void testRetrieveGorupsForuser() throws Exception {
-    // GIVEN
-    Map<String, Object> ldapPropsMap = Maps.newHashMap();
-
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BIND_ANONIMOUSLY.propertyName(), "true");
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_HOST.propertyName(), "ldap.forumsys.com");
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_PORT.propertyName(), "389");
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BASE_DN.propertyName(), "dc=example,dc=com");
-
-
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_OBJECT_CLASS.propertyName(), SchemaConstants.GROUP_OF_UNIQUE_NAMES_OC);
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_NAME_ATTRIBUTE.propertyName(), SchemaConstants.CN_AT);
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_MEMBER_ATTRIBUTE.propertyName(), SchemaConstants.UNIQUE_MEMBER_AT);
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_SEARCH_BASE.propertyName(), "dc=example,dc=com");
-
-
-    AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(ldapPropsMap);
-    LdapConnectionService connectionService = new DefaultLdapConnectionService();
-    LdapNetworkConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
-
-    ldapConfigurationValidatorService.checkGroupAttributes(ldapConnection, "uid=einstein,dc=example,dc=com", ambariLdapConfiguration);
-  }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/6c3dcc78/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationValidatorServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationValidatorServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationValidatorServiceTest.java
new file mode 100644
index 0000000..1c7f75d
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationValidatorServiceTest.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Map;
+
+import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.LdapConfigurationValidatorService;
+import org.apache.ambari.server.ldap.service.LdapConnectionService;
+import org.apache.directory.api.ldap.model.constants.SchemaConstants;
+import org.apache.directory.api.ldap.model.cursor.EntryCursor;
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.apache.directory.api.ldap.model.message.SearchScope;
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.LdapConnectionConfig;
+import org.apache.directory.ldap.client.api.LdapNetworkConnection;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Maps;
+
+public class DefaultLdapConfigurationValidatorServiceTest {
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapConfigurationValidatorService.class);
+  private static final String TEST_USER = "einstein";
+
+  LdapConfigurationValidatorService ldapConfigurationValidatorService = new DefaultLdapConfigurationValidatorService();
+
+
+  @Test
+  public void testCheckAttributes() throws Exception {
+
+    // WHEN
+    LdapConnectionConfig config = new LdapConnectionConfig();
+    config.setLdapHost("localhost");
+    config.setLdapPort(389);
+    LdapConnection connection = new LdapNetworkConnection(config);
+
+    // THEN
+    connection.anonymousBind();
+
+
+    EntryCursor cursor = connection.search("dc=dev,dc=local", "(objectclass=*)", SearchScope.ONELEVEL);
+
+    for (Entry entry : cursor) {
+      assertNotNull(entry);
+      System.out.println(entry);
+    }
+
+    cursor.close();
+
+  }
+
+  @Test
+  public void testCheckUserAttributes() throws Exception {
+    // GIVEN
+    Map<String, Object> ldapPropsMap = Maps.newHashMap();
+
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BIND_ANONIMOUSLY.propertyName(), "true");
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_HOST.propertyName(), "ldap.forumsys.com");
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_PORT.propertyName(), "389");
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BASE_DN.propertyName(), "dc=example,dc=com");
+
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_OBJECT_CLASS.propertyName(), SchemaConstants.PERSON_OC);
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_NAME_ATTRIBUTE.propertyName(), SchemaConstants.UID_AT);
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_SEARCH_BASE.propertyName(), "dc=example,dc=com");
+
+
+    AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(ldapPropsMap);
+    LdapConnectionService connectionService = new DefaultLdapConnectionService();
+    LdapNetworkConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
+
+    ldapConfigurationValidatorService.checkUserAttributes(ldapConnection, "einstein", "", ambariLdapConfiguration);
+  }
+
+  @Test
+  public void testRetrieveGorupsForuser() throws Exception {
+    // GIVEN
+    Map<String, Object> ldapPropsMap = Maps.newHashMap();
+
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BIND_ANONIMOUSLY.propertyName(), "true");
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_HOST.propertyName(), "ldap.forumsys.com");
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_PORT.propertyName(), "389");
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BASE_DN.propertyName(), "dc=example,dc=com");
+
+
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_OBJECT_CLASS.propertyName(), SchemaConstants.GROUP_OF_UNIQUE_NAMES_OC);
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_NAME_ATTRIBUTE.propertyName(), SchemaConstants.CN_AT);
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_MEMBER_ATTRIBUTE.propertyName(), SchemaConstants.UNIQUE_MEMBER_AT);
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_SEARCH_BASE.propertyName(), "dc=example,dc=com");
+
+
+    AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(ldapPropsMap);
+    LdapConnectionService connectionService = new DefaultLdapConnectionService();
+    LdapNetworkConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
+
+    ldapConfigurationValidatorService.checkGroupAttributes(ldapConnection, "uid=einstein,dc=example,dc=com", ambariLdapConfiguration);
+  }
+}
\ No newline at end of file


[05/46] ambari git commit: Updated team page. (yusaku)

Posted by lp...@apache.org.
Updated team page. (yusaku)


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 881e15d8d5c0ad3718e50e4427b8948c723ac255
Parents: b9f2670
Author: Yusaku Sako <yu...@hortonworks.com>
Authored: Tue Oct 17 14:35:15 2017 -0700
Committer: Yusaku Sako <yu...@hortonworks.com>
Committed: Tue Oct 17 14:35:15 2017 -0700

----------------------------------------------------------------------
 docs/pom.xml | 49 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/881e15d8/docs/pom.xml
----------------------------------------------------------------------
diff --git a/docs/pom.xml b/docs/pom.xml
index e041002..a75e093 100644
--- a/docs/pom.xml
+++ b/docs/pom.xml
@@ -196,7 +196,19 @@
             <organization>
                 Hortonworks
             </organization>
-        </developer>        
+        </developer>
+        <developer>
+            <id>anitajebaraj</id>
+            <name>Anita Jebaraj</name>
+            <email>anitajebaraj@apache.org</email>
+            <timezone></timezone>
+            <roles>
+                <role>Committer</role>
+            </roles>
+            <organization>
+                IBM
+            </organization>
+        </developer>
         <developer>
             <id>atkach</id>
             <name>Andrii Tkach</name>
@@ -362,6 +374,17 @@
             </organization>            
         </developer>
         <developer>
+            <id>dgergely</id>
+            <name>Daniel Gergely</name>
+            <email>dgergely</email>
+            <timezone>+1</timezone>
+            <roles>
+                <role>Committer</role>
+            </roles>
+            <organization>
+            </organization>
+        </developer>
+        <developer>
             <id>dillidorai</id>
             <name>Dilli Dorai</name>
             <email>dillidorai@apache.org</email>
@@ -852,6 +875,18 @@
             </organization>
         </developer>
         <developer>
+            <id>qin</id>
+            <name>Qin Liu</name>
+            <email>qin@apache.org</email>
+            <timezone></timezone>
+            <roles>
+                <role>Committer</role>
+            </roles>
+            <organization>
+                IBM
+            </organization>
+        </developer>
+        <developer>
             <id>ramya</id>
             <name>Ramya Sunil</name>
             <email>ramya@apache.org</email>
@@ -1137,6 +1172,18 @@
             </organization>
         </developer>       
         <developer>
+            <id>vishalsuvagia</id>
+            <name>Vishal Suvagia</name>
+            <email>vishalsuvagia@apache.org</email>
+            <timezone></timezone>
+            <roles>
+                <role>Committer</role>
+            </roles>
+            <organization>
+                Hortonworks
+            </organization>
+        </developer>
+        <developer>
             <id>vsairam</id>
             <name>Venkata Sairam Lanka</name>
             <email>vsairam@apache.org</email>


[02/46] ambari git commit: AMBARI-22257. Metrics collector fails to stop after Datanode is stopped in distributed mode. (swagle)

Posted by lp...@apache.org.
AMBARI-22257. Metrics collector fails to stop after Datanode is stopped in distributed mode. (swagle)


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 53f028e92a6a783a161b4540e48484c7ecfaaf44
Parents: 448d6a8
Author: Siddharth Wagle <sw...@hortonworks.com>
Authored: Tue Oct 17 10:47:43 2017 -0700
Committer: Siddharth Wagle <sw...@hortonworks.com>
Committed: Tue Oct 17 10:47:43 2017 -0700

----------------------------------------------------------------------
 .../src/main/resources/stacks/HDP/2.0.6/role_command_order.json    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/53f028e9/ambari-server/src/main/resources/stacks/HDP/2.0.6/role_command_order.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.6/role_command_order.json b/ambari-server/src/main/resources/stacks/HDP/2.0.6/role_command_order.json
index 31f26e3..78a31f1 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0.6/role_command_order.json
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0.6/role_command_order.json
@@ -56,7 +56,7 @@
     "NAMENODE-STOP": ["RESOURCEMANAGER-STOP", "NODEMANAGER-STOP",
         "HISTORYSERVER-STOP", "HBASE_MASTER-STOP", "METRICS_COLLECTOR-STOP"],
     "DATANODE-STOP": ["RESOURCEMANAGER-STOP", "NODEMANAGER-STOP",
-        "HISTORYSERVER-STOP", "HBASE_MASTER-STOP"],
+        "HISTORYSERVER-STOP", "HBASE_MASTER-STOP", "METRICS_COLLECTOR-STOP"],
     "METRICS_GRAFANA-START": ["METRICS_COLLECTOR-START"],
     "METRICS_COLLECTOR-STOP": ["METRICS_GRAFANA-STOP"]
   },


[17/46] ambari git commit: AMBARI-21307 Rest resource for supporting ambari configurations

Posted by lp...@apache.org.
AMBARI-21307 Rest resource for supporting ambari configurations


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: b349538f9f296750ab333fa308d7550eea85387a
Parents: b4eddc9
Author: lpuskas <lp...@apache.org>
Authored: Wed Jul 5 14:20:18 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:41:56 2017 +0200

----------------------------------------------------------------------
 .../resources/ResourceInstanceFactoryImpl.java  |   4 +
 .../services/AmbariConfigurationService.java    | 146 +++++++++++
 .../internal/AbstractProviderModule.java        |   2 +-
 .../AmbariConfigurationResourceProvider.java    | 247 +++++++++++++++++++
 .../internal/DefaultProviderModule.java         |  26 +-
 .../ambari/server/controller/spi/Resource.java  |   5 +-
 .../server/orm/dao/AmbariConfigurationDAO.java  |  92 +++++++
 .../orm/entities/AmbariConfigurationEntity.java |  70 ++++++
 .../orm/entities/ConfigurationBaseEntity.java   | 159 ++++++++++++
 .../authorization/RoleAuthorization.java        |  95 +++----
 .../resources/Ambari-DDL-Postgres-CREATE.sql    |  25 +-
 .../src/main/resources/META-INF/persistence.xml |   2 +
 12 files changed, 809 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b349538f/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceFactoryImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceFactoryImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceFactoryImpl.java
index d0d115d..f5fb6e9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceFactoryImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceFactoryImpl.java
@@ -471,6 +471,10 @@ public class ResourceInstanceFactoryImpl implements ResourceInstanceFactory {
       case RemoteCluster:
         resourceDefinition = new RemoteClusterResourceDefinition();
         break;
+      case AmbariConfiguration:
+        resourceDefinition = new SimpleResourceDefinition(Resource.Type.AmbariConfiguration, "ambariconfiguration", "ambariconfigurations");
+
+        break;
 
       default:
         throw new IllegalArgumentException("Unsupported resource type: " + type);

http://git-wip-us.apache.org/repos/asf/ambari/blob/b349538f/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java
new file mode 100644
index 0000000..0fa6e44
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariConfigurationService.java
@@ -0,0 +1,146 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.api.services;
+
+import java.util.Collections;
+
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.http.HttpStatus;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+
+/**
+ * Rest endpoint for managing ambari configurations. Supports CRUD operations.
+ * Ambari configurations are resources that relate to the ambari server instance even before a cluster is provisioned.
+ *
+ * Ambari configuration resources may be shared with components and services in the cluster
+ * (by recommending them as default values)
+ *
+ * Eg. LDAP configuration is stored as ambariconfiguration.
+ * The request payload has the form:
+ *
+ * <pre>
+ *      {
+ *        "AmbariConfiguration": {
+ *            "type": "ldap-configuration",
+ *            "data": [
+ *                {
+ *                 "authentication.ldap.primaryUrl": "localhost:33389"
+ *                },
+ *                {
+ *                "authentication.ldap.secondaryUrl": "localhost:333"
+ *                 },
+ *                 {
+ *                 "authentication.ldap.baseDn": "dc=ambari,dc=apache,dc=org"
+ *                 }
+ *                 // ......
+ *             ]
+ *         }
+ *     }
+ * </pre>
+ */
+@Path("/configurations/")
+@Api(value = "/configurations", description = "Endpoint for Ambari configuration related operations")
+public class AmbariConfigurationService extends BaseService {
+
+  /**
+   * Creates an ambari configuration resource.
+   *
+   * @param body    the payload in json format
+   * @param headers http headers
+   * @param uri     request uri information
+   * @return
+   */
+  @POST
+  @Produces(MediaType.TEXT_PLAIN)
+  @ApiOperation(value = "Creates an ambari configuration resource")
+  @ApiImplicitParams({
+    @ApiImplicitParam(dataType = "", paramType = PARAM_TYPE_BODY)
+  })
+  @ApiResponses({
+    @ApiResponse(code = HttpStatus.SC_CREATED, message = MSG_SUCCESSFUL_OPERATION),
+    @ApiResponse(code = HttpStatus.SC_ACCEPTED, message = MSG_REQUEST_ACCEPTED),
+    @ApiResponse(code = HttpStatus.SC_BAD_REQUEST, message = MSG_INVALID_ARGUMENTS),
+    @ApiResponse(code = HttpStatus.SC_CONFLICT, message = MSG_RESOURCE_ALREADY_EXISTS),
+    @ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = MSG_NOT_AUTHENTICATED),
+    @ApiResponse(code = HttpStatus.SC_FORBIDDEN, message = MSG_PERMISSION_DENIED),
+    @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR),
+  })
+  public Response createAmbariConfiguration(String body, @Context HttpHeaders headers, @Context UriInfo uri) {
+    return handleRequest(headers, body, uri, Request.Type.POST, createResource(Resource.Type.AmbariConfiguration,
+      Collections.EMPTY_MAP));
+  }
+
+  @GET
+  @Produces(MediaType.TEXT_PLAIN)
+  @ApiOperation(value = "Retrieve ambari configuration resources")
+  public Response getAmbariConfigurations(String body, @Context HttpHeaders headers, @Context UriInfo uri) {
+    return handleRequest(headers, body, uri, Request.Type.GET, createResource(Resource.Type.AmbariConfiguration,
+      Collections.EMPTY_MAP));
+  }
+
+  @GET
+  @Path("{configurationId}")
+  @Produces(MediaType.TEXT_PLAIN)
+  @ApiOperation(value = "Retrieve ambari configuration resource")
+  public Response getAmbariConfiguration(String body, @Context HttpHeaders headers, @Context UriInfo uri,
+                                         @PathParam("configurationId") String configurationId) {
+    return handleRequest(headers, body, uri, Request.Type.GET, createResource(Resource.Type.AmbariConfiguration,
+      Collections.singletonMap(Resource.Type.AmbariConfiguration, configurationId)));
+  }
+
+  @PUT
+  @Produces(MediaType.TEXT_PLAIN)
+  @ApiOperation(value = "Update ambari configuration resources")
+  public Response updateAmbariConfiguration() {
+    throw new UnsupportedOperationException("Not yet implemented");
+  }
+
+  @DELETE
+  @Path("{configurationId}")
+  @Produces(MediaType.TEXT_PLAIN)
+  @ApiOperation(value = "Deletes an ambari configuration resource")
+  @ApiResponses({
+    @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION),
+    @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND),
+    @ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = MSG_NOT_AUTHENTICATED),
+    @ApiResponse(code = HttpStatus.SC_FORBIDDEN, message = MSG_PERMISSION_DENIED),
+    @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR),
+  })
+  public Response deleteAmbariConfiguration(String body, @Context HttpHeaders headers, @Context UriInfo uri,
+                                            @PathParam("configurationId") String configurationId) {
+    return handleRequest(headers, body, uri, Request.Type.DELETE, createResource(Resource.Type.AmbariConfiguration,
+      Collections.singletonMap(Resource.Type.AmbariConfiguration, configurationId)));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/b349538f/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
index 1cd2d10..1501a01 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
@@ -224,7 +224,7 @@ public abstract class AbstractProviderModule implements ProviderModule,
    * are going to work unless refactoring is complete.
    */
   @Inject
-  AmbariManagementController managementController;
+  protected AmbariManagementController managementController;
 
   @Inject
   TimelineMetricCacheProvider metricCacheProvider;

http://git-wip-us.apache.org/repos/asf/ambari/blob/b349538f/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProvider.java
new file mode 100644
index 0000000..5e5af9e
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProvider.java
@@ -0,0 +1,247 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.controller.internal;
+
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.inject.Inject;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.StaticallyInject;
+import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
+import org.apache.ambari.server.controller.spi.NoSuchResourceException;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.RequestStatus;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.ResourceAlreadyExistsException;
+import org.apache.ambari.server.controller.spi.SystemException;
+import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
+import org.apache.ambari.server.controller.utilities.PredicateHelper;
+import org.apache.ambari.server.orm.dao.AmbariConfigurationDAO;
+import org.apache.ambari.server.orm.entities.AmbariConfigurationEntity;
+import org.apache.ambari.server.orm.entities.ConfigurationBaseEntity;
+import org.apache.ambari.server.security.authorization.RoleAuthorization;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Sets;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+/**
+ * Resource provider for AmbariConfiguration resources.
+ */
+@StaticallyInject
+public class AmbariConfigurationResourceProvider extends AbstractAuthorizedResourceProvider {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(AmbariConfigurationResourceProvider.class);
+  private static final String DEFAULT_VERSION_TAG = "Default version";
+  private static final Integer DEFAULT_VERSION = 1;
+
+  /**
+   * Resource property id constants.
+   */
+  private enum ResourcePropertyId {
+
+    ID("AmbariConfiguration/id"),
+    TYPE("AmbariConfiguration/type"),
+    VERSION("AmbariConfiguration/version"),
+    VERSION_TAG("AmbariConfiguration/version_tag"),
+    DATA("AmbariConfiguration/data");
+
+    private String propertyId;
+
+    ResourcePropertyId(String propertyId) {
+      this.propertyId = propertyId;
+    }
+
+    String getPropertyId() {
+      return this.propertyId;
+    }
+
+    public static ResourcePropertyId fromString(String propertyIdStr) {
+      ResourcePropertyId propertyIdFromStr = null;
+
+      for (ResourcePropertyId id : ResourcePropertyId.values()) {
+        if (id.getPropertyId().equals(propertyIdStr)) {
+          propertyIdFromStr = id;
+          break;
+        }
+      }
+
+      if (propertyIdFromStr == null) {
+        throw new IllegalArgumentException("Unsupported property type: " + propertyIdStr);
+      }
+
+      return propertyIdFromStr;
+
+    }
+  }
+
+  private static Set<String> properties = Sets.newHashSet(
+    ResourcePropertyId.ID.getPropertyId(),
+    ResourcePropertyId.TYPE.getPropertyId(),
+    ResourcePropertyId.VERSION.getPropertyId(),
+    ResourcePropertyId.VERSION_TAG.getPropertyId(),
+    ResourcePropertyId.DATA.getPropertyId());
+
+  private static Map<Resource.Type, String> pkPropertyMap = Collections.unmodifiableMap(
+    new HashMap<Resource.Type, String>() {{
+      put(Resource.Type.AmbariConfiguration, ResourcePropertyId.ID.getPropertyId());
+    }}
+  );
+
+
+  @Inject
+  private static AmbariConfigurationDAO ambariConfigurationDAO;
+
+  private Gson gson;
+
+  protected AmbariConfigurationResourceProvider() {
+    super(properties, pkPropertyMap);
+    setRequiredCreateAuthorizations(EnumSet.of(RoleAuthorization.AMBARI_MANAGE_CONFIGURATION));
+    setRequiredDeleteAuthorizations(EnumSet.of(RoleAuthorization.AMBARI_MANAGE_CONFIGURATION));
+
+    gson = new GsonBuilder().create();
+  }
+
+  @Override
+  protected Set<String> getPKPropertyIds() {
+    return Sets.newHashSet("AmbariConfiguration/id");
+  }
+
+  @Override
+  public RequestStatus createResourcesAuthorized(Request request) throws SystemException, UnsupportedPropertyException,
+    ResourceAlreadyExistsException, NoSuchParentResourceException {
+
+    LOGGER.info("Creating new ambari configuration resource ...");
+    AmbariConfigurationEntity ambariConfigurationEntity = getEntityFromRequest(request);
+
+    LOGGER.info("Persisting new ambari configuration: {} ", ambariConfigurationEntity);
+    ambariConfigurationDAO.persist(ambariConfigurationEntity);
+
+    return getRequestStatus(null);
+  }
+
+
+  @Override
+  protected Set<Resource> getResourcesAuthorized(Request request, Predicate predicate) throws SystemException,
+    UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
+    Set<Resource> resources = Sets.newHashSet();
+
+    List<AmbariConfigurationEntity> ambariConfigurationEntities = ambariConfigurationDAO.findAll();
+    for (AmbariConfigurationEntity ambariConfigurationEntity : ambariConfigurationEntities) {
+      try {
+        resources.add(toResource(ambariConfigurationEntity, getPropertyIds()));
+      } catch (AmbariException e) {
+        LOGGER.error("Error while retrieving ambari configuration", e);
+      }
+    }
+    return resources;
+  }
+
+  @Override
+  protected RequestStatus deleteResourcesAuthorized(Request request, Predicate predicate) throws SystemException,
+    UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
+
+    Long idFromRequest = Long.valueOf((String) PredicateHelper.getProperties(predicate).get(ResourcePropertyId.ID.getPropertyId()));
+
+    if (null == idFromRequest) {
+      LOGGER.debug("No resource id provided in the request");
+    } else {
+      LOGGER.debug("Deleting amari configuration with id: {}", idFromRequest);
+      try {
+        ambariConfigurationDAO.deleteById(idFromRequest);
+      } catch (IllegalStateException e) {
+        throw new NoSuchResourceException(e.getMessage());
+      }
+
+    }
+
+    return getRequestStatus(null);
+
+  }
+
+  private Resource toResource(AmbariConfigurationEntity entity, Set<String> requestedIds) throws AmbariException {
+    Resource resource = new ResourceImpl(Resource.Type.AmbariConfiguration);
+    Set<Map<String, String>> configurationSet = gson.fromJson(entity.getConfigurationBaseEntity().getConfigurationData(), Set.class);
+
+    setResourceProperty(resource, ResourcePropertyId.ID.getPropertyId(), entity.getId(), requestedIds);
+    setResourceProperty(resource, ResourcePropertyId.TYPE.getPropertyId(), entity.getConfigurationBaseEntity().getType(), requestedIds);
+    setResourceProperty(resource, ResourcePropertyId.DATA.getPropertyId(), configurationSet, requestedIds);
+
+    return resource;
+  }
+
+  private AmbariConfigurationEntity getEntityFromRequest(Request request) {
+
+    AmbariConfigurationEntity ambariConfigurationEntity = new AmbariConfigurationEntity();
+    ambariConfigurationEntity.setConfigurationBaseEntity(new ConfigurationBaseEntity());
+
+
+    for (ResourcePropertyId resourcePropertyId : ResourcePropertyId.values()) {
+      Object requestValue = getValueFromRequest(resourcePropertyId, request);
+
+      switch (resourcePropertyId) {
+        case DATA:
+          if (requestValue == null) {
+            throw new IllegalArgumentException("No configuration data is provided in the request");
+          }
+
+          ambariConfigurationEntity.getConfigurationBaseEntity().setConfigurationData(gson.toJson(requestValue));
+          break;
+        case TYPE:
+          ambariConfigurationEntity.getConfigurationBaseEntity().setType((String) requestValue);
+          break;
+
+        case VERSION:
+          Integer version = (requestValue == null) ? DEFAULT_VERSION : Integer.valueOf((Integer) requestValue);
+          ambariConfigurationEntity.getConfigurationBaseEntity().setVersion((version));
+          break;
+        case VERSION_TAG:
+          String versionTag = requestValue == null ? DEFAULT_VERSION_TAG : (String) requestValue;
+          ambariConfigurationEntity.getConfigurationBaseEntity().setVersionTag(versionTag);
+          break;
+        default:
+          LOGGER.debug("Ignored property in the request: {}", resourcePropertyId);
+          break;
+      }
+    }
+    ambariConfigurationEntity.getConfigurationBaseEntity().setCreateTimestamp(Calendar.getInstance().getTimeInMillis());
+    return ambariConfigurationEntity;
+
+  }
+
+  private Object getValueFromRequest(ResourcePropertyId resourcePropertyIdEnum, Request request) {
+    LOGGER.debug("Locating resource property [{}] in the request ...", resourcePropertyIdEnum);
+    Object requestValue = null;
+    for (Map<String, Object> propertyMap : request.getProperties()) {
+      if (propertyMap.containsKey(resourcePropertyIdEnum.getPropertyId())) {
+        requestValue = propertyMap.get(resourcePropertyIdEnum.getPropertyId());
+        LOGGER.debug("Found resource property {} in the request, value: {} ...", resourcePropertyIdEnum, requestValue);
+        break;
+      }
+    }
+    return requestValue;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/b349538f/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
index 43779a3..fdf4a97 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
@@ -21,20 +21,18 @@ package org.apache.ambari.server.controller.internal;
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.ambari.server.controller.AmbariManagementController;
-import org.apache.ambari.server.controller.AmbariServer;
 import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.spi.ResourceProvider;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
-
-import com.google.inject.Inject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * The default provider module implementation.
  */
 public class DefaultProviderModule extends AbstractProviderModule {
-  @Inject
-  private AmbariManagementController managementController;
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultProviderModule.class);
 
   // ----- Constructors ------------------------------------------------------
 
@@ -42,9 +40,7 @@ public class DefaultProviderModule extends AbstractProviderModule {
    * Create a default provider module.
    */
   public DefaultProviderModule() {
-    if (managementController == null) {
-      managementController = AmbariServer.getController();
-    }
+    super();
   }
 
 
@@ -52,8 +48,10 @@ public class DefaultProviderModule extends AbstractProviderModule {
 
   @Override
   protected ResourceProvider createResourceProvider(Resource.Type type) {
-    Set<String>               propertyIds    = PropertyHelper.getPropertyIds(type);
-    Map<Resource.Type,String> keyPropertyIds = PropertyHelper.getKeyPropertyIds(type);
+
+    LOGGER.debug("Creating resource provider for the type: {}", type);
+    Set<String> propertyIds = PropertyHelper.getPropertyIds(type);
+    Map<Resource.Type, String> keyPropertyIds = PropertyHelper.getKeyPropertyIds(type);
 
     switch (type.getInternalType()) {
       case Workflow:
@@ -118,10 +116,12 @@ public class DefaultProviderModule extends AbstractProviderModule {
         return new ArtifactResourceProvider(managementController);
       case RemoteCluster:
         return new RemoteClusterResourceProvider();
-
+      case AmbariConfiguration:
+        return new AmbariConfigurationResourceProvider();
       default:
+        LOGGER.debug("Delegating creation of resource provider for: {} to the AbstractControllerResourceProvider", type.getInternalType());
         return AbstractControllerResourceProvider.getResourceProvider(type, propertyIds,
-            keyPropertyIds, managementController);
+          keyPropertyIds, managementController);
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/b349538f/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java
index 362b4e6..7835373 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java
@@ -160,7 +160,8 @@ public interface Resource {
     VersionDefinition,
     ClusterKerberosDescriptor,
     LoggingQuery,
-    RemoteCluster;
+    RemoteCluster,
+    AmbariConfiguration;
 
     /**
      * Get the {@link Type} that corresponds to this InternalType.
@@ -282,6 +283,8 @@ public interface Resource {
     public static final Type ClusterKerberosDescriptor = InternalType.ClusterKerberosDescriptor.getType();
     public static final Type LoggingQuery = InternalType.LoggingQuery.getType();
     public static final Type RemoteCluster = InternalType.RemoteCluster.getType();
+    public static final Type AmbariConfiguration = InternalType.AmbariConfiguration.getType();
+
 
     /**
      * The type name.

http://git-wip-us.apache.org/repos/asf/ambari/blob/b349538f/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AmbariConfigurationDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AmbariConfigurationDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AmbariConfigurationDAO.java
new file mode 100644
index 0000000..dea37eb
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AmbariConfigurationDAO.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.orm.dao;
+
+import java.util.List;
+
+import javax.inject.Inject;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+import javax.persistence.EntityManager;
+import javax.persistence.TypedQuery;
+
+import org.apache.ambari.server.orm.RequiresSession;
+import org.apache.ambari.server.orm.entities.AmbariConfigurationEntity;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.persist.Transactional;
+
+/**
+ * DAO dealing with ambari configuration related JPA operations.
+ */
+
+@Singleton
+// todo extend CrudDao (amend crud dao to handle NPEs)
+public class AmbariConfigurationDAO {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(AmbariConfigurationDAO.class);
+
+  @Inject
+  private Provider<EntityManager> entityManagerProvider;
+
+  /**
+   * DAO utilities for dealing mostly with {@link TypedQuery} results.
+   */
+  @Inject
+  private DaoUtils daoUtils;
+
+  public AmbariConfigurationEntity findByid(Long id) {
+    return entityManagerProvider.get().find(AmbariConfigurationEntity.class, id);
+  }
+
+  @RequiresSession
+  @Transactional
+  public void persist(AmbariConfigurationEntity entity) {
+    LOGGER.debug("Persisting ambari configuration: {}", entity);
+    entityManagerProvider.get().persist(entity);
+  }
+
+  @RequiresSession
+  public List<AmbariConfigurationEntity> findAll() {
+    TypedQuery<AmbariConfigurationEntity> query = entityManagerProvider.get().createNamedQuery(
+      "AmbariConfigurationEntity.findAll", AmbariConfigurationEntity.class);
+    return daoUtils.selectList(query);
+  }
+
+
+  @RequiresSession
+  @Transactional
+  public void deleteById(Long ambariConfigurationId) {
+
+    if (ambariConfigurationId == null) {
+      throw new IllegalArgumentException("No Ambari Configuration id provided.");
+    }
+
+    LOGGER.debug("Removing Ambari Configuration with id :{}", ambariConfigurationId);
+
+    AmbariConfigurationEntity ambariConfigurationEntity = findByid(ambariConfigurationId);
+    if (ambariConfigurationEntity == null) {
+      String msg = String.format("No Ambari Configuration found with id: %s", ambariConfigurationId);
+      LOGGER.debug(msg);
+      throw new IllegalStateException(msg);
+    }
+
+    entityManagerProvider.get().remove(ambariConfigurationEntity);
+    LOGGER.debug("Ambari Configuration with id: {}", ambariConfigurationId);
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/b349538f/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AmbariConfigurationEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AmbariConfigurationEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AmbariConfigurationEntity.java
new file mode 100644
index 0000000..34fa221
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AmbariConfigurationEntity.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.orm.entities;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.MapsId;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "ambari_configuration")
+@NamedQueries({
+  @NamedQuery(
+    name = "AmbariConfigurationEntity.findAll",
+    query = "select ace from AmbariConfigurationEntity ace")
+})
+
+public class AmbariConfigurationEntity {
+
+  @Id
+  @Column(name = "id")
+  private Long id;
+
+  @OneToOne(cascade = CascadeType.ALL)
+  @MapsId
+  @JoinColumn(name = "id")
+  private ConfigurationBaseEntity configurationBaseEntity;
+
+  public Long getId() {
+    return id;
+  }
+
+  public void setId(Long id) {
+    this.id = id;
+  }
+
+  public ConfigurationBaseEntity getConfigurationBaseEntity() {
+    return configurationBaseEntity;
+  }
+
+  public void setConfigurationBaseEntity(ConfigurationBaseEntity configurationBaseEntity) {
+    this.configurationBaseEntity = configurationBaseEntity;
+  }
+
+  @Override
+  public String toString() {
+    return "AmbariConfigurationEntity{" +
+      "id=" + id +
+      ", configurationBaseEntity=" + configurationBaseEntity +
+      '}';
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/b349538f/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ConfigurationBaseEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ConfigurationBaseEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ConfigurationBaseEntity.java
new file mode 100644
index 0000000..9ad30d7
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ConfigurationBaseEntity.java
@@ -0,0 +1,159 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.orm.entities;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.TableGenerator;
+
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+
+@Table(name = "configuration_base")
+@TableGenerator(
+  name = "configuration_id_generator",
+  table = "ambari_sequences",
+  pkColumnName = "sequence_name",
+  valueColumnName = "sequence_value",
+  pkColumnValue = "configuration_id_seq",
+  initialValue = 1
+)
+@Entity
+public class ConfigurationBaseEntity {
+
+  @Id
+  @Column(name = "id")
+  @GeneratedValue(strategy = GenerationType.TABLE, generator = "configuration_id_generator")
+  private Long id;
+
+  @Column(name = "version")
+  private Integer version;
+
+  @Column(name = "version_tag")
+  private String versionTag;
+
+  @Column(name = "type")
+  private String type;
+
+  @Column(name = "data")
+  private String configurationData;
+
+  @Column(name = "attributes")
+  private String configurationAttributes;
+
+  @Column(name = "create_timestamp")
+  private Long createTimestamp;
+
+  public Long getId() {
+    return id;
+  }
+
+  public Integer getVersion() {
+    return version;
+  }
+
+  public void setVersion(Integer version) {
+    this.version = version;
+  }
+
+  public String getVersionTag() {
+    return versionTag;
+  }
+
+  public void setVersionTag(String versionTag) {
+    this.versionTag = versionTag;
+  }
+
+  public String getType() {
+    return type;
+  }
+
+  public void setType(String type) {
+    this.type = type;
+  }
+
+  public String getConfigurationData() {
+    return configurationData;
+  }
+
+  public void setConfigurationData(String configurationData) {
+    this.configurationData = configurationData;
+  }
+
+  public String getConfigurationAttributes() {
+    return configurationAttributes;
+  }
+
+  public void setConfigurationAttributes(String configurationAttributes) {
+    this.configurationAttributes = configurationAttributes;
+  }
+
+  public Long getCreateTimestamp() {
+    return createTimestamp;
+  }
+
+  public void setCreateTimestamp(Long createTimestamp) {
+    this.createTimestamp = createTimestamp;
+  }
+
+  @Override
+  public String toString() {
+    return "ConfigurationBaseEntity{" +
+      "id=" + id +
+      ", version=" + version +
+      ", versionTag='" + versionTag + '\'' +
+      ", type='" + type + '\'' +
+      ", configurationData='" + configurationData + '\'' +
+      ", configurationAttributes='" + configurationAttributes + '\'' +
+      ", createTimestamp=" + createTimestamp +
+      '}';
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+
+    if (o == null || getClass() != o.getClass()) return false;
+
+    ConfigurationBaseEntity that = (ConfigurationBaseEntity) o;
+
+    return new EqualsBuilder()
+      .append(id, that.id)
+      .append(version, that.version)
+      .append(versionTag, that.versionTag)
+      .append(type, that.type)
+      .append(configurationData, that.configurationData)
+      .append(configurationAttributes, that.configurationAttributes)
+      .append(createTimestamp, that.createTimestamp)
+      .isEquals();
+  }
+
+  @Override
+  public int hashCode() {
+    return new HashCodeBuilder(17, 37)
+      .append(id)
+      .append(version)
+      .append(versionTag)
+      .append(type)
+      .append(configurationData)
+      .append(configurationAttributes)
+      .append(createTimestamp)
+      .toHashCode();
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/b349538f/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/RoleAuthorization.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/RoleAuthorization.java b/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/RoleAuthorization.java
index cd35c2c..3c50628 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/RoleAuthorization.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/RoleAuthorization.java
@@ -39,6 +39,7 @@ public enum RoleAuthorization {
   AMBARI_MANAGE_VIEWS("AMBARI.MANAGE_VIEWS"),
   AMBARI_RENAME_CLUSTER("AMBARI.RENAME_CLUSTER"),
   AMBARI_RUN_CUSTOM_COMMAND("AMBARI.RUN_CUSTOM_COMMAND"),
+  AMBARI_MANAGE_CONFIGURATION("AMBARI.MANAGE_CONFIGURATION"),
   CLUSTER_MANAGE_CREDENTIALS("CLUSTER.MANAGE_CREDENTIALS"),
   CLUSTER_MODIFY_CONFIGS("CLUSTER.MODIFY_CONFIGS"),
   CLUSTER_MANAGE_CONFIG_GROUPS("CLUSTER.MANAGE_CONFIG_GROUPS"),
@@ -84,58 +85,58 @@ public enum RoleAuthorization {
   VIEW_USE("VIEW.USE");
 
   public static final Set<RoleAuthorization> AUTHORIZATIONS_VIEW_CLUSTER = EnumSet.of(
-      CLUSTER_VIEW_STATUS_INFO,
-      CLUSTER_VIEW_ALERTS,
-      CLUSTER_VIEW_CONFIGS,
-      CLUSTER_VIEW_METRICS,
-      CLUSTER_VIEW_STACK_DETAILS,
-      CLUSTER_MODIFY_CONFIGS,
-      CLUSTER_MANAGE_CONFIG_GROUPS,
-      CLUSTER_TOGGLE_ALERTS,
-      CLUSTER_TOGGLE_KERBEROS,
-      CLUSTER_UPGRADE_DOWNGRADE_STACK);
+    CLUSTER_VIEW_STATUS_INFO,
+    CLUSTER_VIEW_ALERTS,
+    CLUSTER_VIEW_CONFIGS,
+    CLUSTER_VIEW_METRICS,
+    CLUSTER_VIEW_STACK_DETAILS,
+    CLUSTER_MODIFY_CONFIGS,
+    CLUSTER_MANAGE_CONFIG_GROUPS,
+    CLUSTER_TOGGLE_ALERTS,
+    CLUSTER_TOGGLE_KERBEROS,
+    CLUSTER_UPGRADE_DOWNGRADE_STACK);
 
   public static final Set<RoleAuthorization> AUTHORIZATIONS_UPDATE_CLUSTER = EnumSet.of(
-      CLUSTER_TOGGLE_ALERTS,
-      CLUSTER_TOGGLE_KERBEROS,
-      CLUSTER_UPGRADE_DOWNGRADE_STACK,
-      CLUSTER_MODIFY_CONFIGS,
-      CLUSTER_MANAGE_AUTO_START,
-      SERVICE_MODIFY_CONFIGS);
+    CLUSTER_TOGGLE_ALERTS,
+    CLUSTER_TOGGLE_KERBEROS,
+    CLUSTER_UPGRADE_DOWNGRADE_STACK,
+    CLUSTER_MODIFY_CONFIGS,
+    CLUSTER_MANAGE_AUTO_START,
+    SERVICE_MODIFY_CONFIGS);
 
   public static final Set<RoleAuthorization> AUTHORIZATIONS_VIEW_SERVICE = EnumSet.of(
-      SERVICE_VIEW_ALERTS,
-      SERVICE_VIEW_CONFIGS,
-      SERVICE_VIEW_METRICS,
-      SERVICE_VIEW_STATUS_INFO,
-      SERVICE_COMPARE_CONFIGS,
-      SERVICE_ADD_DELETE_SERVICES,
-      SERVICE_DECOMMISSION_RECOMMISSION,
-      SERVICE_ENABLE_HA,
-      SERVICE_MANAGE_CONFIG_GROUPS,
-      SERVICE_MODIFY_CONFIGS,
-      SERVICE_START_STOP,
-      SERVICE_TOGGLE_MAINTENANCE,
-      SERVICE_TOGGLE_ALERTS,
-      SERVICE_MOVE,
-      SERVICE_RUN_CUSTOM_COMMAND,
-      SERVICE_RUN_SERVICE_CHECK);
+    SERVICE_VIEW_ALERTS,
+    SERVICE_VIEW_CONFIGS,
+    SERVICE_VIEW_METRICS,
+    SERVICE_VIEW_STATUS_INFO,
+    SERVICE_COMPARE_CONFIGS,
+    SERVICE_ADD_DELETE_SERVICES,
+    SERVICE_DECOMMISSION_RECOMMISSION,
+    SERVICE_ENABLE_HA,
+    SERVICE_MANAGE_CONFIG_GROUPS,
+    SERVICE_MODIFY_CONFIGS,
+    SERVICE_START_STOP,
+    SERVICE_TOGGLE_MAINTENANCE,
+    SERVICE_TOGGLE_ALERTS,
+    SERVICE_MOVE,
+    SERVICE_RUN_CUSTOM_COMMAND,
+    SERVICE_RUN_SERVICE_CHECK);
 
   public static final Set<RoleAuthorization> AUTHORIZATIONS_UPDATE_SERVICE = EnumSet.of(
-      SERVICE_ADD_DELETE_SERVICES,
-      SERVICE_DECOMMISSION_RECOMMISSION,
-      SERVICE_ENABLE_HA,
-      SERVICE_MANAGE_CONFIG_GROUPS,
-      SERVICE_MODIFY_CONFIGS,
-      SERVICE_START_STOP,
-      SERVICE_TOGGLE_MAINTENANCE,
-      SERVICE_TOGGLE_ALERTS,
-      SERVICE_MOVE,
-      SERVICE_RUN_CUSTOM_COMMAND,
-      SERVICE_RUN_SERVICE_CHECK,
-      SERVICE_MANAGE_ALERTS,
-      SERVICE_MANAGE_AUTO_START,
-      SERVICE_SET_SERVICE_USERS_GROUPS);
+    SERVICE_ADD_DELETE_SERVICES,
+    SERVICE_DECOMMISSION_RECOMMISSION,
+    SERVICE_ENABLE_HA,
+    SERVICE_MANAGE_CONFIG_GROUPS,
+    SERVICE_MODIFY_CONFIGS,
+    SERVICE_START_STOP,
+    SERVICE_TOGGLE_MAINTENANCE,
+    SERVICE_TOGGLE_ALERTS,
+    SERVICE_MOVE,
+    SERVICE_RUN_CUSTOM_COMMAND,
+    SERVICE_RUN_SERVICE_CHECK,
+    SERVICE_MANAGE_ALERTS,
+    SERVICE_MANAGE_AUTO_START,
+    SERVICE_SET_SERVICE_USERS_GROUPS);
 
   private final String id;
 
@@ -162,7 +163,7 @@ public enum RoleAuthorization {
   /**
    * Safely translates a role authorization Id to a RoleAuthorization
    *
-   * @param authenticationId  an authentication id
+   * @param authenticationId an authentication id
    * @return a RoleAuthorization or null if no translation can be made
    */
   public static RoleAuthorization translate(String authenticationId) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/b349538f/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
index 634db95..01b3324 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -62,8 +62,26 @@ CREATE TABLE clusters (
   desired_cluster_state VARCHAR(255) NOT NULL,
   desired_stack_id BIGINT NOT NULL,
   CONSTRAINT PK_clusters PRIMARY KEY (cluster_id),
-  CONSTRAINT FK_clusters_desired_stack_id FOREIGN KEY (desired_stack_id) REFERENCES stack(stack_id),
-  CONSTRAINT FK_clusters_resource_id FOREIGN KEY (resource_id) REFERENCES adminresource(resource_id));
+  CONSTRAINT FK_clusters_desired_stack_id FOREIGN KEY (desired_stack_id) REFERENCES stack (stack_id),
+  CONSTRAINT FK_clusters_resource_id FOREIGN KEY (resource_id) REFERENCES adminresource (resource_id)
+);
+
+CREATE TABLE configuration_base (
+  id               BIGINT       NOT NULL,
+  version_tag      VARCHAR(255) NOT NULL,
+  version          BIGINT       NOT NULL,
+  type             VARCHAR(255) NOT NULL,
+  data             TEXT         NOT NULL,
+  attributes       TEXT,
+  create_timestamp BIGINT       NOT NULL,
+  CONSTRAINT PK_configuration_base PRIMARY KEY (id)
+);
+
+CREATE TABLE ambari_configuration (
+  id BIGINT NOT NULL,
+  CONSTRAINT PK_ambari_configuration PRIMARY KEY (id),
+  CONSTRAINT FK_ambari_configuration_configuration_base FOREIGN KEY (id) REFERENCES configuration_base (id)
+);
 
 CREATE TABLE clusterconfig (
   config_id BIGINT NOT NULL,
@@ -1090,6 +1108,7 @@ INSERT INTO ambari_sequences (sequence_name, sequence_value) VALUES
   ('remote_cluster_id_seq', 0),
   ('remote_cluster_service_id_seq', 0),
   ('servicecomponent_version_id_seq', 0),
+  ('configuration_id_seq', 0),
   ('hostcomponentdesiredstate_id_seq', 0);
 
 INSERT INTO adminresourcetype (resource_type_id, resource_type_name) VALUES
@@ -1174,6 +1193,7 @@ INSERT INTO roleauthorization(authorization_id, authorization_name)
   SELECT 'AMBARI.ADD_DELETE_CLUSTERS', 'Create new clusters' UNION ALL
   SELECT 'AMBARI.RENAME_CLUSTER', 'Rename clusters' UNION ALL
   SELECT 'AMBARI.MANAGE_SETTINGS', 'Manage administrative settings' UNION ALL
+  SELECT 'AMBARI.MANAGE_CONFIGURATION', 'Manage ambari configuration' UNION ALL
   SELECT 'AMBARI.MANAGE_USERS', 'Manage users' UNION ALL
   SELECT 'AMBARI.MANAGE_GROUPS', 'Manage groups' UNION ALL
   SELECT 'AMBARI.MANAGE_VIEWS', 'Manage Ambari Views' UNION ALL
@@ -1379,6 +1399,7 @@ INSERT INTO permission_roleauthorization(permission_id, authorization_id)
   SELECT permission_id, 'AMBARI.ADD_DELETE_CLUSTERS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
   SELECT permission_id, 'AMBARI.RENAME_CLUSTER' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
   SELECT permission_id, 'AMBARI.MANAGE_SETTINGS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
+  SELECT permission_id, 'AMBARI.MANAGE_CONFIGURATION' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
   SELECT permission_id, 'AMBARI.MANAGE_USERS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
   SELECT permission_id, 'AMBARI.MANAGE_GROUPS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
   SELECT permission_id, 'AMBARI.MANAGE_VIEWS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL

http://git-wip-us.apache.org/repos/asf/ambari/blob/b349538f/ambari-server/src/main/resources/META-INF/persistence.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/META-INF/persistence.xml b/ambari-server/src/main/resources/META-INF/persistence.xml
index e4045ef..0f8e964 100644
--- a/ambari-server/src/main/resources/META-INF/persistence.xml
+++ b/ambari-server/src/main/resources/META-INF/persistence.xml
@@ -96,6 +96,8 @@
     <class>org.apache.ambari.server.orm.entities.KerberosDescriptorEntity</class>
     <class>org.apache.ambari.server.orm.entities.RemoteAmbariClusterEntity</class>
     <class>org.apache.ambari.server.orm.entities.RemoteAmbariClusterServiceEntity</class>
+    <class>org.apache.ambari.server.orm.entities.ConfigurationBaseEntity</class>
+    <class>org.apache.ambari.server.orm.entities.AmbariConfigurationEntity</class>
 
     <properties>
       <property name="eclipselink.cache.size.default" value="10000" />


[23/46] ambari git commit: AMBARI-21307 AddedLDAP configuration provider for loading and maintaining the LDAP configuration in the application

Posted by lp...@apache.org.
AMBARI-21307 AddedLDAP configuration provider for loading and maintaining the LDAP configuration in the application


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 38c2785a4205012e284c91172c2466068a2e8da7
Parents: 3c0b27b
Author: lpuskas <lp...@apache.org>
Authored: Tue Aug 29 14:55:09 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:41:58 2017 +0200

----------------------------------------------------------------------
 .../services/ldap/LdapConfigurationService.java |   1 +
 .../AmbariConfigurationResourceProvider.java    |  35 +++++-
 .../ambari/server/events/AmbariEvent.java       |  11 +-
 .../events/AmbariLdapConfigChangedEvent.java    |  37 ++++++
 .../server/ldap/LdapConfigurationFactory.java   |   2 +-
 .../apache/ambari/server/ldap/LdapModule.java   |   3 +
 .../AmbariLdapConfigurationProvider.java        | 114 +++++++++++++++++++
 .../server/ldap/service/AmbariLdapFacade.java   |   7 +-
 .../server/orm/dao/AmbariConfigurationDAO.java  |  48 ++++++++
 .../orm/entities/AmbariConfigurationEntity.java |   4 +-
 .../DefaultLdapConfigurationServiceTest.java    |  10 +-
 11 files changed, 260 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/38c2785a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
index fc6bd41..1b8427b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ldap/LdapConfigurationService.java
@@ -82,6 +82,7 @@ public class LdapConfigurationService extends AmbariConfigurationService {
   @Produces(MediaType.APPLICATION_JSON)
   public Response validateConfiguration(LdapConfigurationRequest ldapConfigurationRequest) {
 
+    // check if the user is authorized to perform the operation
     authorize();
 
     Set<String> groups = Sets.newHashSet();

http://git-wip-us.apache.org/repos/asf/ambari/blob/38c2785a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProvider.java
index 2302d8b..4f4cc70 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProvider.java
@@ -35,6 +35,9 @@ import org.apache.ambari.server.controller.spi.ResourceAlreadyExistsException;
 import org.apache.ambari.server.controller.spi.SystemException;
 import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
 import org.apache.ambari.server.controller.utilities.PredicateHelper;
+import org.apache.ambari.server.events.AmbariEvent;
+import org.apache.ambari.server.events.AmbariLdapConfigChangedEvent;
+import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
 import org.apache.ambari.server.orm.dao.AmbariConfigurationDAO;
 import org.apache.ambari.server.orm.entities.AmbariConfigurationEntity;
 import org.apache.ambari.server.orm.entities.ConfigurationBaseEntity;
@@ -113,6 +116,10 @@ public class AmbariConfigurationResourceProvider extends AbstractAuthorizedResou
   @Inject
   private AmbariConfigurationDAO ambariConfigurationDAO;
 
+  @Inject
+  private AmbariEventPublisher publisher;
+
+
   private Gson gson;
 
   @AssistedInject
@@ -142,7 +149,18 @@ public class AmbariConfigurationResourceProvider extends AbstractAuthorizedResou
     }
 
     LOGGER.info("Persisting new ambari configuration: {} ", ambariConfigurationEntity);
-    ambariConfigurationDAO.create(ambariConfigurationEntity);
+
+    try {
+      ambariConfigurationDAO.create(ambariConfigurationEntity);
+    } catch (Exception e) {
+      LOGGER.error("Failed to create resource", e);
+      throw new ResourceAlreadyExistsException(e.getMessage());
+    }
+
+    // todo filter by configuration type
+    // notify subscribers about the configuration changes
+    publisher.publish(new AmbariLdapConfigChangedEvent(AmbariEvent.AmbariEventType.LDAP_CONFIG_CHANGED,
+      ambariConfigurationEntity.getId()));
 
     return getRequestStatus(null);
   }
@@ -183,6 +201,10 @@ public class AmbariConfigurationResourceProvider extends AbstractAuthorizedResou
 
     }
 
+    // notify subscribers about the configuration changes
+    publisher.publish(new AmbariLdapConfigChangedEvent(AmbariEvent.AmbariEventType.LDAP_CONFIG_CHANGED, idFromRequest));
+
+
     return getRequestStatus(null);
 
   }
@@ -209,11 +231,15 @@ public class AmbariConfigurationResourceProvider extends AbstractAuthorizedResou
       persistedEntity.getConfigurationBaseEntity().setConfigurationAttributes(entityFromRequest.getConfigurationBaseEntity().getConfigurationAttributes());
 
 
-      ambariConfigurationDAO.create(persistedEntity);
+      ambariConfigurationDAO.update(persistedEntity);
     } catch (AmbariException e) {
       throw new NoSuchParentResourceException(e.getMessage());
     }
 
+    publisher.publish(new AmbariLdapConfigChangedEvent(AmbariEvent.AmbariEventType.LDAP_CONFIG_CHANGED,
+      persistedEntity.getId()));
+
+
     return getRequestStatus(null);
 
   }
@@ -251,6 +277,11 @@ public class AmbariConfigurationResourceProvider extends AbstractAuthorizedResou
       throw new AmbariException("There must be only one resource specified in the request");
     }
 
+    // the configuration type must be set
+    if (getValueFromResourceProperties(ResourcePropertyId.TYPE, resourcePropertiesSet.iterator().next()) == null) {
+      throw new AmbariException("The configuration type must be set");
+    }
+
 
     for (ResourcePropertyId resourcePropertyId : ResourcePropertyId.values()) {
       Object requestValue = getValueFromResourceProperties(resourcePropertyId, resourcePropertiesSet.iterator().next());

http://git-wip-us.apache.org/repos/asf/ambari/blob/38c2785a/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariEvent.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariEvent.java
index 9a5ee79..0f9ff52 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariEvent.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariEvent.java
@@ -140,7 +140,13 @@ public abstract class AmbariEvent {
     /**
      * Local user has been created.
      */
-    USER_CREATED;
+    USER_CREATED,
+
+    /**
+     * LDAP config changed event;
+     */
+    LDAP_CONFIG_CHANGED;
+
   }
 
   /**
@@ -151,8 +157,7 @@ public abstract class AmbariEvent {
   /**
    * Constructor.
    *
-   * @param eventType
-   *          the type of event (not {@code null}).
+   * @param eventType the type of event (not {@code null}).
    */
   public AmbariEvent(AmbariEventType eventType) {
     m_eventType = eventType;

http://git-wip-us.apache.org/repos/asf/ambari/blob/38c2785a/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariLdapConfigChangedEvent.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariLdapConfigChangedEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariLdapConfigChangedEvent.java
new file mode 100644
index 0000000..48799d7
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariLdapConfigChangedEvent.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.events;
+
+/**
+ * Event signaling the creation or changing of an LDAP configuration entry.
+ */
+public class AmbariLdapConfigChangedEvent extends AmbariEvent {
+
+  private Long configurationId;
+
+  /**
+   * Constructor.
+   *
+   * @param eventType the type of event (not {@code null}).
+   */
+  public AmbariLdapConfigChangedEvent(AmbariEventType eventType, Long configurationId) {
+    super(eventType);
+    this.configurationId = configurationId;
+  }
+
+  public Long getConfigurationId() {
+    return configurationId;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/38c2785a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationFactory.java
index bcd6e39..57cdf6e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationFactory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationFactory.java
@@ -18,4 +18,4 @@ import java.util.Map;
 
 public interface LdapConfigurationFactory {
   AmbariLdapConfiguration createLdapConfiguration(Map<String, Object> configuration);
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/38c2785a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
index 3ae4587..81f2a44 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
@@ -15,6 +15,7 @@
 
 package org.apache.ambari.server.ldap;
 
+import org.apache.ambari.server.ldap.service.AmbariLdapConfigurationProvider;
 import org.apache.ambari.server.ldap.service.AmbariLdapFacade;
 import org.apache.ambari.server.ldap.service.LdapConnectionService;
 import org.apache.ambari.server.ldap.service.LdapFacade;
@@ -35,6 +36,8 @@ public class LdapModule extends AbstractModule {
     bind(LdapConfigurationService.class).to(DefaultLdapConfigurationService.class);
     bind(LdapConnectionService.class).to(DefaultLdapConnectionService.class);
 
+    bind(AmbariLdapConfiguration.class).toProvider(AmbariLdapConfigurationProvider.class);
+
     install(new FactoryModuleBuilder().build(LdapConfigurationFactory.class));
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/38c2785a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java
new file mode 100644
index 0000000..7f3e8a9
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service;
+
+import java.util.Map;
+import java.util.Set;
+
+import javax.inject.Inject;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+
+import org.apache.ambari.server.events.AmbariLdapConfigChangedEvent;
+import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
+import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.orm.dao.AmbariConfigurationDAO;
+import org.apache.ambari.server.orm.entities.AmbariConfigurationEntity;
+import org.apache.ambari.server.security.authorization.AmbariLdapAuthenticationProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.eventbus.Subscribe;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+/**
+ * Provider implementation for LDAP configurations. It needs to be registered in the related GUICE module as a provider
+ * It's responsible for managing LDAP configurations in the application.
+ * Whenever requested, this provider returns an AmbariLdapConfiguration which is always in sync with the persisted LDAP
+ * configuration resource.
+ *
+ * The provider receives notifications on CRUD operations related to the persisted resource and reloads the cached
+ * configuration instance accordingly.
+ */
+@Singleton
+public class AmbariLdapConfigurationProvider implements Provider<AmbariLdapConfiguration> {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(AmbariLdapAuthenticationProvider.class);
+  private AmbariLdapConfiguration instance;
+
+  @Inject
+  private AmbariEventPublisher publisher;
+
+  @Inject
+  private Provider<AmbariConfigurationDAO> ambariConfigurationDAOProvider;
+
+  private Gson gson = new GsonBuilder().create();
+
+  @Inject
+  public AmbariLdapConfigurationProvider() {
+  }
+
+  @Inject
+  void register() {
+    publisher.register(this);
+  }
+
+  @Override
+  public AmbariLdapConfiguration get() {
+    return instance != null ? instance : loadInstance(null);
+  }
+
+  /**
+   * Loads the AmbariLdapConfiguration from the database.
+   *
+   * @param configurationId the configuration id
+   * @return the AmbariLdapConfiguration instance
+   */
+  private AmbariLdapConfiguration loadInstance(Long configurationId) {
+    AmbariConfigurationEntity configEntity = null;
+
+    LOGGER.info("Loading LDAP configuration ...");
+    if (null != configurationId) {
+
+      LOGGER.debug("Reloading configuration based on the provied id: {}", configurationId);
+      configEntity = ambariConfigurationDAOProvider.get().findByPK(configurationId);
+
+    } else {
+
+      LOGGER.debug("Initial loading of the ldap configuration ...");
+      configEntity = ambariConfigurationDAOProvider.get().getLdapConfiguration();
+
+    }
+
+    if (configEntity != null) {
+      Set propertyMaps = gson.fromJson(configEntity.getConfigurationBaseEntity().getConfigurationData(), Set.class);
+      instance = new AmbariLdapConfiguration((Map<String, Object>) propertyMaps.iterator().next());
+    }
+
+    LOGGER.info("Loaded LDAP configuration instance: [ {} ]", instance);
+
+    return instance;
+  }
+
+  @Subscribe
+  public void ambariLdapConfigChanged(AmbariLdapConfigChangedEvent event) {
+    LOGGER.info("LDAP config changed event received: {}", event);
+    loadInstance(event.getConfigurationId());
+    LOGGER.info("Refreshed LDAP config instance.");
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/38c2785a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
index 683ed43..90a5ba7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
@@ -19,6 +19,7 @@ import java.util.Map;
 import java.util.Set;
 
 import javax.inject.Inject;
+import javax.inject.Provider;
 import javax.inject.Singleton;
 
 import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
@@ -54,6 +55,10 @@ public class AmbariLdapFacade implements LdapFacade {
   @Inject
   private LdapConnectionService ldapConnectionService;
 
+  //todo remove this, added for testing purposes only
+  @Inject
+  private Provider<AmbariLdapConfiguration> ambariLdapConfigurationProvider;
+
   @Inject
   public AmbariLdapFacade() {
   }
@@ -75,7 +80,7 @@ public class AmbariLdapFacade implements LdapFacade {
   @Override
   public void detectAttributes(AmbariLdapConfiguration ambariLdapConfiguration) {
     LOGGER.info("Detecting LDAP configuration attributes ...");
-    throw new UnsupportedOperationException("Not yet implemented");
+    LOGGER.info("LDAP config: {}", ambariLdapConfigurationProvider.get());
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/38c2785a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AmbariConfigurationDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AmbariConfigurationDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AmbariConfigurationDAO.java
index 5710a7f..83293ef 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AmbariConfigurationDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AmbariConfigurationDAO.java
@@ -16,8 +16,13 @@ package org.apache.ambari.server.orm.dao;
 
 import javax.inject.Inject;
 import javax.inject.Singleton;
+import javax.persistence.EntityExistsException;
+import javax.persistence.EntityNotFoundException;
+import javax.persistence.TypedQuery;
 
 import org.apache.ambari.server.orm.entities.AmbariConfigurationEntity;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.google.inject.persist.Transactional;
 
@@ -29,6 +34,8 @@ import com.google.inject.persist.Transactional;
 @Singleton
 public class AmbariConfigurationDAO extends CrudDAO<AmbariConfigurationEntity, Long> {
 
+  private static final Logger LOGGER = LoggerFactory.getLogger(AmbariConfigurationDAO.class);
+
   @Inject
   public AmbariConfigurationDAO() {
     super(AmbariConfigurationEntity.class);
@@ -36,6 +43,47 @@ public class AmbariConfigurationDAO extends CrudDAO<AmbariConfigurationEntity, L
 
   @Transactional
   public void create(AmbariConfigurationEntity entity) {
+    // make  sure only one LDAP config entry exists
+    if ("ldap-configuration".equals(entity.getConfigurationBaseEntity().getType())) {
+      AmbariConfigurationEntity ldapConfigEntity = getLdapConfiguration();
+      if (ldapConfigEntity != null) {
+        LOGGER.error("Only one LDAP configuration entry can exist!");
+        throw new EntityExistsException("LDAP configuration entity already exists!");
+      }
+    }
     super.create(entity);
   }
+
+
+  @Transactional
+  public void update(AmbariConfigurationEntity entity) {
+    if (entity.getId() == null || findByPK(entity.getId()) == null) {
+      String msg = String.format("The entity with id [ %s ] is not found", entity.getId());
+      LOGGER.debug(msg);
+      throw new EntityNotFoundException(msg);
+    }
+
+    // updating the existing entity
+    super.merge(entity);
+    entityManagerProvider.get().flush();
+  }
+
+  /**
+   * Returns the LDAP configuration from the database.
+   *
+   * @return the configuration entity
+   */
+  @Transactional
+  public AmbariConfigurationEntity getLdapConfiguration() {
+    LOGGER.info("Looking up the LDAP configuration ....");
+    AmbariConfigurationEntity ldapConfigEntity = null;
+
+    TypedQuery<AmbariConfigurationEntity> query = entityManagerProvider.get().createNamedQuery(
+      "AmbariConfigurationEntity.findByType", AmbariConfigurationEntity.class);
+    query.setParameter("typeName", "ldap-configuration");
+
+    ldapConfigEntity = daoUtils.selectSingle(query);
+    LOGGER.info("Returned entity: {} ", ldapConfigEntity);
+    return ldapConfigEntity;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/38c2785a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AmbariConfigurationEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AmbariConfigurationEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AmbariConfigurationEntity.java
index 34fa221..c9f4695 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AmbariConfigurationEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AmbariConfigurationEntity.java
@@ -29,8 +29,8 @@ import javax.persistence.Table;
 @Table(name = "ambari_configuration")
 @NamedQueries({
   @NamedQuery(
-    name = "AmbariConfigurationEntity.findAll",
-    query = "select ace from AmbariConfigurationEntity ace")
+    name = "AmbariConfigurationEntity.findByType",
+    query = "select ace from AmbariConfigurationEntity ace where ace.configurationBaseEntity.type = :typeName")
 })
 
 public class AmbariConfigurationEntity {

http://git-wip-us.apache.org/repos/asf/ambari/blob/38c2785a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
index 2b7448e..b5978a5 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConfigurationServiceTest.java
@@ -28,6 +28,7 @@ import org.apache.directory.api.ldap.model.message.SearchScope;
 import org.apache.directory.ldap.client.api.LdapConnection;
 import org.apache.directory.ldap.client.api.LdapConnectionConfig;
 import org.apache.directory.ldap.client.api.LdapNetworkConnection;
+import org.apache.directory.ldap.client.api.search.FilterBuilder;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -46,15 +47,18 @@ public class DefaultLdapConfigurationServiceTest {
 
     // WHEN
     LdapConnectionConfig config = new LdapConnectionConfig();
-    config.setLdapHost("localhost");
+    config.setLdapHost("172.22.112.167");
     config.setLdapPort(389);
     LdapConnection connection = new LdapNetworkConnection(config);
 
     // THEN
-    connection.anonymousBind();
+    connection.bind("CN=Robert Levas,CN=Users,DC=HWQE,DC=HORTONWORKS,DC=COM", "Hadoop1234");
 
+    String filter = FilterBuilder.and(
+      FilterBuilder.equal(SchemaConstants.OBJECT_CLASS_AT, "person"),
+      FilterBuilder.equal("name", "User1 Levas")).toString();
 
-    EntryCursor cursor = connection.search("dc=dev,dc=local", "(objectclass=*)", SearchScope.ONELEVEL);
+    EntryCursor cursor = connection.search("OU=levas,DC=hwqe,DC=hortonworks,DC=com", filter, SearchScope.SUBTREE);
 
     for (Entry entry : cursor) {
       assertNotNull(entry);


[16/46] ambari git commit: AMBARI-21307 Added new resource related changes to the db creation ddl-s

Posted by lp...@apache.org.
AMBARI-21307 Added new resource related changes to the db creation ddl-s


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: f55185c9c199ba3c90a1e094547611d312001456
Parents: b349538
Author: lpuskas <lp...@apache.org>
Authored: Thu Jul 6 18:15:18 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:41:56 2017 +0200

----------------------------------------------------------------------
 .../AmbariConfigurationResourceProvider.java    | 12 ++--
 .../server/orm/dao/AmbariConfigurationDAO.java  | 65 ++------------------
 .../apache/ambari/server/orm/dao/DaoUtils.java  | 13 +---
 .../main/resources/Ambari-DDL-Derby-CREATE.sql  | 21 +++++++
 .../main/resources/Ambari-DDL-MySQL-CREATE.sql  | 20 ++++++
 .../main/resources/Ambari-DDL-Oracle-CREATE.sql | 20 ++++++
 .../resources/Ambari-DDL-Postgres-CREATE.sql    | 14 ++---
 .../resources/Ambari-DDL-SQLAnywhere-CREATE.sql | 20 ++++++
 .../resources/Ambari-DDL-SQLServer-CREATE.sql   | 20 ++++++
 9 files changed, 120 insertions(+), 85 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/f55185c9/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProvider.java
index 5e5af9e..e8f186d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariConfigurationResourceProvider.java
@@ -97,14 +97,14 @@ public class AmbariConfigurationResourceProvider extends AbstractAuthorizedResou
     }
   }
 
-  private static Set<String> properties = Sets.newHashSet(
+  private static Set<String> PROPERTIES = Sets.newHashSet(
     ResourcePropertyId.ID.getPropertyId(),
     ResourcePropertyId.TYPE.getPropertyId(),
     ResourcePropertyId.VERSION.getPropertyId(),
     ResourcePropertyId.VERSION_TAG.getPropertyId(),
     ResourcePropertyId.DATA.getPropertyId());
 
-  private static Map<Resource.Type, String> pkPropertyMap = Collections.unmodifiableMap(
+  private static Map<Resource.Type, String> PK_PROPERTY_MAP = Collections.unmodifiableMap(
     new HashMap<Resource.Type, String>() {{
       put(Resource.Type.AmbariConfiguration, ResourcePropertyId.ID.getPropertyId());
     }}
@@ -117,7 +117,7 @@ public class AmbariConfigurationResourceProvider extends AbstractAuthorizedResou
   private Gson gson;
 
   protected AmbariConfigurationResourceProvider() {
-    super(properties, pkPropertyMap);
+    super(PROPERTIES, PK_PROPERTY_MAP);
     setRequiredCreateAuthorizations(EnumSet.of(RoleAuthorization.AMBARI_MANAGE_CONFIGURATION));
     setRequiredDeleteAuthorizations(EnumSet.of(RoleAuthorization.AMBARI_MANAGE_CONFIGURATION));
 
@@ -126,7 +126,7 @@ public class AmbariConfigurationResourceProvider extends AbstractAuthorizedResou
 
   @Override
   protected Set<String> getPKPropertyIds() {
-    return Sets.newHashSet("AmbariConfiguration/id");
+    return Sets.newHashSet(ResourcePropertyId.ID.getPropertyId());
   }
 
   @Override
@@ -137,7 +137,7 @@ public class AmbariConfigurationResourceProvider extends AbstractAuthorizedResou
     AmbariConfigurationEntity ambariConfigurationEntity = getEntityFromRequest(request);
 
     LOGGER.info("Persisting new ambari configuration: {} ", ambariConfigurationEntity);
-    ambariConfigurationDAO.persist(ambariConfigurationEntity);
+    ambariConfigurationDAO.create(ambariConfigurationEntity);
 
     return getRequestStatus(null);
   }
@@ -170,7 +170,7 @@ public class AmbariConfigurationResourceProvider extends AbstractAuthorizedResou
     } else {
       LOGGER.debug("Deleting amari configuration with id: {}", idFromRequest);
       try {
-        ambariConfigurationDAO.deleteById(idFromRequest);
+        ambariConfigurationDAO.removeByPK(idFromRequest);
       } catch (IllegalStateException e) {
         throw new NoSuchResourceException(e.getMessage());
       }

http://git-wip-us.apache.org/repos/asf/ambari/blob/f55185c9/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AmbariConfigurationDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AmbariConfigurationDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AmbariConfigurationDAO.java
index dea37eb..c29a423 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AmbariConfigurationDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AmbariConfigurationDAO.java
@@ -14,79 +14,24 @@
 
 package org.apache.ambari.server.orm.dao;
 
-import java.util.List;
-
 import javax.inject.Inject;
-import javax.inject.Provider;
 import javax.inject.Singleton;
-import javax.persistence.EntityManager;
-import javax.persistence.TypedQuery;
 
-import org.apache.ambari.server.orm.RequiresSession;
 import org.apache.ambari.server.orm.entities.AmbariConfigurationEntity;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.inject.persist.Transactional;
 
 /**
  * DAO dealing with ambari configuration related JPA operations.
  */
 
 @Singleton
-// todo extend CrudDao (amend crud dao to handle NPEs)
-public class AmbariConfigurationDAO {
-
-  private static final Logger LOGGER = LoggerFactory.getLogger(AmbariConfigurationDAO.class);
-
-  @Inject
-  private Provider<EntityManager> entityManagerProvider;
+public class AmbariConfigurationDAO extends CrudDAO<AmbariConfigurationEntity, Long> {
 
-  /**
-   * DAO utilities for dealing mostly with {@link TypedQuery} results.
-   */
   @Inject
-  private DaoUtils daoUtils;
-
-  public AmbariConfigurationEntity findByid(Long id) {
-    return entityManagerProvider.get().find(AmbariConfigurationEntity.class, id);
-  }
-
-  @RequiresSession
-  @Transactional
-  public void persist(AmbariConfigurationEntity entity) {
-    LOGGER.debug("Persisting ambari configuration: {}", entity);
-    entityManagerProvider.get().persist(entity);
+  public AmbariConfigurationDAO() {
+    super(AmbariConfigurationEntity.class);
   }
 
-  @RequiresSession
-  public List<AmbariConfigurationEntity> findAll() {
-    TypedQuery<AmbariConfigurationEntity> query = entityManagerProvider.get().createNamedQuery(
-      "AmbariConfigurationEntity.findAll", AmbariConfigurationEntity.class);
-    return daoUtils.selectList(query);
+  public void create(AmbariConfigurationEntity entity) {
+    super.create(entity);
   }
-
-
-  @RequiresSession
-  @Transactional
-  public void deleteById(Long ambariConfigurationId) {
-
-    if (ambariConfigurationId == null) {
-      throw new IllegalArgumentException("No Ambari Configuration id provided.");
-    }
-
-    LOGGER.debug("Removing Ambari Configuration with id :{}", ambariConfigurationId);
-
-    AmbariConfigurationEntity ambariConfigurationEntity = findByid(ambariConfigurationId);
-    if (ambariConfigurationEntity == null) {
-      String msg = String.format("No Ambari Configuration found with id: %s", ambariConfigurationId);
-      LOGGER.debug(msg);
-      throw new IllegalStateException(msg);
-    }
-
-    entityManagerProvider.get().remove(ambariConfigurationEntity);
-    LOGGER.debug("Ambari Configuration with id: {}", ambariConfigurationId);
-  }
-
-
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/f55185c9/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/DaoUtils.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/DaoUtils.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/DaoUtils.java
index cd3faf0..e6112ad 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/DaoUtils.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/DaoUtils.java
@@ -18,8 +18,6 @@
 
 package org.apache.ambari.server.orm.dao;
 
-import static org.apache.ambari.server.orm.DBAccessor.DbType;
-
 import java.util.Collections;
 import java.util.List;
 
@@ -31,19 +29,10 @@ import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Root;
 
-import org.apache.ambari.server.orm.DBAccessor;
-
-import com.google.inject.Inject;
 import com.google.inject.Singleton;
 
 @Singleton
 public class DaoUtils {
-  @Inject
-  private DBAccessor dbAccessor;
-
-  public DbType getDbType() {
-    return dbAccessor.getDbType();
-  }
 
   public <T> List<T> selectAll(EntityManager entityManager, Class<T> entityClass) {
     CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
@@ -92,7 +81,7 @@ public class DaoUtils {
 
   public void setParameters(Query query, Object... parameters) {
     for (int i = 0; i < parameters.length; i++) {
-      query.setParameter(i+1, parameters[i]);
+      query.setParameter(i + 1, parameters[i]);
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/f55185c9/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
index 614af1e..cebd33e 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
@@ -84,6 +84,23 @@ CREATE TABLE clusterconfig (
   CONSTRAINT UQ_config_type_tag UNIQUE (version_tag, type_name, cluster_id),
   CONSTRAINT UQ_config_type_version UNIQUE (cluster_id, type_name, version));
 
+CREATE TABLE configuration_base (
+  id BIGINT NOT NULL,
+  version_tag VARCHAR(255) NOT NULL,
+  version BIGINT NOT NULL,
+  type VARCHAR(255) NOT NULL,
+  data VARCHAR(3000) NOT NULL,
+  attributes VARCHAR(3000),
+  create_timestamp BIGINT NOT NULL,
+  CONSTRAINT PK_configuration_base PRIMARY KEY (id)
+);
+
+CREATE TABLE ambari_configuration (
+  id BIGINT NOT NULL,
+  CONSTRAINT PK_ambari_configuration PRIMARY KEY (id),
+  CONSTRAINT FK_ambari_configuration_configuration_base FOREIGN KEY (id) REFERENCES configuration_base (id)
+);
+
 CREATE TABLE serviceconfig (
   service_config_id BIGINT NOT NULL,
   cluster_id BIGINT NOT NULL,
@@ -1146,6 +1163,8 @@ INSERT INTO ambari_sequences (sequence_name, sequence_value)
   union all
   select 'servicecomponent_version_id_seq', 0 FROM SYSIBM.SYSDUMMY1
   union all
+  select 'configuration_id_seq', 0 FROM SYSIBM.SYSDUMMY1
+  union all
   select 'hostcomponentdesiredstate_id_seq', 0 FROM SYSIBM.SYSDUMMY1;
 
 
@@ -1246,6 +1265,7 @@ INSERT INTO roleauthorization(authorization_id, authorization_name)
   SELECT 'AMBARI.ADD_DELETE_CLUSTERS', 'Create new clusters' FROM SYSIBM.SYSDUMMY1 UNION ALL
   SELECT 'AMBARI.RENAME_CLUSTER', 'Rename clusters' FROM SYSIBM.SYSDUMMY1 UNION ALL
   SELECT 'AMBARI.MANAGE_SETTINGS', 'Manage settings' FROM SYSIBM.SYSDUMMY1 UNION ALL
+  SELECT 'AMBARI.MANAGE_CONFIGURATION', 'Manage ambari configurations' FROM SYSIBM.SYSDUMMY1 UNION ALL
   SELECT 'AMBARI.MANAGE_USERS', 'Manage users' FROM SYSIBM.SYSDUMMY1 UNION ALL
   SELECT 'AMBARI.MANAGE_GROUPS', 'Manage groups' FROM SYSIBM.SYSDUMMY1 UNION ALL
   SELECT 'AMBARI.MANAGE_VIEWS', 'Manage Ambari Views' FROM SYSIBM.SYSDUMMY1 UNION ALL
@@ -1447,6 +1467,7 @@ INSERT INTO permission_roleauthorization(permission_id, authorization_id)
   SELECT permission_id, 'AMBARI.ADD_DELETE_CLUSTERS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR'  UNION ALL
   SELECT permission_id, 'AMBARI.RENAME_CLUSTER' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR'  UNION ALL
   SELECT permission_id, 'AMBARI.MANAGE_SETTINGS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR'  UNION ALL
+  SELECT permission_id, 'AMBARI.MANAGE_CONFIGURATION' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR'  UNION ALL
   SELECT permission_id, 'AMBARI.MANAGE_USERS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR'  UNION ALL
   SELECT permission_id, 'AMBARI.MANAGE_GROUPS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR'  UNION ALL
   SELECT permission_id, 'AMBARI.MANAGE_VIEWS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR'  UNION ALL

http://git-wip-us.apache.org/repos/asf/ambari/blob/f55185c9/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
index 530411a..b8b506a 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -104,6 +104,23 @@ CREATE TABLE clusterconfig (
   CONSTRAINT UQ_config_type_tag UNIQUE (cluster_id, type_name, version_tag),
   CONSTRAINT UQ_config_type_version UNIQUE (cluster_id, type_name, version));
 
+CREATE TABLE configuration_base (
+  id BIGINT NOT NULL,
+  version_tag VARCHAR(100) NOT NULL,
+  version BIGINT NOT NULL,
+  type VARCHAR(100) NOT NULL,
+  data LONGTEXT NOT NULL,
+  attributes LONGTEXT,
+  create_timestamp BIGINT NOT NULL,
+  CONSTRAINT PK_configuration_base PRIMARY KEY (id)
+);
+
+CREATE TABLE ambari_configuration (
+  id BIGINT NOT NULL,
+  CONSTRAINT PK_ambari_configuration PRIMARY KEY (id),
+  CONSTRAINT FK_ambari_configuration_configuration_base FOREIGN KEY (id) REFERENCES configuration_base (id)
+);
+
 CREATE TABLE serviceconfig (
   service_config_id BIGINT NOT NULL,
   cluster_id BIGINT NOT NULL,
@@ -1110,6 +1127,7 @@ INSERT INTO ambari_sequences(sequence_name, sequence_value) VALUES
   ('remote_cluster_id_seq', 0),
   ('remote_cluster_service_id_seq', 0),
   ('servicecomponent_version_id_seq', 0),
+  ('configuration_id_seq', 0),
   ('hostcomponentdesiredstate_id_seq', 0);
 
 INSERT INTO adminresourcetype (resource_type_id, resource_type_name) VALUES
@@ -1194,6 +1212,7 @@ INSERT INTO roleauthorization(authorization_id, authorization_name)
   SELECT 'AMBARI.ADD_DELETE_CLUSTERS', 'Create new clusters' UNION ALL
   SELECT 'AMBARI.RENAME_CLUSTER', 'Rename clusters' UNION ALL
   SELECT 'AMBARI.MANAGE_SETTINGS', 'Manage administrative settings' UNION ALL
+  SELECT 'AMBARI.MANAGE_CONFIGURATION', 'Manage ambari configuration' UNION ALL
   SELECT 'AMBARI.MANAGE_USERS', 'Manage users' UNION ALL
   SELECT 'AMBARI.MANAGE_GROUPS', 'Manage groups' UNION ALL
   SELECT 'AMBARI.MANAGE_VIEWS', 'Manage Ambari Views' UNION ALL
@@ -1399,6 +1418,7 @@ INSERT INTO permission_roleauthorization(permission_id, authorization_id)
   SELECT permission_id, 'AMBARI.ADD_DELETE_CLUSTERS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
   SELECT permission_id, 'AMBARI.RENAME_CLUSTER' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
   SELECT permission_id, 'AMBARI.MANAGE_SETTINGS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
+  SELECT permission_id, 'AMBARI.MANAGE_CONFIGURATION' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
   SELECT permission_id, 'AMBARI.MANAGE_USERS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
   SELECT permission_id, 'AMBARI.MANAGE_GROUPS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
   SELECT permission_id, 'AMBARI.MANAGE_VIEWS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL

http://git-wip-us.apache.org/repos/asf/ambari/blob/f55185c9/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
index ebe5f12..1e90426 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -84,6 +84,23 @@ CREATE TABLE clusterconfig (
   CONSTRAINT UQ_config_type_tag UNIQUE (cluster_id, type_name, version_tag),
   CONSTRAINT UQ_config_type_version UNIQUE (cluster_id, type_name, version));
 
+CREATE TABLE configuration_base (
+  id NUMBER(19) NOT NULL,
+  version_tag VARCHAR(255) NOT NULL,
+  version NUMBER(19) NOT NULL,
+  type VARCHAR(255) NOT NULL,
+  data CLOB NOT NULL,
+  attributes CLOB,
+  create_timestamp NUMBER(19) NOT NULL,
+  CONSTRAINT PK_configuration_base PRIMARY KEY (id)
+);
+
+CREATE TABLE ambari_configuration (
+  id NUMBER(19) NOT NULL,
+  CONSTRAINT PK_ambari_configuration PRIMARY KEY (id),
+  CONSTRAINT FK_ambari_configuration_configuration_base FOREIGN KEY (id) REFERENCES configuration_base (id)
+);
+
 CREATE TABLE serviceconfig (
   service_config_id NUMBER(19) NOT NULL,
   cluster_id NUMBER(19) NOT NULL,
@@ -1089,6 +1106,7 @@ INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('ambari_oper
 INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('remote_cluster_id_seq', 0);
 INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('remote_cluster_service_id_seq', 0);
 INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('servicecomponent_version_id_seq', 0);
+INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('configuration_id_seq', 0);
 INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('hostcomponentdesiredstate_id_seq', 0);
 
 INSERT INTO metainfo("metainfo_key", "metainfo_value") values ('version', '${ambariSchemaVersion}');
@@ -1192,6 +1210,7 @@ INSERT INTO roleauthorization(authorization_id, authorization_name)
   SELECT 'AMBARI.ADD_DELETE_CLUSTERS', 'Create new clusters' FROM dual UNION ALL
   SELECT 'AMBARI.RENAME_CLUSTER', 'Rename clusters' FROM dual UNION ALL
   SELECT 'AMBARI.MANAGE_SETTINGS', 'Manage settings' FROM dual UNION ALL
+  SELECT 'AMBARI.MANAGE_CONFIGURATION', 'Manage ambari configuration' FROM dual UNION ALL
   SELECT 'AMBARI.MANAGE_USERS', 'Manage users' FROM dual UNION ALL
   SELECT 'AMBARI.MANAGE_GROUPS', 'Manage groups' FROM dual UNION ALL
   SELECT 'AMBARI.MANAGE_VIEWS', 'Manage Ambari Views' FROM dual UNION ALL
@@ -1397,6 +1416,7 @@ INSERT INTO permission_roleauthorization(permission_id, authorization_id)
   SELECT permission_id, 'AMBARI.ADD_DELETE_CLUSTERS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
   SELECT permission_id, 'AMBARI.RENAME_CLUSTER' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
   SELECT permission_id, 'AMBARI.MANAGE_SETTINGS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
+  SELECT permission_id, 'AMBARI.MANAGE_CONFIGURATION' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
   SELECT permission_id, 'AMBARI.MANAGE_USERS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
   SELECT permission_id, 'AMBARI.MANAGE_GROUPS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
   SELECT permission_id, 'AMBARI.MANAGE_VIEWS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL

http://git-wip-us.apache.org/repos/asf/ambari/blob/f55185c9/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
index 01b3324..583a51b 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -67,13 +67,13 @@ CREATE TABLE clusters (
 );
 
 CREATE TABLE configuration_base (
-  id               BIGINT       NOT NULL,
-  version_tag      VARCHAR(255) NOT NULL,
-  version          BIGINT       NOT NULL,
-  type             VARCHAR(255) NOT NULL,
-  data             TEXT         NOT NULL,
-  attributes       TEXT,
-  create_timestamp BIGINT       NOT NULL,
+  id BIGINT NOT NULL,
+  version_tag VARCHAR(255) NOT NULL,
+  version BIGINT NOT NULL,
+  type VARCHAR(255) NOT NULL,
+  data TEXT NOT NULL,
+  attributes TEXT,
+  create_timestamp BIGINT NOT NULL,
   CONSTRAINT PK_configuration_base PRIMARY KEY (id)
 );
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/f55185c9/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
index f64ff80..2104b2d 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
@@ -83,6 +83,23 @@ CREATE TABLE clusterconfig (
   CONSTRAINT UQ_config_type_tag UNIQUE (cluster_id, type_name, version_tag),
   CONSTRAINT UQ_config_type_version UNIQUE (cluster_id, type_name, version));
 
+CREATE TABLE configuration_base (
+  id NUMERIC(19) NOT NULL,
+  version_tag VARCHAR(255) NOT NULL,
+  version NUMERIC(19) NOT NULL,
+  type VARCHAR(255) NOT NULL,
+  data TEXT NOT NULL,
+  attributes TEXT,
+  create_timestamp NUMERIC(19) NOT NULL,
+  CONSTRAINT PK_configuration_base PRIMARY KEY (id)
+);
+
+CREATE TABLE ambari_configuration (
+  id NUMERIC(19) NOT NULL,
+  CONSTRAINT PK_ambari_configuration PRIMARY KEY (id),
+  CONSTRAINT FK_ambari_configuration_configuration_base FOREIGN KEY (id) REFERENCES configuration_base (id)
+);
+
 CREATE TABLE serviceconfig (
   service_config_id NUMERIC(19) NOT NULL,
   cluster_id NUMERIC(19) NOT NULL,
@@ -1088,6 +1105,7 @@ INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('remote_clus
 INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('remote_cluster_service_id_seq', 0);
 INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('servicecomponent_version_id_seq', 0);
 INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('hostcomponentdesiredstate_id_seq', 0);
+INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('configuration_id_seq', 0);
 
 insert into adminresourcetype (resource_type_id, resource_type_name)
   select 1, 'AMBARI'
@@ -1188,6 +1206,7 @@ insert into adminpermission(permission_id, permission_name, resource_type_id, pe
     SELECT 'AMBARI.ADD_DELETE_CLUSTERS', 'Create new clusters' UNION ALL
     SELECT 'AMBARI.RENAME_CLUSTER', 'Rename clusters' UNION ALL
     SELECT 'AMBARI.MANAGE_SETTINGS', 'Manage settings' UNION ALL
+    SELECT 'AMBARI.MANAGE_CONFIGURATION', 'Manage ambari configuration' UNION ALL
     SELECT 'AMBARI.MANAGE_USERS', 'Manage users' UNION ALL
     SELECT 'AMBARI.MANAGE_GROUPS', 'Manage groups' UNION ALL
     SELECT 'AMBARI.MANAGE_VIEWS', 'Manage Ambari Views' UNION ALL
@@ -1393,6 +1412,7 @@ insert into adminpermission(permission_id, permission_name, resource_type_id, pe
     SELECT permission_id, 'AMBARI.ADD_DELETE_CLUSTERS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
     SELECT permission_id, 'AMBARI.RENAME_CLUSTER' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
     SELECT permission_id, 'AMBARI.MANAGE_SETTINGS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
+    SELECT permission_id, 'AMBARI.MANAGE_CONFIGURATION' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
     SELECT permission_id, 'AMBARI.MANAGE_USERS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
     SELECT permission_id, 'AMBARI.MANAGE_GROUPS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
     SELECT permission_id, 'AMBARI.MANAGE_VIEWS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL

http://git-wip-us.apache.org/repos/asf/ambari/blob/f55185c9/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
index 7a3feaf..7d248b6 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
@@ -97,6 +97,23 @@ CREATE TABLE clusterconfig (
   CONSTRAINT UQ_config_type_tag UNIQUE (cluster_id, type_name, version_tag),
   CONSTRAINT UQ_config_type_version UNIQUE (cluster_id, type_name, version));
 
+CREATE TABLE configuration_base (
+  id BIGINT NOT NULL,
+  version_tag VARCHAR(255) NOT NULL,
+  version BIGINT NOT NULL,
+  type VARCHAR(255) NOT NULL,
+  data VARCHAR(MAX) NOT NULL,
+  attributes VARCHAR(MAX),
+  create_timestamp BIGINT NOT NULL,
+  CONSTRAINT PK_configuration_base PRIMARY KEY (id)
+);
+
+CREATE TABLE ambari_configuration (
+  id BIGINT NOT NULL,
+  CONSTRAINT PK_ambari_configuration PRIMARY KEY (id),
+  CONSTRAINT FK_ambari_configuration_configuration_base FOREIGN KEY (id) REFERENCES configuration_base (id)
+);
+
 CREATE TABLE serviceconfig (
   service_config_id BIGINT NOT NULL,
   cluster_id BIGINT NOT NULL,
@@ -1113,6 +1130,7 @@ BEGIN TRANSACTION
     ('remote_cluster_id_seq', 0),
     ('remote_cluster_service_id_seq', 0),
     ('servicecomponent_version_id_seq', 0),
+    ('configuration_id_seq', 0),
     ('hostcomponentdesiredstate_id_seq', 0);
 
   insert into adminresourcetype (resource_type_id, resource_type_name)
@@ -1201,6 +1219,7 @@ BEGIN TRANSACTION
     SELECT 'AMBARI.ADD_DELETE_CLUSTERS', 'Create new clusters' UNION ALL
     SELECT 'AMBARI.RENAME_CLUSTER', 'Rename clusters' UNION ALL
     SELECT 'AMBARI.MANAGE_SETTINGS', 'Manage settings' UNION ALL
+    SELECT 'AMBARI.MANAGE_CONFIGURATION', 'Manage ambari configuration' UNION ALL
     SELECT 'AMBARI.MANAGE_USERS', 'Manage users' UNION ALL
     SELECT 'AMBARI.MANAGE_GROUPS', 'Manage groups' UNION ALL
     SELECT 'AMBARI.MANAGE_VIEWS', 'Manage Ambari Views' UNION ALL
@@ -1406,6 +1425,7 @@ BEGIN TRANSACTION
     SELECT permission_id, 'AMBARI.ADD_DELETE_CLUSTERS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
     SELECT permission_id, 'AMBARI.RENAME_CLUSTER' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
     SELECT permission_id, 'AMBARI.MANAGE_SETTINGS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
+    SELECT permission_id, 'AMBARI.MANAGE_CONFIGURATION' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
     SELECT permission_id, 'AMBARI.MANAGE_USERS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
     SELECT permission_id, 'AMBARI.MANAGE_GROUPS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
     SELECT permission_id, 'AMBARI.MANAGE_VIEWS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL


[14/46] ambari git commit: AMBARI-22267 - Version registration failure during patch upgrade + Debian + Oracle run (jonathanhurley)

Posted by lp...@apache.org.
AMBARI-22267 - Version registration failure during patch upgrade + Debian + Oracle run (jonathanhurley)


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: b4eddc9770eda0e47fe025254ba6143a581a7855
Parents: 2ae81d9
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Wed Oct 18 19:27:34 2017 -0400
Committer: Jonathan Hurley <jh...@hortonworks.com>
Committed: Wed Oct 18 19:41:23 2017 -0400

----------------------------------------------------------------------
 .../ambari/server/orm/entities/RepositoryVersionEntity.java    | 5 +----
 .../ambari/server/orm/entities/ServiceDesiredStateEntity.java  | 6 +++---
 2 files changed, 4 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b4eddc97/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
index b4f59dc..7eedc4d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
@@ -21,13 +21,11 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Set;
 
-import javax.persistence.Basic;
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.EnumType;
 import javax.persistence.Enumerated;
-import javax.persistence.FetchType;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
@@ -92,7 +90,7 @@ import com.google.inject.Provider;
         query = "SELECT repositoryVersion FROM RepositoryVersionEntity repositoryVersion WHERE repositoryVersion.version = :version ORDER BY repositoryVersion.id DESC"),
     @NamedQuery(
         name = "findByServiceDesiredVersion",
-        query = "SELECT DISTINCT sd.desiredRepositoryVersion from ServiceDesiredStateEntity sd WHERE sd.desiredRepositoryVersion IN ?1") })
+        query = "SELECT repositoryVersion FROM RepositoryVersionEntity repositoryVersion WHERE repositoryVersion IN (SELECT DISTINCT sd1.desiredRepositoryVersion FROM ServiceDesiredStateEntity sd1 WHERE sd1.desiredRepositoryVersion IN ?1)") })
 @StaticallyInject
 public class RepositoryVersionEntity {
   private static final Logger LOG = LoggerFactory.getLogger(RepositoryVersionEntity.class);
@@ -129,7 +127,6 @@ public class RepositoryVersionEntity {
   @Enumerated(value = EnumType.STRING)
   private RepositoryType type = RepositoryType.STANDARD;
 
-  @Basic(fetch=FetchType.LAZY)
   @Lob
   @Column(name="version_xml", insertable = true, updatable = true)
   private String versionXml;

http://git-wip-us.apache.org/repos/asf/ambari/blob/b4eddc97/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java
index fc26478..dbb999e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java
@@ -39,20 +39,20 @@ import org.apache.commons.lang.builder.EqualsBuilder;
 @Entity
 public class ServiceDesiredStateEntity {
 
-  @Column(name = "cluster_id", nullable = false, insertable = false, updatable = false, length = 10)
   @Id
+  @Column(name = "cluster_id", nullable = false, insertable = false, updatable = false, length = 10)  
   private Long clusterId;
 
-  @Column(name = "service_name", nullable = false, insertable = false, updatable = false)
   @Id
+  @Column(name = "service_name", nullable = false, insertable = false, updatable = false)
   private String serviceName;
 
   @Column(name = "desired_state", nullable = false, insertable = true, updatable = true)
   @Enumerated(value = EnumType.STRING)
   private State desiredState = State.INIT;
 
-  @Column(name = "desired_host_role_mapping", nullable = false, insertable = true, updatable = true, length = 10)
   @Basic
+  @Column(name = "desired_host_role_mapping", nullable = false, insertable = true, updatable = true, length = 10)  
   private int desiredHostRoleMapping = 0;
 
   @Column(name = "maintenance_state", nullable = false, insertable = true, updatable = true)


[44/46] ambari git commit: AMBARI-21307 Added unit test, minor fixes

Posted by lp...@apache.org.
AMBARI-21307 Added unit test, minor fixes


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 3f64c096256951bfe4f124161b8b9eb4baf8af86
Parents: e3676a7
Author: lpuskas <lp...@apache.org>
Authored: Wed Oct 18 15:07:28 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:42:03 2017 +0200

----------------------------------------------------------------------
 .../DefaultLdapAttributeDetectionService.java   |   2 +-
 .../ads/detectors/AttributeDetectorFactory.java |  21 +--
 ...efaultLdapAttributeDetectionServiceTest.java | 188 +++++++++++++++++++
 3 files changed, 198 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/3f64c096/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
index 25abce7..a9a9b53 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionService.java
@@ -118,7 +118,7 @@ public class DefaultLdapAttributeDetectionService implements LdapAttributeDetect
     try {
 
       LdapConnectionTemplate ldapConnectionTemplate = ldapConnectionTemplateFactory.create(ambariLdapConfiguration);
-      AttributeDetector<Entry> groupAttributeDetector = attributeDetectorFactory.groupAttributDetector();
+      AttributeDetector<Entry> groupAttributeDetector = attributeDetectorFactory.groupAttributeDetector();
 
       SearchRequest searchRequest = assembleGroupSearchRequest(ldapConnectionTemplate, ambariLdapConfiguration);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/3f64c096/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/AttributeDetectorFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/AttributeDetectorFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/AttributeDetectorFactory.java
index 8155461..eba0bd9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/AttributeDetectorFactory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/detectors/AttributeDetectorFactory.java
@@ -33,21 +33,18 @@ public class AttributeDetectorFactory {
   private static final Logger LOG = LoggerFactory.getLogger(AttributeDetectorFactory.class);
   private static final String USER_ATTRIBUTES_DETECTORS = "UserAttributesDetectors";
   private static final String GROUP_ATTRIBUTES_DETECTORS = "GroupAttributesDetectors";
-
-
-  /**
-   * The set of user attribute detectors, configured by GUICE (check the relevant guice module implementation)
-   */
-  @Inject
-  @Named(USER_ATTRIBUTES_DETECTORS)
-  private Set<AttributeDetector> userAttributeDetectors;
-
   /**
    * The set of group attribute detectors, configured by GUICE (check the relevant guice module implementation)
    */
   @Inject
   @Named(GROUP_ATTRIBUTES_DETECTORS)
   Set<AttributeDetector> groupAttributeDetectors;
+  /**
+   * The set of user attribute detectors, configured by GUICE (check the relevant guice module implementation)
+   */
+  @Inject
+  @Named(USER_ATTRIBUTES_DETECTORS)
+  private Set<AttributeDetector> userAttributeDetectors;
 
   @Inject
   public AttributeDetectorFactory() {
@@ -59,7 +56,7 @@ public class AttributeDetectorFactory {
    * @return the constructed ChainedAttributeDetector instance
    */
   public ChainedAttributeDetector userAttributDetector() {
-    LOG.info("Creating instance with user attribute detectors: [{}]", userAttributDetector());
+    LOG.info("Creating instance with user attribute detectors: [{}]", userAttributeDetectors);
     return new ChainedAttributeDetector(userAttributeDetectors);
   }
 
@@ -69,8 +66,8 @@ public class AttributeDetectorFactory {
    * @return the constructed ChainedAttributeDetector instance
    */
 
-  public ChainedAttributeDetector groupAttributDetector() {
-    LOG.info("Creating instance with group attribute detectors: [{}]", groupAttributDetector());
+  public ChainedAttributeDetector groupAttributeDetector() {
+    LOG.info("Creating instance with group attribute detectors: [{}]", groupAttributeDetectors);
     return new ChainedAttributeDetector(groupAttributeDetectors);
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/3f64c096/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java
new file mode 100644
index 0000000..09dea1c
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapAttributeDetectionServiceTest.java
@@ -0,0 +1,188 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ads;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfigKeys;
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.domain.AmbariLdapConfigurationFactory;
+import org.apache.ambari.server.ldap.domain.TestAmbariLdapConfigurationFactory;
+import org.apache.ambari.server.ldap.service.AmbariLdapException;
+import org.apache.ambari.server.ldap.service.ads.detectors.AttributeDetectorFactory;
+import org.apache.ambari.server.ldap.service.ads.detectors.ChainedAttributeDetector;
+import org.apache.ambari.server.ldap.service.ads.detectors.GroupMemberAttrDetector;
+import org.apache.ambari.server.ldap.service.ads.detectors.UserNameAttrDetector;
+import org.apache.directory.api.ldap.model.entry.DefaultEntry;
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.message.SearchRequest;
+import org.apache.directory.api.ldap.model.message.SearchScope;
+import org.apache.directory.ldap.client.template.EntryMapper;
+import org.apache.directory.ldap.client.template.LdapConnectionTemplate;
+import org.easymock.EasyMock;
+import org.easymock.EasyMockRule;
+import org.easymock.EasyMockSupport;
+import org.easymock.Mock;
+import org.easymock.TestSubject;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+
+public class DefaultLdapAttributeDetectionServiceTest extends EasyMockSupport {
+  @Rule
+  public EasyMockRule mocks = new EasyMockRule(this);
+
+  @Mock
+  private AttributeDetectorFactory attributeDetectorFactoryMock;
+
+  @Mock
+  private LdapConnectionTemplateFactory ldapConnectionTemplateFactoryMock;
+
+  @Mock
+  private LdapConnectionTemplate ldapConnectionTemplateMock;
+
+  @Mock
+  private SearchRequest searchRequestMock;
+
+
+  private AmbariLdapConfigurationFactory ldapConfigurationFactory = new TestAmbariLdapConfigurationFactory();
+
+  @TestSubject
+  private DefaultLdapAttributeDetectionService defaultLdapAttributeDetectionService = new DefaultLdapAttributeDetectionService();
+
+  @Before
+  public void before() {
+    resetAll();
+  }
+
+  @Test
+  @SuppressWarnings("unchecked")
+  public void shouldLdapUserAttributeDetection() throws Exception {
+    // GIVEN
+    Map<String, Object> configMap = Maps.newHashMap();
+    configMap.put(AmbariLdapConfigKeys.USER_SEARCH_BASE.key(), "dc=example,dc=com");
+    AmbariLdapConfiguration ldapConfiguration = ldapConfigurationFactory.createLdapConfiguration(configMap);
+
+    List<Object> entryList = Lists.newArrayList(new DefaultEntry("uid=gauss"));
+
+    EasyMock.expect(ldapConnectionTemplateFactoryMock.create(ldapConfiguration)).andReturn(ldapConnectionTemplateMock);
+
+    EasyMock.expect(ldapConnectionTemplateMock.search(EasyMock.anyObject(SearchRequest.class), EasyMock.anyObject(entryMapperMock().getClass())))
+      .andReturn(entryList);
+
+    EasyMock.expect(ldapConnectionTemplateMock.newSearchRequest(EasyMock.anyString(), EasyMock.anyString(),
+      EasyMock.anyObject(SearchScope.class))).andReturn(searchRequestMock);
+
+    EasyMock.expect(attributeDetectorFactoryMock.userAttributDetector())
+      .andReturn(new ChainedAttributeDetector(Sets.newHashSet(new UserNameAttrDetector())));
+
+    EasyMock.expect(searchRequestMock.setSizeLimit(50)).andReturn(searchRequestMock);
+
+    // WHEN
+    replayAll();
+    AmbariLdapConfiguration decorated = defaultLdapAttributeDetectionService.detectLdapUserAttributes(ldapConfiguration);
+
+    // THEN
+    Assert.assertNotNull(decorated);
+    Assert.assertEquals("N/A", ldapConfiguration.userNameAttribute());
+  }
+
+  @Test(expected = AmbariLdapException.class)
+  public void testShouldUserAttributeDetectionFailWhenLdapOerationFails() throws Exception {
+    // GIVEN
+    Map<String, Object> configMap = Maps.newHashMap();
+    configMap.put(AmbariLdapConfigKeys.USER_SEARCH_BASE.key(), "dc=example,dc=com");
+    AmbariLdapConfiguration ldapConfiguration = ldapConfigurationFactory.createLdapConfiguration(configMap);
+
+    EasyMock.expect(ldapConnectionTemplateFactoryMock.create(ldapConfiguration)).andThrow(new AmbariLdapException("Testing ..."));
+
+    // WHEN
+    replayAll();
+    AmbariLdapConfiguration decorated = defaultLdapAttributeDetectionService.detectLdapUserAttributes(ldapConfiguration);
+
+    // THEN
+    // exception is thrown
+
+  }
+
+
+  @Test
+  @SuppressWarnings("unchecked")
+  public void shouldLdapGroupAttributeDetection() throws Exception {
+    // GIVEN
+    Map<String, Object> configMap = Maps.newHashMap();
+    configMap.put(AmbariLdapConfigKeys.GROUP_SEARCH_BASE.key(), "dc=example,dc=com");
+    AmbariLdapConfiguration ldapConfiguration = ldapConfigurationFactory.createLdapConfiguration(configMap);
+
+    List<Object> entryList = Lists.newArrayList(new DefaultEntry("uid=gauss"));
+
+    EasyMock.expect(ldapConnectionTemplateFactoryMock.create(ldapConfiguration)).andReturn(ldapConnectionTemplateMock);
+
+    EasyMock.expect(ldapConnectionTemplateMock.search(EasyMock.anyObject(SearchRequest.class), EasyMock.anyObject(entryMapperMock().getClass())))
+      .andReturn(entryList);
+
+    EasyMock.expect(ldapConnectionTemplateMock.newSearchRequest(EasyMock.anyString(), EasyMock.anyString(),
+      EasyMock.anyObject(SearchScope.class))).andReturn(searchRequestMock);
+
+    EasyMock.expect(attributeDetectorFactoryMock.groupAttributeDetector())
+      .andReturn(new ChainedAttributeDetector(Sets.newHashSet(new GroupMemberAttrDetector())));
+
+    EasyMock.expect(searchRequestMock.setSizeLimit(50)).andReturn(searchRequestMock);
+
+    // WHEN
+    replayAll();
+    AmbariLdapConfiguration decorated = defaultLdapAttributeDetectionService.detectLdapGroupAttributes(ldapConfiguration);
+
+    // THEN
+    Assert.assertNotNull(decorated);
+    Assert.assertEquals("N/A", ldapConfiguration.groupMemberAttribute());
+  }
+
+  @Test(expected = AmbariLdapException.class)
+  public void testShouldGroupAttributeDetectionFailWhenLdapOerationFails() throws Exception {
+    // GIVEN
+    Map<String, Object> configMap = Maps.newHashMap();
+    configMap.put(AmbariLdapConfigKeys.GROUP_SEARCH_BASE.key(), "dc=example,dc=com");
+    AmbariLdapConfiguration ldapConfiguration = ldapConfigurationFactory.createLdapConfiguration(configMap);
+
+    EasyMock.expect(ldapConnectionTemplateFactoryMock.create(ldapConfiguration)).andThrow(new AmbariLdapException("Testing ..."));
+
+    // WHEN
+    replayAll();
+    AmbariLdapConfiguration decorated = defaultLdapAttributeDetectionService.detectLdapGroupAttributes(ldapConfiguration);
+
+    // THEN
+    // exception is thrown
+
+  }
+
+
+  private EntryMapper<Entry> entryMapperMock() {
+    return new EntryMapper<Entry>() {
+      @Override
+      public Entry map(Entry entry) throws LdapException {
+        return null;
+      }
+    };
+  }
+
+}
\ No newline at end of file


[21/46] ambari git commit: AMBARI-21307 Draft implementation of the group related attributes

Posted by lp...@apache.org.
AMBARI-21307 Draft implementation of the group related attributes


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: a65608b80166dad543744fea922a62cc571c2a9f
Parents: 5f2fbc1
Author: lpuskas <lp...@apache.org>
Authored: Tue Aug 8 13:54:29 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:41:57 2017 +0200

----------------------------------------------------------------------
 .../server/ldap/AmbariLdapConfiguration.java    |  22 +-
 .../ldap/LdapConfigurationValidatorService.java |  34 +--
 .../apache/ambari/server/ldap/LdapModule.java   |   4 +-
 .../server/ldap/service/AmbariLdapFacade.java   |  25 +-
 .../ldap/service/LdapConnectionService.java     |  35 +++
 .../ambari/server/ldap/service/LdapFacade.java  |   9 +-
 .../ad/AdLdapConfigurationValidatorService.java | 177 --------------
 ...efaultLdapConfigurationValidatorService.java | 232 +++++++++++++++++++
 .../ad/DefaultLdapConnectionService.java        |  63 +++++
 .../service/ad/LdapConfigurationConverter.java  |  50 ----
 ...AdLdapConfigurationValidatorServiceTest.java | 129 -----------
 ...ltLdapConfigurationValidatorServiceTest.java | 156 +++++++++++++
 12 files changed, 552 insertions(+), 384 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/a65608b8/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
index 519f400..a6ff80b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/AmbariLdapConfiguration.java
@@ -53,7 +53,7 @@ public class AmbariLdapConfiguration {
     GROUP_OBJECT_CLASS("ambari.ldap.group.object.class"),
     GROUP_NAME_ATTRIBUTE("ambari.ldap.group.name.attribute"),
     GROUP_MEMBER_ATTRIBUTE("ambari.ldap.group.member.attribute"),
-    GROUP_SEARCH_BASE("ambari.ldap.group.member.attribute"),
+    GROUP_SEARCH_BASE("ambari.ldap.group.search.base"),
     DN_ATTRIBUTE("authentication.ldap.dnAttribute");
 
     private String propertyName;
@@ -126,4 +126,24 @@ public class AmbariLdapConfiguration {
     return (String) configurationValue(LdapConfigProperty.USER_NAME_ATTRIBUTE);
   }
 
+  public String userSearchBase() {
+    return (String) configurationValue(LdapConfigProperty.USER_SEARCH_BASE);
+  }
+
+  public String groupObjectClass() {
+    return (String) configurationValue(LdapConfigProperty.GROUP_OBJECT_CLASS);
+  }
+
+  public String groupNameAttribute() {
+    return (String) configurationValue(LdapConfigProperty.GROUP_NAME_ATTRIBUTE);
+  }
+
+  public String groupMemberAttribute() {
+    return (String) configurationValue(LdapConfigProperty.GROUP_MEMBER_ATTRIBUTE);
+  }
+
+  public String groupSearchBase() {
+    return (String) configurationValue(LdapConfigProperty.GROUP_SEARCH_BASE);
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/a65608b8/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationValidatorService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationValidatorService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationValidatorService.java
index 4667721..7efa3b7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationValidatorService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapConfigurationValidatorService.java
@@ -14,8 +14,11 @@
 
 package org.apache.ambari.server.ldap;
 
+import java.util.Set;
+
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ldap.service.AmbariLdapException;
+import org.apache.directory.ldap.client.api.LdapConnection;
 
 /**
  * Collection of operations for validating ldap configuration.
@@ -26,27 +29,32 @@ public interface LdapConfigurationValidatorService {
   /**
    * Tests the connection based on the provided configuration.
    *
-   * @param configuration the ambari ldap configuration instance
+   * @param ldapConnection connection instance
+   * @param configuration  the ambari ldap configuration instance
    * @throws AmbariLdapException if the connection is not possible
    */
-  void checkConnection(AmbariLdapConfiguration configuration) throws AmbariLdapException;
+  void checkConnection(LdapConnection ldapConnection, AmbariLdapConfiguration configuration) throws AmbariLdapException;
+
 
   /**
-   * Checks whether the group related LDAP attributes in the configuration are correct.
+   * Implements LDAP user related configuration settings validation logic.
+   * Implementers communicate with the LDAP server (search, bind) to validate attributes in the provided configuration
+   * instance
    *
-   * @param configuration the configuration instance holding the available properties
-   * @throws AmbariException if the attributes are not valid
+   * @param ldapConnection connection instance used to connect to the LDAP server
+   * @param testUserName   the test username
+   * @param testPassword   the test password
+   * @param configuration  the available ldap configuration
+   * @return The DN of the found user entry
+   * @throws AmbariException if the connection couldn't be estabilisheds
    */
-  void checkGroupAttributes(AmbariLdapConfiguration configuration) throws AmbariException;
+  String checkUserAttributes(LdapConnection ldapConnection, String testUserName, String testPassword, AmbariLdapConfiguration configuration) throws AmbariLdapException;
 
   /**
-   * Tries to connect to the LDAP server with the given credentials.
-   * Primarily used for testing the user before performing other operations (eg. attribute detection)s
+   * Checks whether the group related LDAP attributes in the configuration are correct.
    *
-   * @param username      the username
-   * @param password      the password
-   * @param configuration the available ldap configuration
-   * @throws AmbariException if the connection couldn't be estabilished
+   * @throws AmbariException if the attributes are not valid
    */
-  void checkUserAttributes(String username, String password, AmbariLdapConfiguration configuration) throws AmbariException;
+  Set<String> checkGroupAttributes(LdapConnection ldapConnection, String userDn, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException;
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/a65608b8/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
index 625ce8b..545f220 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/LdapModule.java
@@ -17,7 +17,7 @@ package org.apache.ambari.server.ldap;
 
 import org.apache.ambari.server.ldap.service.AmbariLdapFacade;
 import org.apache.ambari.server.ldap.service.LdapFacade;
-import org.apache.ambari.server.ldap.service.ad.AdLdapConfigurationValidatorService;
+import org.apache.ambari.server.ldap.service.ad.DefaultLdapConfigurationValidatorService;
 
 import com.google.inject.AbstractModule;
 import com.google.inject.assistedinject.FactoryModuleBuilder;
@@ -30,7 +30,7 @@ public class LdapModule extends AbstractModule {
   @Override
   protected void configure() {
     bind(LdapFacade.class).to(AmbariLdapFacade.class);
-    bind(LdapConfigurationValidatorService.class).to(AdLdapConfigurationValidatorService.class);
+    bind(LdapConfigurationValidatorService.class).to(DefaultLdapConfigurationValidatorService.class);
 
     install(new FactoryModuleBuilder().build(LdapConfigurationFactory.class));
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/a65608b8/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
index abd028a..abb464b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapFacade.java
@@ -16,13 +16,14 @@
 package org.apache.ambari.server.ldap.service;
 
 import java.util.Map;
+import java.util.Set;
 
 import javax.inject.Inject;
 import javax.inject.Singleton;
 
-import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
 import org.apache.ambari.server.ldap.LdapConfigurationValidatorService;
+import org.apache.directory.ldap.client.api.LdapConnection;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -51,17 +52,21 @@ public class AmbariLdapFacade implements LdapFacade {
   private LdapConfigurationValidatorService ldapConfigurationValidatorService;
 
   @Inject
+  private LdapConnectionService ldapConnectionService;
+
+  @Inject
   public AmbariLdapFacade() {
   }
 
   @Override
-  public void checkConnection(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariException {
+  public void checkConnection(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
     try {
       LOGGER.info("Validating LDAP connection related configuration based on: {}", ambariLdapConfiguration);
-      ldapConfigurationValidatorService.checkConnection(ambariLdapConfiguration);
+      LdapConnection connection = ldapConnectionService.createLdapConnection(ambariLdapConfiguration);
+      ldapConfigurationValidatorService.checkConnection(connection, ambariLdapConfiguration);
     } catch (AmbariLdapException e) {
       LOGGER.error("Validating LDAP connection configuration failed", e);
-      throw new AmbariException("Validating LDAP connection configuration failed", e);
+      throw e;
     }
     LOGGER.info("Validating LDAP connection related configuration: SUCCESS");
   }
@@ -74,7 +79,7 @@ public class AmbariLdapFacade implements LdapFacade {
   }
 
   @Override
-  public void checkLdapAttibutes(Map<String, Object> parameters, AmbariLdapConfiguration ldapConfiguration) throws AmbariException {
+  public void checkLdapAttibutes(Map<String, Object> parameters, AmbariLdapConfiguration ldapConfiguration) throws AmbariLdapException {
     String userName = getTestUserNameFromParameters(parameters);
     String testUserPass = getTestUserPasswordFromParameters(parameters);
 
@@ -82,8 +87,14 @@ public class AmbariLdapFacade implements LdapFacade {
       throw new IllegalArgumentException("No test user available for testing LDAP attributes");
     }
 
-    LOGGER.info("Testing LDAP attributes with test user: {}", userName);
-    ldapConfigurationValidatorService.checkUserAttributes(userName, testUserPass, ldapConfiguration);
+    LdapConnection ldapConnection = ldapConnectionService.createLdapConnection(ldapConfiguration);
+
+    LOGGER.info("Testing LDAP user attributes with test user: {}", userName);
+    String userDn = ldapConfigurationValidatorService.checkUserAttributes(ldapConnection, userName, testUserPass, ldapConfiguration);
+
+    LOGGER.info("Testing LDAP group attributes with test user dn: {}", userDn);
+    Set<String> groups = ldapConfigurationValidatorService.checkGroupAttributes(ldapConnection, userDn, ldapConfiguration);
+
   }
 
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a65608b8/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionService.java
new file mode 100644
index 0000000..50ee8ed
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapConnectionService.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service;
+
+import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.directory.ldap.client.api.LdapNetworkConnection;
+
+/**
+ * Contract defining factory methods for creating LDAP connection instances.
+ * Implementers contain the logic of creating different connection instances and the afferent boilerplate code.
+ */
+public interface LdapConnectionService {
+
+  /**
+   * Creates an LdapConnection instance based on the provided configuration
+   *
+   * @param ambariLdapConfiguration configuration instance with information for creating the connection instance
+   * @return a set up LdapConnection instance
+   */
+  LdapNetworkConnection createLdapConnection(AmbariLdapConfiguration ambariLdapConfiguration);
+
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/a65608b8/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
index 38553f0..7bb1198 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/LdapFacade.java
@@ -16,7 +16,6 @@ package org.apache.ambari.server.ldap.service;
 
 import java.util.Map;
 
-import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
 
 /**
@@ -29,9 +28,9 @@ public interface LdapFacade {
    * Tests the connection to the LDAP server based on the provided configuration.
    *
    * @param ambariLdapConfiguration the available ldap related configuration
-   * @throws AmbariException if the connection fails or other problems occur during the operation
+   * @throws AmbariLdapException if the connection fails or other problems occur during the operation
    */
-  void checkConnection(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariException;
+  void checkConnection(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException;
 
 
   /**
@@ -46,7 +45,7 @@ public interface LdapFacade {
    *
    * @param parameters              a map of property name and value pairs holding information to facilitate checking the attributes
    * @param ambariLdapConfiguration configutration instance with available attributes
-   * @throws AmbariException if the attribute checking fails
+   * @throws AmbariLdapException if the attribute checking fails
    */
-  void checkLdapAttibutes(Map<String, Object> parameters, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariException;
+  void checkLdapAttibutes(Map<String, Object> parameters, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException;
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/a65608b8/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/AdLdapConfigurationValidatorService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/AdLdapConfigurationValidatorService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/AdLdapConfigurationValidatorService.java
deleted file mode 100644
index 11e8655..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/AdLdapConfigurationValidatorService.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.service.ad;
-
-import java.io.IOException;
-import java.util.List;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.LdapConfigurationValidatorService;
-import org.apache.ambari.server.ldap.service.AmbariLdapException;
-import org.apache.directory.api.ldap.model.cursor.EntryCursor;
-import org.apache.directory.api.ldap.model.cursor.SearchCursor;
-import org.apache.directory.api.ldap.model.entry.Entry;
-import org.apache.directory.api.ldap.model.message.SearchScope;
-import org.apache.directory.api.ldap.model.name.Dn;
-import org.apache.directory.ldap.client.api.LdapConnectionConfig;
-import org.apache.directory.ldap.client.api.LdapNetworkConnection;
-import org.apache.directory.ldap.client.api.search.FilterBuilder;
-import org.apache.directory.shared.ldap.constants.SchemaConstants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.Lists;
-
-/**
- * Implementation of the validation logic using the Apache Directory API.
- */
-@Singleton
-public class AdLdapConfigurationValidatorService implements LdapConfigurationValidatorService {
-
-  private static final Logger LOGGER = LoggerFactory.getLogger(AdLdapConfigurationValidatorService.class);
-
-  @Inject
-  private LdapConfigurationConverter ldapConfigurationConverter;
-
-  /**
-   * Facilitating the instantiation
-   */
-  @Inject
-  public AdLdapConfigurationValidatorService() {
-  }
-
-  @Override
-  public void checkConnection(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
-    try {
-      LOGGER.info("Testing the connection based on the configuration: {}", ambariLdapConfiguration);
-
-      LdapConnectionConfig connectionConfig = ldapConfigurationConverter.getLdapConnectionConfig(ambariLdapConfiguration);
-      LdapNetworkConnection connection = new LdapNetworkConnection(connectionConfig);
-
-      if (ambariLdapConfiguration.bindAnonimously()) {
-        LOGGER.debug("Binding anonimously ...");
-        connection.bind();
-      } else {
-        LOGGER.debug("Binding with manager DN and manager password ...");
-        connection.bind(ambariLdapConfiguration.managerDn(), ambariLdapConfiguration.managerPassword());
-      }
-
-      if (connection.isConnected()) {
-        LOGGER.info("Successfully connected to the LDAP server.");
-      }
-
-      connection.close();
-
-    } catch (Exception e) {
-      LOGGER.warn("Could not bind to the LDAP server base don the provided configuration ...");
-      throw new AmbariLdapException(e);
-    }
-  }
-
-
-  /**
-   * Checks the user attributes provided in the configuration instance by issuing a search for a (known) test user in the LDAP.
-   * Attributes are considered correct if there is at least one entry found.
-   *
-   * Invalid attributes are signaled by throwing an exception.
-   *
-   * @param username                the username
-   * @param password                the password
-   * @param ambariLdapConfiguration configuration instance holding ldap configuration details
-   * @throws AmbariException if the attributes are not valid or any errors occurs
-   */
-  @Override
-  public void checkUserAttributes(String username, String password, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariException {
-    LdapNetworkConnection connection = null;
-    SearchCursor searchCursor = null;
-    try {
-      LOGGER.info("Checking user attributes for user {} r ...", username);
-
-      LdapConnectionConfig connectionConfig = ldapConfigurationConverter.getLdapConnectionConfig(ambariLdapConfiguration);
-      connection = new LdapNetworkConnection(connectionConfig);
-
-
-      if (!ambariLdapConfiguration.bindAnonimously()) {
-        LOGGER.debug("Anonimous binding not supported, binding with the manager detailas...");
-        connection.bind(ambariLdapConfiguration.managerDn(), ambariLdapConfiguration.managerPassword());
-      } else {
-        LOGGER.debug("Binding anonimously ...");
-        connection.bind();
-      }
-
-      if (!connection.isConnected()) {
-        LOGGER.error("Not connected to the LDAP server. Connection instance: {}", connection);
-        throw new IllegalStateException("The connection to the LDAP server is not alive");
-      }
-
-      // set up a filter based on the provided attributes
-      String filter = FilterBuilder.and(
-        FilterBuilder.equal(SchemaConstants.OBJECT_CLASS_AT, ambariLdapConfiguration.userObjectClass()),
-        FilterBuilder.equal(ambariLdapConfiguration.userNameAttribute(), username))
-        .toString();
-
-      LOGGER.info("Searching for the user: {} using the search filter: {}", username, filter);
-      EntryCursor entryCursor = connection.search(new Dn(ambariLdapConfiguration.baseDn()), filter, SearchScope.SUBTREE);
-
-      // collecting search result entries
-      List<Entry> users = Lists.newArrayList();
-      for (Entry entry : entryCursor) {
-        users.add(entry);
-      }
-
-      // there should be at least one user found
-      if (users.isEmpty()) {
-        String msg = String.format("There are no users found using the filter: [ %s ]. Try changing the attribute values", filter);
-        LOGGER.error(msg);
-        throw new Exception(msg);
-      }
-
-      LOGGER.info("Attibute validation succeeded. Filter: {}", filter);
-
-    } catch (Exception e) {
-
-      LOGGER.error("Error while checking user attributes.");
-      throw new AmbariException("Error while checking user attributes", e);
-
-    } finally {
-
-      LOGGER.debug("Closing the connection and searchresult ...");
-
-      if (null != searchCursor) {
-        searchCursor.close();
-      }
-
-      if (null != connection) {
-        try {
-          connection.close();
-        } catch (IOException e) {
-          LOGGER.error("Exception occurred while closing the connection", e);
-        }
-      }
-
-    }
-  }
-
-  @Override
-  public void checkGroupAttributes(AmbariLdapConfiguration configuration) throws AmbariException {
-
-  }
-
-
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/a65608b8/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorService.java
new file mode 100644
index 0000000..838ef4c
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorService.java
@@ -0,0 +1,232 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ad;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Set;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.LdapConfigurationValidatorService;
+import org.apache.ambari.server.ldap.service.AmbariLdapException;
+import org.apache.ambari.server.ldap.service.LdapConnectionService;
+import org.apache.directory.api.ldap.codec.decorators.SearchResultEntryDecorator;
+import org.apache.directory.api.ldap.model.cursor.EntryCursor;
+import org.apache.directory.api.ldap.model.cursor.SearchCursor;
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.message.Response;
+import org.apache.directory.api.ldap.model.message.SearchRequest;
+import org.apache.directory.api.ldap.model.message.SearchRequestImpl;
+import org.apache.directory.api.ldap.model.message.SearchScope;
+import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.LdapNetworkConnection;
+import org.apache.directory.ldap.client.api.search.FilterBuilder;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+
+/**
+ * Implementation of the validation logic using the Apache Directory API.
+ */
+@Singleton
+public class DefaultLdapConfigurationValidatorService implements LdapConfigurationValidatorService {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapConfigurationValidatorService.class);
+
+  @Inject
+  private LdapConnectionService ldapConnectionService;
+
+  /**
+   * Facilitating the instantiation
+   */
+  @Inject
+  public DefaultLdapConfigurationValidatorService() {
+  }
+
+  @Override
+  public void checkConnection(LdapConnection ldapConnection, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+    try {
+      bind(ambariLdapConfiguration, ldapConnection);
+    } catch (LdapException e) {
+      LOGGER.error("Could not connect to the LDAP server", e);
+      throw new AmbariLdapException(e);
+    }
+  }
+
+
+  /**
+   * Checks the user attributes provided in the configuration instance by issuing a search for a (known) test user in the LDAP.
+   * Attributes are considered correct if there is at least one entry found.
+   *
+   * Invalid attributes are signaled by throwing an exception.
+   *
+   * @param testUserName            the test username
+   * @param testPassword            the test password
+   * @param ambariLdapConfiguration configuration instance holding ldap configuration details
+   * @throws AmbariException if the attributes are not valid or any errors occurs
+   */
+  @Override
+  public String checkUserAttributes(LdapConnection ldapConnection, String testUserName, String testPassword, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+    LdapNetworkConnection connection = null;
+    SearchCursor searchCursor = null;
+    String userDn = null;
+    try {
+      LOGGER.info("Checking user attributes for user {} r ...", testUserName);
+
+      // bind anonimously or with manager data
+      bind(ambariLdapConfiguration, connection);
+
+      // set up a filter based on the provided attributes
+      String filter = FilterBuilder.and(
+        FilterBuilder.equal(SchemaConstants.OBJECT_CLASS_AT, ambariLdapConfiguration.userObjectClass()),
+        FilterBuilder.equal(ambariLdapConfiguration.userNameAttribute(), testUserName))
+        .toString();
+
+      LOGGER.info("Searching for the user: {} using the search filter: {}", testUserName, filter);
+      EntryCursor entryCursor = connection.search(new Dn(ambariLdapConfiguration.userSearchBase()), filter, SearchScope.SUBTREE);
+
+      // collecting search result entries
+      List<Entry> users = Lists.newArrayList();
+      for (Entry entry : entryCursor) {
+        users.add(entry);
+        userDn = entry.getDn().getNormName();
+      }
+
+      // there should be at least one user found
+      if (users.isEmpty()) {
+        String msg = String.format("There are no users found using the filter: [ %s ]. Try changing the attribute values", filter);
+        LOGGER.error(msg);
+        throw new Exception(msg);
+      }
+
+      LOGGER.info("Attibute validation succeeded. Filter: {}", filter);
+
+    } catch (Exception e) {
+
+      LOGGER.error("User attributes validation failed.", e);
+      throw new AmbariLdapException(e.getMessage(), e);
+
+    } finally {
+      closeResources(connection, searchCursor);
+    }
+    return userDn;
+  }
+
+
+  @Override
+  public Set<String> checkGroupAttributes(LdapConnection ldapConnection, String userDn, AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
+    SearchCursor searchCursor = null;
+    Set<Response> groupResponses = Sets.newHashSet();
+
+    try {
+      LOGGER.info("Checking group attributes for user dn {} ...", userDn);
+
+      bind(ambariLdapConfiguration, ldapConnection);
+
+      // set up a filter based on the provided attributes
+      String filter = FilterBuilder.and(
+        FilterBuilder.equal(SchemaConstants.OBJECT_CLASS_AT, ambariLdapConfiguration.groupObjectClass()),
+        FilterBuilder.equal(ambariLdapConfiguration.groupMemberAttribute(), userDn)
+      ).toString();
+
+      LOGGER.info("Searching for the groups the user dn: {} is member of using the search filter: {}", userDn, filter);
+
+      // assemble a search request
+      SearchRequest searchRequest = new SearchRequestImpl();
+      searchRequest.setFilter(filter);
+      searchRequest.setBase(new Dn(ambariLdapConfiguration.groupSearchBase()));
+      searchRequest.setScope(SearchScope.SUBTREE);
+      searchRequest.addAttributes(ambariLdapConfiguration.groupMemberAttribute(), ambariLdapConfiguration.groupNameAttribute());
+
+      // perform the search
+      searchCursor = ldapConnection.search(searchRequest);
+
+      for (Response response : searchCursor) {
+        groupResponses.add(response);
+      }
+
+    } catch (Exception e) {
+
+      LOGGER.error("User attributes validation failed.", e);
+      throw new AmbariLdapException(e.getMessage(), e);
+
+    } finally {
+
+      closeResources(ldapConnection, searchCursor);
+
+    }
+
+    return processGroupResults(groupResponses, ambariLdapConfiguration);
+  }
+
+  private void bind(AmbariLdapConfiguration ambariLdapConfiguration, LdapConnection connection) throws LdapException {
+    LOGGER.info("Connecting to LDAP ....");
+    if (!ambariLdapConfiguration.bindAnonimously()) {
+      LOGGER.debug("Anonimous binding not supported, binding with the manager detailas...");
+      connection.bind(ambariLdapConfiguration.managerDn(), ambariLdapConfiguration.managerPassword());
+    } else {
+      LOGGER.debug("Binding anonimously ...");
+      connection.bind();
+    }
+
+    if (!connection.isConnected()) {
+      LOGGER.error("Not connected to the LDAP server. Connection instance: {}", connection);
+      throw new IllegalStateException("The connection to the LDAP server is not alive");
+    }
+    LOGGER.info("Connected to LDAP.");
+  }
+
+
+  private Set<String> processGroupResults(Set<Response> groupResponses, AmbariLdapConfiguration ambariLdapConfiguration) {
+    Set<String> groupStrSet = Sets.newHashSet();
+    for (Response response : groupResponses) {
+      Entry entry = ((SearchResultEntryDecorator) response).getEntry();
+      groupStrSet.add(entry.get(ambariLdapConfiguration.groupNameAttribute()).get().getString());
+    }
+
+    LOGGER.debug("Extracted group names from group search responses: {}", groupStrSet);
+    return groupStrSet;
+  }
+
+  private void closeResources(LdapConnection connection, SearchCursor searchCursor) {
+    LOGGER.debug("Housekeeping: closing the connection and the search cursor ...");
+
+    if (null != searchCursor) {
+      // this method is idempotent
+      searchCursor.close();
+    }
+
+    if (null != connection) {
+      try {
+        connection.close();
+      } catch (IOException e) {
+        LOGGER.error("Exception occurred while closing the connection", e);
+      }
+    }
+  }
+
+}
+
+
+

http://git-wip-us.apache.org/repos/asf/ambari/blob/a65608b8/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConnectionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConnectionService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConnectionService.java
new file mode 100644
index 0000000..b5559d9
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConnectionService.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ad;
+
+import javax.inject.Singleton;
+
+import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.service.LdapConnectionService;
+import org.apache.directory.ldap.client.api.LdapConnectionConfig;
+import org.apache.directory.ldap.client.api.LdapNetworkConnection;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Singleton
+public class DefaultLdapConnectionService implements LdapConnectionService {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapConnectionService.class);
+
+  @Override
+  public LdapNetworkConnection createLdapConnection(AmbariLdapConfiguration ambariLdapConfiguration) {
+    LOGGER.debug("Creating ldap connection instance from: {}", ambariLdapConfiguration);
+    return new LdapNetworkConnection(getLdapConnectionConfig(ambariLdapConfiguration));
+  }
+
+  private LdapConnectionConfig getLdapConnectionConfig(AmbariLdapConfiguration ambariAmbariLdapConfiguration) {
+    LOGGER.debug("Creating a configuration instance based on the ambari configuration: {}", ambariAmbariLdapConfiguration);
+
+    LdapConnectionConfig ldapConnectionConfig = new LdapConnectionConfig();
+    ldapConnectionConfig.setLdapHost(ambariAmbariLdapConfiguration.ldapServerHost());
+    ldapConnectionConfig.setLdapPort(ambariAmbariLdapConfiguration.ldapServerPort());
+    ldapConnectionConfig.setUseSsl(ambariAmbariLdapConfiguration.useSSL());
+
+    //todo set the other values as required
+    return ldapConnectionConfig;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/a65608b8/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/LdapConfigurationConverter.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/LdapConfigurationConverter.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/LdapConfigurationConverter.java
deleted file mode 100644
index a8839f1..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ad/LdapConfigurationConverter.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.service.ad;
-
-import javax.inject.Singleton;
-
-import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
-import org.apache.directory.ldap.client.api.LdapConnectionConfig;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Converts between ambari specific ldap types and the 3rd party ldap library
- */
-@Singleton
-public class LdapConfigurationConverter {
-
-  private static final Logger LOGGER = LoggerFactory.getLogger(LdapConfigurationConverter.class);
-
-  /**
-   * Creates a {@link LdapConnectionConfig} instance based on the provided ambari specific configurations
-   *
-   * @param ambariAmbariLdapConfiguration
-   * @return
-   */
-  public LdapConnectionConfig getLdapConnectionConfig(AmbariLdapConfiguration ambariAmbariLdapConfiguration) {
-    LOGGER.debug("Creating a configuration instance based on the ambari configuration: {}", ambariAmbariLdapConfiguration);
-
-    LdapConnectionConfig ldapConnectionConfig = new LdapConnectionConfig();
-    ldapConnectionConfig.setLdapHost(ambariAmbariLdapConfiguration.ldapServerHost());
-    ldapConnectionConfig.setLdapPort(ambariAmbariLdapConfiguration.ldapServerPort());
-    ldapConnectionConfig.setUseSsl(ambariAmbariLdapConfiguration.useSSL());
-
-    //todo set the other values as required
-    return ldapConnectionConfig;
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/a65608b8/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ad/AdLdapConfigurationValidatorServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ad/AdLdapConfigurationValidatorServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ad/AdLdapConfigurationValidatorServiceTest.java
deleted file mode 100644
index 0f57099..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ad/AdLdapConfigurationValidatorServiceTest.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.ldap.service.ad;
-
-import static org.junit.Assert.assertNotNull;
-
-import java.util.Map;
-
-import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
-import org.apache.ambari.server.ldap.LdapConfigurationValidatorService;
-import org.apache.directory.api.ldap.model.cursor.EntryCursor;
-import org.apache.directory.api.ldap.model.cursor.SearchCursor;
-import org.apache.directory.api.ldap.model.entry.Entry;
-import org.apache.directory.api.ldap.model.message.Response;
-import org.apache.directory.api.ldap.model.message.SearchRequest;
-import org.apache.directory.api.ldap.model.message.SearchRequestImpl;
-import org.apache.directory.api.ldap.model.message.SearchResultEntry;
-import org.apache.directory.api.ldap.model.message.SearchScope;
-import org.apache.directory.api.ldap.model.name.Dn;
-import org.apache.directory.ldap.client.api.LdapConnection;
-import org.apache.directory.ldap.client.api.LdapConnectionConfig;
-import org.apache.directory.ldap.client.api.LdapNetworkConnection;
-import org.apache.directory.ldap.client.api.search.FilterBuilder;
-import org.apache.directory.shared.ldap.constants.SchemaConstants;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.Maps;
-
-public class AdLdapConfigurationValidatorServiceTest {
-  private static final Logger LOGGER = LoggerFactory.getLogger(AdLdapConfigurationValidatorService.class);
-  private static final String TEST_USER = "Jocika10";
-
-  LdapConfigurationValidatorService ldapConfigurationValidatorService = new AdLdapConfigurationValidatorService();
-
-
-  @Test
-  public void testCheckAttributes() throws Exception {
-
-    // WHEN
-    LdapConnectionConfig config = new LdapConnectionConfig();
-    config.setLdapHost("localhost");
-    config.setLdapPort(389);
-    LdapConnection connection = new LdapNetworkConnection(config);
-
-    // THEN
-    connection.anonymousBind();
-
-
-    EntryCursor cursor = connection.search("dc=dev,dc=local", "(objectclass=*)", SearchScope.ONELEVEL);
-
-    for (Entry entry : cursor) {
-      assertNotNull(entry);
-      System.out.println(entry);
-    }
-
-    cursor.close();
-
-  }
-
-  @Test
-  public void testCheckUserAttributes() throws Exception {
-    Map<String, Object> ldapPropsMap = Maps.newHashMap();
-
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BIND_ANONIMOUSLY.propertyName(), true);
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_HOST.propertyName(), "localhost");
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_PORT.propertyName(), "389");
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BASE_DN.propertyName(), "dc=dev,dc=local");
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_OBJECT_CLASS.propertyName(), SchemaConstants.PERSON_OC);
-    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_NAME_ATTRIBUTE.propertyName(), SchemaConstants.UID_AT);
-
-    AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(ldapPropsMap);
-
-
-    try {
-      LOGGER.info("Authenticating user {} against the LDAP server ...", TEST_USER);
-      LdapConfigurationConverter ldapConfigurationConverter = new LdapConfigurationConverter();
-
-      LdapConnectionConfig connectionConfig = ldapConfigurationConverter.getLdapConnectionConfig(ambariLdapConfiguration);
-      LdapNetworkConnection connection = new LdapNetworkConnection(connectionConfig);
-
-      String filter = FilterBuilder.and(
-        FilterBuilder.equal(SchemaConstants.OBJECT_CLASS_AT, ambariLdapConfiguration.userObjectClass()),
-        FilterBuilder.equal(ambariLdapConfiguration.userNameAttribute(), TEST_USER))
-        .toString();
-
-      SearchRequest searchRequest = new SearchRequestImpl();
-      searchRequest.setBase(new Dn(ambariLdapConfiguration.baseDn()));
-      searchRequest.setFilter(filter);
-      searchRequest.setScope(SearchScope.SUBTREE);
-
-      LOGGER.info("loking up user: {} based on the filtr: {}", TEST_USER, filter);
-
-      connection.bind();
-      SearchCursor searchCursor = connection.search(searchRequest);
-
-      while (searchCursor.next()) {
-        Response response = searchCursor.get();
-
-        // process the SearchResultEntry
-        if (response instanceof SearchResultEntry) {
-          Entry resultEntry = ((SearchResultEntry) response).getEntry();
-          System.out.println(resultEntry);
-        }
-      }
-
-      searchCursor.close();
-
-    } catch (Exception e) {
-      throw new AmbariException("Error during user authentication check", e);
-    }
-
-  }
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/a65608b8/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorServiceTest.java
new file mode 100644
index 0000000..5c9d304
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/ldap/service/ad/DefaultLdapConfigurationValidatorServiceTest.java
@@ -0,0 +1,156 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.ldap.service.ad;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Map;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.ldap.AmbariLdapConfiguration;
+import org.apache.ambari.server.ldap.LdapConfigurationValidatorService;
+import org.apache.ambari.server.ldap.service.LdapConnectionService;
+import org.apache.directory.api.ldap.model.cursor.EntryCursor;
+import org.apache.directory.api.ldap.model.cursor.SearchCursor;
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.apache.directory.api.ldap.model.message.Response;
+import org.apache.directory.api.ldap.model.message.SearchRequest;
+import org.apache.directory.api.ldap.model.message.SearchRequestImpl;
+import org.apache.directory.api.ldap.model.message.SearchResultEntry;
+import org.apache.directory.api.ldap.model.message.SearchScope;
+import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.LdapConnectionConfig;
+import org.apache.directory.ldap.client.api.LdapNetworkConnection;
+import org.apache.directory.ldap.client.api.search.FilterBuilder;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Maps;
+
+public class DefaultLdapConfigurationValidatorServiceTest {
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLdapConfigurationValidatorService.class);
+  private static final String TEST_USER = "einstein";
+
+  LdapConfigurationValidatorService ldapConfigurationValidatorService = new DefaultLdapConfigurationValidatorService();
+
+
+  @Test
+  public void testCheckAttributes() throws Exception {
+
+    // WHEN
+    LdapConnectionConfig config = new LdapConnectionConfig();
+    config.setLdapHost("localhost");
+    config.setLdapPort(389);
+    LdapConnection connection = new LdapNetworkConnection(config);
+
+    // THEN
+    connection.anonymousBind();
+
+
+    EntryCursor cursor = connection.search("dc=dev,dc=local", "(objectclass=*)", SearchScope.ONELEVEL);
+
+    for (Entry entry : cursor) {
+      assertNotNull(entry);
+      System.out.println(entry);
+    }
+
+    cursor.close();
+
+  }
+
+  @Test
+  public void testCheckUserAttributes() throws Exception {
+    Map<String, Object> ldapPropsMap = Maps.newHashMap();
+
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BIND_ANONIMOUSLY.propertyName(), false);
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_HOST.propertyName(), "ldap.forumsys.com");
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_PORT.propertyName(), "389");
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BASE_DN.propertyName(), "dc=example,dc=com");
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_OBJECT_CLASS.propertyName(), SchemaConstants.PERSON_OC);
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_OBJECT_CLASS.propertyName(), SchemaConstants.GROUP_OF_UNIQUE_NAMES_OC);
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_NAME_ATTRIBUTE.propertyName(), SchemaConstants.CN_AT);
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_MEMBER_ATTRIBUTE.propertyName(), SchemaConstants.UNIQUE_MEMBER_AT);
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_NAME_ATTRIBUTE.propertyName(), SchemaConstants.UID_AT);
+
+    AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(ldapPropsMap);
+
+
+    try {
+      LOGGER.info("Authenticating user {} against the LDAP server ...", TEST_USER);
+      LdapConnectionService connectionService = new DefaultLdapConnectionService();
+      LdapNetworkConnection connection = connectionService.createLdapConnection(ambariLdapConfiguration);
+
+      String filter = FilterBuilder.and(
+        FilterBuilder.equal(SchemaConstants.OBJECT_CLASS_AT, ambariLdapConfiguration.userObjectClass()),
+        FilterBuilder.equal(ambariLdapConfiguration.userNameAttribute(), TEST_USER))
+        .toString();
+
+      SearchRequest searchRequest = new SearchRequestImpl();
+      searchRequest.setBase(new Dn(ambariLdapConfiguration.baseDn()));
+      searchRequest.setFilter(filter);
+      searchRequest.setScope(SearchScope.SUBTREE);
+
+      LOGGER.info("loking up user: {} based on the filtr: {}", TEST_USER, filter);
+
+      connection.bind();
+      SearchCursor searchCursor = connection.search(searchRequest);
+
+      while (searchCursor.next()) {
+        Response response = searchCursor.get();
+
+        // process the SearchResultEntry
+        if (response instanceof SearchResultEntry) {
+          Entry resultEntry = ((SearchResultEntry) response).getEntry();
+          System.out.println(resultEntry);
+        }
+      }
+
+      searchCursor.close();
+
+    } catch (Exception e) {
+      throw new AmbariException("Error during user authentication check", e);
+    }
+
+  }
+
+  @Test
+  public void testRetrieveGorupsForuser() throws Exception {
+    // GIVEN
+    Map<String, Object> ldapPropsMap = Maps.newHashMap();
+
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BIND_ANONIMOUSLY.propertyName(), "true");
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_HOST.propertyName(), "ldap.forumsys.com");
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.LDAP_SERVER_PORT.propertyName(), "389");
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.BASE_DN.propertyName(), "dc=example,dc=com");
+
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_OBJECT_CLASS.propertyName(), SchemaConstants.PERSON_OC);
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.USER_NAME_ATTRIBUTE.propertyName(), SchemaConstants.UID_AT);
+
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_OBJECT_CLASS.propertyName(), SchemaConstants.GROUP_OF_UNIQUE_NAMES_OC);
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_NAME_ATTRIBUTE.propertyName(), SchemaConstants.CN_AT);
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_MEMBER_ATTRIBUTE.propertyName(), SchemaConstants.UNIQUE_MEMBER_AT);
+    ldapPropsMap.put(AmbariLdapConfiguration.LdapConfigProperty.GROUP_SEARCH_BASE.propertyName(), "dc=example,dc=com");
+
+
+    AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(ldapPropsMap);
+    LdapConnectionService connectionService = new DefaultLdapConnectionService();
+    LdapNetworkConnection ldapConnection = connectionService.createLdapConnection(ambariLdapConfiguration);
+
+    ldapConfigurationValidatorService.checkGroupAttributes(ldapConnection, "uid=einstein,dc=example,dc=com", ambariLdapConfiguration);
+  }
+}
\ No newline at end of file


[41/46] ambari git commit: AMBARI-21307 cleand apache ditectory related dependencies

Posted by lp...@apache.org.
AMBARI-21307 cleand apache ditectory related dependencies


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: e1fe7b60007044aa47523f410c4e3f1f2f52f846
Parents: 71292fb
Author: lpuskas <lp...@apache.org>
Authored: Wed Oct 11 17:54:57 2017 +0200
Committer: lpuskas <lp...@apache.org>
Committed: Thu Oct 19 14:42:02 2017 +0200

----------------------------------------------------------------------
 ambari-funtest/pom.xml | 67 ------------------------------------
 ambari-project/pom.xml | 51 ---------------------------
 ambari-server/pom.xml  | 84 ++++++++-------------------------------------
 3 files changed, 14 insertions(+), 188 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/e1fe7b60/ambari-funtest/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-funtest/pom.xml b/ambari-funtest/pom.xml
index bb2068d..6466af3 100644
--- a/ambari-funtest/pom.xml
+++ b/ambari-funtest/pom.xml
@@ -197,73 +197,6 @@
       <artifactId>spring-ldap-core</artifactId>
     </dependency>
     <dependency>
-      <groupId>org.apache.directory.server</groupId>
-      <artifactId>apacheds-server-annotations</artifactId>
-      <scope>test</scope>
-      <exclusions>
-        <exclusion>
-          <groupId>net.sf.ehcache</groupId>
-          <artifactId>ehcache-core</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.directory.server</groupId>
-      <artifactId>apacheds-core-integ</artifactId>
-      <scope>test</scope>
-      <exclusions>
-        <exclusion>
-          <groupId>net.sf.ehcache</groupId>
-          <artifactId>ehcache-core</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.directory.server</groupId>
-      <artifactId>apacheds-server-integ</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.directory.server</groupId>
-      <artifactId>apacheds-jdbm</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.directory.server</groupId>
-      <artifactId>apacheds-kerberos-codec</artifactId>
-      <exclusions>
-        <exclusion>
-          <groupId>net.sf.ehcache</groupId>
-          <artifactId>ehcache-core</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.directory.server</groupId>
-      <artifactId>apacheds-core</artifactId>
-      <scope>test</scope>
-      <exclusions>
-        <exclusion>
-          <groupId>net.sf.ehcache</groupId>
-          <artifactId>ehcache-core</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.directory.server</groupId>
-      <artifactId>apacheds-protocol-ldap</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.directory.server</groupId>
-      <artifactId>kerberos-client</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.directory.shared</groupId>
-      <artifactId>shared-ldap</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
       <version>1.7.20</version>

http://git-wip-us.apache.org/repos/asf/ambari/blob/e1fe7b60/ambari-project/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-project/pom.xml b/ambari-project/pom.xml
index e4d4423..f6e3bc7 100644
--- a/ambari-project/pom.xml
+++ b/ambari-project/pom.xml
@@ -162,57 +162,6 @@
         <version>2.0.4.RELEASE</version>
       </dependency>
       <dependency>
-        <groupId>org.apache.directory.server</groupId>
-        <artifactId>apacheds-server-annotations</artifactId>
-        <version>2.0.0-M19</version>
-      </dependency>
-      <dependency>
-        <groupId>org.apache.directory.server</groupId>
-        <artifactId>apacheds-core-integ</artifactId>
-        <version>2.0.0-M19</version>
-      </dependency>
-      <dependency>
-        <groupId>org.apache.directory.server</groupId>
-        <artifactId>apacheds-server-integ</artifactId>
-        <version>2.0.0-M19</version>
-      </dependency>
-      <dependency>
-        <groupId>org.apache.directory.server</groupId>
-        <artifactId>apacheds-jdbm</artifactId>
-        <version>2.0.0-M5</version>
-      </dependency>
-      <dependency>
-        <groupId>org.apache.directory.server</groupId>
-        <artifactId>apacheds-kerberos-codec</artifactId>
-        <version>2.0.0-M19</version>
-      </dependency>
-      <dependency>
-        <groupId>org.apache.directory.server</groupId>
-        <artifactId>apacheds-core</artifactId>
-        <version>2.0.0-M19</version>
-      </dependency>
-      <dependency>
-        <groupId>org.apache.directory.server</groupId>
-        <artifactId>kerberos-client</artifactId>
-        <version>2.0.0-M19</version>
-      </dependency>
-      <dependency>
-        <groupId>org.apache.directory.server</groupId>
-        <artifactId>apacheds-protocol-ldap</artifactId>
-        <version>2.0.0-M19</version>
-        <exclusions>
-          <exclusion>
-            <groupId>org.apache.directory.jdbm</groupId>
-            <artifactId>apacheds-jdbm1</artifactId>
-          </exclusion>
-        </exclusions>
-      </dependency>
-      <dependency>
-        <groupId>org.apache.directory.shared</groupId>
-        <artifactId>shared-ldap</artifactId>
-        <version>0.9.17</version>
-      </dependency>
-      <dependency>
         <groupId>org.slf4j</groupId>
         <artifactId>slf4j-api</artifactId>
         <version>${slf4j.version}</version>

http://git-wip-us.apache.org/repos/asf/ambari/blob/e1fe7b60/ambari-server/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-server/pom.xml b/ambari-server/pom.xml
index 8d52821..a86acf5 100644
--- a/ambari-server/pom.xml
+++ b/ambari-server/pom.xml
@@ -1225,73 +1225,6 @@
       <artifactId>spring-ldap-core</artifactId>
     </dependency>
     <dependency>
-      <groupId>org.apache.directory.server</groupId>
-      <artifactId>apacheds-server-annotations</artifactId>
-      <scope>test</scope>
-      <exclusions>
-        <exclusion>
-          <groupId>net.sf.ehcache</groupId>
-          <artifactId>ehcache-core</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.directory.server</groupId>
-      <artifactId>apacheds-core-integ</artifactId>
-      <scope>test</scope>
-      <exclusions>
-        <exclusion>
-          <groupId>net.sf.ehcache</groupId>
-          <artifactId>ehcache-core</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.directory.server</groupId>
-      <artifactId>apacheds-server-integ</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.directory.server</groupId>
-      <artifactId>apacheds-jdbm</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.directory.server</groupId>
-      <artifactId>apacheds-kerberos-codec</artifactId>
-      <exclusions>
-        <exclusion>
-          <groupId>net.sf.ehcache</groupId>
-          <artifactId>ehcache-core</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.directory.server</groupId>
-      <artifactId>apacheds-core</artifactId>
-      <scope>test</scope>
-      <exclusions>
-        <exclusion>
-          <groupId>net.sf.ehcache</groupId>
-          <artifactId>ehcache-core</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.directory.server</groupId>
-      <artifactId>apacheds-protocol-ldap</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.directory.server</groupId>
-      <artifactId>kerberos-client</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.directory.shared</groupId>
-      <artifactId>shared-ldap</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
     </dependency>
@@ -1622,6 +1555,12 @@
       <groupId>org.apache.hadoop</groupId>
       <artifactId>hadoop-auth</artifactId>
       <version>${hadoop.version}</version>
+      <exclusions>
+        <exclusion>
+          <groupId>org.apache.directory.server</groupId>
+          <artifactId>apacheds-kerberos-codec</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>org.apache.hadoop</groupId>
@@ -1689,9 +1628,14 @@
       <version>4.2.2</version>
     </dependency>
     <dependency>
-      <groupId>org.apache.directory.api</groupId>
-      <artifactId>api-all</artifactId>
-      <version>${ldap-api.version}</version>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>apacheds-all</artifactId>
+      <version>2.0.0-M24</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>kerberos-client</artifactId>
+      <version>2.0.0-M24</version>
     </dependency>
     <dependency>
       <groupId>com.networknt</groupId>