mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Fixed bug: CLOUDSTACK-7214 added a config for ldap connection read timeout.
This commit is contained in:
parent
a7e3861f5e
commit
cd2f27a662
@ -22,13 +22,18 @@ import javax.inject.Inject;
|
|||||||
import javax.naming.directory.SearchControls;
|
import javax.naming.directory.SearchControls;
|
||||||
|
|
||||||
import org.apache.cloudstack.api.command.LdapListConfigurationCmd;
|
import org.apache.cloudstack.api.command.LdapListConfigurationCmd;
|
||||||
|
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||||
|
import org.apache.cloudstack.framework.config.Configurable;
|
||||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||||
|
|
||||||
import com.cloud.utils.Pair;
|
import com.cloud.utils.Pair;
|
||||||
|
|
||||||
public class LdapConfiguration {
|
public class LdapConfiguration implements Configurable{
|
||||||
private final static String factory = "com.sun.jndi.ldap.LdapCtxFactory";
|
private final static String factory = "com.sun.jndi.ldap.LdapCtxFactory";
|
||||||
|
|
||||||
|
private static final ConfigKey<Long> ldapReadTimeout = new ConfigKey<Long>(Long.class, "ldap.read.timeout", "Secure", "1000",
|
||||||
|
"LDAP connection Timeout in milli sec", true, ConfigKey.Scope.Global, 1l);
|
||||||
|
|
||||||
private final static int scope = SearchControls.SUBTREE_SCOPE;
|
private final static int scope = SearchControls.SUBTREE_SCOPE;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@ -148,4 +153,18 @@ public class LdapConfiguration {
|
|||||||
public String getCommonNameAttribute() {
|
public String getCommonNameAttribute() {
|
||||||
return "cn";
|
return "cn";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getReadTimeout() {
|
||||||
|
return ldapReadTimeout.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getConfigComponentName() {
|
||||||
|
return LdapConfiguration.class.getSimpleName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConfigKey<?>[] getConfigKeys() {
|
||||||
|
return new ConfigKey<?>[] {ldapReadTimeout};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ public class LdapContextFactory {
|
|||||||
|
|
||||||
environment.put(Context.INITIAL_CONTEXT_FACTORY, factory);
|
environment.put(Context.INITIAL_CONTEXT_FACTORY, factory);
|
||||||
environment.put(Context.PROVIDER_URL, url);
|
environment.put(Context.PROVIDER_URL, url);
|
||||||
environment.put("com.sun.jndi.ldap.read.timeout", "500");
|
environment.put("com.sun.jndi.ldap.read.timeout", _ldapConfiguration.getReadTimeout().toString());
|
||||||
environment.put("com.sun.jndi.ldap.connect.pool", "true");
|
environment.put("com.sun.jndi.ldap.connect.pool", "true");
|
||||||
|
|
||||||
enableSSL(environment);
|
enableSSL(environment);
|
||||||
|
|||||||
@ -16,12 +16,16 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package groovy.org.apache.cloudstack.ldap
|
package groovy.org.apache.cloudstack.ldap
|
||||||
|
|
||||||
|
import org.apache.cloudstack.framework.config.ConfigKey
|
||||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||||
import com.cloud.utils.Pair
|
import com.cloud.utils.Pair
|
||||||
import org.apache.cloudstack.api.ServerApiException
|
import org.apache.cloudstack.api.ServerApiException
|
||||||
|
import org.apache.cloudstack.framework.config.impl.ConfigDepotImpl
|
||||||
|
import org.apache.cloudstack.framework.config.impl.ConfigurationVO
|
||||||
import org.apache.cloudstack.ldap.LdapConfiguration
|
import org.apache.cloudstack.ldap.LdapConfiguration
|
||||||
import org.apache.cloudstack.ldap.LdapConfigurationVO
|
import org.apache.cloudstack.ldap.LdapConfigurationVO
|
||||||
import org.apache.cloudstack.ldap.LdapManager
|
import org.apache.cloudstack.ldap.LdapManager
|
||||||
|
import org.apache.cxf.common.util.StringUtils
|
||||||
|
|
||||||
import javax.naming.directory.SearchControls
|
import javax.naming.directory.SearchControls
|
||||||
|
|
||||||
@ -253,4 +257,27 @@ class LdapConfigurationSpec extends spock.lang.Specification {
|
|||||||
groupObject << [null, "", "uniquemember"]
|
groupObject << [null, "", "uniquemember"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def "Test getReadTimeout"() {
|
||||||
|
given: "We have configdao for ldap group object"
|
||||||
|
def configDao = Mock(ConfigurationDao)
|
||||||
|
ConfigurationVO configurationVo = new ConfigurationVO("ldap.read.timeout", LdapConfiguration.ldapReadTimeout);
|
||||||
|
configurationVo.setValue(timeout)
|
||||||
|
configDao.findById("ldap.read.timeout") >> configurationVo
|
||||||
|
|
||||||
|
def configDepotImpl = Mock(ConfigDepotImpl)
|
||||||
|
configDepotImpl.global() >> configDao
|
||||||
|
ConfigKey.init(configDepotImpl)
|
||||||
|
|
||||||
|
def ldapManger = Mock(LdapManager)
|
||||||
|
LdapConfiguration ldapConfiguration = new LdapConfiguration(configDao, ldapManger)
|
||||||
|
|
||||||
|
def expected = timeout == null ? 1000 : timeout.toLong() //1000 is the default value
|
||||||
|
|
||||||
|
def result = ldapConfiguration.getReadTimeout()
|
||||||
|
expect:
|
||||||
|
result == expected
|
||||||
|
where:
|
||||||
|
timeout << ["1000000", "1000", null]
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user