Activation de l'authentification de base pour l'accès aux services Web
Vous pouvez configurer l'authentification de base pour que vos applications client puissent accéder aux services Web.
Pourquoi et quand exécuter cette tâche
Si vous devez utiliser votre application client de service Web avec l'authentification de base pour accéder aux ressources de service Web protégées, le client doit fournir le nom d'utilisateur et le mot de passe dans la demande lorsqu'il communique avec le fournisseur de services.
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 le domaine de connexion dans le fichier server.xml et liez le domaine au fournisseur de services.
<application id="TransportSecurityProvider" name="TransportSecurityProvider" location="TransportSecurityProvider.war" type="ear"> <application-bnd> <security-role name="Employee"> <user name="employee0" /> <group name="employeeGroup" /> </security-role> <security-role name="Manager"> <user name="manager0" /> </security-role> <security-role name="AllAuthenticated"> <special-subject type="ALL_AUTHENTICATED_USERS" /> </security-role> </application-bnd> </application> <basicRegistry id="basic" realm="BasicRealm"> <user name="employee0" password="emp0pwd" /> <user name="employee1" password="emp1pwd" /> <user name="manager0" password="mgr0pwd" /> <group name="employeeGroup"> <member name="employee0" /> <member name="employee1" /> </group> </basicRegistry>
- 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>Only Managers</web-resource-name> <url-pattern>/manager/*</url-pattern> <http-method>GET</http-method> <http-method>POST</http-method> </web-resource-collection> <auth-constraint id="AuthConstraint_manager"> <role-name>Manager</role-name> </auth-constraint> </security-constraint> <security-constraint> <web-resource-collection> <web-resource-name>Employees</web-resource-name> <url-pattern>/employee/*</url-pattern> <http-method>GET</http-method> <http-method>POST</http-method> </web-resource-collection> <auth-constraint id="AuthConstraint_employee"> <role-name>Employee</role-name> </auth-constraint> </security-constraint> <!-- SECURITY ROLES --> <security-role id="Staff"> <role-name>Employee</role-name> <role-name>Manager</role-name> </security-role> <!-- AUTHENTICATION METHOD: Basic authentication --> <login-config id="LoginConfig"> <auth-method>BASIC</auth-method> <realm-name>Authentication</realm-name> </login-config> </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).
- L'élément login-config du fichier ibm-ws-bnd.xml n'a d'effet que dans une application de service Web reposant sur un EJB (archive JAR). Dans le cas d'une application Web, l'élément login-config est ignoré et la valeur du même élément figurant dans le fichier web.xml est utilisée.
- Créez des services Web.
- 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 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"> <!-- POJO service reference binding--> <service-ref name="service/SayHelloPojoService"> <port name="SayHelloPojoPort" namespace="http://ibm.com/ws/jaxws/transport/security/" username="employee1" password="{xor}OjIvbi8oOw==" /> </service-ref> <!-- Stateless service reference binding--> <service-ref name="service/SayHelloStatelessService"> <port name="SayHelloStatelessPort" namespace="http://ibm.com/ws/jaxws/transport/security/" username="employee1" password="{xor}OjIvbi8oOw==" /> </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.
- Les valeurs des attributs username et password doivent correspondre au nom d'utilisateur et au mot de passe de l'élément basicRegistry figurant dans le fichier server.xml. Le mot de passe peut être codé avec la commande securityUtility.
- 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;
- Configurez l'application client dans le fichier server.xml.
Référence associée:

Dispositions pour les centres de documentation | Commentaires

http://www14.software.ibm.com/webapp/wsbroker/redirect?version=phil&product=was-libcore-mp&topic=twlp_sec_ws_basicauth
Nom du fichier : twlp_sec_ws_basicauth.html