Google Analytics

2014年6月11日 星期三

Struts2修改struts-default.xml的方法

緣起

筆者由於所屬的專案遇到struts2的安全性問題:s2-020。依照官方的建議其升級至2.3.16.2版時,發現會會受到另一個struts issue : WW-4254的影響,導致系統無法使用,所以改採用官方提供的workaround方式,修改sttuts2預設的設定檔(struts-default.xml)參數。

修改方式

1. 改web.xml
<filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
        <init-param>
            <param-name>config</param-name>
            <param-value>struts-default_new.xml,struts-plugin.xml,struts.xml</param-value>
        </init-param>
    </filter>

2. 於專案使用的strus2的jar檔或source code目錄(src\core\src\main\resources)下,取得該版staruts的struts-default.xml,依據官網建議,將:
<interceptor-ref name="params"> <param name="excludeParams">dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*</param> </interceptor-ref> 改為 <interceptor-ref name="params"> <param name="excludeParams">^class\..*,^dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,^parameters\..*,^action:.*,^method:.*</param> </interceptor-ref>

3. 修改後,另存新檔為struts-default_new.xml,放到專案中。

沒有留言:

張貼留言