|
@@ -21,12 +21,13 @@ import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.FileNotFoundException;
|
|
|
import java.io.IOException;
|
|
|
-import java.util.*;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Properties;
|
|
|
|
|
|
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.lang.StringUtils;
|
|
|
import org.apache.commons.logging.Log;
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
@@ -47,23 +48,34 @@ public class Configuration {
|
|
|
public static final String SRVR_KSTR_DIR_KEY = "security.server.keys_dir";
|
|
|
public static final String SRVR_CRT_NAME_KEY = "security.server.cert_name";
|
|
|
public static final String SRVR_KEY_NAME_KEY = "security.server.key_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 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_KEY = "security.server.crt_pass";
|
|
|
- public static final String PASSPHRASE_ENV_KEY = "security.server.passphrase_env_var";
|
|
|
+ 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 RESOURCES_DIR_KEY = "resources.dir";
|
|
|
|
|
|
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";
|
|
|
+ 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 = ".";
|
|
|
public static final String SRVR_CRT_NAME_DEFAULT = "ca.crt";
|
|
@@ -111,28 +123,39 @@ public class Configuration {
|
|
|
this.properties = properties;
|
|
|
|
|
|
configsMap = new HashMap<String, String>();
|
|
|
- configsMap.put(SRVR_KSTR_DIR_KEY, properties.getProperty(SRVR_KSTR_DIR_KEY, SRVR_KSTR_DIR_DEFAULT));
|
|
|
- configsMap.put(SRVR_KSTR_DIR_KEY, properties.getProperty(SRVR_KSTR_DIR_KEY, SRVR_KSTR_DIR_DEFAULT));
|
|
|
- configsMap.put(SRVR_CRT_NAME_KEY, properties.getProperty(SRVR_CRT_NAME_KEY, SRVR_CRT_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(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(LDAP_USER_DEFAULT_ROLE_KEY, properties.getProperty(LDAP_USER_DEFAULT_ROLE_KEY, LDAP_USER_DEFAULT_ROLE_DEFAULT));
|
|
|
- configsMap.put(RESOURCES_DIR_KEY, properties.getProperty(RESOURCES_DIR_KEY, RESOURCES_DIR_DEFAULT));
|
|
|
+ configsMap.put(SRVR_KSTR_DIR_KEY, properties.getProperty(
|
|
|
+ SRVR_KSTR_DIR_KEY, SRVR_KSTR_DIR_DEFAULT));
|
|
|
+ configsMap.put(SRVR_KSTR_DIR_KEY, properties.getProperty(
|
|
|
+ SRVR_KSTR_DIR_KEY, SRVR_KSTR_DIR_DEFAULT));
|
|
|
+ configsMap.put(SRVR_CRT_NAME_KEY, properties.getProperty(
|
|
|
+ SRVR_CRT_NAME_KEY, SRVR_CRT_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(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(LDAP_USER_DEFAULT_ROLE_KEY, properties.getProperty(
|
|
|
+ LDAP_USER_DEFAULT_ROLE_KEY, LDAP_USER_DEFAULT_ROLE_DEFAULT));
|
|
|
+ configsMap.put(RESOURCES_DIR_KEY, properties.getProperty(
|
|
|
+ RESOURCES_DIR_KEY, RESOURCES_DIR_DEFAULT));
|
|
|
try {
|
|
|
- File passFile = new File(configsMap.get(SRVR_KSTR_DIR_KEY) + File.separator
|
|
|
- + configsMap.get(SRVR_CRT_PASS_FILE_KEY));
|
|
|
- if (passFile.exists()) {
|
|
|
- String srvrCrtPass = FileUtils.readFileToString(passFile);
|
|
|
- configsMap.put(SRVR_CRT_PASS_KEY, srvrCrtPass.trim());
|
|
|
- } else {
|
|
|
- LOG.info("Not found pass file at " + passFile);
|
|
|
- }
|
|
|
- } catch (IOException e) {
|
|
|
+ File passFile = new File(configsMap.get(SRVR_KSTR_DIR_KEY) + File.separator
|
|
|
+ + configsMap.get(SRVR_CRT_PASS_FILE_KEY));
|
|
|
+ if (passFile.exists()) {
|
|
|
+ String srvrCrtPass = FileUtils.readFileToString(passFile);
|
|
|
+ configsMap.put(SRVR_CRT_PASS_KEY, srvrCrtPass.trim());
|
|
|
+ } else {
|
|
|
+ LOG.info("Not found pass file at " + passFile);
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
throw new RuntimeException("Error reading certificate password from file");
|
|
|
}
|
|
@@ -211,14 +234,23 @@ public class Configuration {
|
|
|
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));
|
|
|
+ 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;
|
|
|
}
|