java Web專案中properties配置檔案中的密碼加密
阿新 • • 發佈:2019-01-11
get到一項新技能(properties檔案中value替換),之前也想過properties中配置項暴露但沒有落實,今天看到部落格分享一下:
我們使用的專案經常是這個樣子的:
1 |
< bean id = "dataSource" class = "org.apache.commons.dbcp.BasicDataSource" |
2 |
destroy-method = "close" |
3 |
p:driverClassName = "oracle.jdbc.driver.OracleDriver" |
4 |
p:url = "jdbc:oracle:thin:@127.0.0.1:1523:orcl" |
5 |
p:username = "czw" |
6 |
p:password = "czw" /> |
這裡會有一個致命的問題,如果有一個具備中介軟體伺服器機器訪問許可權的人,看到了這個例如applicationContext.xml的檔案,並且開啟該檔案,智商再低下的人也會知道資料庫的使用者名稱和密碼是什麼。這對於對安全有一定要求的行業是必須杜絕的,這個也是在一般技術面試中會問到的一個問題。那就讓我們繼續往下,解答這個問題吧!
首先,我們需要將配置檔案抽取到property中來:
01 |
< bean class = "org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" |
02 |
p:location = "classpath:jdbc.properties" |
03 |
p:fileEncoding = "utf-8" |
04 |
/> |
|