Vous pouvez configurer la communication SSL pour vos applications client pour l'accès aux services Web.
Avant de commencer
Vous devez remplir les conditions préalables suivantes avant d'activer la communication SSL pour l'accès aux services Web :
Remarque : L'utilitaire keytool se trouve dans le répertoire d'installation Java™.
Pourquoi et quand exécuter cette tâche
Si vous devez utiliser votre application client de service Web avec le protocole HTTP sécurisé pour accéder aux ressources de service Web protégées, tous les messages sont chiffrés conformément à la spécification SSL.
Procédure
- Activez les fonctions jaxws-2.2,
servlet-3.0(ou servlet-3.1) et
appSecurity-2.0 dans le fichier
server.xml.
<featureManager>
<feature>jaxws-2.2</feature>
<feature>servlet-3.0</feature>
<feature>appSecurity-2.0</feature>
</featureManager>
- Configurez les éléments SSL dans le fichier server.xml.
<sslDefault sslRef="customizeSSLConfig" />
<ssl id="customizeSSLConfig" keyStoreRef="serverKeyStore" trustStoreRef="serverTrustStore" />
<keyStore id="serverKeyStore" location="myKey.jks" type="JKS" password="passw0rd" />
<keyStore id="serverTrustStore" location="myKey.jks" type="JKS" password="passw0rd" />
- Configurez le fournisseur de services en spécifiant les noeuds finaux de services Web.
- Créez des services Web.
@WebService(serviceName = "SayHelloPojoService",
portName = "SayHelloPojoPort")
public class SayHelloPojoService implements SayHelloService {
...
}
@WebService(serviceName = "SayHelloStatelessService",
portName = "SayHelloStatelessPort",
endpointInterface = "com.ibm.ws.jaxws.transport.server.security.SayHelloService")
@Stateless(name = "SayHelloSessionBean")
public class SayHelloStatelessService implements SayHelloLocal {
...
}
- Configurez le fichier ibm-ws-bnd.xml pour le fournisseur de services.
<?xml version="1.0" encoding="UTF-8"?>
<webservices-bnd xmlns="http://websphere.ibm.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee
http://websphere.ibm.com/xml/ns/javaee/ibm-ws-bnd_1_0.xsd "
version="1.0">
<http-publishing>
<webservice-security>
<security-constraint>
<web-resource-collection>
<web-resource-name>All</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
</webservice-security>
</http-publishing>
</webservices-bnd>
Remarque : Le fichier ibm-ws-bnd.xml doit se trouver dans le répertoire
/WEB-INF d'une application Web ou dans le répertoire
/META-INF d'une application de service Web reposant sur un EJB (archive JAR).
- Configurez le client de service en spécifiant les noeuds finaux de services Web. Par exemple, l'application client est une application Web nommée TransportSecurityClient.war.
- Configurez l'application client dans le fichier server.xml.
<application id="TransportSecurityClient" name="TransportSecurityClient"
location="TransportSecurityClient.war"
context-root="TransportSecurityClient" type="war" />
- Configurez le fichier ibm-ws-bnd.xml pour l'application client.
<?xml version="1.0" encoding="UTF-8"?>
<webservices-bnd id="idvalue0" version="1.0" xmlns="http://websphere.ibm.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee
http://websphere.ibm.com/xml/ns/javaee/ibm-ws-bnd_1_0.xsd " >
<!-- POJO service reference binding-->
<service-ref name="service/SayHelloPojoService">
<port name="SayHelloPojoPort"
namespace="http://ibm.com/ws/jaxws/transport/security/"
ssl-ref="customizeSSLConfig"/>
<properties http.conduit.tlsClientParameters.disableCNCheck="true" />
</service-ref>
<!-- Stateless service reference binding-->
<service-ref name="service/SayHelloStatelessService">
<port name="SayHelloStatelessPort"
namespace="http://ibm.com/ws/jaxws/transport/security/"
ssl-ref="customizeSSLConfig"/>
<properties http.conduit.tlsClientParameters.disableCNCheck="true" />
</service-ref>
</webservices-bnd>
Remarque : - Le fichier ibm-ws-bnd.xml doit se trouver dans le répertoire /WEB-INF de l'application Web client.
- La valeur de l'attribut ssl-ref doit correspondre à la valeur d'ID de l'élément
ssl dans le fichier server.xml.
- Si l'attribut ssl-ref n'est pas spécifié dans le fichier
ibm-ws-bnd.xml, la configuration SSL par défaut du profil Liberty est utilisée par le moteur de services Web si elle existe.
- L'attribut http.conduit.tlsClientParameters.disableCNcheck est utilisé pour contrôler la validation du serveur distant. Associez false à cet attribut dans un environnement de production car la vérification hostName est ignorée si cet attribut a la valeur true.
- Générez les modules de remplacement client via l'emplacement WSDL.
@WebServiceClient(name = "SayHelloPojoService",
targetNamespace = "http://ibm.com/ws/jaxws/transport/security/",
wsdlLocation = "https://localhost:8020/TransportSecurityProvider/unauthorized/employPojoService?wsdl")
public class SayHelloPojoService
extends Service
{...}
@WebServiceClient(name = "SayHelloStatelessService",
targetNamespace = "http://ibm.com/ws/jaxws/transport/security/",
wsdlLocation = "https://localhost:8020/TransportSecurityProvider/unauthorized/EmployStatelessService?wsdl")
public class SayHelloStatelessService
extends Service
{...}
- Utilisez l'annotation @WebServiceRef pour injecter le service Web dans le servlet, par exemple TestJaxWsTransportSecurityServlet.
@WebServiceRef(name = "service/SayHelloPojoService")
SayHelloPojoService pojoService;
@WebServiceRef(name = "service/SayHelloStatelessService")
SayHelloStatelessService statelessService;