欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

在 Tomcat 中設置 HTTP 基本認證

系統 2576 0

在 Tomcat 中設置 HTTP 基本認證的示例

  1. 在 $TOMCAT_HOME\conf\tomcat-users.xml 文件中配置角色和用戶:
              
                <
              
              
                tomcat-users
              
              
                >
              
              
                <
              
              
                role 
              
              
                rolename
              
              
                ="all"
              
              
                />
              
              
                <
              
              
                role 
              
              
                rolename
              
              
                ="admin"
              
              
                />
              
              
                <
              
              
                user 
              
              
                username
              
              
                ="all"
              
              
                 password
              
              
                ="all"
              
              
                 roles
              
              
                ="all"
              
              
                />
              
              
                <
              
              
                user 
              
              
                username
              
              
                ="admin"
              
              
                 password
              
              
                ="admin"
              
              
                 roles
              
              
                ="admin,all"
              
              
                />
              
              
                </
              
              
                tomcat-users
              
              
                >
              
            
  2. 新建一個 Java Web 工程,編輯 web.xml 文件。
  3. 配置 <security-constraint/> 元素,指定角色可訪問的資源集和可使用的 HTTP 方法。
              
                <
              
              
                security-constraint
              
              
                >
              
              
                <
              
              
                web-resource-collection
              
              
                >
              
              
                <
              
              
                web-resource-name
              
              
                >
              
              Public resources
              
                </
              
              
                web-resource-name
              
              
                >
              
              
                <
              
              
                url-pattern
              
              
                >
              
              /home/*
              
                </
              
              
                url-pattern
              
              
                >
              
              
                <
              
              
                http-method
              
              
                >
              
              HEAD
              
                </
              
              
                http-method
              
              
                >
              
              
                <
              
              
                http-method
              
              
                >
              
              GET
              
                </
              
              
                http-method
              
              
                >
              
              
                </
              
              
                web-resource-collection
              
              
                >
              
              
                <
              
              
                auth-constraint
              
              
                >
              
              
                <
              
              
                role-name
              
              
                >
              
              all
              
                </
              
              
                role-name
              
              
                >
              
              
                </
              
              
                auth-constraint
              
              
                >
              
              
                </
              
              
                security-constraint
              
              
                >
              
              
                <
              
              
                security-constraint
              
              
                >
              
              
                <
              
              
                web-resource-collection
              
              
                >
              
              
                <
              
              
                web-resource-name
              
              
                >
              
              Secret resources
              
                </
              
              
                web-resource-name
              
              
                >
              
              
                <
              
              
                url-pattern
              
              
                >
              
              /blog/*
              
                </
              
              
                url-pattern
              
              
                >
              
              
                <
              
              
                url-pattern
              
              
                >
              
              /photo/*
              
                </
              
              
                url-pattern
              
              
                >
              
              
                <
              
              
                http-method
              
              
                >
              
              HEAD
              
                </
              
              
                http-method
              
              
                >
              
              
                <
              
              
                http-method
              
              
                >
              
              GET
              
                </
              
              
                http-method
              
              
                >
              
              
                <
              
              
                http-method
              
              
                >
              
              POST
              
                </
              
              
                http-method
              
              
                >
              
              
                <
              
              
                http-method
              
              
                >
              
              PUT
              
                </
              
              
                http-method
              
              
                >
              
              
                </
              
              
                web-resource-collection
              
              
                >
              
              
                <
              
              
                auth-constraint
              
              
                >
              
              
                <
              
              
                role-name
              
              
                >
              
              admin
              
                </
              
              
                role-name
              
              
                >
              
              
                </
              
              
                auth-constraint
              
              
                >
              
              
                </
              
              
                security-constraint
              
              
                >
              
            
  4. 配置 <login-config/> 元素,指定認證方式為基本認證,并指定安全域。
              
                <
              
              
                login-config
              
              
                >
              
              
                <
              
              
                auth-method
              
              
                >
              
              BASIC
              
                </
              
              
                auth-method
              
              
                >
              
              
                <
              
              
                realm-name
              
              
                >
              
              hueyhome
              
                </
              
              
                realm-name
              
              
                >
              
              
                </
              
              
                login-config
              
              
                >
              
            

測試:

a) 無認證信息請求

      C:\Users\huey>
      
        curl -I http://localhost:8080/helloweb/home/index.html
      
      
        HTTP/1.1 401 Unauthorized
      
      

Server: Apache-Coyote/1.1

Pragma: No-cache

Cache-Control: no-cache

Expires: Thu, 01 Jan 1970 08:00:00 CST


      
        WWW-Authenticate: Basic realm="hueyhome"
      
      

Content-Type: text/html;charset=utf-8

Content-Length: 951

Date: Mon, 18 May 2015 14:10:55 GMT
    

b) 錯誤認證信息請求

      C:\Users\huey>
      
        curl -I -u "all:none" http://localhost:8080/helloweb/home/index.html
      
      
        HTTP/1.1 401 Unauthorized
      
      

Server: Apache-Coyote/1.1

Pragma: No-cache

Cache-Control: no-cache

Expires: Thu, 01 Jan 1970 08:00:00 CST


      
        WWW-Authenticate: Basic realm="hueyhome"
      
      

Content-Type: text/html;charset=utf-8

Content-Length: 951

Date: Mon, 18 May 2015 14:19:01 GMT
    

c) 正確認證信息但該用戶無指定資源的訪問權限

      C:\Users\huey>
      
        curl -I -u "all:all" http://localhost:8080/helloweb/blog/index.html
      
      
        HTTP/1.1 403 Forbidden
      
      

Server: Apache-Coyote/1.1

Pragma: No-cache

Cache-Control: no-cache

Expires: Thu, 01 Jan 1970 08:00:00 CST

Content-Type: text/html;charset=utf-8

Content-Length: 1057

Date: Mon, 18 May 2015 14:11:57 GMT
    

d)?正確認證信息且該用戶無指定資源的訪問權限

      C:\Users\huey>
      
        curl -I -u "all:all" http://localhost:8080/helloweb/home/index.html
      
      
        HTTP/1.1 200 OK
      
      

Server: Apache-Coyote/1.1

Pragma: No-cache

Cache-Control: no-cache

Expires: Thu, 01 Jan 1970 08:00:00 CST

Accept-Ranges: bytes

ETag: W/"317-1431758220112"

Last-Modified: Sat, 16 May 2015 06:37:00 GMT

Content-Type: text/html

Content-Length: 317

Date: Mon, 18 May 2015 14:11:04 GMT
    

?

在 Tomcat 中設置 HTTP 基本認證


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 日本高清色惰www在线视频 | 九九热爱视频精品视频高清 | 午夜久久久久久久久久一区二区 | 天天影院免费看电影 | 日韩高清免费在线观看 | 女猛烈无遮挡性视频免费 | 日韩视频在线精品视频免费观看 | av黄色在线免费观看 | 成人综合激情 | 久综合色| 亚州综合| 性xxxx视频播放免费 | 蜜桃视频在线免费播放 | 嫩草影院网影院在线 | 欧美日韩黄 | 国产精品成人国产乱一区 | 欧美四虎 | 日韩欧美亚洲国产 | 亚洲国产精品久久久久网站 | 精品久久久久久久久久久久久久 | 亚洲欧美日韩高清 | 亚洲国产一区二区视频 | 欧美日韩一区二区在线视频 | 国产精品久久av | 色哟哟哟在线精品观看视频 | 成年人xxxx| 免费欧美黄色 | 美国黄色毛片 | 激情五月六月婷婷 | 99人体做爰视频 | 午夜小视频免费 | 一区二区在线视频 | 91久久综合 | 一本大道久久a久久精二百 日韩三级中文 | 欧美一区二区三区在观看 | 亚洲成a人片在线观看中文 在线a人片免费观看国产 | 欧美一区二区三区大片 | 性xxxxx| 91av在线播放 | 一区二区日本 | 亚洲人人 |