配置Tomcat下的web应用服务的安全权限

来源:互联网 发布:网络证券销售怎么样 编辑:程序博客网 时间:2024/05/29 12:25

一:使用tomcat的Policy文件。

因为Tomcat就是用Java写的,所以也有像javapolicy一样的安全机制,它的Policy文件在Tomcat的安装目录下的conf目录下,名叫catalina.policy的文件。默认的情况下Tomcat的服务都是在非安全模式下运行的,那如何让tomcat服务在安全模式下运行呢,就是如何把Policy安全机制引用进去,大概有两种方式:

①:运行catalina.bat文件,后面加上“-security”参数。

②:运用tomcat提供的配置tomcat服务的图形化工具,即运行bin目录下的tomcat6w.exe,然后打开java的tab页,在java options输入域中加入下面的内容,然后重新启动tomcat服务。

-Djava.security.manager

-Djava.security.policy=%SECURITY_POLICY_FILE%

%SECURITY_POLICY_FILE%为catalina.policy文件所在磁盘的位置。

注意catalina.policy文件中的如下的注释:

// These permissions are granted by default to all web applications
// In addition, a web application will be given a read FilePermission
// and JndiPermission for all files and directories in its document root.

意思就不用说了!

二:配置Tomcat的web.xml文件,给http协议的请求添加安全权限

我们知道HTTP协议有很多请求方式,如put,get,delete,post等,但是像put这种方式就可以往服务器端添加文件,或修改服务器端文件的内容,这对web应用服务的安全性带来一定的影响,tomcat服务器也对其下的web应用程序也有这方面的安全保护,比如在tomcat的安装目录下的conf目录下的web.xml中加入如下内容,然后重新启动tomcat服务。

<security-constraint>
      <web-resource-collection>
  <!-- Define the context-relative URL(s) to be protected -->
         <url-pattern>/jsp/security/protected/*</url-pattern>
  <!-- If you list http methods, only those methods are protected -->
         <http-method>PUT</http-method>
      </web-resource-collection>
      <auth-constraint>
         <!-- Anyone with one of the listed roles may access this area -->
      </auth-constraint>
    </security-constraint>

    <!-- Default login configuration uses form-based authentication -->
    <login-config>
      <auth-method>BASIC</auth-method>
    </login-config>

这样就禁止了HTTP协议的put请求来访问tomcat站点下的所有web应用服务。同样的也可以在web应用服务下的web.xml中进行上面的配置,这时它的作用域只是针对该web应用程序。

更多tomcat中web.xml的配置参照:

http://www.blogjava.net/baoyaer/articles/107428.html

这里还向大家推荐一个工具,它是一种可以模拟浏览器发送HTTP请求的图形化工具,方便大家对配置的安全权限进行测试。

Fiddler下载:http://www.onlinedown.net/soft/73207.htm

Fiddler的使用:http://blog.sina.com.cn/s/blog_5077e9d00100bgdk.html

是不是已经按耐不住,想体验一把了!