Share via


透過 SOAP 的 SQL Server 驗證

針對 SQL Server 2005 中的原生 XML Web Service,可以使用下列類型的安全性主體來管理安全性:

  • Windows 使用者或群組帳戶,或兩者
  • SQL Server 登入

將 Windows 帳戶用於 HTTP 結束點驗證時,不需要額外的 SOAP 驗證標頭。如需有關 HTTP 端點驗證的詳細資訊,請參閱<結束點驗證類型>及<GRANT 端點權限 (Transact-SQL)>。

然而,當使用 SQL Server 登入時,用戶端應用程式還必須為 SOAP 驗證另外實作 Web 服務安全性 (WS-Security) 標頭,才能將 SQL Server 登入資訊納入和提交給伺服器。

針對 SQL Server 登入的 SOAP 驗證,可以使用任何 HTTP 驗證類型。此外,用來在 HTTP 層進行驗證的使用者帳戶只需要本機伺服器的 Windows 存取權,不一定需要 SQL Server 登入。

ms180919.note(zh-tw,SQL.90).gif附註:
針對透過 SOAP 的 SQL Server 型驗證,結束點的 LOGIN_TYPE 選項必須設定為混合模式 (LOGIN_TYPE=MIXED)。若要在混合模式中操作結束點,也需要將結束點設定為透過安全通訊端層 (SSL) 通道提供服務。如需詳細資訊,請參閱<CREATE ENDPOINT (Transact-SQL)>。

使用 WS-Security 標頭來驗證 SQL Server 登入 (只限混合模式)

WS-Security 是建議的規格,用於擴充 SOAP 訊息結構以保護 Web 服務的安全。尤其是針對 SQL Server 2005,您可視需要使用 WS-Security 來提供驗證機制,而透過擴充 SOAP 訊息的結構,在 SOAP 訊息內即可直接於 SOAP 用戶端與 SQL Server 執行個體之間傳遞認證及 Token。

如果下列條件為真,您可以使用 WS-Security 標頭來提供 SQL Server 使用者及密碼資訊,以作為 SOAP 用戶端應用程式的一部份:

  • 已在混合模式中安裝了 SQL Server 2005 的執行個體。這表示同時支援 Windows 及 SQL Server 登入。
  • 端點具有下列設定:
    • LOGIN_TYPE = MIXED。
    • PORTS=(SSL),已指定 SSL 類型通訊埠。
  • 結束點權限已授與給不屬於 Windows 登入的使用者 (如 SQL Server 登入)。

當 SOAP 要求中包含 WS-Security 標頭時,標頭中的認證會覆寫先前對結束點執行 HTTP 型驗證所使用的任何認證。

使用 WS-Security 標頭進行 SQL Server 驗證

WS-Security 標頭可以用在傳送給 SQL Server 2005 執行個體的 SOAP 要求,以支援下列項目:

  • 傳輸 SQL Server 授權 (SQL-Auth) 認證
  • 處理已過期的 SQL Server 密碼

傳輸 SQL-Auth 認證

下例顯示 WS-Security 標頭如何用在 SQL Server 2005 執行個體的 SOAP 要求,以傳輸 SQL Server 授權 (SQL-Auth) 認證。

<SOAP-ENV:Header>
            <wsse:Security  xmlns:wsse=
                        "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
            <wsse:UsernameToken>
                        <wsse:Username>JohnDoe</wsse:Username>
            <wsse:Password Type=
                        "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">pass-word1</wsse:Password>
            </wsse:UsernameToken>
            </wsse:Security>
</SOAP-ENV:Header>

在此範例中,<wsse:UserNameToken> 元素是用來包含下列兩個子元素:

  • 具有 SQL Server 使用者名稱的 <wsse:Username> 元素。
  • 具有選擇性 Type 屬性設為 "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText" 值的 <wsse:Password> 元素。這是用來包含使用者的密碼文字。
ms180919.note(zh-tw,SQL.90).gif附註:
當 SQL Server 2005 及 HTTP SOAP 結束點支援混合模式時,需要一個 SSL 通訊埠,才能至少提供使用者認證的標準加密。

處理已過期的 SQL Server 密碼

SQL Server 2005 提供密碼過期功能。當伺服器在登入嘗試期間判斷使用者的密碼已過期時,密碼功能會要求用戶端同時以使用者的舊密碼及新密碼回應,才能順利地完成登入程序。

若要更新用戶端以支援此功能,您可以使用下列 WS-Security 標頭作為範本範例來完成此程序。

<SOAP-ENV:Header>
 <wsse:Security  xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
            <wsse:UsernameToken>
                        <wsse:Username>JohnDoe</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">pass-word2</wsse:Password>
            <sql:OldPassword Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText" xmlns:sql="https://schemas.microsoft.com/sqlserver/2004/SOAP">pass-word1</sql:OldPassword>
            </wsse:UsernameToken>
 </wsse:Security>
</SOAP-ENV:Header>

變更密碼也可以當作 SOAP 工作階段的一部份來執行。但只有在初始化新的工作階段時,才能接受變更密碼的要求。

例如,若要將變更密碼當作新 SOAP 工作階段的一部份,請將下列內容加入 <SOAP-ENV:Header> 區段:

