Sécurisation d'un service Web avec une règle de sécurité de services Web

Vous pouvez développer et sécuriser une API Java™ des services Web XML (JAX-WS) avec une règle de sécurité de services Web dans IBM® WebSphere Application Server Liberty. Les exemples sont mis à disposition sous forme de tutoriel pour expliquer les étapes générales impliquées dans le développement et la sécurisation d'un service Web dans Liberty. Ne les utilisez pas dans un environnement de production. Passez en revue vos propres exigences relatives à la sécurité afin de développer le contrat WSDL (Web Services Description Language) et la règle de sécurité de services Web pour la protection de vos applications de service Web.

Pourquoi et quand exécuter cette tâche

Cette tâche explique comment développer une application de service Web JAX-WS simple et comment la sécuriser avec une règle de sécurité de services Web.

Cette tâche utilise deux magasins de clés : enc-sender.jceks et enc-receiver.jceks. Il s'agit d'exemples de magasin de clés de sécurité de services Web qui sont livrés avec la version traditionnelle de WebSphere Application Server. Si vous avez accès à une installation traditionnelle, vous les trouverez dans l'un des répertoires suivants :

racine_profil/etc/ws-security/samples

REP_BASE_WAS/profileTemplates/defaultdocuments/etc/ws-security/samples

