SecurityManager一般不起作用

在普通webapp、或java application中,如果没有特别指定,System.getSecurityManager()的返回值都是空的,也就是说拿不到SecurityManager,也不会用它去做任何检查。

所以,在这些程序中通过反射直接访问一个对象的私有变量的值,是可以得手的。 有些框架也直接利用这个默认设置来耍流氓,比如Spring的@Resource实现。

但在applet、java web start等环境中SecurityManager默认是有的,这时直接通过反射访问私有变量就会失败。

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.