簡體   English   中英

jetty 8 web.xml:允許低特權用戶僅訪問一個頁面,而其他用戶則需要通過安全性約束來訪問管理員用戶

[英]jetty 8 web.xml: Allow low-privilege user to access just one page, admin user required for all others via security-constraints

我想保護我的Web應用程序的安全,以便只有“管理員”用戶可以訪問所有頁面,但是特殊的“測試”用戶可以訪問狀態頁面。

這是我嘗試過的:

在web.xml中:

  <security-constraint>
    <web-resource-collection>
      <web-resource-name>Everything else</web-resource-name>
      <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
      <role-name>admin</role-name>
    </auth-constraint>
  </security-constraint>

  <security-constraint>
    <web-resource-collection>
      <web-resource-name>Status page</web-resource-name>
      <url-pattern>/status/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
      <role-name>test</role-name>
      <role-name>admin</role-name>
    </auth-constraint>
  </security-constraint>

  <login-config>
    <auth-method>BASIC</auth-method>     <!-- Use http basic authentication -->
    <realm-name>MyApp Realm</realm-name>  <!-- users are defined in this realm -->
  </login-config>

不幸的是,當我嘗試與測試用戶一起訪問狀態頁面( https:// localhost:444 / app-0.0.1-SNAPSHOT / hbr / status )時,我得到以下信息:

Problem accessing /app-0.0.1-SNAPSHOT/hbr/status. Reason: 
     !role

知道我該如何解決嗎?

事實證明,“狀態”頁面不是應用程序的根目錄,而是子服務“ hbr”的一部分(“ hbr”是唯一的子服務,這就是為什么我沒有注意到)。 對第二個安全性約束的以下更改導致應用程序按預期運行:

  <security-constraint>
    <web-resource-collection>
      <web-resource-name>Status page</web-resource-name>
      <url-pattern>hbr/status/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
      <role-name>test</role-name>
      <role-name>admin</role-name>
    </auth-constraint>
  </security-constraint>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM