IBatisNet -- 保護你的配置檔案及對映檔案資訊
阿新 • • 發佈:2018-12-31
通常情況下我們在使用IBatisNet的時候,配置檔案和對映檔案都是暴露在外的,如果能進入到伺服器,那麼你的程式的操作資料庫的SQL語句,資料庫連線字串等資訊都將很輕鬆的被看到,這樣是很危險的。然而IBatisnet自身也沒有提供配置檔案直接加密的方法,但我們可以用變通的方式來儘可能的保護這些檔案中的資訊。IBatisnet的對映檔案等可以指定為內嵌的資源,利用這個我們可以把一些敏感資訊寫到另外一個配置檔案中,並設定這個配置檔案的Build Action為embedded Resource。具體操作如下:
一、假設我們對映檔案的路徑為 [email protected]/,我們將所有的對映檔案都設定為“內嵌的資源”,SqlMap.config檔案直接在根目錄下。
二、建立一個properties.config檔案,新增一些敏感資訊(即不能直接讓別人看到的資訊)。如下:
<?xml version="1.0" encoding="utf-8" ?>
<settings>
<!-- User application and configured property settings go here.-->
<!-- Example: <add key="settingName" value="settingValue"/> -->
<add key="provider" value="sqlServer1.1"/>
<add
key="connectionString"
value="server=.;database=DocumentSystem;uid=sa;pwd="/>
<add key="root" value="TVSystem.Web._Maps."/>
<add key="assembly" value="TVSystem.Web"/>
</settings>
三、SqlMap.config檔案的配置
<? xml version="1.0" encoding="utf-8"?>
<sqlMapConfig
xmlns="http://ibatis.apache.org/dataMapper"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<properties embedded="TVSystem.Web.properties.config"/>
<settings>
<setting useStatementNamespaces="false"/>
</settings >
<providers resource="providers.config"/>
<!-- Database connection information -->
<database>
<provider name="${provider}"/>
<dataSource name="DocumentSystem" connectionString="${connectionString}"/>
</database>
<sqlMaps>
<sqlMap embedded="${root}Department.xml,${assembly}"/>
<sqlMap embedded="${root}Stream.xml,${assembly}"/>
<sqlMap embedded="${root}Employees.xml,${assembly}"/>
<sqlMap embedded="${root}Relations.xml,${assembly}"/>
</sqlMaps>
</sqlMapConfig>
這樣釋出後的程式碼中,只能看到SqlMap.config中的內容,對映檔案和資料庫連線字串等資訊就被編譯到DLL中去了。
一、假設我們對映檔案的路徑為 [email protected]/,我們將所有的對映檔案都設定為“內嵌的資源”,SqlMap.config檔案直接在根目錄下。
二、建立一個properties.config檔案,新增一些敏感資訊(即不能直接讓別人看到的資訊)。如下:
<?xml version="1.0" encoding="utf-8" ?>
<settings>
<!-- User application and configured property settings go here.-->
<!-- Example: <add key="settingName" value="settingValue"/>
<add key="provider" value="sqlServer1.1"/>
<add
key="connectionString"
value="server=.;database=DocumentSystem;uid=sa;pwd="/>
<add key="root" value="TVSystem.Web._Maps."/>
<add key="assembly" value="TVSystem.Web"/>
</settings>
三、SqlMap.config檔案的配置
<?
<sqlMapConfig
xmlns="http://ibatis.apache.org/dataMapper"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<properties embedded="TVSystem.Web.properties.config"/>
<settings>
<setting useStatementNamespaces="false"/>
</settings
<providers resource="providers.config"/>
<!-- Database connection information -->
<database>
<provider name="${provider}"/>
<dataSource name="DocumentSystem" connectionString="${connectionString}"/>
</database>
<sqlMaps>
<sqlMap embedded="${root}Department.xml,${assembly}"/>
<sqlMap embedded="${root}Stream.xml,${assembly}"/>
<sqlMap embedded="${root}Employees.xml,${assembly}"/>
<sqlMap embedded="${root}Relations.xml,${assembly}"/>
</sqlMaps>
</sqlMapConfig>
這樣釋出後的程式碼中,只能看到SqlMap.config中的內容,對映檔案和資料庫連線字串等資訊就被編譯到DLL中去了。