ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amag...@apache.org
Subject [ambari] branch trunk updated: AMBARI-23289. Add SSO integration support information to service information via Ambari's REST API (amagyar)
Date Sat, 24 Mar 2018 17:10:14 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/trunk by this push:
     new a8c2d0d  AMBARI-23289. Add SSO integration support information to service information
via Ambari's REST API (amagyar)
a8c2d0d is described below

commit a8c2d0de1b17ae5804e1819e1b7c94e560930a00
Author: Attila Magyar <amagyar@hortonworks.com>
AuthorDate: Tue Mar 20 17:18:37 2018 +0100

    AMBARI-23289. Add SSO integration support information to service information via Ambari's
REST API (amagyar)
---
 .../ambari/server/controller/ServiceResponse.java  | 36 +++++++++++-
 .../server/controller/StackServiceResponse.java    | 11 ++++
 .../internal/AmbariServerConfigurationHandler.java | 38 +++++++++++-
 .../internal/ServiceResourceProvider.java          | 20 +++++++
 .../internal/StackServiceResourceProvider.java     |  8 ++-
 .../apache/ambari/server/state/ServiceImpl.java    | 34 ++++++++++-
 .../apache/ambari/server/state/ServiceInfo.java    |  4 ++
 .../AmbariServerConfigurationHandlerTest.java      | 67 ++++++++++++++++++++++
 8 files changed, 211 insertions(+), 7 deletions(-)

diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceResponse.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceResponse.java
index ed1832a..2c6c4c4 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceResponse.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceResponse.java
@@ -36,16 +36,22 @@ public class ServiceResponse {
   private String maintenanceState;
   private boolean credentialStoreSupported;
   private boolean credentialStoreEnabled;
+  private final boolean ssoIntegrationSupported;
+  private final boolean ssoIntegrationDesired;
+  private final boolean ssoIntegrationEnabled;
 
   public ServiceResponse(Long clusterId, String clusterName, String serviceName,
-      StackId desiredStackId, String desiredRepositoryVersion,
-      RepositoryVersionState repositoryVersionState, String desiredState,
-      boolean credentialStoreSupported, boolean credentialStoreEnabled) {
+                         StackId desiredStackId, String desiredRepositoryVersion,
+                         RepositoryVersionState repositoryVersionState, String desiredState,
+                         boolean credentialStoreSupported, boolean credentialStoreEnabled,
boolean ssoIntegrationSupported, boolean ssoIntegrationDesired, boolean ssoIntegrationEnabled)
{
     this.clusterId = clusterId;
     this.clusterName = clusterName;
     this.serviceName = serviceName;
     this.desiredStackId = desiredStackId;
     this.repositoryVersionState = repositoryVersionState;
+    this.ssoIntegrationSupported = ssoIntegrationSupported;
+    this.ssoIntegrationDesired = ssoIntegrationDesired;
+    this.ssoIntegrationEnabled = ssoIntegrationEnabled;
     setDesiredState(desiredState);
     this.desiredRepositoryVersion = desiredRepositoryVersion;
     this.credentialStoreSupported = credentialStoreSupported;
@@ -229,6 +235,30 @@ public class ServiceResponse {
   }
 
   /**
+   * Indicates if this service supports single sign-on integration.
+   */
+  @ApiModelProperty(name = "sso_integration_supported")
+  public boolean isSsoIntegrationSupported() {
+    return ssoIntegrationSupported;
+  }
+
+  /**
+   * Indicates whether the service is chosen for SSO integration or not
+   */
+  @ApiModelProperty(name = "sso_integration_desired")
+  public boolean isSsoIntegrationDesired() {
+    return ssoIntegrationDesired;
+  }
+
+  /**
+   * Indicates whether the service is configured for SSO integration or not
+   */
+  @ApiModelProperty(name = "sso_integration_enabled")
+  public boolean isSsoIntegrationEnabled() {
+    return ssoIntegrationEnabled;
+  }
+
+  /**
    * Interface to help correct Swagger documentation generation
    */
   public interface ServiceResponseSwagger extends ApiModel {
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/StackServiceResponse.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/StackServiceResponse.java
index fd67fec..503f56a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/StackServiceResponse.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/StackServiceResponse.java
@@ -79,6 +79,8 @@ public class StackServiceResponse {
 
   private boolean isSupportDeleteViaUI;
 
+  private final boolean ssoIntegrationSupported;
+
   /**
    * Constructor.
    *
@@ -114,6 +116,7 @@ public class StackServiceResponse {
     credentialStoreSupported = service.isCredentialStoreSupported();
     credentialStoreEnabled = service.isCredentialStoreEnabled();
     isSupportDeleteViaUI = service.isSupportDeleteViaUI();
+    ssoIntegrationSupported = service.isSingleSignOnSupported();
   }
 
   @ApiModelProperty(name = "selection")
@@ -332,6 +335,14 @@ public class StackServiceResponse {
     return isSupportDeleteViaUI;
   }
 
+  /**
+   * Indicates if this service supports single sign-on integration.
+   */
+  @ApiModelProperty(name = "sso_integration_supported")
+  public boolean isSsoIntegrationSupported() {
+    return ssoIntegrationSupported;
+  }
+
   public interface StackServiceResponseSwagger extends ApiModel {
     @ApiModelProperty(name = "StackServices")
     public StackServiceResponse getStackServiceResponse();
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariServerConfigurationHandler.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariServerConfigurationHandler.java
index f96ad08..e84a72e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariServerConfigurationHandler.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariServerConfigurationHandler.java
@@ -18,13 +18,19 @@
 
 package org.apache.ambari.server.controller.internal;
 
+import static org.apache.ambari.server.configuration.AmbariServerConfigurationCategory.SSO_CONFIGURATION;
+import static org.apache.ambari.server.configuration.AmbariServerConfigurationKey.SSO_ENABED_SERVICES;
+
 import java.io.File;
 import java.io.IOException;
 import java.nio.charset.Charset;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.StaticallyInject;
@@ -49,11 +55,11 @@ import com.google.inject.Inject;
  * AmbariServerConfigurationHandler handles Ambari server specific configuration properties.
  */
 @StaticallyInject
-class AmbariServerConfigurationHandler extends RootServiceComponentConfigurationHandler {
+public class AmbariServerConfigurationHandler extends RootServiceComponentConfigurationHandler
{
   private static final Logger LOGGER = LoggerFactory.getLogger(AmbariServerConfigurationHandler.class);
 
   @Inject
-  private static AmbariConfigurationDAO ambariConfigurationDAO;
+  static AmbariConfigurationDAO ambariConfigurationDAO;
 
   @Inject
   private static AmbariEventPublisher publisher;
@@ -188,4 +194,32 @@ class AmbariServerConfigurationHandler extends RootServiceComponentConfiguration
                                           Map<String, Object> operationParameters)
throws SystemException {
     throw new SystemException(String.format("The requested operation is not supported for
this category: %s", categoryName));
   }
+
+  public SsoEnabledServices getSsoEnabledSevices() {
+    return new SsoEnabledServices(
+      ambariConfigurationDAO.findByCategory(SSO_CONFIGURATION.getCategoryName()).stream()
+      .filter(each -> SSO_ENABED_SERVICES.key().equalsIgnoreCase(each.getPropertyName()))
+      .findFirst()
+      .map(entity -> entity.getPropertyValue())
+      .orElse(""));
+  }
+
+  public static class SsoEnabledServices {
+    private final String commaSeparatedServices;
+
+    SsoEnabledServices(String commaSeparatedServices) {
+      this.commaSeparatedServices = commaSeparatedServices.trim();
+    }
+
+    public boolean contains(String serviceName) {
+      return "*".equals(commaSeparatedServices) || serviceList().contains(serviceName.toUpperCase());
+    }
+
+    private Set<String> serviceList() {
+      return Arrays.asList(commaSeparatedServices.split(",")).stream()
+        .map(String::trim)
+        .map(String::toUpperCase)
+        .collect(Collectors.toSet());
+    }
+  }
 }
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
index 8c40dcb..f6fbce0 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
@@ -120,6 +120,15 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
   public static final String SERVICE_DESIRED_REPO_VERSION_ID_PROPERTY_ID = PropertyHelper.getPropertyId(
       "ServiceInfo", "desired_repository_version_id");
 
+  private static final String SSO_INTEGRATION_SUPPORTED_PROPERTY_ID = PropertyHelper.getPropertyId(
+    "ServiceInfo", "sso_integration_supported");
+
+  private static final String SSO_INTEGRATION_ENABLED_PROPERTY_ID = PropertyHelper.getPropertyId(
+    "ServiceInfo", "sso_integration_enabled");
+
+  private static final String SSO_INTEGRATION_DESIRED_PROPERTY_ID = PropertyHelper.getPropertyId(
+    "ServiceInfo", "sso_integration_desired");
+
   protected static final String SERVICE_REPOSITORY_STATE = "ServiceInfo/repository_state";
 
   //Parameters from the predicate
@@ -159,6 +168,10 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
     PROPERTY_IDS.add(QUERY_PARAMETERS_RECONFIGURE_CLIENT);
     PROPERTY_IDS.add(QUERY_PARAMETERS_START_DEPENDENCIES);
 
+    PROPERTY_IDS.add(SSO_INTEGRATION_SUPPORTED_PROPERTY_ID);
+    PROPERTY_IDS.add(SSO_INTEGRATION_ENABLED_PROPERTY_ID);
+    PROPERTY_IDS.add(SSO_INTEGRATION_DESIRED_PROPERTY_ID);
+
     // keys
     KEY_PROPERTY_IDS.put(Resource.Type.Service, SERVICE_SERVICE_NAME_PROPERTY_ID);
     KEY_PROPERTY_IDS.put(Resource.Type.Cluster, SERVICE_CLUSTER_NAME_PROPERTY_ID);
@@ -275,6 +288,13 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
       setResourceProperty(resource, SERVICE_REPOSITORY_STATE,
           response.getRepositoryVersionState(), requestedIds);
 
+      setResourceProperty(resource, SSO_INTEGRATION_SUPPORTED_PROPERTY_ID,
+        response.isSsoIntegrationSupported(), requestedIds);
+      setResourceProperty(resource, SSO_INTEGRATION_ENABLED_PROPERTY_ID,
+        response.isSsoIntegrationEnabled(), requestedIds);
+      setResourceProperty(resource, SSO_INTEGRATION_DESIRED_PROPERTY_ID,
+        response.isSsoIntegrationDesired(), requestedIds);
+
       Map<String, Object> serviceSpecificProperties = getServiceSpecificProperties(
           response.getClusterName(), response.getServiceName(), requestedIds);
 
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackServiceResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackServiceResourceProvider.java
index a4bf32b..a6a63fe 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackServiceResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackServiceResourceProvider.java
@@ -102,6 +102,9 @@ public class StackServiceResourceProvider extends ReadOnlyResourceProvider
{
   private static final String SUPPORT_DELETE_VIA_UI = PropertyHelper.getPropertyId(
       "StackServices", "support_delete_via_ui");
 
+  private static final String SSO_INTEGRATION_SUPPORTED_PROPERTY_ID = PropertyHelper.getPropertyId(
+    "StackServices", "sso_integration_supported");
+
   /**
    * The key property ids for a StackVersion resource.
    */
@@ -132,7 +135,8 @@ public class StackServiceResourceProvider extends ReadOnlyResourceProvider
{
       CREDENTIAL_STORE_SUPPORTED,
       CREDENTIAL_STORE_REQUIRED,
       CREDENTIAL_STORE_ENABLED,
-      SUPPORT_DELETE_VIA_UI);
+      SUPPORT_DELETE_VIA_UI,
+      SSO_INTEGRATION_SUPPORTED_PROPERTY_ID);
 
   /**
    * KerberosServiceDescriptorFactory used to create KerberosServiceDescriptor instances
@@ -239,6 +243,8 @@ public class StackServiceResourceProvider extends ReadOnlyResourceProvider
{
     setResourceProperty(resource, SUPPORT_DELETE_VIA_UI,
         response.isSupportDeleteViaUI(), requestedIds);
 
+    setResourceProperty(resource, SSO_INTEGRATION_SUPPORTED_PROPERTY_ID, response.isSsoIntegrationSupported(),
requestedIds);
+
     return resource;
   }
 
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
index c638f9f..03cc7c4 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
@@ -36,6 +36,7 @@ import org.apache.ambari.server.ObjectNotFoundException;
 import org.apache.ambari.server.ServiceComponentNotFoundException;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.controller.ServiceResponse;
+import org.apache.ambari.server.controller.internal.AmbariServerConfigurationHandler;
 import org.apache.ambari.server.controller.internal.DeleteHostComponentStatusMetaData;
 import org.apache.ambari.server.events.MaintenanceModeEvent;
 import org.apache.ambari.server.events.ServiceInstalledEvent;
@@ -79,12 +80,20 @@ public class ServiceImpl implements Service {
   private boolean isClientOnlyService;
   private boolean isCredentialStoreSupported;
   private boolean isCredentialStoreRequired;
+  private final boolean ssoIntegrationSupported;
+  private final String ssoEnabledConfiguration;
   private AmbariMetaInfo ambariMetaInfo;
   private AtomicReference<MaintenanceState> maintenanceState = new AtomicReference<>();
 
   @Inject
   private ServiceConfigDAO serviceConfigDAO;
 
+  @Inject
+  private ConfigHelper configHelper;
+
+  @Inject
+  private AmbariServerConfigurationHandler ambariServerConfigurationHandler;
+
   private final ClusterServiceDAO clusterServiceDAO;
   private final ServiceDesiredStateDAO serviceDesiredStateDAO;
   private final ClusterDAO clusterDAO;
@@ -138,6 +147,8 @@ public class ServiceImpl implements Service {
     isClientOnlyService = sInfo.isClientOnlyService();
     isCredentialStoreSupported = sInfo.isCredentialStoreSupported();
     isCredentialStoreRequired = sInfo.isCredentialStoreRequired();
+    ssoIntegrationSupported = sInfo.isSingleSignOnSupported();
+    ssoEnabledConfiguration = sInfo.getSingleSignOnEnabledConfiguration();
 
     persist(serviceEntity);
   }
@@ -185,6 +196,8 @@ public class ServiceImpl implements Service {
     isCredentialStoreSupported = sInfo.isCredentialStoreSupported();
     isCredentialStoreRequired = sInfo.isCredentialStoreRequired();
     displayName = sInfo.getDisplayName();
+    ssoIntegrationSupported = sInfo.isSingleSignOnSupported();
+    ssoEnabledConfiguration = sInfo.getSingleSignOnEnabledConfiguration();
   }
 
 
@@ -362,7 +375,8 @@ public class ServiceImpl implements Service {
 
     ServiceResponse r = new ServiceResponse(cluster.getClusterId(), cluster.getClusterName(),
         getName(), desiredStackId, desiredRespositoryVersion.getVersion(), getRepositoryState(),
-        getDesiredState().toString(), isCredentialStoreSupported(), isCredentialStoreEnabled());
+        getDesiredState().toString(), isCredentialStoreSupported(), isCredentialStoreEnabled(),
+      ssoIntegrationSupported, isSsoIntegrationDesired(), isSsoIntegrationEnabled());
 
     r.setDesiredRepositoryVersionId(desiredRespositoryVersion.getId());
 
@@ -676,4 +690,22 @@ public class ServiceImpl implements Service {
   private ServiceDesiredStateEntity getServiceDesiredStateEntity() {
     return serviceDesiredStateDAO.findByPK(serviceDesiredStateEntityPK);
   }
+
+  public boolean isSsoIntegrationDesired() {
+    return ambariServerConfigurationHandler.getSsoEnabledSevices().contains(serviceName);
+  }
+
+  public boolean isSsoIntegrationEnabled() {
+    return ssoIntegrationSupported && ssoEnabledConfigValid() && "true".equalsIgnoreCase(ssoEnabledConfigValue());
+  }
+
+  private boolean ssoEnabledConfigValid() {
+    return ssoEnabledConfiguration != null && ssoEnabledConfiguration.split("/").length
== 2;
+  }
+
+  private String ssoEnabledConfigValue() {
+    String configType = ssoEnabledConfiguration.split("/")[0];
+    String propertyName = ssoEnabledConfiguration.split("/")[1];
+    return configHelper.getValueFromDesiredConfigurations(cluster, configType, propertyName);
+  }
 }
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceInfo.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceInfo.java
index 6ac5f4e..58f6bbb 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceInfo.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceInfo.java
@@ -653,6 +653,10 @@ public class ServiceInfo implements Validable {
     return (singleSignOnInfo != null) && singleSignOnInfo.isSupported();
   }
 
+  public String getSingleSignOnEnabledConfiguration() {
+    return singleSignOnInfo != null ? singleSignOnInfo.getEnabledConfiguration() : null;
+  }
+
   @Override
   public String toString() {
     StringBuilder sb = new StringBuilder();
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AmbariServerConfigurationHandlerTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AmbariServerConfigurationHandlerTest.java
new file mode 100644
index 0000000..8c1130c
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AmbariServerConfigurationHandlerTest.java
@@ -0,0 +1,67 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one
+ *  * or more contributor license agreements.  See the NOTICE file
+ *  * distributed with this work for additional information
+ *  * regarding copyright ownership.  The ASF licenses this file
+ *  * to you 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 static java.util.Collections.singletonList;
+import static org.apache.ambari.server.configuration.AmbariServerConfigurationCategory.SSO_CONFIGURATION;
+import static org.apache.ambari.server.configuration.AmbariServerConfigurationKey.SSO_ENABED_SERVICES;
+import static org.easymock.EasyMock.expect;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.ambari.server.orm.dao.AmbariConfigurationDAO;
+import org.apache.ambari.server.orm.entities.AmbariConfigurationEntity;
+import org.easymock.EasyMockRunner;
+import org.easymock.EasyMockSupport;
+import org.easymock.Mock;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(EasyMockRunner.class)
+public class AmbariServerConfigurationHandlerTest extends EasyMockSupport {
+  @Mock
+  private AmbariConfigurationDAO ambariConfigurationDAO;
+  private AmbariServerConfigurationHandler ambariServerConfigurationHandler;
+
+  @Before
+  public void setUp() throws Exception {
+    ambariServerConfigurationHandler = new AmbariServerConfigurationHandler();
+    AmbariServerConfigurationHandler.ambariConfigurationDAO = ambariConfigurationDAO;
+  }
+
+  @Test
+  public void testCheckingIfSsoIsEnabledPerEachService() {
+    expect(ambariConfigurationDAO.findByCategory(SSO_CONFIGURATION.getCategoryName())).andReturn(singletonList(ssoConfig("SERVICE1,
SERVICE2"))).anyTimes();
+    replayAll();
+    assertTrue(ambariServerConfigurationHandler.getSsoEnabledSevices().contains("SERVICE1"));
+    assertTrue(ambariServerConfigurationHandler.getSsoEnabledSevices().contains("SERVICE2"));
+    assertFalse(ambariServerConfigurationHandler.getSsoEnabledSevices().contains("SERVICE3"));
+  }
+
+  private AmbariConfigurationEntity ssoConfig(String services) {
+    AmbariConfigurationEntity entity = new AmbariConfigurationEntity();
+    entity.setCategoryName(SSO_CONFIGURATION.getCategoryName());
+    entity.setPropertyName(SSO_ENABED_SERVICES.key());
+    entity.setPropertyValue(services);
+    return entity;
+  }
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
amagyar@apache.org.

Mime
View raw message