Procédure

  1. Créez le contrat WSDL et la règle de sécurité de services Web. Dans cet exemple, un contrat WSDL associé à une règle de sécurité de services Web pour une application de fournisseur de services Web JAX-WS est créé. Le modèle de règle de sécurité de services Web appelé Jeton de nom d'utilisateur avec protection asymétrique des messages du jeton X509 (authentification mutuelle) est utilisé. Le client signe et chiffre le corps SOAP, et signe et chiffre le jeton de nom d'utilisateur dans le message de demande. Dans le message de réponse, le fournisseur signe et chiffre le corps SOAP. Pour une description complète des contraintes de sécurité de cet exemple, voir Jeton de nom d'utilisateur avec protection des messages asymétrique du jeton X509 (authentification mutuelle).
    1. Créez un contrat WSDL pour votre service. L'exemple suivant illustre un contrat WSDL :
      <?xml version="1.0" encoding="UTF-8"?>
      <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                        xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
                        xmlns:tns="http://com/ibm/was/wssample/sei/echo/"
                        xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="WSSampleSei"
                        targetNamespace="http://com/ibm/was/wssample/sei/echo/">
        <wsdl:types>
          <xsd:schema targetNamespace="http://com/ibm/was/wssample/sei/echo/"
                      xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <xsd:element name="echoStringResponse">
              <xsd:complexType>
                <xsd:sequence>
                  <xsd:element name="echoResponse" type="xsd:string" />
                </xsd:sequence>
              </xsd:complexType>
            </xsd:element>
            <xsd:element name="echoStringInput">
              <xsd:complexType>
                <xsd:sequence>
                  <xsd:element name="echoInput" type="xsd:string" />
                </xsd:sequence>
              </xsd:complexType>
            </xsd:element>
          </xsd:schema>
        </wsdl:types>
        <wsdl:message name="echoOperationRequest">
          <wsdl:part element="tns:echoStringInput" name="parameter" />
        </wsdl:message>
        <wsdl:message name="echoOperationResponse">
          <wsdl:part element="tns:echoStringResponse" name="parameter" />
        </wsdl:message>
        <wsdl:portType name="EchoServicePortType">
          <wsdl:operation name="echoOperation">
            <wsdl:input message="tns:echoOperationRequest" />
            <wsdl:output message="tns:echoOperationResponse" />
          </wsdl:operation>
        </wsdl:portType>
        <wsdl:binding name="Echo1SOAP" type="tns:EchoServicePortType">
          <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
          <wsdl:operation name="echoOperation">
            <soap:operation soapAction="echoOperation" style="document" />
            <wsdl:input>
              <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output>
              <soap:body use="literal" />
            </wsdl:output>
          </wsdl:operation>
        </wsdl:binding>
        <wsdl:service name="Echo1Service">
          <wsdl:port binding="tns:Echo1SOAP" name="Echo1ServicePort">
            <soap:address location="http://localhost:8010/WSSampleSei/Echo1Service" />
          </wsdl:port>
        </wsdl:service>
      </wsdl:definitions>
    2. Ajoutez les espaces de nom nécessaires à la prise en charge de la règle de sécurité à votre fichier WSDL dans l'élément wsdl:definitions. L'exemple suivant représente les espaces de nom ajoutés :
      xmlns:wsp="http://www.w3.org/ns/ws-policy"
      xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
      xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702"
      xmlns:sp13="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802"
      xmlns:wsaws="http://www.w3.org/2005/08/addressing"
    3. Ajoutez le fragment de règle de sécurité de services Web à votre fichier WSDL juste avant l'élément wsdl:binding. Le modèle de règle de l'exemple Jeton de nom d'utilisateur avec protection des messages asymétrique du jeton X509 (authentification mutuelle) est utilisé dans cet exemple.
    4. Ajoutez un élément wsp:PolicyReference pour votre règle de sécurité à votre élément wsdl:binding. L'exemple suivant illustre l'élément wsp:PolicyReference :
      <wsp:PolicyReference URI="#AsymmetricX509MutualAuthenticationWithUnt" />
    5. Vérifiez que votre fichier WSDL ressemble à l'exemple ci-dessous. L'exemple suivant illustre le fichier WSDL final :
      <?xml version="1.0" encoding="UTF-8"?>
      <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                        xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
                        xmlns:tns="http://com/ibm/was/wssample/sei/echo/"
                        xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="WSSampleSei"
                        xmlns:wsp="http://www.w3.org/ns/ws-policy"
                        xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
                        xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702"
                        xmlns:sp13="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802"
                        xmlns:wsaws="http://www.w3.org/2005/08/addressing"
                        targetNamespace="http://com/ibm/was/wssample/sei/echo/">
        <wsdl:types>
          <xsd:schema targetNamespace="http://com/ibm/was/wssample/sei/echo/"
                      xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <xsd:element name="echoStringResponse">
              <xsd:complexType>
                <xsd:sequence>
                  <xsd:element name="echoResponse" type="xsd:string" />
                </xsd:sequence>
              </xsd:complexType>
            </xsd:element>
            <xsd:element name="echoStringInput">
              <xsd:complexType>
                <xsd:sequence>
                  <xsd:element name="echoInput" type="xsd:string" />
                </xsd:sequence>
              </xsd:complexType>
            </xsd:element>
          </xsd:schema>
        </wsdl:types>
        <wsdl:message name="echoOperationRequest">
          <wsdl:part element="tns:echoStringInput" name="parameter" />
        </wsdl:message>
        <wsdl:message name="echoOperationResponse">
          <wsdl:part element="tns:echoStringResponse" name="parameter" />
        </wsdl:message>
        <wsdl:portType name="EchoServicePortType">
          <wsdl:operation name="echoOperation">
            <wsdl:input message="tns:echoOperationRequest" />
            <wsdl:output message="tns:echoOperationResponse" />
          </wsdl:operation>
        </wsdl:portType>
        <wsp:Policy wsu:Id="AsymmetricX509MutualAuthenticationWithUnt">
          <wsp:ExactlyOne>
            <wsp:All>
              <sp:SignedEncryptedSupportingTokens xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702">
                <wsp:Policy>
                  <sp:UsernameToken sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient">
                    <wsp:Policy>
                      <sp:WssUsernameToken10 />
                    </wsp:Policy>
                  </sp:UsernameToken>
                </wsp:Policy>
              </sp:SignedEncryptedSupportingTokens>
              <sp:AsymmetricBinding>
                <wsp:Policy>
                  <sp:InitiatorToken>
                    <wsp:Policy>
                      <sp:X509Token sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient">
                        <wsp:Policy>
                          <sp:WssX509V3Token10 />
                          <sp:RequireIssuerSerialReference />
                        </wsp:Policy>
                      </sp:X509Token>
                    </wsp:Policy>
                  </sp:InitiatorToken>
                  <sp:RecipientToken>
                    <wsp:Policy>
                      <sp:X509Token sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/Never">
                        <wsp:Policy>
                          <sp:WssX509V3Token10 />
                          <sp:RequireIssuerSerialReference />
                        </wsp:Policy>
                      </sp:X509Token>
                    </wsp:Policy>
                  </sp:RecipientToken>
                  <sp:Layout>
                    <wsp:Policy>
                      <sp:Strict />
                    </wsp:Policy>
                  </sp:Layout>
                  <sp:IncludeTimestamp />
                  <sp:OnlySignEntireHeadersAndBody />
                  <sp:EncryptSignature />
                  <sp:AlgorithmSuite>
                    <wsp:Policy>
                      <sp:Basic128 />
                    </wsp:Policy>
                  </sp:AlgorithmSuite>
                </wsp:Policy>
              </sp:AsymmetricBinding>
              <sp:Wss11>
                <wsp:Policy>
                  <sp:MustSupportRefKeyIdentifier />
                  <sp:MustSupportRefIssuerSerial />
                  <sp:MustSupportRefThumbprint />
                  <sp:MustSupportRefEncryptedKey />
                  <sp:RequireSignatureConfirmation />
                </wsp:Policy>
              </sp:Wss11>
              <sp:SignedParts>
                <sp:Body />
              </sp:SignedParts>
              <sp:EncryptedParts>
                <sp:Body />
              </sp:EncryptedParts>
            </wsp:All>
          </wsp:ExactlyOne>
        </wsp:Policy>
        <wsdl:binding name="Echo1SOAP" type="tns:EchoServicePortType">
          <wsp:PolicyReference URI="#AsymmetricX509MutualAuthenticationWithUnt" />
          <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
          <wsdl:operation name="echoOperation">
            <soap:operation soapAction="echoOperation" style="document" />
            <wsdl:input>
              <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output>
              <soap:body use="literal" />
            </wsdl:output>
          </wsdl:operation>
        </wsdl:binding>
        <wsdl:service name="Echo1Service">
          <wsdl:port binding="tns:Echo1SOAP" name="Echo1ServicePort">
            <soap:address location="http://localhost:8010/WSSampleSei/Echo1Service" />
          </wsdl:port>
        </wsdl:service>
      </wsdl:definitions>
  2. Créez l'application de service Web avec le fichier WSDL. Vous pouvez effectuer cette étape avant ou après l'ajout de la règle de sécurité de services Web au fichier WSDL. Vous pouvez utiliser des outils pris en charge pour créer une application de service Web JAX-WS depuis le fichier WSDL que vous avez développé à la section précédente.
    L'exemple suivant illustre une application de service Web développée à partir du fichier WSDL à l'aide de l'outil Rational Application Developer (RAD) :
    @javax.jws.WebService (endpointInterface="com.ibm.was.wssample.sei.echo.EchoServicePortType",
                           targetNamespace="http://com/ibm/was/wssample/sei/echo/", 
                           serviceName="Echo1Service", 
                           wsdlLocation = "WEB-INF/wsdl/Echo.wsdl",
                           portName="Echo1ServicePort")
    public class Echo1SOAPImpl {
    
      public EchoStringResponse echoOperation(EchoStringInput parameter) {
        String strInput = (parameter == null ? "input_is_null" : parameter.getEchoInput() );
        try {
          com.ibm.was.wssample.sei.echo.EchoStringResponse strOutput = new EchoStringResponse();
          strOutput.setEchoResponse( "Echo1SOAPImpl>>" + strInput );
          return strOutput;
        } catch (java.lang.Exception ex) {
          ex.printStackTrace();
        }
      }
    
    @WebService (name = "EchoServicePortType", 
                 targetNamespace = "http://com/ibm/was/wssample/sei/echo/")
    @SOAPBinding (parameterStyle = SOAPBinding.ParameterStyle.BARE)
    @XmlSeeAlso ({
        ObjectFactory.class
    })
    
    public interface EchoServicePortType {
    
      @WebMethod (action = "echoOperation")
      @WebResult (name = "echoStringResponse", targetNamespace = "http://com/ibm/was/wssample/sei/echo/", partName = "parameter")
      public  EchoStringResponse echoOperation(
        @WebParam (name = "echoStringInput", targetNamespace = "http://com/ibm/was/wssample/sei/echo/", partName = "parameter")
        EchoStringInput parameter);
    
    }
    Le code suivant illustre un client de service Web géré qui appelle une application de fournisseur de services Web :
    @WebServlet("ClientServlet")
    public class ClientServlet extends HttpServlet {
    
      @WebServiceRef (value=Echo1Service.class, wsdlLocation="Echo.wsdl")
      Echo1Service echo1Service;
    
      public  ClientServlet() {
        super ();
      }
    
      protected void doGet(HttpServletRequest request,
                           HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response);
      } 
    
      protected void doPost(HttpServletRequest request,
                            HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response);
      }
    
      private void processRequest(HttpServletRequest req,
                                  HttpServletResponse resp) throws ServletException, IOException {
    
        String endpointURL = "http://localhost:8010/WSSampleSei/Echo1Service";
    
        Echo1ServicePortProxy proxy = new Echo1ServicePortProxy(echo1Service);
        proxy._getDescriptor().setEndpoint(endpointURL);
    
        echoParm = new ObjectFactory().createEchoStringInput();
        echoParm.setEchoInput("Hello");
    
        String retval = proxy.echoOperation(echoParm).getEchoResponse();
    
      }
    }
    L'exemple suivant illustre la structure du fichier war de l'application de fournisseur de services Web :
    WEB-INF/web.xml
    WEB-INF/wsdl/Echo.wsdl
    WEB-INF/classes/com/ibm/was/wssample/sei/echo/Echo1SOAPImpl.class
    WEB-INF/classes/com/ibm/was/wssample/sei/echo/EchoServicePortType.class
    WEB-INF/classes/com/ibm/was/wssample/sei/echo/EchoStringInput.class
    WEB-INF/classes/com/ibm/was/wssample/sei/echo/EchoStringResponse.class
    WEB-INF/classes/com/ibm/was/wssample/sei/echo/ObjectFactory.class
    WEB-INF/classes/com/ibm/was/wssample/sei/echo/package-info.class
    L'exemple suivant illustre la structure du fichier war de l'application client de service Web :
    WEB-INF/web.xml
    WEB-INF/wsdl/Echo.wsdl
    WEB-INF/classes/com/ibm/was/wssample/client/ClientServlet.class
    WEB-INF/classes/com/ibm/was/wssample/client/SampleClient.class
    WEB-INF/classes/com/ibm/was/wssample/sei/echo/Echo1Service.class
    WEB-INF/classes/com/ibm/was/wssample/sei/echo/Echo1ServicePortProxy.class
    WEB-INF/classes/com/ibm/was/wssample/sei/echo/EchoStringInput.class
    WEB-INF/classes/com/ibm/was/wssample/sei/echo/EchoStringResponse.class
    WEB-INF/classes/com/ibm/was/wssample/sei/echo/ObjectFactory.class
    WEB-INF/classes/com/ibm/was/wssample/sei/echo/package-info.class     
  3. Développez le gestionnaire d'appel. Vous devez développer un gestionnaire d'appel pour extraire les mots de passe associés au nom d'utilisateur et aux clés du fichier de clés. Le mot de passe associé au nom d'utilisateur est utilisé lorsque vous générez les jetons de nom d'utilisateur. Les mots de passe associés au fichier de clés sont utilisés pour l'accès aux clés privés dans le fichier de clés. Le gestionnaire d'appel doit renvoyer des mots de passe en texte en clair et être conditionné et installé comme une fonction utilisateur Liberty.
    L'exemple de code suivant illustre un gestionnaire d'appel :
    package com.ibm.ws.wssecurity.example.cbh;
    
    import java.util.HashMap;
    import java.util.Map;
    import javax.security.auth.callback.Callback;
    import javax.security.auth.callback.CallbackHandler;
    import org.apache.ws.security.WSPasswordCallback;
    
    public class SamplePasswordCallback implements CallbackHandler {
      private Map<String, String> userPasswords = new HashMap<String, String>();
      private Map<String, String> keyPasswords = new HashMap<String, String>();
      public SamplePasswordCallback() {
        // some example user passwords
        userPasswords.put("user1", "user1pswd");
        userPasswords.put("admin", "adminpswd");
        // some example key passwords
        keyPasswords.put("alice", "keypwsd");
        keyPasswords.put("bob", "keypswd");
      }
      public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
        for (int i = 0; i < callbacks.length; i++) {
          WSPasswordCallback pwcb = (WSPasswordCallback)callbacks[i];
          String id = pwcb.getIdentifier();
          String pass = null;
          switch (pwcb.getUsage()) {
            case WSPasswordCallback.USERNAME_TOKEN_UNKNOWN:
            case WSPasswordCallback.USERNAME_TOKEN:
              pass = userPasswords.get(id);
              pwcb.setPassword(pass);
              break;
            case WSPasswordCallback.SIGNATURE:
            case WSPasswordCallback.DECRYPT:
              pass = keyPasswords.get(id);
              pwcb.setPassword(pass);
              break;
          }
        }
      }
    }
    L'exemple suivant illustre le fichier MANIFEST.MF qui est conditionné avec le gestionnaire d'appel :
    Manifest-Version: 1.0
    Bnd-LastModified: 1359415594428
    Build-Identifier: SNAPSHOT-Mon Jan 28 17:26:34 CST 2013
    Bundle-Copyright: The Program materials contained in this file are IBM
    copyright materials. 5724-I63, 5724-J08, 5724-H89, 5724-H88, 5655-W65
    Copyright International Business Machines Corp. 1999, 2012 All Rights
    Reserved * Licensed Materials - Property of IBM US Government Users
    Restricted Rights - Use, duplication or disclosure restricted by GSA ADP
    Schedule Contract with IBM Corp.
    Bundle-Description: An PasswordCallbackHandler; version=1.0.0
    Bundle-ManifestVersion: 2
    Bundle-Name: wssecuritycbh
    Bundle-SymbolicName: com.ibm.ws.wssecurity.example.cbh
    Bundle-Vendor: IBM
    Bundle-Version: 1.0.0
    Created-By: 1.6.0 (IBM Corporation)
    Export-Package: com.ibm.ws.wssecurity.example.cbh;uses:="com.ibm.websphe
    re.ras.annotation,javax.security.auth.callback";version="1.0.0"
    Import-Package: com.ibm.websphere.ras,com.ibm.websphere.ras.annotation,c
    om.ibm.ws.ffdc,javax.security.auth.callback,org.apache.ws.security;version="[1.6,2)"
    Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version>=1.6))"
    Tool: Bnd-2.1.0.20120920-170235
    WS-TraceGroup: WSSecurity
    1. Créez un fichier JAR avec le gestionnaire d'appel et le fichier manifeste de la fonction, wsseccbh-1.0.mf. Créez un fichier JAR appelé SampleCbh.jar dont le contenu est le suivant :
      META-INF/MANIFEST.MF
      com/ibm/ws/wssecurity/example/cbh/SamplePasswordCallback.class
      L'exemple suivant illustre le fichier wsseccbh-1.0.mf :
      Subsystem-ManifestVersion: 1
      Subsystem-SymbolicName: wsseccbh-1.0; visibility:=public
      Subsystem-Version: 1.0.0
      Subsystem-Content: com.ibm.ws.wssecurity.example.cbh; version="[1,1.0.100)";
          location:="lib/"; type="osgi.bundle"; start-phase:=APPLICATION_EARLY
      
      Subsystem-Type: osgi.subsystem.feature
      IBM-Feature-Version: 2
      
      IBM-API-Package: com.ibm.ws.wssecurity.example.cbh; version="1.0"; type="internal"
    2. Copiez le fichier JAR du gestionnaire d'appel et le fichier manifeste de la fonction dans l'annuaire d'utilisateurs de Liberty. L'exemple suivant indique l'emplacement auquel le fichier JAR du gestionnaire d'appel et le fichier manifeste de la fonction sont copiés :
      build.image/wlp/usr/extension/lib/SampleCbh.jar
      build.image/wlp/usr/extension/lib/features/wsseccbh-1.0.mf
  4. Configurez la sécurité de services Web sur le serveur Liberty. Activez la fonction de sécurité de services Web dans le fichier de configuration de serveur Liberty server.xml et configurez la sécurité de services Web pour l'application de fournisseur de services Web et l'application client de service Web qui ont été développées dans les sections précédentes.
    L'exemple suivant illustre la configuration de la sécurité de services Web :
    <server>
      <featureManager>
        <feature>usr:wsseccbh-1.0</feature>
        <feature>servlet-3.0</feature>
        <feature>appSecurity-2.0</feature>
        <feature>jsp-2.2</feature>
        <feature>jaxws-2.2</feature>
        <feature>wsSecurity-1.1</feature>
      </featureManager>
      <basicRegistry id="basic" realm="customRealm">
        <user name="user1" password="user1pswd" />
        <user name="user2" password="user2pswd" />
      </basicRegistry>
      <wsSecurityProvider id="default"
        ws-security.callback-handler="com.ibm.ws.wssecurity.example.cbh.SamplePasswordCallback"
        ws-security.signature.username="bob">
        <signatureProperties org.apache.ws.security.crypto.merlin.keystore.type="jceks"
          org.apache.ws.security.crypto.merlin.keystore.password="storepswd"
          org.apache.ws.security.crypto.merlin.keystore.alias="bob"
          org.apache.ws.security.crypto.merlin.file="${server.config.dir}/enc-receiver.jceks" />
        <encryptionProperties org.apache.ws.security.crypto.merlin.keystore.type="jceks"
          org.apache.ws.security.crypto.merlin.keystore.password="storepswd"
          org.apache.ws.security.crypto.merlin.keystore.alias="alice"
          org.apache.ws.security.crypto.merlin.file="${server.config.dir}/enc-receiver.jceks" />
      </wsSecurityProvider>
      <wsSecurityClient id="default"
        ws-security.password="security"
        ws-security.username="user1"
        ws-security.callback-handler="com.ibm.ws.wssecurity.example.cbh.SamplePasswordCallback"
        ws-security.encryption.username="alice">
        <signatureProperties org.apache.ws.security.crypto.merlin.keystore.type="jceks"
          org.apache.ws.security.crypto.merlin.keystore.password="storepswd"
          org.apache.ws.security.crypto.merlin.keystore.alias="alice"
          org.apache.ws.security.crypto.merlin.file="${server.config.dir}/enc-sender.jceks"/>
        <encryptionProperties org.apache.ws.security.crypto.merlin.keystore.type="jceks"
          org.apache.ws.security.crypto.merlin.keystore.password="storepswd"
          org.apache.ws.security.crypto.merlin.keystore.alias="bob"
          org.apache.ws.security.crypto.merlin.file="${server.config.dir}/enc-sender.jceks" />
      </wsSecurityClient>
    </server>

