javaWeb禁止http不安全请求方式

<security-constraint> 的子元素 <http-method> 是可选的,如果没有 <http-method> 元素,这表示将禁止所有 HTTP 方法访问相应的资源。

如果 <security-constraint> 中没有 <auth-constraint> 子元素的话,配置实际上是不起中用的。

<security-constraint>
  <web-resource-collection>   
   <web-resource-name>baseproject</web-resource-name>   
   <url-pattern>/*</url-pattern>   
   <http-method>GET</http-method>   
   <http-method>PUT</http-method>   
   <http-method>HEAD</http-method>   
   <http-method>TRACE</http-method>   
   <http-method>POST</http-method>   
   <http-method>DELETE</http-method>   
   <http-method>OPTIONS</http-method>   
  </web-resource-collection>   
  <auth-constraint>   
   <description>baseproject</description>   
   <role-name>All Role</role-name>   
  </auth-constraint>   
  <user-data-constraint>   
   <transport-guarantee>NONE</transport-guarantee>   
  </user-data-constraint>   
</security-constraint> 

只要在web.xml里配置这些就可以禁止http请求方法,http-method里写请求方法。当使用以上禁止的方法发送请求时会报错403 Forbidden,一般测试使用ajax或者form表单提交即可。

使用login-config可以配置身份验证的操作。

BASIC:HTTP规范,Base64   
<web-app>   
    ......   
    <login-config>   
        <auth-method>BASIC</auth-method>   
    </login-config>   
    ......   
</web-app>   
  
DIGEST:HTTP规范,数据完整性强一些,但不是SSL   
<web-app>   
    ......   
    <login-config>   
        <auth-method>DIGEST</auth-method>   
    </login-config>   
    ......   
</web-app>   
  
CLIENT-CERT:J2EE规范,数据完整性很强,公共钥匙(PKC)   
<web-app>   
    ......   
    <login-config>   
        <auth-method>CLIENT-CERT</auth-method>   
    </login-config>   
    ......   
</web-app>   

这是四种验证方式。

具体是要百度

资料

http请求方法

WebDAV:

webdav是引用网络中储存空间的一种办法。具体来说通过webdav可以将支持这个功能的网盘或者挂到网络上的硬盘接入到应用,从而作为这个应用的同步空间。

举个例子,比如有一个笔记软件,你记完笔记后想要将笔记同步到网络中,可能这个笔记软件的公司没有为软件提供云同步空间,但是这个软件可以让你选择是存储在dropbox,google drive,one drive或者webdav里。因为前三个在国内使用体验不好,所以你可以通过webdav,将你的比如坚果云网盘接入到这个笔记应用里作为同步空间


原文地址:https://www.cnblogs.com/zhangzhicheng/p/7360578.html