diff --git a/cachecloud-open-common/src/main/java/com/sohu/cache/util/ConstUtils.java b/cachecloud-open-common/src/main/java/com/sohu/cache/util/ConstUtils.java index e8c7257b..aad7d1e1 100644 --- a/cachecloud-open-common/src/main/java/com/sohu/cache/util/ConstUtils.java +++ b/cachecloud-open-common/src/main/java/com/sohu/cache/util/ConstUtils.java @@ -1,322 +1,328 @@ -package com.sohu.cache.util; - -import java.util.ArrayList; -import java.util.List; -import java.util.ResourceBundle; - -import com.sohu.cache.enums.SshAuthTypeEnum; - -/** - * cachecloud常量 - * @author leifu - * @Date 2016年3月1日 - * @Time 下午12:54:45 - */ -public class ConstUtils { - // cache的类型区分 - public static final int CACHE_TYPE_REDIS_CLUSTER = 2; - public static final int CACHE_REDIS_SENTINEL = 5; - public static final int CACHE_REDIS_STANDALONE = 6; - - // 数据源名称 - public static final String REDIS = "redis"; - public static final String MACHINE = "machine"; - - // redis job/trigger name/group - public static final String REDIS_JOB_NAME = "redisJob"; - public static final String REDIS_JOB_GROUP = "redis"; - public static final String REDIS_TRIGGER_GROUP = "redis-"; - - // machine job/trigger name/group - public static final String MACHINE_JOB_NAME = "machineJob"; - public static final String MACHINE_JOB_GROUP = "machine"; - public static final String MACHINE_TRIGGER_GROUP = "machine-"; - - // machine monitor job/trigger name/group - public static final String MACHINE_MONITOR_JOB_NAME = "machineMonitorJob"; - public static final String MACHINE_MONITOR_JOB_GROUP = "machineMonitor"; - public static final String MACHINE_MONITOR_TRIGGER_GROUP = "machineMonitor-"; - - - // redis-slowlog job/trigger name/group - public static final String REDIS_SLOWLOG_JOB_NAME = "redisSlowLogJob"; - public static final String REDIS_SLOWLOG_JOB_GROUP = "redisSlowLog"; - public static final String REDIS_SLOWLOG_TRIGGER_GROUP = "redisSlowLog-"; - - // 创建trigger时,dataMap的数据key - public static final String HOST_KEY = "host_key"; - public static final String PORT_KEY = "port_key"; - public static final String APP_KEY = "app_key"; - public static final String HOST_ID_KEY = "host_id_key"; - // server job/trigger name/group - public static final String SERVER_JOB_NAME = "serverJob"; - public static final String SERVER_JOB_GROUP = "server"; - public static final String SERVER_TRIGGER_GROUP = "server-"; - - //mysql收集数据的时间字段 - public static final String COLLECT_TIME = "CollectTime"; - - // 触发时间 - public static final String TRIGGER_TIME_KEY = "trigger_time_key"; - - // 容量转换 - public static final int _1024 = 1024; - - // 表示空字符串 - public static final String EMPTY = ""; - - /** - * 服务端版本 - */ - public static final String CACHECLOUD_VERSION = "master"; - - /** - * 机器报警阀值 - */ - public static double DEFAULT_CPU_USAGE_RATIO_THRESHOLD = 80.0; - public static double CPU_USAGE_RATIO_THRESHOLD = DEFAULT_CPU_USAGE_RATIO_THRESHOLD; - - - public static double DEFAULT_MEMORY_USAGE_RATIO_THRESHOLD = 80.0; - public static double MEMORY_USAGE_RATIO_THRESHOLD = DEFAULT_MEMORY_USAGE_RATIO_THRESHOLD; - - public static double DEFAULT_LOAD_THRESHOLD = 8.0; - public static double LOAD_THRESHOLD = DEFAULT_LOAD_THRESHOLD; - - /** - * 应用客户端连接数报警阀值 - */ - public static int DEFAULT_APP_CLIENT_CONN_THRESHOLD = 2000; - public static int APP_CLIENT_CONN_THRESHOLD = DEFAULT_APP_CLIENT_CONN_THRESHOLD; - - /** - * 机器统一的用户名、密码、端口 - */ - public static String DEFAULT_USERNAME = "cachecloud"; - public static String USERNAME = DEFAULT_USERNAME; - - public static String DEFAULT_PASSWORD = "cachecloud"; - public static String PASSWORD = DEFAULT_PASSWORD; - - public static int DEFAULT_SSH_PORT_DEFAULT = 22; - public static int SSH_PORT_DEFAULT = DEFAULT_SSH_PORT_DEFAULT; - - - /** - * 管理员相关 - */ - public static String DEFAULT_SUPER_ADMIN_NAME = "admin"; - public static String SUPER_ADMIN_NAME = DEFAULT_SUPER_ADMIN_NAME; - - public static String DEFAULT_SUPER_ADMIN_PASS = "admin"; - public static String SUPER_ADMIN_PASS = DEFAULT_SUPER_ADMIN_PASS; - - public static String DEFAULT_SUPER_ADMINS="admin"; - public static String SUPER_ADMINS = DEFAULT_SUPER_ADMINS; - - public static List SUPER_MANAGER; - - /** - * ldap登陆 - */ - public static String DEFAULT_LDAP_URL = EMPTY; - public static String LDAP_URL = DEFAULT_LDAP_URL; - - /** - * 登陆邮箱后缀 - */ - public static String EMAIL_SUFFIX = ""; - - /** - * 是否为调试 - */ - public static boolean IS_DEBUG; - - /** - * 联系人 - */ - public static String DEFAULT_CONTACT = "user1:(xx@zz.com, user1:135xxxxxxxx)
user2: (user2@zz.com, user2:138xxxxxxxx)"; - public static String CONTACT = DEFAULT_CONTACT; - - - /** - * 文档地址 - */ - public static String DEFAULT_DOCUMENT_URL = "http://cachecloud.github.io"; - public static String DOCUMENT_URL = DEFAULT_DOCUMENT_URL; - - /** - * 报警相关 - */ - public static String DEFAULT_EMAILS = "xx@sohu.com,yy@qq.com"; - public static String EMAILS = DEFAULT_EMAILS; - - public static String DEFAULT_PHONES = "13812345678,13787654321"; - public static String PHONES = DEFAULT_PHONES; - - /** - * 邮箱报警接口 - */ - public static String DEFAULT_EMAIL_ALERT_INTERFACE = EMPTY; - public static String EMAIL_ALERT_INTERFACE = DEFAULT_EMAIL_ALERT_INTERFACE; - - /** - * 短信报警接口 - */ - public static String DEFAULT_MOBILE_ALERT_INTERFACE = EMPTY; - public static String MOBILE_ALERT_INTERFACE = DEFAULT_MOBILE_ALERT_INTERFACE; - - /** - * maven仓库地址 - */ - public static String DEFAULT_MAVEN_WAREHOUSE = "http://your_maven_house"; - public static String MAVEN_WAREHOUSE = DEFAULT_MAVEN_WAREHOUSE; - - - /** - * 客户端可用版本 - */ - public static String DEFAULT_GOOD_CLIENT_VERSIONS = "1.0-SNAPSHOT"; - public static String GOOD_CLIENT_VERSIONS = DEFAULT_GOOD_CLIENT_VERSIONS; - - /** - * 客户端警告版本 - */ - public static String DEFAULT_WARN_CLIENT_VERSIONS = "0.1"; - public static String WARN_CLIENT_VERSIONS = DEFAULT_WARN_CLIENT_VERSIONS; - - - /** - * 客户端错误版本 - */ - public static String DEFAULT_ERROR_CLIENT_VERSIONS = "0.0"; - public static String ERROR_CLIENT_VERSIONS = DEFAULT_ERROR_CLIENT_VERSIONS; - - /** - * redis-migrate-tool相关路径 - */ - public static String DEFAULT_REDIS_MIGRATE_TOOL_HOME = "/opt/cachecloud/redis-migrate-tool/"; - public static String REDIS_MIGRATE_TOOL_HOME = DEFAULT_REDIS_MIGRATE_TOOL_HOME; - - public static String getRedisMigrateToolCmd() { - return REDIS_MIGRATE_TOOL_HOME + "src/redis-migrate-tool"; - } - - public static String getRedisMigrateToolDir() { - return REDIS_MIGRATE_TOOL_HOME + "data/"; - } - - /** - * redis-migrate-tool端口 - */ - public static int REDIS_MIGRATE_TOOL_PORT = 8888; - - /** - * 1是session,2是cookie(参考UserLoginTypeEnum) - */ - public static int DEFAULT_USER_LOGIN_TYPE = 1; - public static int USER_LOGIN_TYPE = DEFAULT_USER_LOGIN_TYPE; - - /** - * cookie登录方式所需要的域 - */ - public static String DEFAULT_COOKIE_DOMAIN = EMPTY; - public static String COOKIE_DOMAIN = DEFAULT_COOKIE_DOMAIN; - - /** - * cachecloud根目录,这个要与cachecloud-init.sh脚本中的目录一致 - */ - public static String DEFAULT_CACHECLOUD_BASE_DIR = "/opt"; - public static String CACHECLOUD_BASE_DIR = DEFAULT_CACHECLOUD_BASE_DIR; - - /** - * MNON_DIR根目录 - */ - public static String DEFAULT_NMON_DIR = "/opt/cachecloud"; - public static String NMON_DIR = DEFAULT_NMON_DIR; - - /** - * 是否定期清理各种统计数据:(详见CleanUpStatisticsJob) - */ - public static boolean DEFAULT_WHETHER_SCHEDULE_CLEAN_DATA = false; - public static boolean WHETHER_SCHEDULE_CLEAN_DATA = DEFAULT_WHETHER_SCHEDULE_CLEAN_DATA; - - - /** - * appkey秘钥 - */ - public static String DEFAULT_APP_SECRET_BASE_KEY = "cachecloud-2014"; - public static String APP_SECRET_BASE_KEY = DEFAULT_APP_SECRET_BASE_KEY; - - - /** - * 机器性能统计周期(分钟) - */ - public static int DEFAULT_MACHINE_STATS_CRON_MINUTE = 1; - public static int MACHINE_STATS_CRON_MINUTE = DEFAULT_MACHINE_STATS_CRON_MINUTE; - - - /** - * ssh授权方式:参考SshAuthTypeEnum - */ - public static int DEFAULT_SSH_AUTH_TYPE = SshAuthTypeEnum.PASSWORD.getValue(); - public static int SSH_AUTH_TYPE = DEFAULT_SSH_AUTH_TYPE; - - /** - * public key pem - */ - public static String DEFAULT_PUBLIC_KEY_PEM = ""; - public static String PUBLIC_KEY_PEM = DEFAULT_PUBLIC_KEY_PEM; - - /** - * 网站域名 - */ - public static final String CC_DOMAIN = "http://your.domain.com"; - - /** - * 领导邮件 - */ - public static List LEADER_EMAIL_LIST = new ArrayList(); - static { - } - - static { - ResourceBundle applicationResourceBundle = ResourceBundle.getBundle("application"); - IS_DEBUG = "true".equals(applicationResourceBundle.getString("isDebug")); - } - - /** - * 逗号 - */ - public static final String COMMA = ","; - - /** - * 换行 - */ - public static final String NEXT_LINE = "\n"; - - /** - * 空格 - */ - public static final String SPACE = " "; - - - /** - * 冒号 - */ - public static final String COLON = ":"; - - - /** - * 内部错误 - */ - public static final String INNER_ERROR = "cachecloud_inner_error"; - - /** - * 登录跳转参数 - */ - public final static String RREDIRECT_URL_PARAM = "redirectUrl"; - -} - - +package com.sohu.cache.util; + +import java.util.ArrayList; +import java.util.List; +import java.util.ResourceBundle; + +import com.sohu.cache.enums.SshAuthTypeEnum; + +/** + * cachecloud常量 + * @author leifu + * @Date 2016年3月1日 + * @Time 下午12:54:45 + */ +public class ConstUtils { + // cache的类型区分 + public static final int CACHE_TYPE_REDIS_CLUSTER = 2; + public static final int CACHE_REDIS_SENTINEL = 5; + public static final int CACHE_REDIS_STANDALONE = 6; + + // 数据源名称 + public static final String REDIS = "redis"; + public static final String MACHINE = "machine"; + + // redis job/trigger name/group + public static final String REDIS_JOB_NAME = "redisJob"; + public static final String REDIS_JOB_GROUP = "redis"; + public static final String REDIS_TRIGGER_GROUP = "redis-"; + + // machine job/trigger name/group + public static final String MACHINE_JOB_NAME = "machineJob"; + public static final String MACHINE_JOB_GROUP = "machine"; + public static final String MACHINE_TRIGGER_GROUP = "machine-"; + + // machine monitor job/trigger name/group + public static final String MACHINE_MONITOR_JOB_NAME = "machineMonitorJob"; + public static final String MACHINE_MONITOR_JOB_GROUP = "machineMonitor"; + public static final String MACHINE_MONITOR_TRIGGER_GROUP = "machineMonitor-"; + + + // redis-slowlog job/trigger name/group + public static final String REDIS_SLOWLOG_JOB_NAME = "redisSlowLogJob"; + public static final String REDIS_SLOWLOG_JOB_GROUP = "redisSlowLog"; + public static final String REDIS_SLOWLOG_TRIGGER_GROUP = "redisSlowLog-"; + + // 创建trigger时,dataMap的数据key + public static final String HOST_KEY = "host_key"; + public static final String PORT_KEY = "port_key"; + public static final String APP_KEY = "app_key"; + public static final String HOST_ID_KEY = "host_id_key"; + // server job/trigger name/group + public static final String SERVER_JOB_NAME = "serverJob"; + public static final String SERVER_JOB_GROUP = "server"; + public static final String SERVER_TRIGGER_GROUP = "server-"; + + //mysql收集数据的时间字段 + public static final String COLLECT_TIME = "CollectTime"; + + // 触发时间 + public static final String TRIGGER_TIME_KEY = "trigger_time_key"; + + // 容量转换 + public static final int _1024 = 1024; + + // 表示空字符串 + public static final String EMPTY = ""; + + /** + * 服务端版本 + */ + public static final String CACHECLOUD_VERSION = "master"; + + /** + * 机器报警阀值 + */ + public static double DEFAULT_CPU_USAGE_RATIO_THRESHOLD = 80.0; + public static double CPU_USAGE_RATIO_THRESHOLD = DEFAULT_CPU_USAGE_RATIO_THRESHOLD; + + + public static double DEFAULT_MEMORY_USAGE_RATIO_THRESHOLD = 80.0; + public static double MEMORY_USAGE_RATIO_THRESHOLD = DEFAULT_MEMORY_USAGE_RATIO_THRESHOLD; + + public static double DEFAULT_LOAD_THRESHOLD = 8.0; + public static double LOAD_THRESHOLD = DEFAULT_LOAD_THRESHOLD; + + /** + * 应用客户端连接数报警阀值 + */ + public static int DEFAULT_APP_CLIENT_CONN_THRESHOLD = 2000; + public static int APP_CLIENT_CONN_THRESHOLD = DEFAULT_APP_CLIENT_CONN_THRESHOLD; + + /** + * 机器统一的用户名、密码、端口 + */ + public static String DEFAULT_USERNAME = "cachecloud"; + public static String USERNAME = DEFAULT_USERNAME; + + public static String DEFAULT_PASSWORD = "cachecloud"; + public static String PASSWORD = DEFAULT_PASSWORD; + + public static int DEFAULT_SSH_PORT_DEFAULT = 22; + public static int SSH_PORT_DEFAULT = DEFAULT_SSH_PORT_DEFAULT; + + + /** + * 管理员相关 + */ + public static String DEFAULT_SUPER_ADMIN_NAME = "admin"; + public static String SUPER_ADMIN_NAME = DEFAULT_SUPER_ADMIN_NAME; + + public static String DEFAULT_SUPER_ADMIN_PASS = "admin"; + public static String SUPER_ADMIN_PASS = DEFAULT_SUPER_ADMIN_PASS; + + public static String DEFAULT_SUPER_ADMINS="admin"; + public static String SUPER_ADMINS = DEFAULT_SUPER_ADMINS; + + public static List SUPER_MANAGER; + + /** + * ldap登陆 + */ + public static String DEFAULT_LDAP_URL = EMPTY; + public static String LDAP_URL = DEFAULT_LDAP_URL; + public static String DEFAULT_LDAP_BASEDN = EMPTY; + public static String LDAP_BASEDN = DEFAULT_LDAP_BASEDN; + public static String DEFAULT_LDAP_BINDDN = EMPTY; + public static String LDAP_BINDDN = DEFAULT_LDAP_BINDDN; + public static String DEFAULT_LDAP_BINDDN_PASSWORD = EMPTY; + public static String LDAP_BINDDN_PASSWORD = DEFAULT_LDAP_BINDDN_PASSWORD; + + /** + * 登陆邮箱后缀 + */ + public static String EMAIL_SUFFIX = ""; + + /** + * 是否为调试 + */ + public static boolean IS_DEBUG; + + /** + * 联系人 + */ + public static String DEFAULT_CONTACT = "user1:(xx@zz.com, user1:135xxxxxxxx)
user2: (user2@zz.com, user2:138xxxxxxxx)"; + public static String CONTACT = DEFAULT_CONTACT; + + + /** + * 文档地址 + */ + public static String DEFAULT_DOCUMENT_URL = "http://cachecloud.github.io"; + public static String DOCUMENT_URL = DEFAULT_DOCUMENT_URL; + + /** + * 报警相关 + */ + public static String DEFAULT_EMAILS = "xx@sohu.com,yy@qq.com"; + public static String EMAILS = DEFAULT_EMAILS; + + public static String DEFAULT_PHONES = "13812345678,13787654321"; + public static String PHONES = DEFAULT_PHONES; + + /** + * 邮箱报警接口 + */ + public static String DEFAULT_EMAIL_ALERT_INTERFACE = EMPTY; + public static String EMAIL_ALERT_INTERFACE = DEFAULT_EMAIL_ALERT_INTERFACE; + + /** + * 短信报警接口 + */ + public static String DEFAULT_MOBILE_ALERT_INTERFACE = EMPTY; + public static String MOBILE_ALERT_INTERFACE = DEFAULT_MOBILE_ALERT_INTERFACE; + + /** + * maven仓库地址 + */ + public static String DEFAULT_MAVEN_WAREHOUSE = "http://your_maven_house"; + public static String MAVEN_WAREHOUSE = DEFAULT_MAVEN_WAREHOUSE; + + + /** + * 客户端可用版本 + */ + public static String DEFAULT_GOOD_CLIENT_VERSIONS = "1.0-SNAPSHOT"; + public static String GOOD_CLIENT_VERSIONS = DEFAULT_GOOD_CLIENT_VERSIONS; + + /** + * 客户端警告版本 + */ + public static String DEFAULT_WARN_CLIENT_VERSIONS = "0.1"; + public static String WARN_CLIENT_VERSIONS = DEFAULT_WARN_CLIENT_VERSIONS; + + + /** + * 客户端错误版本 + */ + public static String DEFAULT_ERROR_CLIENT_VERSIONS = "0.0"; + public static String ERROR_CLIENT_VERSIONS = DEFAULT_ERROR_CLIENT_VERSIONS; + + /** + * redis-migrate-tool相关路径 + */ + public static String DEFAULT_REDIS_MIGRATE_TOOL_HOME = "/opt/cachecloud/redis-migrate-tool/"; + public static String REDIS_MIGRATE_TOOL_HOME = DEFAULT_REDIS_MIGRATE_TOOL_HOME; + + public static String getRedisMigrateToolCmd() { + return REDIS_MIGRATE_TOOL_HOME + "src/redis-migrate-tool"; + } + + public static String getRedisMigrateToolDir() { + return REDIS_MIGRATE_TOOL_HOME + "data/"; + } + + /** + * redis-migrate-tool端口 + */ + public static int REDIS_MIGRATE_TOOL_PORT = 8888; + + /** + * 1是session,2是cookie(参考UserLoginTypeEnum) + */ + public static int DEFAULT_USER_LOGIN_TYPE = 1; + public static int USER_LOGIN_TYPE = DEFAULT_USER_LOGIN_TYPE; + + /** + * cookie登录方式所需要的域 + */ + public static String DEFAULT_COOKIE_DOMAIN = EMPTY; + public static String COOKIE_DOMAIN = DEFAULT_COOKIE_DOMAIN; + + /** + * cachecloud根目录,这个要与cachecloud-init.sh脚本中的目录一致 + */ + public static String DEFAULT_CACHECLOUD_BASE_DIR = "/opt"; + public static String CACHECLOUD_BASE_DIR = DEFAULT_CACHECLOUD_BASE_DIR; + + /** + * MNON_DIR根目录 + */ + public static String DEFAULT_NMON_DIR = "/opt/cachecloud"; + public static String NMON_DIR = DEFAULT_NMON_DIR; + + /** + * 是否定期清理各种统计数据:(详见CleanUpStatisticsJob) + */ + public static boolean DEFAULT_WHETHER_SCHEDULE_CLEAN_DATA = false; + public static boolean WHETHER_SCHEDULE_CLEAN_DATA = DEFAULT_WHETHER_SCHEDULE_CLEAN_DATA; + + + /** + * appkey秘钥 + */ + public static String DEFAULT_APP_SECRET_BASE_KEY = "cachecloud-2014"; + public static String APP_SECRET_BASE_KEY = DEFAULT_APP_SECRET_BASE_KEY; + + + /** + * 机器性能统计周期(分钟) + */ + public static int DEFAULT_MACHINE_STATS_CRON_MINUTE = 1; + public static int MACHINE_STATS_CRON_MINUTE = DEFAULT_MACHINE_STATS_CRON_MINUTE; + + + /** + * ssh授权方式:参考SshAuthTypeEnum + */ + public static int DEFAULT_SSH_AUTH_TYPE = SshAuthTypeEnum.PASSWORD.getValue(); + public static int SSH_AUTH_TYPE = DEFAULT_SSH_AUTH_TYPE; + + /** + * public key pem + */ + public static String DEFAULT_PUBLIC_KEY_PEM = ""; + public static String PUBLIC_KEY_PEM = DEFAULT_PUBLIC_KEY_PEM; + + /** + * 网站域名 + */ + public static final String CC_DOMAIN = "http://your.domain.com"; + + /** + * 领导邮件 + */ + public static List LEADER_EMAIL_LIST = new ArrayList(); + static { + } + + static { + ResourceBundle applicationResourceBundle = ResourceBundle.getBundle("application"); + IS_DEBUG = "true".equals(applicationResourceBundle.getString("isDebug")); + } + + /** + * 逗号 + */ + public static final String COMMA = ","; + + /** + * 换行 + */ + public static final String NEXT_LINE = "\n"; + + /** + * 空格 + */ + public static final String SPACE = " "; + + + /** + * 冒号 + */ + public static final String COLON = ":"; + + + /** + * 内部错误 + */ + public static final String INNER_ERROR = "cachecloud_inner_error"; + + /** + * 登录跳转参数 + */ + public final static String RREDIRECT_URL_PARAM = "redirectUrl"; + +} + + diff --git a/cachecloud-open-common/src/main/java/com/sohu/cache/web/util/LoginUtil.java b/cachecloud-open-common/src/main/java/com/sohu/cache/web/util/LoginUtil.java index fe06143c..7582a980 100644 --- a/cachecloud-open-common/src/main/java/com/sohu/cache/web/util/LoginUtil.java +++ b/cachecloud-open-common/src/main/java/com/sohu/cache/web/util/LoginUtil.java @@ -1,60 +1,138 @@ -package com.sohu.cache.web.util; - -import java.util.Hashtable; - -import javax.naming.directory.DirContext; -import javax.naming.directory.InitialDirContext; - -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.sohu.cache.util.ConstUtils; - -/** - * 域账户LDAP登陆简单工具 - * - * @author leifu - * @Time 2014年6月12日 - */ -public class LoginUtil { - - private final static Logger logger = LoggerFactory.getLogger(LoginUtil.class); - - public static boolean passportCheck(String username, String password) { - //LDAP登陆地址 - String ldapUrl = ConstUtils.LDAP_URL; - if (StringUtils.isBlank(ldapUrl)) { - logger.warn("ldap url is empty!!"); - return true; - } - if (ConstUtils.IS_DEBUG) { - logger.warn("isDebug=true return"); - return true; - } - Hashtable env = new Hashtable(); - env.put("java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory"); - env.put("java.naming.provider.url", ldapUrl); - env.put("java.naming.security.authentication", "simple"); - env.put("java.naming.security.principal", username + ConstUtils.EMAIL_SUFFIX); - env.put("java.naming.security.credentials", password); - DirContext ctx = null; - try { - ctx = new InitialDirContext(env); - if (ctx != null) { - return true; - } - } catch (Exception e) { - logger.error("username {} passportCheck: " + e.getMessage(), username, e); - } finally { - if (ctx != null) { - try { - ctx.close(); - } catch (Exception e) { - logger.error(e.getMessage(), e); - } - } - } - return false; - } -} +package com.sohu.cache.web.util; + +import java.util.Hashtable; + +import javax.naming.NamingEnumeration; +import javax.naming.directory.DirContext; +import javax.naming.directory.InitialDirContext; +import javax.naming.directory.SearchControls; +import javax.naming.directory.SearchResult; + +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.sohu.cache.util.ConstUtils; + +/** + * * 域账户LDAP登陆简单工具 + * * + * * @author leifu + * * @Time 2014年6月12日 + */ +public class LoginUtil { + + private final static Logger logger = LoggerFactory.getLogger(LoginUtil.class); + + public static boolean passportCheck(String username, String password) { + + logger.info(username + "登录尝试"); + String ldapUrl = ConstUtils.LDAP_URL; + String ldapBaseDN = ConstUtils.LDAP_BASEDN; + String ldapBindDN = ConstUtils.LDAP_BINDDN; + String ldapBindPassword = ConstUtils.LDAP_BINDDN_PASSWORD; + if (StringUtils.isBlank(ldapUrl)) { + logger.warn("ldap url is empty!!"); + return true; + } else if (StringUtils.isBlank(ldapBaseDN)) { + logger.warn("ldap baseDN is empty!!, baseDN={}", ldapBaseDN); + return false; + } + if (ConstUtils.IS_DEBUG) { + logger.warn("isDebug=true return"); + return true; + } + Hashtable env = new Hashtable(); + env.put("java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory"); + env.put("java.naming.provider.url", ldapUrl); + env.put("java.naming.security.authentication", "simple"); + if (StringUtils.isNotBlank(ldapBindDN)) { + env.put("java.naming.security.principal", ldapBindDN); + env.put("java.naming.security.credentials", ldapBindPassword); + } else { + env.put("java.naming.security.principal", username + ldapBaseDN); + env.put("java.naming.security.credentials", password); + } + DirContext ctx = null; + try { + ctx = new InitialDirContext(env); + if (ctx != null) { + if (StringUtils.isBlank(ldapBindDN)) { + return true; + } + String prefix = "uid="; + String uid = prefix + username; + String userDN = getUserDN(uid, ctx, ldapBaseDN); + return authenricate(username, userDN, password); + } + } catch (Exception e) { + logger.error("username {} passportCheck: " + e.getMessage(), username, e); + } finally { + if (ctx != null) { + try { + ctx.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + } + } + return false; + } + + public static String getUserDN(String uid, DirContext ctx, String baseDN) { + String userDN = ""; + try { + SearchControls sc = new SearchControls(); + sc.setSearchScope(SearchControls.SUBTREE_SCOPE); + logger.info("uid={}", uid); + NamingEnumeration en = ctx.search(baseDN, uid, sc); + if (en == null || !en.hasMoreElements()) { + logger.warn("未找到该用户"); + } + while (en != null && en.hasMoreElements()) { + Object obj = en.nextElement(); + if (obj instanceof SearchResult) { + SearchResult si = (SearchResult) obj; + userDN = si.getName() + "," + baseDN; + logger.info("userDN={}", userDN); + } else { + logger.warn(obj.toString()); + } + } + } catch (Exception e) { + logger.warn("查找用户时产生异常。"); + e.printStackTrace(); + } + + return userDN; + } + + public static boolean authenricate(String UID, String userDN, String password) { + boolean valide = false; + DirContext ctx = null; + try { + Hashtable env = new Hashtable(); + env.put("java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory"); + env.put("java.naming.provider.url", ConstUtils.LDAP_URL); + env.put("java.naming.security.authentication", "simple"); + env.put("java.naming.security.principal", userDN); + env.put("java.naming.security.credentials", password); + ctx = new InitialDirContext(env); + logger.info("username {} 验证通过 ", UID); + valide = true; + } catch (Exception e) { + logger.error("username {} 验证失败 ", UID, e); + valide = false; + } finally { + if (ctx != null) { + try { + ctx.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + } + } + + return valide; + } +} diff --git a/cachecloud-open-web/src/main/java/com/sohu/cache/web/service/impl/ConfigServiceImpl.java b/cachecloud-open-web/src/main/java/com/sohu/cache/web/service/impl/ConfigServiceImpl.java index d5d5cc73..81fc8803 100644 --- a/cachecloud-open-web/src/main/java/com/sohu/cache/web/service/impl/ConfigServiceImpl.java +++ b/cachecloud-open-web/src/main/java/com/sohu/cache/web/service/impl/ConfigServiceImpl.java @@ -1,233 +1,245 @@ -package com.sohu.cache.web.service.impl; - -import java.util.Arrays; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import org.apache.commons.collections.MapUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.sohu.cache.constant.UserLoginTypeEnum; -import com.sohu.cache.dao.ConfigDao; -import com.sohu.cache.entity.SystemConfig; -import com.sohu.cache.util.ConstUtils; -import com.sohu.cache.web.enums.SuccessEnum; -import com.sohu.cache.web.service.ConfigService; - -/** - * @author leifu - * @Date 2016年5月23日 - * @Time 上午10:35:26 - */ -public class ConfigServiceImpl implements ConfigService { - - private Logger logger = LoggerFactory.getLogger(ConfigServiceImpl.class); - - private ConfigDao configDao; - - public void init() { - reloadSystemConfig(); - } - - /** - * 加载配置 - */ - public void reloadSystemConfig() { - logger.info("===========ConfigServiceImpl reload config start============"); - // 加载配置 - Map configMap = getConfigMap(); - - // 文案相关 - ConstUtils.CONTACT = MapUtils.getString(configMap, "cachecloud.contact", ConstUtils.DEFAULT_CONTACT); - logger.info("{}: {}", "ConstUtils.CONTACT", ConstUtils.CONTACT); - - ConstUtils.DOCUMENT_URL = MapUtils.getString(configMap, "cachecloud.documentUrl", - ConstUtils.DEFAULT_DOCUMENT_URL); - logger.info("{}: {}", "ConstUtils.DOCUMENT_URL", ConstUtils.DOCUMENT_URL); - - - ConstUtils.MAVEN_WAREHOUSE = MapUtils.getString(configMap, "cachecloud.mavenWareHouse", - ConstUtils.DEFAULT_MAVEN_WAREHOUSE); - logger.info("{}: {}", "ConstUtils.MAVEN_WAREHOUSE", ConstUtils.MAVEN_WAREHOUSE); - - - // 报警相关配置 - ConstUtils.EMAILS = MapUtils.getString(configMap, "cachecloud.owner.email", ConstUtils.DEFAULT_EMAILS); - logger.info("{}: {}", "ConstUtils.EMAILS", ConstUtils.EMAILS); - - ConstUtils.PHONES = MapUtils.getString(configMap, "cachecloud.owner.phone", ConstUtils.DEFAULT_PHONES); - logger.info("{}: {}", "ConstUtils.PHONES", ConstUtils.PHONES); - - - // ssh相关配置 - ConstUtils.USERNAME = MapUtils.getString(configMap, "cachecloud.machine.ssh.name", ConstUtils.DEFAULT_USERNAME); - logger.info("{}: {}", "ConstUtils.USERNAME", ConstUtils.USERNAME); - - - ConstUtils.PASSWORD = MapUtils.getString(configMap, "cachecloud.machine.ssh.password", - ConstUtils.DEFAULT_PASSWORD); - logger.info("{}: {}", "ConstUtils.PASSWORD", ConstUtils.PASSWORD); - - - ConstUtils.SSH_PORT_DEFAULT = Integer.parseInt(MapUtils.getString(configMap, "cachecloud.machine.ssh.port", - String.valueOf(ConstUtils.DEFAULT_SSH_PORT_DEFAULT))); - logger.info("{}: {}", "ConstUtils.SSH_PORT_DEFAULT", ConstUtils.SSH_PORT_DEFAULT); - - - // 管理员相关配置 - ConstUtils.SUPER_ADMIN_NAME = MapUtils.getString(configMap, "cachecloud.admin.user.name", - ConstUtils.DEFAULT_SUPER_ADMIN_NAME); - logger.info("{}: {}", "ConstUtils.SUPER_ADMIN_NAME", ConstUtils.SUPER_ADMIN_NAME); - - - ConstUtils.SUPER_ADMIN_PASS = MapUtils.getString(configMap, "cachecloud.admin.user.password", - ConstUtils.DEFAULT_SUPER_ADMIN_PASS); - logger.info("{}: {}", "ConstUtils.SUPER_ADMIN_PASS", ConstUtils.SUPER_ADMIN_PASS); - - - ConstUtils.SUPER_ADMINS = MapUtils.getString(configMap, "cachecloud.superAdmin", - ConstUtils.DEFAULT_SUPER_ADMINS); - logger.info("{}: {}", "ConstUtils.SUPER_ADMINS", ConstUtils.SUPER_ADMINS); - - - ConstUtils.SUPER_MANAGER = Arrays.asList(ConstUtils.SUPER_ADMINS.split(",")); - logger.info("{}: {}", "ConstUtils.SUPER_MANAGER", ConstUtils.SUPER_MANAGER); - - - // 机器报警阀值 - ConstUtils.CPU_USAGE_RATIO_THRESHOLD = MapUtils.getDoubleValue(configMap, "machine.cpu.alert.ratio", - ConstUtils.DEFAULT_CPU_USAGE_RATIO_THRESHOLD); - logger.info("{}: {}", "ConstUtils.CPU_USAGE_RATIO_THRESHOLD", ConstUtils.CPU_USAGE_RATIO_THRESHOLD); - - ConstUtils.MEMORY_USAGE_RATIO_THRESHOLD = MapUtils.getDoubleValue(configMap, "machine.mem.alert.ratio", - ConstUtils.DEFAULT_MEMORY_USAGE_RATIO_THRESHOLD); - logger.info("{}: {}", "ConstUtils.MEMORY_USAGE_RATIO_THRESHOLD", ConstUtils.MEMORY_USAGE_RATIO_THRESHOLD); - - ConstUtils.LOAD_THRESHOLD = MapUtils.getDoubleValue(configMap, "machine.load.alert.ratio", - ConstUtils.DEFAULT_LOAD_THRESHOLD); - logger.info("{}: {}", "ConstUtils.LOAD_THRESHOLD", ConstUtils.LOAD_THRESHOLD); - - - - // 客户端版本 - ConstUtils.GOOD_CLIENT_VERSIONS = MapUtils.getString(configMap, "cachecloud.good.client", - ConstUtils.DEFAULT_GOOD_CLIENT_VERSIONS); - logger.info("{}: {}", "ConstUtils.GOOD_CLIENT_VERSIONS", ConstUtils.GOOD_CLIENT_VERSIONS); - - ConstUtils.WARN_CLIENT_VERSIONS = MapUtils.getString(configMap, "cachecloud.warn.client", - ConstUtils.DEFAULT_WARN_CLIENT_VERSIONS); - logger.info("{}: {}", "ConstUtils.WARN_CLIENT_VERSIONS", ConstUtils.WARN_CLIENT_VERSIONS); - - ConstUtils.ERROR_CLIENT_VERSIONS = MapUtils.getString(configMap, "cachecloud.error.client", - ConstUtils.DEFAULT_ERROR_CLIENT_VERSIONS); - logger.info("{}: {}", "ConstUtils.ERROR_CLIENT_VERSIONS", ConstUtils.ERROR_CLIENT_VERSIONS); - - //redis-migrate-tool安装路径 - ConstUtils.REDIS_MIGRATE_TOOL_HOME = MapUtils.getString(configMap, "redis.migrate.tool.home", - ConstUtils.DEFAULT_REDIS_MIGRATE_TOOL_HOME); - logger.info("{}: {}", "ConstUtils.REDIS_MIGRATE_TOOL_HOME", ConstUtils.REDIS_MIGRATE_TOOL_HOME); - - //用户登录状态方式 - ConstUtils.USER_LOGIN_TYPE = MapUtils.getIntValue(configMap, "cachecloud.user.login.type", ConstUtils.DEFAULT_USER_LOGIN_TYPE); - UserLoginTypeEnum userLoginTypeEnum = UserLoginTypeEnum.getLoginTypeEnum(ConstUtils.USER_LOGIN_TYPE); - logger.info("{}: {}, {}", "ConstUtils.USER_LOGIN_TYPE", userLoginTypeEnum.getType(), userLoginTypeEnum.getDesc()); - - //cookie登录方式所需要的domain - ConstUtils.COOKIE_DOMAIN = MapUtils.getString(configMap, "cachecloud.cookie.domain", ConstUtils.DEFAULT_COOKIE_DOMAIN); - logger.info("{}: {}", "ConstUtils.COOKIE_DOMAIN", ConstUtils.COOKIE_DOMAIN); - - //cachecloud根目录 - ConstUtils.CACHECLOUD_BASE_DIR = MapUtils.getString(configMap, "cachecloud.base.dir", ConstUtils.DEFAULT_CACHECLOUD_BASE_DIR); - logger.info("{}: {}", "ConstUtils.CACHECLOUD_BASE_DIR", ConstUtils.CACHECLOUD_BASE_DIR); - - //应用客户端连接报警阀值 - ConstUtils.APP_CLIENT_CONN_THRESHOLD = MapUtils.getIntValue(configMap, "cachecloud.app.client.conn.threshold", ConstUtils.DEFAULT_APP_CLIENT_CONN_THRESHOLD); - logger.info("{}: {}", "ConstUtils.APP_CLIENT_CONN_THRESHOLD", ConstUtils.APP_CLIENT_CONN_THRESHOLD); - - //邮件报警接口 - ConstUtils.EMAIL_ALERT_INTERFACE = MapUtils.getString(configMap, "cachecloud.email.alert.interface", ConstUtils.DEFAULT_EMAIL_ALERT_INTERFACE); - logger.info("{}: {}", "ConstUtils.EMAIL_ALERT_INTERFACE", ConstUtils.EMAIL_ALERT_INTERFACE); - - //短信报警接口 - ConstUtils.MOBILE_ALERT_INTERFACE = MapUtils.getString(configMap, "cachecloud.mobile.alert.interface", ConstUtils.DEFAULT_MOBILE_ALERT_INTERFACE); - logger.info("{}: {}", "ConstUtils.MOBILE_ALERT_INTERFACE", ConstUtils.MOBILE_ALERT_INTERFACE); - - //LDAP登录地址 - ConstUtils.LDAP_URL = MapUtils.getString(configMap, "cachecloud.ldap.url", ConstUtils.DEFAULT_LDAP_URL); - logger.info("{}: {}", "ConstUtils.LDAP_URL", ConstUtils.LDAP_URL); - - //是否定期清理各种统计数据(详见CleanUpStatisticsJob) - ConstUtils.WHETHER_SCHEDULE_CLEAN_DATA = MapUtils.getBooleanValue(configMap, "cachecloud.whether.schedule.clean.data", ConstUtils.DEFAULT_WHETHER_SCHEDULE_CLEAN_DATA); - logger.info("{}: {}", "ConstUtils.WHETHER_SCHEDULE_CLEAN_DATA", ConstUtils.WHETHER_SCHEDULE_CLEAN_DATA); - - // app secret key - ConstUtils.APP_SECRET_BASE_KEY = MapUtils.getString(configMap, "cachecloud.app.secret.base.key", ConstUtils.DEFAULT_APP_SECRET_BASE_KEY); - logger.info("{}: {}", "ConstUtils.APP_SECRET_KEY", ConstUtils.APP_SECRET_BASE_KEY); - - // 机器性能统计周期(分钟) - ConstUtils.MACHINE_STATS_CRON_MINUTE = MapUtils.getIntValue(configMap, "cachecloud.machine.stats.cron.minute", ConstUtils.DEFAULT_MACHINE_STATS_CRON_MINUTE); - logger.info("{}: {}", "ConstUtils.MACHINE_STATS_CRON_MINUTE", ConstUtils.MACHINE_STATS_CRON_MINUTE); - - //ssh授权方式 - ConstUtils.SSH_AUTH_TYPE = MapUtils.getIntValue(configMap, "cachecloud.ssh.auth.type", ConstUtils.DEFAULT_SSH_AUTH_TYPE); - logger.info("{}: {}", "ConstUtils.SSH_AUTH", ConstUtils.SSH_AUTH_TYPE); - - //public key pem - ConstUtils.PUBLIC_KEY_PEM = MapUtils.getString(configMap, "cachecloud.public.key.pem", ConstUtils.DEFAULT_PUBLIC_KEY_PEM); - logger.info("{}: {}", "ConstUtils.PUBLIC_KEY_PEM", ConstUtils.PUBLIC_KEY_PEM); - - //nmon根目录 - ConstUtils.NMON_DIR = MapUtils.getString(configMap, "cachecloud.nmon.dir", ConstUtils.DEFAULT_NMON_DIR); - logger.info("{}: {}", "ConstUtils.NMON_DIR", ConstUtils.NMON_DIR); - - logger.info("===========ConfigServiceImpl reload config end============"); - } - - @Override - public SuccessEnum updateConfig(Map configMap) { - for (Entry entry : configMap.entrySet()) { - String configKey = entry.getKey(); - String configValue = entry.getValue(); - try { - configDao.update(configKey, configValue); - } catch (Exception e) { - logger.error("key {} value {} update faily" + e.getMessage(), configKey, configValue, e); - return SuccessEnum.FAIL; - } - } - return SuccessEnum.SUCCESS; - } - - @Override - public List getConfigList(int status) { - try { - return configDao.getConfigList(status); - } catch (Exception e) { - logger.error(e.getMessage(), e); - return Collections.emptyList(); - } - } - - /** - * 获取所有配置的key-value - * - * @return - */ - private Map getConfigMap() { - Map configMap = new LinkedHashMap(); - List systemConfigList = getConfigList(1); - for (SystemConfig systemConfig : systemConfigList) { - configMap.put(systemConfig.getConfigKey(), systemConfig.getConfigValue()); - } - return configMap; - } - - public void setConfigDao(ConfigDao configDao) { - this.configDao = configDao; - } - -} +package com.sohu.cache.web.service.impl; + +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.commons.collections.MapUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.sohu.cache.constant.UserLoginTypeEnum; +import com.sohu.cache.dao.ConfigDao; +import com.sohu.cache.entity.SystemConfig; +import com.sohu.cache.util.ConstUtils; +import com.sohu.cache.web.enums.SuccessEnum; +import com.sohu.cache.web.service.ConfigService; + +/** + * @author leifu + * @Date 2016年5月23日 + * @Time 上午10:35:26 + */ +public class ConfigServiceImpl implements ConfigService { + + private Logger logger = LoggerFactory.getLogger(ConfigServiceImpl.class); + + private ConfigDao configDao; + + public void init() { + reloadSystemConfig(); + } + + /** + * 加载配置 + */ + public void reloadSystemConfig() { + logger.info("===========ConfigServiceImpl reload config start============"); + // 加载配置 + Map configMap = getConfigMap(); + + // 文案相关 + ConstUtils.CONTACT = MapUtils.getString(configMap, "cachecloud.contact", ConstUtils.DEFAULT_CONTACT); + logger.info("{}: {}", "ConstUtils.CONTACT", ConstUtils.CONTACT); + + ConstUtils.DOCUMENT_URL = MapUtils.getString(configMap, "cachecloud.documentUrl", + ConstUtils.DEFAULT_DOCUMENT_URL); + logger.info("{}: {}", "ConstUtils.DOCUMENT_URL", ConstUtils.DOCUMENT_URL); + + + ConstUtils.MAVEN_WAREHOUSE = MapUtils.getString(configMap, "cachecloud.mavenWareHouse", + ConstUtils.DEFAULT_MAVEN_WAREHOUSE); + logger.info("{}: {}", "ConstUtils.MAVEN_WAREHOUSE", ConstUtils.MAVEN_WAREHOUSE); + + + // 报警相关配置 + ConstUtils.EMAILS = MapUtils.getString(configMap, "cachecloud.owner.email", ConstUtils.DEFAULT_EMAILS); + logger.info("{}: {}", "ConstUtils.EMAILS", ConstUtils.EMAILS); + + ConstUtils.PHONES = MapUtils.getString(configMap, "cachecloud.owner.phone", ConstUtils.DEFAULT_PHONES); + logger.info("{}: {}", "ConstUtils.PHONES", ConstUtils.PHONES); + + + // ssh相关配置 + ConstUtils.USERNAME = MapUtils.getString(configMap, "cachecloud.machine.ssh.name", ConstUtils.DEFAULT_USERNAME); + logger.info("{}: {}", "ConstUtils.USERNAME", ConstUtils.USERNAME); + + + ConstUtils.PASSWORD = MapUtils.getString(configMap, "cachecloud.machine.ssh.password", + ConstUtils.DEFAULT_PASSWORD); + logger.info("{}: {}", "ConstUtils.PASSWORD", ConstUtils.PASSWORD); + + + ConstUtils.SSH_PORT_DEFAULT = Integer.parseInt(MapUtils.getString(configMap, "cachecloud.machine.ssh.port", + String.valueOf(ConstUtils.DEFAULT_SSH_PORT_DEFAULT))); + logger.info("{}: {}", "ConstUtils.SSH_PORT_DEFAULT", ConstUtils.SSH_PORT_DEFAULT); + + + // 管理员相关配置 + ConstUtils.SUPER_ADMIN_NAME = MapUtils.getString(configMap, "cachecloud.admin.user.name", + ConstUtils.DEFAULT_SUPER_ADMIN_NAME); + logger.info("{}: {}", "ConstUtils.SUPER_ADMIN_NAME", ConstUtils.SUPER_ADMIN_NAME); + + + ConstUtils.SUPER_ADMIN_PASS = MapUtils.getString(configMap, "cachecloud.admin.user.password", + ConstUtils.DEFAULT_SUPER_ADMIN_PASS); + logger.info("{}: {}", "ConstUtils.SUPER_ADMIN_PASS", ConstUtils.SUPER_ADMIN_PASS); + + + ConstUtils.SUPER_ADMINS = MapUtils.getString(configMap, "cachecloud.superAdmin", + ConstUtils.DEFAULT_SUPER_ADMINS); + logger.info("{}: {}", "ConstUtils.SUPER_ADMINS", ConstUtils.SUPER_ADMINS); + + + ConstUtils.SUPER_MANAGER = Arrays.asList(ConstUtils.SUPER_ADMINS.split(",")); + logger.info("{}: {}", "ConstUtils.SUPER_MANAGER", ConstUtils.SUPER_MANAGER); + + + // 机器报警阀值 + ConstUtils.CPU_USAGE_RATIO_THRESHOLD = MapUtils.getDoubleValue(configMap, "machine.cpu.alert.ratio", + ConstUtils.DEFAULT_CPU_USAGE_RATIO_THRESHOLD); + logger.info("{}: {}", "ConstUtils.CPU_USAGE_RATIO_THRESHOLD", ConstUtils.CPU_USAGE_RATIO_THRESHOLD); + + ConstUtils.MEMORY_USAGE_RATIO_THRESHOLD = MapUtils.getDoubleValue(configMap, "machine.mem.alert.ratio", + ConstUtils.DEFAULT_MEMORY_USAGE_RATIO_THRESHOLD); + logger.info("{}: {}", "ConstUtils.MEMORY_USAGE_RATIO_THRESHOLD", ConstUtils.MEMORY_USAGE_RATIO_THRESHOLD); + + ConstUtils.LOAD_THRESHOLD = MapUtils.getDoubleValue(configMap, "machine.load.alert.ratio", + ConstUtils.DEFAULT_LOAD_THRESHOLD); + logger.info("{}: {}", "ConstUtils.LOAD_THRESHOLD", ConstUtils.LOAD_THRESHOLD); + + + + // 客户端版本 + ConstUtils.GOOD_CLIENT_VERSIONS = MapUtils.getString(configMap, "cachecloud.good.client", + ConstUtils.DEFAULT_GOOD_CLIENT_VERSIONS); + logger.info("{}: {}", "ConstUtils.GOOD_CLIENT_VERSIONS", ConstUtils.GOOD_CLIENT_VERSIONS); + + ConstUtils.WARN_CLIENT_VERSIONS = MapUtils.getString(configMap, "cachecloud.warn.client", + ConstUtils.DEFAULT_WARN_CLIENT_VERSIONS); + logger.info("{}: {}", "ConstUtils.WARN_CLIENT_VERSIONS", ConstUtils.WARN_CLIENT_VERSIONS); + + ConstUtils.ERROR_CLIENT_VERSIONS = MapUtils.getString(configMap, "cachecloud.error.client", + ConstUtils.DEFAULT_ERROR_CLIENT_VERSIONS); + logger.info("{}: {}", "ConstUtils.ERROR_CLIENT_VERSIONS", ConstUtils.ERROR_CLIENT_VERSIONS); + + //redis-migrate-tool安装路径 + ConstUtils.REDIS_MIGRATE_TOOL_HOME = MapUtils.getString(configMap, "redis.migrate.tool.home", + ConstUtils.DEFAULT_REDIS_MIGRATE_TOOL_HOME); + logger.info("{}: {}", "ConstUtils.REDIS_MIGRATE_TOOL_HOME", ConstUtils.REDIS_MIGRATE_TOOL_HOME); + + //用户登录状态方式 + ConstUtils.USER_LOGIN_TYPE = MapUtils.getIntValue(configMap, "cachecloud.user.login.type", ConstUtils.DEFAULT_USER_LOGIN_TYPE); + UserLoginTypeEnum userLoginTypeEnum = UserLoginTypeEnum.getLoginTypeEnum(ConstUtils.USER_LOGIN_TYPE); + logger.info("{}: {}, {}", "ConstUtils.USER_LOGIN_TYPE", userLoginTypeEnum.getType(), userLoginTypeEnum.getDesc()); + + //cookie登录方式所需要的domain + ConstUtils.COOKIE_DOMAIN = MapUtils.getString(configMap, "cachecloud.cookie.domain", ConstUtils.DEFAULT_COOKIE_DOMAIN); + logger.info("{}: {}", "ConstUtils.COOKIE_DOMAIN", ConstUtils.COOKIE_DOMAIN); + + //cachecloud根目录 + ConstUtils.CACHECLOUD_BASE_DIR = MapUtils.getString(configMap, "cachecloud.base.dir", ConstUtils.DEFAULT_CACHECLOUD_BASE_DIR); + logger.info("{}: {}", "ConstUtils.CACHECLOUD_BASE_DIR", ConstUtils.CACHECLOUD_BASE_DIR); + + //应用客户端连接报警阀值 + ConstUtils.APP_CLIENT_CONN_THRESHOLD = MapUtils.getIntValue(configMap, "cachecloud.app.client.conn.threshold", ConstUtils.DEFAULT_APP_CLIENT_CONN_THRESHOLD); + logger.info("{}: {}", "ConstUtils.APP_CLIENT_CONN_THRESHOLD", ConstUtils.APP_CLIENT_CONN_THRESHOLD); + + //邮件报警接口 + ConstUtils.EMAIL_ALERT_INTERFACE = MapUtils.getString(configMap, "cachecloud.email.alert.interface", ConstUtils.DEFAULT_EMAIL_ALERT_INTERFACE); + logger.info("{}: {}", "ConstUtils.EMAIL_ALERT_INTERFACE", ConstUtils.EMAIL_ALERT_INTERFACE); + + //短信报警接口 + ConstUtils.MOBILE_ALERT_INTERFACE = MapUtils.getString(configMap, "cachecloud.mobile.alert.interface", ConstUtils.DEFAULT_MOBILE_ALERT_INTERFACE); + logger.info("{}: {}", "ConstUtils.MOBILE_ALERT_INTERFACE", ConstUtils.MOBILE_ALERT_INTERFACE); + + //LDAP登录地址 + ConstUtils.LDAP_URL = MapUtils.getString(configMap, "cachecloud.ldap.url", ConstUtils.DEFAULT_LDAP_URL); + logger.info("{}: {}", "ConstUtils.LDAP_URL", ConstUtils.LDAP_URL); + + //LDAP BaseDN + ConstUtils.LDAP_BASEDN = MapUtils.getString(configMap, "cachecloud.ldap.basedn", ConstUtils.DEFAULT_LDAP_BASEDN); + logger.info("{}: {}", "ConstUtils.LDAP_BASEDN", ConstUtils.LDAP_BASEDN); + + //LDAP BindDN + ConstUtils.LDAP_BINDDN = MapUtils.getString(configMap, "cachecloud.ldap.binddn", ConstUtils.DEFAULT_LDAP_BINDDN); + logger.info("{}: {}", "ConstUtils.LDAP_BINDDN", ConstUtils.LDAP_BINDDN); + + //LDAP BindDN Password + ConstUtils.LDAP_BINDDN_PASSWORD = MapUtils.getString(configMap, "cachecloud.ldap.bindpassword", ConstUtils.DEFAULT_LDAP_BINDDN_PASSWORD); + logger.info("{}: {}", "ConstUtils.LDAP_BINDDN_PASSWORD", ConstUtils.LDAP_BINDDN_PASSWORD); + + //是否定期清理各种统计数据(详见CleanUpStatisticsJob) + ConstUtils.WHETHER_SCHEDULE_CLEAN_DATA = MapUtils.getBooleanValue(configMap, "cachecloud.whether.schedule.clean.data", ConstUtils.DEFAULT_WHETHER_SCHEDULE_CLEAN_DATA); + logger.info("{}: {}", "ConstUtils.WHETHER_SCHEDULE_CLEAN_DATA", ConstUtils.WHETHER_SCHEDULE_CLEAN_DATA); + + // app secret key + ConstUtils.APP_SECRET_BASE_KEY = MapUtils.getString(configMap, "cachecloud.app.secret.base.key", ConstUtils.DEFAULT_APP_SECRET_BASE_KEY); + logger.info("{}: {}", "ConstUtils.APP_SECRET_KEY", ConstUtils.APP_SECRET_BASE_KEY); + + // 机器性能统计周期(分钟) + ConstUtils.MACHINE_STATS_CRON_MINUTE = MapUtils.getIntValue(configMap, "cachecloud.machine.stats.cron.minute", ConstUtils.DEFAULT_MACHINE_STATS_CRON_MINUTE); + logger.info("{}: {}", "ConstUtils.MACHINE_STATS_CRON_MINUTE", ConstUtils.MACHINE_STATS_CRON_MINUTE); + + //ssh授权方式 + ConstUtils.SSH_AUTH_TYPE = MapUtils.getIntValue(configMap, "cachecloud.ssh.auth.type", ConstUtils.DEFAULT_SSH_AUTH_TYPE); + logger.info("{}: {}", "ConstUtils.SSH_AUTH", ConstUtils.SSH_AUTH_TYPE); + + //public key pem + ConstUtils.PUBLIC_KEY_PEM = MapUtils.getString(configMap, "cachecloud.public.key.pem", ConstUtils.DEFAULT_PUBLIC_KEY_PEM); + logger.info("{}: {}", "ConstUtils.PUBLIC_KEY_PEM", ConstUtils.PUBLIC_KEY_PEM); + + //nmon根目录 + ConstUtils.NMON_DIR = MapUtils.getString(configMap, "cachecloud.nmon.dir", ConstUtils.DEFAULT_NMON_DIR); + logger.info("{}: {}", "ConstUtils.NMON_DIR", ConstUtils.NMON_DIR); + + logger.info("===========ConfigServiceImpl reload config end============"); + } + + @Override + public SuccessEnum updateConfig(Map configMap) { + for (Entry entry : configMap.entrySet()) { + String configKey = entry.getKey(); + String configValue = entry.getValue(); + try { + configDao.update(configKey, configValue); + } catch (Exception e) { + logger.error("key {} value {} update faily" + e.getMessage(), configKey, configValue, e); + return SuccessEnum.FAIL; + } + } + return SuccessEnum.SUCCESS; + } + + @Override + public List getConfigList(int status) { + try { + return configDao.getConfigList(status); + } catch (Exception e) { + logger.error(e.getMessage(), e); + return Collections.emptyList(); + } + } + + /** + * 获取所有配置的key-value + * + * @return + */ + private Map getConfigMap() { + Map configMap = new LinkedHashMap(); + List systemConfigList = getConfigList(1); + for (SystemConfig systemConfig : systemConfigList) { + configMap.put(systemConfig.getConfigKey(), systemConfig.getConfigValue()); + } + return configMap; + } + + public void setConfigDao(ConfigDao configDao) { + this.configDao = configDao; + } + +} diff --git a/script/cachecloud.sql b/script/cachecloud.sql index 798dcc80..4dc2d42b 100644 --- a/script/cachecloud.sql +++ b/script/cachecloud.sql @@ -883,13 +883,19 @@ insert into system_config(config_key,config_value,info,status,order_id) values(' insert into system_config(config_key,config_value,info,status,order_id) values('cachecloud.email.alert.interface','','邮件报警接口(说明:http://cachecloud.github.io 邮件和短信报警接口规范)',1,25); insert into system_config(config_key,config_value,info,status,order_id) values('cachecloud.mobile.alert.interface','','短信报警接口(说明:http://cachecloud.github.io 邮件和短信报警接口规范)',1,26); insert into system_config(config_key,config_value,info,status,order_id) values('cachecloud.ldap.url','','LDAP接口地址(例如:ldap://ldap.xx.com)',1,27); +insert into system_config(config_key,config_value,info,status,order_id) values('cachecloud.ldap.basedn','','LDAP Base DN(例如:dc=sohu,dc=com)',1,28); +insert into system_config(config_key,config_value,info,status,order_id) values('cachecloud.ldap.binddn','','LDAP Bind DN(ldap管理员,例如:cn=admin,ou=user,dc=sohu,dc=com)',1,29); +insert into system_config(config_key,config_value,info,status,order_id) values('cachecloud.ldap.bindpassword','','LDAP Bind password(ldap管理员密码)',1,30); + +insert into system_config(config_key,config_value,info,status,order_id) values('cachecloud.whether.schedule.clean.data','false','是否定期清理统计数据',1,31); + +insert into system_config(config_key,config_value,info,status,order_id) values('cachecloud.app.secret.base.key','cachecloud-2014','appkey秘钥基准key',1,32); +insert into system_config(config_key,config_value,info,status,order_id) values('cachecloud.machine.stats.cron.minute','1','机器性能统计周期(分钟)',1,33); + +insert into system_config(config_key,config_value,info,status,order_id) values('cachecloud.nmon.dir','/opt/cachecloud','nmon安装目录',1,34); -insert into system_config(config_key,config_value,info,status,order_id) values('cachecloud.whether.schedule.clean.data','false','是否定期清理统计数据',1,28); -insert into system_config(config_key,config_value,info,status,order_id) values('cachecloud.app.secret.base.key','cachecloud-2014','appkey秘钥基准key',1,29); -insert into system_config(config_key,config_value,info,status,order_id) values('cachecloud.machine.stats.cron.minute','1','机器性能统计周期(分钟)',1,30); -insert into system_config(config_key,config_value,info,status,order_id) values('cachecloud.nmon.dir','/opt/cachecloud','nmon安装目录',1,31); DROP TABLE IF EXISTS `app_data_migrate_status`; CREATE TABLE `app_data_migrate_status` (