Résultats

Vous avez sécurisé un service Web avec une règle de sécurité de services Web.

Exemple

L'exemple de règle de sécurité de services Web qui a été créé au cours de la première étape génère des messages de demande et de réponse SOAP qui sont similaires aux messages ci-après.
L'exemple suivant illustre le message de demande SOAP :
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
                   xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
                   soap:mustUnderstand="1">
      <wsse:BinarySecurityToken
        EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"
        ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"
        wsu:Id="X509-B1165B2A578AFFC7D613649595665924">...
      </wsse:BinarySecurityToken>
      <wsu:Timestamp wsu:Id="TS-1">
        <wsu:Created>2013-04-03T03:26:06.549Z</wsu:Created>
        <wsu:Expires>2013-04-03T03:31:06.549Z</wsu:Expires>
      </wsu:Timestamp>
      <xenc:EncryptedKey xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Id="EK-B1165B2A578AFFC7D613649595666705">
        <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"></xenc:EncryptionMethod>
        <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
          <wsse:SecurityTokenReference>
            <ds:X509Data>
              <ds:X509IssuerSerial>
                <ds:X509IssuerName>CN=Bob,O=IBM,C=US</ds:X509IssuerName>
                <ds:X509SerialNumber>24054675667389</ds:X509SerialNumber>
              </ds:X509IssuerSerial>
            </ds:X509Data>
          </wsse:SecurityTokenReference>
        </ds:KeyInfo>
        <xenc:CipherData>
          <xenc:CipherValue>...</xenc:CipherValue>
        </xenc:CipherData>
        <xenc:ReferenceList>
          <xenc:DataReference URI="#ED-4"></xenc:DataReference>
          <xenc:DataReference URI="#ED-5"></xenc:DataReference>
          <xenc:DataReference URI="#ED-6"></xenc:DataReference>
        </xenc:ReferenceList>
      </xenc:EncryptedKey>
      <xenc:EncryptedData
        xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Id="ED-6" Type="http://www.w3.org/2001/04/xmlenc#Element">
        <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"></xenc:EncryptionMethod>
        <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
          <wsse:SecurityTokenReference
            xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
            xmlns:wsse11="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd"
            wsse11:TokenType="http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#EncryptedKey">
            <wsse:Reference URI="#EK-B1165B2A578AFFC7D613649595666705"></wsse:Reference>
          </wsse:SecurityTokenReference>
        </ds:KeyInfo>
        <xenc:CipherData>
          <xenc:CipherValue>...</xenc:CipherValue>
        </xenc:CipherData>
      </xenc:EncryptedData>
      <xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
                          Id="ED-5"
                          Type="http://www.w3.org/2001/04/xmlenc#Element">
        <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"></xenc:EncryptionMethod>
        <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
          <wsse:SecurityTokenReference
            xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
            xmlns:wsse11="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd"
            wsse11:TokenType="http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#EncryptedKey">
            <wsse:Reference URI="#EK-B1165B2A578AFFC7D613649595666705"></wsse:Reference>
          </wsse:SecurityTokenReference>
        </ds:KeyInfo>
        <xenc:CipherData>
          <xenc:CipherValue>...</xenc:CipherValue>
        </xenc:CipherData>
      </xenc:EncryptedData>
    </wsse:Security>
  </SOAP-ENV:Header>
  <soap:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
             wsu:Id="Id-1788936596">
    <xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
                        Id="ED-4"
                        Type="http://www.w3.org/2001/04/xmlenc#Content">
      <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"></xenc:EncryptionMethod>
      <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
        <wsse:SecurityTokenReference
          xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
          xmlns:wsse11="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd"
          wsse11:TokenType="http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#EncryptedKey">
          <wsse:Reference URI="#EK-B1165B2A578AFFC7D613649595666705"></wsse:Reference>
        </wsse:SecurityTokenReference>
      </ds:KeyInfo>
      <xenc:CipherData>
        <xenc:CipherValue>...</xenc:CipherValue>
      </xenc:CipherData>
    </xenc:EncryptedData>
  </soap:Body>
