簡體   English   中英

寧靜的Web服務的范圍(請求,會話,應用程序)

[英]Scope of a restful webservice(request,session,application)

完整申請的范圍是什么? 實際上,我想創建一個Login模塊,以便僅在身份驗證成功后才能訪問下一個Web服務。

這是一個如何對Java Web應用程序使用聲明式容器管理的安全性的示例:

添加約束以強制使用HTTPS

<security-constraint>
    <web-resource-collection>
        <web-resource-name>SSL Secured WebService</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee> 
    </user-data-constraint>
</security-constraint>

防止非管理用戶插入,更新和刪除位於/services/products/*

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Authenticated administrators only</web-resource-name>
        <url-pattern>/services/products/*</url-pattern>
        <http-method>POST</http-method>
        <http-method>PUT</http-method>
        <http-method>DELETE</http-method>
    </web-resource-collection>
    <auth-constraint>
        <role-name>ADMIN</role-name>
    </auth-constraint>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>

強制執行基本身份驗證

<login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>BookStore-Authentication-REALM</realm-name>
</login-config>

定義安全角色ADMIN

<security-role>
    <role-name>ADMIN</role-name>
</security-role>

此外,您將需要創建一個定制的數據庫領域,該數據庫領域知道所有用戶和密碼在數據庫中的位置。 該領域需要映射到此應用程序。 每個應用服務器可以使用自己的shema來完成此操作。 下面是JBoss AS 7.1的示例

WEB-INF文件夾中創建一個jboss-web.xml文件,其中包含以下內容。

<?xml version="1.0" encoding="UTF-8"?>
<jboss>
    <security-domain>RealmName</security-domain>
</jboss>

由於<ulr-patter>表達式的使用非常有限,因此這種安全性可能無法滿足您的所有限制要求。 在這種情況下,您可能需要使用編程安全性。 有關更多信息,請訪問Oracle文檔站點。

JAX-RS根資源類在請求范圍內進行管理。 因此,默認情況下,靜態的Web服務casse的請求范圍是確定范圍的,並且不需要指定范圍的任何注釋。可以將通過@RequestScoped或@ApplicationScoped注釋的CDI(上下文或雙端注入)托管Bean轉換為JAX-RS資源類。

暫無
暫無

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

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