Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AMBARI-24907. Updated service metainfo to declare LDAP integration support #2621

Merged
merged 2 commits into from Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -36,7 +36,6 @@
import org.apache.ambari.annotations.ApiIgnore;
import org.apache.ambari.server.controller.internal.ProvisionAction;
import org.apache.ambari.server.topology.ConfigRecommendationStrategy;
import org.apache.ambari.server.topology.Configurable;
import org.apache.ambari.server.topology.ConfigurableHelper;
import org.apache.ambari.server.topology.Configuration;

Expand Down
Expand Up @@ -41,13 +41,15 @@ public class ServiceResponse {
private final boolean ssoIntegrationEnabled;
private final boolean ssoIntegrationRequiresKerberos;
private final boolean kerberosEnabled;
private final boolean ldapIntegrationSupported;
private final boolean ldapIntegrationEnabled;

public ServiceResponse(Long clusterId, String clusterName, String serviceName,
StackId desiredStackId, String desiredRepositoryVersion,
RepositoryVersionState repositoryVersionState, String desiredState,
boolean credentialStoreSupported, boolean credentialStoreEnabled, boolean ssoIntegrationSupported,
boolean ssoIntegrationDesired, boolean ssoIntegrationEnabled, boolean ssoIntegrationRequiresKerberos,
boolean kerberosEnabled) {
boolean kerberosEnabled, boolean ldapIntegrationSupported, boolean ldapIntegrationEnabled) {
this.clusterId = clusterId;
this.clusterName = clusterName;
this.serviceName = serviceName;
Expand All @@ -62,6 +64,8 @@ public ServiceResponse(Long clusterId, String clusterName, String serviceName,
this.credentialStoreEnabled = credentialStoreEnabled;
this.ssoIntegrationRequiresKerberos = ssoIntegrationRequiresKerberos;
this.kerberosEnabled = kerberosEnabled;
this.ldapIntegrationSupported = ldapIntegrationSupported;
this.ldapIntegrationEnabled = ldapIntegrationEnabled;
}

/**
Expand Down Expand Up @@ -277,6 +281,24 @@ public boolean isSsoIntegrationRequiresKerberos() {
public boolean isKerberosEnabled() {
return kerberosEnabled;
}

/**
* Indicates if this service supports LDAP integration.
*/
@ApiModelProperty(name = "ldap_integration_supported")
public boolean isLdapIntegrationSupported() {
return ldapIntegrationSupported;
}

/**
* Indicates whether the service is configured for LDAP integration or not
*/
@ApiModelProperty(name = "ldap_integration_enabled")
public boolean isLdapIntegrationEnabled() {
return ldapIntegrationEnabled;
}



/**
* Interface to help correct Swagger documentation generation
Expand Down
Expand Up @@ -139,6 +139,12 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
private static final String KERBEROS_ENABLED_PROPERTY_ID = PropertyHelper.getPropertyId(
"ServiceInfo", "kerberos_enabled");

private static final String LDAP_INTEGRATION_SUPPORTED_PROPERTY_ID = PropertyHelper.getPropertyId(
"ServiceInfo", "ldap_integration_supported");

private static final String LDAP_INTEGRATION_ENABLED_PROPERTY_ID = PropertyHelper.getPropertyId(
"ServiceInfo", "ldap_integration_enabled");

public static final String OPERATION_TYPE = "operation_type";

protected static final String SERVICE_REPOSITORY_STATE = "ServiceInfo/repository_state";
Expand Down Expand Up @@ -185,6 +191,10 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
PROPERTY_IDS.add(SSO_INTEGRATION_DESIRED_PROPERTY_ID);
PROPERTY_IDS.add(SSO_INTEGRATION_REQUIRES_KERBEROS_PROPERTY_ID);
PROPERTY_IDS.add(KERBEROS_ENABLED_PROPERTY_ID);

PROPERTY_IDS.add(LDAP_INTEGRATION_SUPPORTED_PROPERTY_ID);
PROPERTY_IDS.add(LDAP_INTEGRATION_ENABLED_PROPERTY_ID);

PROPERTY_IDS.add(OPERATION_TYPE);

// keys
Expand Down Expand Up @@ -326,6 +336,10 @@ public Set<ServiceResponse> invoke() throws AmbariException {
setResourceProperty(resource, KERBEROS_ENABLED_PROPERTY_ID,
response.isKerberosEnabled(), requestedIds);

setResourceProperty(resource, LDAP_INTEGRATION_SUPPORTED_PROPERTY_ID, response.isLdapIntegrationSupported(), requestedIds);
setResourceProperty(resource, LDAP_INTEGRATION_ENABLED_PROPERTY_ID, response.isLdapIntegrationEnabled(), requestedIds);


Map<String, Object> serviceSpecificProperties = getServiceSpecificProperties(
response.getClusterName(), response.getServiceName(), requestedIds);

Expand Down
Expand Up @@ -87,6 +87,8 @@ public class ServiceImpl implements Service {
private boolean isCredentialStoreRequired;
private final boolean ssoIntegrationSupported;
private final Predicate ssoEnabledTest;
private final boolean ldapIntegrationSupported;
private final Predicate ldapEnabledTest;
private final boolean ssoRequiresKerberos;
private final Predicate kerberosEnabledTest;
private AmbariMetaInfo ambariMetaInfo;
Expand Down Expand Up @@ -169,6 +171,9 @@ public class ServiceImpl implements Service {
serviceName);
}

ldapIntegrationSupported = sInfo.isLdapSupported();
ldapEnabledTest = StringUtils.isNotBlank(sInfo.getLdapEnabledTest()) ? PredicateUtils.fromJSON(sInfo.getLdapEnabledTest()) : null;

persist(serviceEntity);
}

Expand Down Expand Up @@ -226,6 +231,9 @@ public class ServiceImpl implements Service {
"Automated SSO integration will not be allowed for this service.",
serviceName);
}

ldapIntegrationSupported = sInfo.isLdapSupported();
ldapEnabledTest = StringUtils.isNotBlank(sInfo.getLdapEnabledTest()) ? PredicateUtils.fromJSON(sInfo.getLdapEnabledTest()) : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe for code reuse, make compileKerberosEnabledPredicate generic?

  private Predicate compilePredicate(String json) {
    if (StringUtils.isNotBlank(json)) {
      return PredicateUtils.fromJSON(json);
    }
    return null;
  }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops.. already merged... :|

}


Expand Down Expand Up @@ -414,7 +422,7 @@ public ServiceResponse convertToResponse() {
getName(), desiredStackId, desiredRespositoryVersion.getVersion(), getRepositoryState(),
getDesiredState().toString(), isCredentialStoreSupported(), isCredentialStoreEnabled(),
ssoIntegrationSupported, isSsoIntegrationDesired(), isSsoIntegrationEnabled(existingConfigurations),
isKerberosRequiredForSsoIntegration(), isKerberosEnabled(existingConfigurations));
isKerberosRequiredForSsoIntegration(), isKerberosEnabled(existingConfigurations), ldapIntegrationSupported,isLdapIntegrationEnabeled(existingConfigurations));

r.setDesiredRepositoryVersionId(desiredRespositoryVersion.getId());

Expand Down Expand Up @@ -797,4 +805,8 @@ private boolean isSsoIntegrationEnabled(Map<String, Map<String, String>> existin
private boolean isKerberosRequiredForSsoIntegration() {
return ssoRequiresKerberos;
}

private boolean isLdapIntegrationEnabeled(Map<String, Map<String, String>> existingConfigurations) {
return ldapIntegrationSupported && ldapEnabledTest != null && ldapEnabledTest.evaluate(existingConfigurations);
}
}
Expand Up @@ -167,6 +167,12 @@ public enum ServiceAdvisorType {
@XmlElements(@XmlElement(name = "sso"))
private SingleSignOnInfo singleSignOnInfo;

/**
* LDAP support information
*/
@XmlElements(@XmlElement(name = "ldap"))
private ServiceLdapInfo ldapInfo;

public Boolean isRestartRequiredAfterChange() {
return restartRequiredAfterChange;
}
Expand Down Expand Up @@ -719,6 +725,38 @@ public String getSingleSignOnEnabledTest() {
public boolean isKerberosRequiredForSingleSignOnIntegration() {
return singleSignOnInfo != null && singleSignOnInfo.isKerberosRequired();
}

/**
* Gets a new value for LDAP integration support
*/
public ServiceLdapInfo getLdapInfo() {
return ldapInfo;
}

/**
* Sets a new value for LDAP integration support
*
* @param ldapInfo
* a {@link ServiceLdapInfo}
*/
public void setLdapInfo(ServiceLdapInfo ldapInfo) {
this.ldapInfo = ldapInfo;
}

/**
* @return whether this service supports single sign-on integration
*/
public boolean isLdapSupported() {
return (ldapInfo != null) && ldapInfo.isSupported();
}

/**
* @return the configuration specification that can be used to determine if LDAP
* has been enabled or not.
*/
public String getLdapEnabledTest() {
return ldapInfo != null ? ldapInfo.getLdapEnabledTest() : null;
}

@Override
public String toString() {
Expand Down Expand Up @@ -1332,6 +1370,11 @@ public String apply(ServicePropertyInfo servicePropertyInfo) {
}
}
}

if (ldapInfo != null && ldapInfo.isSupported() && StringUtils.isBlank(ldapInfo.getLdapEnabledTest())) {
setValid(false);
addError("LDAP support is indicated for service " + getName() + " but no test configuration has been set by ldapEnabledTest.");
}
}

public enum Selection {
Expand Down
@@ -0,0 +1,159 @@
/*
* 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.state;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

import org.apache.ambari.server.collections.PredicateUtils;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
* {@link ServiceLdapInfo} encapsulates meta information about a service's
* support LDAP integration
* <p>
* The data is expected to be like
*
* <pre>
* &lt;ldap&gt;
* &lt;supported&gt;true&lt;/supported&gt;
* &lt;ldapEnabledTest&gt;
* {
* "equals": [
* "service-site/ranger.authentication.method",
* "LDAP"
* ]
* }
* &lt;/ldapEnabledTest&gt;
* &lt;/ldap&gt;
* </pre>
*/
@XmlAccessorType(XmlAccessType.FIELD)
public class ServiceLdapInfo {

/**
* Indicates whether the relevant service supports LDAP integration
* (<code>true</code>) or not (<code>false</code>).
*/
@XmlElement(name = "supported")
private Boolean supported = Boolean.FALSE;

/**
* The configuration that can be used to determine if LDAP integration has been
* enabled.
* <p>
* It is expected that this value is in the form of a valid JSON predicate
* ({@link PredicateUtils#fromJSON(String)}
*/
@XmlElement(name = "ldapEnabledTest")
private String ldapEnabledTest = null;

/**
* Default constructor
*/
public ServiceLdapInfo() {
this(Boolean.FALSE, null);
}

/**
* Constructor taking in values for supported and the configuration that can be
* used to determine if it is enabled for not.
*
* @param supported
* true if LDAP integration is supported; false otherwise
* @param ldapEnabledTest
* the configuration that can be used to determine if LDAP integration
* has been enabled
*/
public ServiceLdapInfo(Boolean supported, String ldapEnabledTest) {
this.supported = supported;
this.ldapEnabledTest = ldapEnabledTest;
}

/**
* Gets the value whether if the service supports LDAP integration.
* <p>
* <code>null</code> indicates the value was not set
*
* @return true if LDAP integration is supported; false if LDAP integration is
* not supported; null if not specified
*/
public Boolean getSupported() {
return supported;
}

/**
* Tests whether the service supports LDAP integration.
*
* @return true if LDAP integration is supported; false otherwise
*/
public boolean isSupported() {
return Boolean.TRUE.equals(supported);
}

/**
* Sets the value indicating whether the service supports LDAP integration.
*
* @param supported
* true if LDAP integration is supported; false if LDAP integration is
* not supported; null if not specified
*/
public void setSupported(Boolean supported) {
this.supported = supported;
}

/**
* Gets the configuration specification that can be used to determine if LDAP
* has been enabled or not.
*
* @return a configuration specification (a valid JSON predicate)
*/
public String getLdapEnabledTest() {
return ldapEnabledTest;
}

/**
* Sets the configuration specification that can be used to determine if LDAP
* has been enabled or not.
*
* @param ldapEnabledTest
* a configuration specification (a valid JSON predicate)
*/
public void setLdapEnabledTest(String ldapEnabledTest) {
this.ldapEnabledTest = ldapEnabledTest;
}

@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}

@Override
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}

@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}