<sqloptions:sqlSession xmlns:sqloptions="https://schemas.microsoft.com/sqlserver/2004/SOAP/Options" initiate="true"/>

如需詳細資訊,請參閱<使用 SOAP 工作階段>。

此外,可稍微修改 <wsse:UserNameToken> 元素以包含下列三個子元素,這和上述傳送使用者認證的範例有點不同:

  • 具有 SQL Server 使用者名稱的 <wsse:Username> 元素。
  • 具有選擇性 Type 屬性設為 "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText" 值的 <wsse:Password> 元素。這是用來包含使用者的新密碼文字。
  • 具有選擇性 Type 屬性設為 "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"" 值的 <sql:OldPassword> 元素。這是用來包含使用者的舊密碼文字。

WS-Security 標頭的 XML 結構描述

下列是僅限實作於 SQL Server 2005 之 WS-Security 標頭的結構描述片段。

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sql="https://schemas.microsoft.com/sqlserver/2004/SOAP" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
  <xsd:import namespace="https://schemas.microsoft.com/sqlserver/2004/SOAP" />
  <xsd:annotation>
    <xsd:documentation xml:lang="en">(c) Copyright 2004, Microsoft Corporation The following schema for Microsoft SQL Server is presented in XML format and is for informational purposes only. Microsoft Corporation ("Microsoft") may have trademarks, copyrights, or other intellectual property rights covering subject matter in the schema. Microsoft does not make any representation or warranty regarding the schema or any product or item developed based on the schema. The schema is provided to you on an AS IS basis. Microsoft disclaims all express, implied and statutory warranties, including but not limited to the implied warranties of merchantability, fitness for a particular purpose, and freedom from infringement. Without limiting the generality of the foregoing, Microsoft does not make any warranty of any kind that any item developed based on the schema, or any portion of the schema, will not infringe any copyright, patent, trade secret, or other intellectual property right of any person or entity in any country. It is your responsibility to seek licenses for such intellectual property rights where appropriate. MICROSOFT SHALL NOT BE LIABLE FOR ANY DAMAGES OF ANY KIND ARISING OUT OF OR IN CONNECTION WITH THE USE OF THE SCHEMA, INCLUDING WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL (INCLUDING ANY LOST PROFITS), PUNITIVE OR SPECIAL DAMAGES, WHETHER OR NOT MICROSOFT HAS BEEN ADVISED OF SUCH DAMAGES.</xsd:documentation> 
  </xsd:annotation>
  <xsd:element name="Security">
    <xsd:complexType>
      <xsd:sequence minOccurs="1" maxOccurs="1">
        <xsd:element name="UsernameToken">
          <xsd:complexType>
            <xsd:sequence minOccurs="1" maxOccurs="1">
              <xsd:element name="Username" type="xsd:string" />
              <xsd:element name="Password">
                <xsd:complexType>
                  <xsd:simpleContent>
                    <xsd:extension base="xsd:string">
                      <xsd:attribute name="Type" type="xsd:anyURI" />
                    </xsd:extension>
                  </xsd:simpleContent>
                </xsd:complexType>
              </xsd:element>
              <xsd:element name="OldPassword" type="sql:OldPassword" minOccurs="0" />
            </xsd:sequence>
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sql="https://schemas.microsoft.com/sqlserver/2004/SOAP" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="https://schemas.microsoft.com/sqlserver/2004/SOAP">
  <xsd:annotation>
    <xsd:documentation xml:lang="en">(c) Copyright 2004, Microsoft Corporation The following schema for Microsoft SQL Server is presented in XML format and is for informational purposes only. Microsoft Corporation ("Microsoft") may have trademarks, copyrights, or other intellectual property rights covering subject matter in the schema. Microsoft does not make any representation or warranty regarding the schema or any product or item developed based on the schema. The schema is provided to you on an AS IS basis. Microsoft disclaims all express, implied and statutory warranties, including but not limited to the implied warranties of merchantability, fitness for a particular purpose, and freedom from infringement. Without limiting the generality of the foregoing, Microsoft does not make any warranty of any kind that any item developed based on the schema, or any portion of the schema, will not infringe any copyright, patent, trade secret, or other intellectual property right of any person or entity in any country. It is your responsibility to seek licenses for such intellectual property rights where appropriate. MICROSOFT SHALL NOT BE LIABLE FOR ANY DAMAGES OF ANY KIND ARISING OUT OF OR IN CONNECTION WITH THE USE OF THE SCHEMA, INCLUDING WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL (INCLUDING ANY LOST PROFITS), PUNITIVE OR SPECIAL DAMAGES, WHETHER OR NOT MICROSOFT HAS BEEN ADVISED OF SUCH DAMAGES.</xsd:documentation> 
  </xsd:annotation>
  <xsd:complexType name="OldPassword">
    <xsd:simpleContent>
      <xsd:extension base="xsd:string">
        <xsd:attribute name="Type" type="xsd:anyURI" />
      </xsd:extension>
    </xsd:simpleContent>
  </xsd:complexType>
</xsd:schema>

請參閱

參考

將 SOAP 標頭加入用戶端應用程式
結束點驗證類型

其他資源

驗證模式

說明及資訊

取得 SQL Server 2005 協助