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,將你的比如堅果雲網盤接入到這個筆記應用里作為同步空間



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM