##关于Struts2.5的全局方法调用配置说明及相应的SMI的两种解决方案
Struts2.5与2.3跟之前版本的区别,请参阅帮助文档 struts-2.5.1-all\struts-2.5.1\docs\docs\action-configuration.html 官方解释的已经很详细了,下面贴出自己的一些废话。。。
1、
由之前的不严格的Dynamic Method Invocation 升级到了 - Strict DMI
说白了,就是防止坏蛋攻击和破解,提升这小子的安全性。
Struts2给她起了个名字,叫做SMI
Strict Method Invocation
In Struts 2.5 the Strict DMI was extended and it's called Strict Method Invocation aka SMI. You can imagine that the DMI is a "border police", where SMI is a "tax police" and keeps eye on internals. With this version, SMI is enabled by default (strict-method-invocation attribute is set to true by default in struts-default package), you have option to disable it per package - there is no global switch to disable SMI for the whole application. To gain advantage of new configuration option please use the latest DTD definition:
需要在相关版本的限定文件中使用,才能进行有效的配置 自己去看帮助文档粘贴吧~
这是官方给出的配置方案
SMI works in the following way:
<allowed-methods> / @AllowedMethods is defined per action - SMI works without switching it on but just for those actions (plus adding <global-allowed-methods/>)
SMI is enabled but no <allowed-methods> / @AllowedMethods are defined - SMI works but only with <global-allowed-methods/>
SMI is disabled - call to any action method is allowed that matches the default RegEx - ([A-Za-z0-9_$]*)
You can redefine the default RegEx by using a constant as follow <constant name="struts.strictMethodInvocation.methodRegex" value="([a-zA-Z]*)"/>
我测试了一下,
<constant name="struts.strictMethodInvocation.methodRegex" value="([a-zA-Z]*)"/>
这个配置说是可以替换<global-allowed-methods/>
的默认值, 但是,亲测,没什么鸟用。 <global-allowed-methods/>
也没有什么默认值。 后期用到再论。
2、SMI解决方案
首先要说的是, 下面这个2.3之前的配置已经没有效果了,删了就是
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
想要实现之前的效果,这里提两种解决方案
一个是 在当前的action标签下,添加<allowed-methods>动作类的方法名,…,…</allowed-methods>
, 放在<action>
里面,至于放在什么位置,自己看DTD报错提示吧。
这种设计在后期可以增强配置文件可读性,实现了指定方法的高维护性的访问设计,增强了框架的安全性。 适合实际开发使用。
一个是 在顶层的包中再添加一个配置
<global-allowed-methods>regex:([A-Za-z0-9_$]*)</global-allowed-methods>
至于说放在什么位置,还是上面的废话 —— 自己去看DTD报错提示吧~~
这样的话,意思就是说,除了火星文之外的任意的方法名均可正常访问。
不设限制,与之前的使用无异。
如需要转载 请注明文章出处 **https://my.oschina.net/u/3032872/blog/1648374 ** 谢谢~