com.github.javaclub.sso.common.SSOProperties Maven / Gradle / Ivy
/**
* Copyright (c) 2011-2018.
*
* Licensed 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 com.github.javaclub.sso.common;
import java.util.Map.Entry;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.logging.Logger;
import com.github.javaclub.sso.common.util.Utils;
/**
*
* Properties 辅助工具类
*
*/
public class SSOProperties {
private static final Logger logger = Logger.getLogger("SSOProperties");
private final Properties properties;
public SSOProperties(Properties properties) {
this.properties = properties;
}
public SSOProperties(Properties mergeProperties, String runMode) {
this.properties = extractRunMode(mergeProperties, runMode);
}
public SSOProperties(Properties mergeProperties, String runMode, String currentMode) {
this.properties = extractRunMode(mergeProperties, runMode, currentMode);
}
public String get(String key) {
String val = properties.getProperty(key);
return null == val ? null : val.trim();
}
/**
* properties 提取当前模式配置
* --------------------
* dev_mode 开发模式
* test_mode 测试模式
* online_mode 生产模式
* --------------------
* eclipse 开发模式配置,启动参数 Arguments 属性 VM
* arguments 设置 -Dsso.run.mode=dev_mode
*/
public static Properties extractRunMode( Properties prop, String runMode ) {
return extractRunMode(prop, runMode, "online_mode");
}
/**
*
* properties 提取当前模式配置
*
*
* @param prop
* 配置文件 Properties
* @param runMode
* 当前配置模式
* @param defaultMode
* 默认模式
* @return
*/
public static Properties extractRunMode( Properties prop, String runMode, String defaultMode ) {
if ( prop == null || runMode == null || defaultMode == null ) {
return null;
}
/**
* 获取路由规则, 系统属性设置mode优先
*/
Properties properties = new Properties();
String mode = System.getProperty(runMode);
if ( mode == null ) {
String str = prop.getProperty(runMode);
mode = (str != null) ? str : defaultMode;
}
logger.info("sso.run.mode=" + mode);
properties.put(runMode, mode);
Set> es = prop.entrySet();
for ( Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy