MCPcopy Create free account
hub / github.com/diyhi/bbs / getDatabaseParameter

Method getDatabaseParameter

src/test/java/cms/Init.java:208–243  ·  view source on GitHub ↗

获取数据库参数 @return

()

Source from the content-addressed store, hash-verified

206 * @return
207 */
208 private static Install getDatabaseParameter(){
209 Install install = new Install();
210
211 //读取数据库配置文件
212 Properties properties = YmlUtils.getYml("application.yml");
213 //数据库连接地址
214 String jdbc_url = properties.getProperty("spring.datasource.url");
215 //数据库用户名
216 String jdbc_user = properties.getProperty("spring.datasource.username");
217 //数据库密码
218 String jdbc_password = properties.getProperty("spring.datasource.password");
219 //盐值 数据库密码加密所需的salt(盐)
220 String salt = properties.getProperty("jasypt.encryptor.password");
221
222 if(salt != null && !salt.trim().isEmpty()){
223 PooledPBEStringEncryptor encryptor = JasyptUtil.config(salt);
224 encryptor.setPassword(salt.trim());//加密所需的salt(盐)
225
226 if(jdbc_url != null && !jdbc_url.trim().isEmpty() && PropertyValueEncryptionUtils.isEncryptedValue(jdbc_url.trim())){//判断是否为加密值 被ENC()包裹
227 jdbc_url = PropertyValueEncryptionUtils.decrypt(jdbc_url, encryptor);
228 }
229 if(jdbc_user != null && !jdbc_user.trim().isEmpty() && PropertyValueEncryptionUtils.isEncryptedValue(jdbc_user.trim())){//判断是否为加密值 被ENC()包裹
230 jdbc_user = PropertyValueEncryptionUtils.decrypt(jdbc_user, encryptor);
231 }
232 if(jdbc_password != null && !jdbc_password.trim().isEmpty() && PropertyValueEncryptionUtils.isEncryptedValue(jdbc_password.trim())){//判断是否为加密值 被ENC()包裹
233 jdbc_password = PropertyValueEncryptionUtils.decrypt(jdbc_password, encryptor);
234 }
235
236 }
237
238 install.setDatabaseUser(jdbc_user);//数据库用户名
239 install.setDatabasePassword(jdbc_password);//数据库密码
240 install.setDatabaseURL(jdbc_url);//数据库连接地址
241
242 return install;
243 }
244
245
246 /**

Callers 1

getConnectionMethod · 0.95

Calls 6

getYmlMethod · 0.95
configMethod · 0.95
getPropertyMethod · 0.80
setPasswordMethod · 0.80
isEmptyMethod · 0.45
decryptMethod · 0.45

Tested by

no test coverage detected