|
@@ -21,13 +21,12 @@ import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
-import java.net.URI;
|
|
|
|
-import java.net.URISyntaxException;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.Map;
|
|
|
|
-import java.util.Properties;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
+import org.apache.ambari.server.security.ClientSecurityType;
|
|
|
|
+import org.apache.ambari.server.security.authorization.LdapServerProperties;
|
|
import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.io.FileUtils;
|
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
|
@@ -41,8 +40,8 @@ import com.google.inject.Singleton;
|
|
@Singleton
|
|
@Singleton
|
|
public class Configuration {
|
|
public class Configuration {
|
|
|
|
|
|
- private static final String AMBARI_CONF_VAR = "AMBARI_CONF_DIR";
|
|
|
|
- private static final String CONFIG_FILE = "ambari.properties";
|
|
|
|
|
|
+ public static final String AMBARI_CONF_VAR = "AMBARI_CONF_DIR";
|
|
|
|
+ public static final String CONFIG_FILE = "ambari.properties";
|
|
public static final String BOOTSTRAP_DIR = "bootstrap.dir";
|
|
public static final String BOOTSTRAP_DIR = "bootstrap.dir";
|
|
public static final String BOOTSTRAP_SCRIPT = "bootstrap.script";
|
|
public static final String BOOTSTRAP_SCRIPT = "bootstrap.script";
|
|
public static final String SRVR_KSTR_DIR_KEY = "security.server.keys_dir";
|
|
public static final String SRVR_KSTR_DIR_KEY = "security.server.keys_dir";
|
|
@@ -51,14 +50,39 @@ public class Configuration {
|
|
public static final String KSTR_NAME_KEY = "security.server.keystore_name";
|
|
public static final String KSTR_NAME_KEY = "security.server.keystore_name";
|
|
public static final String SRVR_CRT_PASS_FILE_KEY = "security.server.crt_pass_file";
|
|
public static final String SRVR_CRT_PASS_FILE_KEY = "security.server.crt_pass_file";
|
|
public static final String SRVR_CRT_PASS_KEY = "security.server.crt_pass";
|
|
public static final String SRVR_CRT_PASS_KEY = "security.server.crt_pass";
|
|
|
|
+ public static final String PASSPHRASE_ENV_KEY = "security.server.passphrase_env_var";
|
|
|
|
+ public static final String PASSPHRASE_KEY = "security.server.passphrase";
|
|
|
|
+
|
|
public static final String CLIENT_SECURITY_KEY = "client.security";
|
|
public static final String CLIENT_SECURITY_KEY = "client.security";
|
|
|
|
+ public static final String LDAP_USE_SSL_KEY = "authorization.ldap.useSSL";
|
|
|
|
+ public static final String LDAP_PRIMARY_URL_KEY = "authorization.ldap.primaryUrl";
|
|
|
|
+ public static final String LDAP_SECONDARY_URL_KEY = "authorization.ldap.secondaryUrl";
|
|
|
|
+ public static final String LDAP_BASE_DN_KEY = "authorization.ldap.baseDn";
|
|
|
|
+ public static final String LDAP_BIND_ANONYMOUSLY_KEY = "authorization.ldap.bindAnonymously";
|
|
|
|
+ public static final String LDAP_MANAGER_DN_KEY = "authorization.ldap.managerDn";
|
|
|
|
+ public static final String LDAP_MANAGER_PASSWORD_KEY = "authorization.ldap.managerPassword";
|
|
|
|
+ public static final String LDAP_USERNAME_ATTRIBUTE_KEY = "authorization.ldap.usernameAttribute";
|
|
|
|
+ public static final String LDAP_USER_DEFAULT_ROLE_KEY = "authorization.ldap.userDefaultRole";
|
|
|
|
+
|
|
private static final String SRVR_KSTR_DIR_DEFAULT = ".";
|
|
private static final String SRVR_KSTR_DIR_DEFAULT = ".";
|
|
- private static final String SRVR_CRT_NAME_DEFAULT = "ca.crt";
|
|
|
|
- private static final String SRVR_KEY_NAME_DEFAULT = "ca.key";
|
|
|
|
- private static final String KSTR_NAME_DEFAULT = "keystore.p12";
|
|
|
|
|
|
+ public static final String SRVR_CRT_NAME_DEFAULT = "ca.crt";
|
|
|
|
+ public static final String SRVR_KEY_NAME_DEFAULT = "ca.key";
|
|
|
|
+ public static final String KSTR_NAME_DEFAULT = "keystore.p12";
|
|
private static final String SRVR_CRT_PASS_FILE_DEFAULT ="pass.txt";
|
|
private static final String SRVR_CRT_PASS_FILE_DEFAULT ="pass.txt";
|
|
|
|
+ private static final String PASSPHRASE_ENV_DEFAULT = "AMBARI_PASSPHRASE";
|
|
|
|
+
|
|
|
|
+
|
|
private static final String CLIENT_SECURITY_DEFAULT = "local";
|
|
private static final String CLIENT_SECURITY_DEFAULT = "local";
|
|
|
|
|
|
|
|
+ private static final String LDAP_USER_SEARCH_FILTER_DEFAULT = "({attribute}={0})";
|
|
|
|
+ private static final String LDAP_USER_DEFAULT_ROLE_DEFAULT = "user";
|
|
|
|
+ private static final String LDAP_BIND_ANONYMOUSLY_DEFAULT = "true";
|
|
|
|
+
|
|
|
|
+ //For embedded server only - should be removed later
|
|
|
|
+ private static final String LDAP_PRIMARY_URL_DEFAULT = "localhost:33389";
|
|
|
|
+ private static final String LDAP_BASE_DN_DEFAULT = "dc=ambari,dc=apache,dc=org";
|
|
|
|
+ private static final String LDAP_USERNAME_ATTRIBUTE_DEFAULT = "uid";
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -91,7 +115,11 @@ public class Configuration {
|
|
configsMap.put(SRVR_KEY_NAME_KEY, properties.getProperty(SRVR_KEY_NAME_KEY, SRVR_KEY_NAME_DEFAULT));
|
|
configsMap.put(SRVR_KEY_NAME_KEY, properties.getProperty(SRVR_KEY_NAME_KEY, SRVR_KEY_NAME_DEFAULT));
|
|
configsMap.put(KSTR_NAME_KEY, properties.getProperty(KSTR_NAME_KEY, KSTR_NAME_DEFAULT));
|
|
configsMap.put(KSTR_NAME_KEY, properties.getProperty(KSTR_NAME_KEY, KSTR_NAME_DEFAULT));
|
|
configsMap.put(SRVR_CRT_PASS_FILE_KEY, properties.getProperty(SRVR_CRT_PASS_FILE_KEY, SRVR_CRT_PASS_FILE_DEFAULT));
|
|
configsMap.put(SRVR_CRT_PASS_FILE_KEY, properties.getProperty(SRVR_CRT_PASS_FILE_KEY, SRVR_CRT_PASS_FILE_DEFAULT));
|
|
|
|
+
|
|
|
|
+ configsMap.put(PASSPHRASE_ENV_KEY, properties.getProperty(PASSPHRASE_ENV_KEY, PASSPHRASE_ENV_DEFAULT));
|
|
|
|
+ configsMap.put(PASSPHRASE_KEY, System.getenv(configsMap.get(PASSPHRASE_ENV_KEY)));
|
|
configsMap.put(CLIENT_SECURITY_KEY, properties.getProperty(CLIENT_SECURITY_KEY, CLIENT_SECURITY_DEFAULT));
|
|
configsMap.put(CLIENT_SECURITY_KEY, properties.getProperty(CLIENT_SECURITY_KEY, CLIENT_SECURITY_DEFAULT));
|
|
|
|
+ configsMap.put(LDAP_USER_DEFAULT_ROLE_KEY, properties.getProperty(LDAP_USER_DEFAULT_ROLE_KEY, LDAP_USER_DEFAULT_ROLE_DEFAULT));
|
|
|
|
|
|
try {
|
|
try {
|
|
File passFile = new File(configsMap.get(SRVR_KSTR_DIR_KEY) + File.separator
|
|
File passFile = new File(configsMap.get(SRVR_KSTR_DIR_KEY) + File.separator
|
|
@@ -116,7 +144,10 @@ public class Configuration {
|
|
Properties properties = new Properties();
|
|
Properties properties = new Properties();
|
|
|
|
|
|
// get the configuration directory and filename
|
|
// get the configuration directory and filename
|
|
- String confDir = System.getenv(AMBARI_CONF_VAR);
|
|
|
|
|
|
+
|
|
|
|
+ String confDir = System.getProperty(AMBARI_CONF_VAR);
|
|
|
|
+ if (confDir == null)
|
|
|
|
+ confDir = System.getenv(AMBARI_CONF_VAR);
|
|
if (confDir == null) {
|
|
if (confDir == null) {
|
|
confDir = "/etc/ambari";
|
|
confDir = "/etc/ambari";
|
|
}
|
|
}
|
|
@@ -159,4 +190,35 @@ public class Configuration {
|
|
return configsMap;
|
|
return configsMap;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Gets client security type
|
|
|
|
+ * @return appropriate ClientSecurityType
|
|
|
|
+ */
|
|
|
|
+ public ClientSecurityType getClientSecurityType() {
|
|
|
|
+ return ClientSecurityType.fromString(properties.getProperty(CLIENT_SECURITY_KEY));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setClientSecurityType(ClientSecurityType type) {
|
|
|
|
+ properties.setProperty(CLIENT_SECURITY_KEY, type.toString());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets parameters of LDAP server to connect to
|
|
|
|
+ * @return LdapServerProperties object representing connection parameters
|
|
|
|
+ */
|
|
|
|
+ public LdapServerProperties getLdapServerProperties() {
|
|
|
|
+ LdapServerProperties ldapServerProperties = new LdapServerProperties();
|
|
|
|
+
|
|
|
|
+ ldapServerProperties.setPrimaryUrl(properties.getProperty(LDAP_PRIMARY_URL_KEY, LDAP_PRIMARY_URL_DEFAULT));
|
|
|
|
+ ldapServerProperties.setSecondaryUrl(properties.getProperty(LDAP_SECONDARY_URL_KEY));
|
|
|
|
+ ldapServerProperties.setUseSsl("true".equalsIgnoreCase(properties.getProperty(LDAP_USE_SSL_KEY)));
|
|
|
|
+ ldapServerProperties.setAnonymousBind("true".equalsIgnoreCase(properties.getProperty(LDAP_BIND_ANONYMOUSLY_KEY, LDAP_BIND_ANONYMOUSLY_DEFAULT)));
|
|
|
|
+ ldapServerProperties.setManagerDn(properties.getProperty(LDAP_MANAGER_DN_KEY));
|
|
|
|
+ ldapServerProperties.setManagerPassword(properties.getProperty(LDAP_MANAGER_PASSWORD_KEY));
|
|
|
|
+ ldapServerProperties.setBaseDN(properties.getProperty(LDAP_BASE_DN_KEY, LDAP_BASE_DN_DEFAULT));
|
|
|
|
+ ldapServerProperties.setUsernameAttribute(properties.getProperty(LDAP_USERNAME_ATTRIBUTE_KEY, LDAP_USERNAME_ATTRIBUTE_DEFAULT));
|
|
|
|
+
|
|
|
|
+ return ldapServerProperties;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|