</soap:Envelope>
L'exemple suivant illustre un message de réponse SOAP :
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
                   xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
                   soap:mustUnderstand="1">
      <wsu:Timestamp wsu:Id="TS-7">
        <wsu:Created>2013-04-03T03:26:07.286Z</wsu:Created>
        <wsu:Expires>2013-04-03T03:31:07.286Z</wsu:Expires>
      </wsu:Timestamp>
      <xenc:EncryptedKey xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Id="EK-B1165B2A578AFFC7D613649595673129">
        <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"></xenc:EncryptionMethod>
        <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
          <wsse:SecurityTokenReference>
            <ds:X509Data>
              <ds:X509IssuerSerial>
                <ds:X509IssuerName>CN=Alice,O=IBM,C=US</ds:X509IssuerName>
                <ds:X509SerialNumber>24054530212598</ds:X509SerialNumber>
              </ds:X509IssuerSerial>
            </ds:X509Data>
          </wsse:SecurityTokenReference>
        </ds:KeyInfo>
        <xenc:CipherData>
          <xenc:CipherValue>...</xenc:CipherValue>
        </xenc:CipherData>
        <xenc:ReferenceList>
          <xenc:DataReference URI="#ED-10"></xenc:DataReference>
          <xenc:DataReference URI="#ED-11"></xenc:DataReference>
          <xenc:DataReference URI="#ED-12"></xenc:DataReference>
        </xenc:ReferenceList>
      </xenc:EncryptedKey>
      <xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
                          Id="ED-12"
                          Type="http://www.w3.org/2001/04/xmlenc#Element">
        <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"></xenc:EncryptionMethod>
        <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
          <wsse:SecurityTokenReference
            xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
            xmlns:wsse11="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd"
            wsse11:TokenType="http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#EncryptedKey">
            <wsse:Reference URI="#EK-B1165B2A578AFFC7D613649595673129"></wsse:Reference>
          </wsse:SecurityTokenReference>
        </ds:KeyInfo>
        <xenc:CipherData>
          <xenc:CipherValue>...</xenc:CipherValue>
        </xenc:CipherData>
      </xenc:EncryptedData>
      <xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
                          Id="ED-11"
                          Type="http://www.w3.org/2001/04/xmlenc#Element">
        <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"></xenc:EncryptionMethod>
        <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
          <wsse:SecurityTokenReference
            xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
            xmlns:wsse11="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd"
            wsse11:TokenType="http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#EncryptedKey">
            <wsse:Reference URI="#EK-B1165B2A578AFFC7D613649595673129"></wsse:Reference>
          </wsse:SecurityTokenReference>
        </ds:KeyInfo>
        <xenc:CipherData>
          <xenc:CipherValue>...</xenc:CipherValue>
        </xenc:CipherData>
      </xenc:EncryptedData>
    </wsse:Security>
  </SOAP-ENV:Header>
  <soap:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
             wsu:Id="Id-2035943749">
    <xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
                        Id="ED-10"
                        Type="http://www.w3.org/2001/04/xmlenc#Content">
      <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"></xenc:EncryptionMethod>
      <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
        <wsse:SecurityTokenReference
          xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
          xmlns:wsse11="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd"
          wsse11:TokenType="http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#EncryptedKey">
          <wsse:Reference URI="#EK-B1165B2A578AFFC7D613649595673129"></wsse:Reference>
        </wsse:SecurityTokenReference>
      </ds:KeyInfo>
      <xenc:CipherData>
        <xenc:CipherValue>...</xenc:CipherValue>
      </xenc:CipherData>
    </xenc:EncryptedData>
  </soap:Body>
</soap:Envelope>

Que faire ensuite

A présent, vous pouvez développer votre propre fichier WSDL et protéger l'application de service Web avec une règle de sécurité de services Web qui satisfait vos exigences relatives à la sécurité.

Icône indiquant le type de rubrique Rubrique Tâche



Icône d'horodatage Dernière mise à jour: Tuesday, 6 December 2016
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=twlp_wssec_securing
Nom du fichier : twlp_wssec_securing.html