IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Services Web Java Discussion :

Pb Appel à un WebService sécurisé - tomcat + netbeans + metro


Sujet :

Services Web Java

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    6
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 6
    Points : 4
    Points
    4
    Par défaut Pb Appel à un WebService sécurisé - tomcat + netbeans + metro
    Bonjour à tous,

    Je ne parviens pas à résoudre ce problème
    Je dois sécuriser des Web Services sous netbeans avec apache tomcat 5.5 pour serveur d'applications.

    J'ai installé Metro, WSIT, JAX-WS.. (Cf: https://metro.dev.java.net/1.1/ )
    Et je souhaite utiliser des WebServices sécurisé par authentification basique et par SSL.
    J'ai généré le certificat via l'outil keytool, comme décrit dans les différents tuto.
    Au déploiement, coté serveur, je ne remarque aucun problème (acceptation du certif, authentification...)
    Si je me contente d'une connexion sécurisée en https, pas de problème. Mais dès que j'ajoute une authentification, le client ne veut rien entendre (Visual Studio, ou même Netbeans).

    Ce qui est très difficile pour moi, c'est de ne pas pouvoir trouver l'origine du problème: config de tomcat, installation de metro, déploiement d'un WS netbeans, utilisation d'un WS depuis visual studio...? Ce n'est pas vraiment évident : /


    Authentification BASIC via MemoryRealm (tomcat-users)
    Si je ne passe pas par SSL :
    Au niveau de l'appel au webservice: déclenchement de "WebException" avec pour propriété status "ProtocolError", code 505 "http version not supported"

    Coté Visual Studio, cela donne donc:

    Sans SSL
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
     
    L'exception System.Net.WebException n'a pas été gérée
     
      Message="La demande a échoué avec l'état HTTP 505 : Version HTTP Non Supportée."
     
      Source="System.Web.Services"
     
      StackTrace:
     
           à System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
     
           à System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
     
           à WindowsApplication1.WebReference.ServicesService.operation(Int32 p1, Int32 p2, Int32 p3) dans E:\Mes documents\Visual Studio Projects\WindowsApplication1\WindowsApplication1\Web References\WebReference\Reference.cs:ligne 80
     
           à WindowsApplication1.Form1.button1_Click(Object sender, EventArgs e) dans E:\Mes documents\Visual Studio Projects\WindowsApplication1\WindowsApplication1\Form1.cs:ligne 41
     
           à System.Windows.Forms.Control.OnClick(EventArgs e)
     
           à System.Windows.Forms.Button.OnClick(EventArgs e)
     
           à System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
     
           à System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
     
           à System.Windows.Forms.Control.WndProc(Message& m)
     
           à System.Windows.Forms.ButtonBase.WndProc(Message& m)
     
           à System.Windows.Forms.Button.WndProc(Message& m)
     
           à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
     
           à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
     
           à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
     
           à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
     
           à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
     
           à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
     
           à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
     
           à System.Windows.Forms.Application.Run(Form mainForm)
     
           à WindowsApplication1.Program.Main() dans E:\Mes documents\Visual Studio Projects\WindowsApplication1\WindowsApplication1\Program.cs:ligne 17
     
           à System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
     
           à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
     
           à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
     
           à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
     
           à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
     
           à System.Threading.ThreadHelper.ThreadStart()

    Avec SSL:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
     
    L'exception System.Net.WebException n'a pas été gérée
     
      Message="La connexion sous-jacente a été fermée : Impossible d'établir une relation de confiance pour le canal sécurisé SSL/TLS."
     
      Source="System.Web.Services"
     
      StackTrace:
     
           à System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request)
     
           à System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request)
     
           à System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
     
           à ClientConsole.WebReference.ServicesService.operation(Int32 p1, Int32 p2, Int32 p3) dans E:\Mes documents\Visual Studio 2005\Projects\ClientConsole\ClientConsole\Web References\WebReference\Reference.cs:ligne 80
     
           à ClientConsole.Program.Main(String[] args) dans E:\Mes documents\Visual Studio 2005\Projects\ClientConsole\ClientConsole\Program.cs:ligne 21
     
           à System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
     
           à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
     
           à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
     
           à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
     
           à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
     
           à System.Threading.ThreadHelper.ThreadStart()
    Je n'arrive pas non plus a jouter ce web service client dans un projet Netbeans:
    fenêtre Pop-up:
    "Problem with downloading wsdl or schema file. Check the URL, proxy settings or whether the server is running."

    Si cela peut aider, voici le web.xml de mon appli et une partie du server.xml

    web.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
     
    <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <listener>
     <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
    </listener>
     
    <servlet>
    <servlet-name>Services</servlet-name>
          <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>
        <servlet-mapping>
            <servlet-name>Services</servlet-name>
            <url-pattern>/Services</url-pattern>
        </servlet-mapping>
        <session-config>
            <session-timeout>
                30
            </session-timeout>
        </session-config>
        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
     
        <security-constraint>
            <display-name>SSL transport for ServicesService </display-name>
            <web-resource-collection>
                <web-resource-name>Secure Area</web-resource-name>
                <description/>
                <url-pattern>/Services/*</url-pattern>
                <url-pattern>/*</url-pattern>
                <url-pattern>/ServicesService/*</url-pattern>
                <http-method>GET</http-method>
                <http-method>POST</http-method>
                <http-method>HEAD</http-method>
                <http-method>PUT</http-method>
                <http-method>OPTIONS</http-method>
                <http-method>TRACE</http-method>
                <http-method>DELETE</http-method>
                </web-resource-collection>
     
            <auth-constraint>
                <role-name>wsclient</role-name>
            </auth-constraint>
            <user-data-constraint>
                <description/>
                <transport-guarantee>CONFIDENTIAL</transport-guarantee>
            </user-data-constraint>
        </security-constraint>
        <login-config>
            <auth-method>BASIC</auth-method>
            <realm-name>MemoryRealm</realm-name>
        </login-config>
        <security-role>
            <description/>
            <role-name>wsclient</role-name>
        </security-role>
    </web-app>
    server.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    [...]
        <Connector port="8443" maxHttpHeaderSize="8192"
                   maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
                   enableLookups="true" disableUploadTimeout="true"
                   acceptCount="100" scheme="https" secure="true" SSLEnabled="true"
                   keystoreFile=chemin/vers/apache-tomcat-5.5/keystore"
    	       keystorePass="password" clientAuth="false" sslProtocol="TLS"/>
    [...]
          <Realm className="org.apache.catalina.realm.MemoryRealm" />
    [...]

    Toute aide est la bienvenue.
    Merci.

    Saitou-San

  2. #2
    Candidat au Club
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    6
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 6
    Points : 4
    Points
    4
    Par défaut
    Bonjour à tous,
    J'ai résolu une partie du problème. C'était peut-être du à tomcat, au niveau de la compatibilité http 1.0 et http 1.1.
    Au final, j'ai du ajouter ce bout de code dans mon client sous visual studio:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    [...]
    System.Net.ServicePointManager.ServerCertificateValidationCallback = TrustAllCertificateCallback;
    
    ServicePointManager.Expect100continue = false;
    
    // Instanciation de la classe proxy permettant
    // l'appel distant au Webservice            
    ServicesService vWSClient = new ServicesService();
    [...]
    Désormais, un autre problème subsiste et je pense que les modifs sont peut à mener du coté serveur (configuration d'apache tomcat, librairie de metro...)

    Le web service est accessible et fonctionnel lorsque je ne passe pas par l'assistant netbeans pour configurer la sécurisation (c'est à dire en bidouillant juste mon web.xml).
    Si j'essaie de suivre la démarche officielle de l'assistant (choix du mode de sécurisation, choix de l'algorithme de cryptage, etc...) l'on m'adresse un warning:
    "Avertissement de l'outil personnalisé: Au moins une importation ServiceDescriptionFormatExtension facultative a été ignorée"

    A l'exécution, j'ai une exception System.Web.Services.Protocols.SoapException, "Security Requirements not met - No Security header in message".

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
     
    L'exception System.Web.Services.Protocols.SoapException n'a pas été gérée
     
      Message="Security Requirements not met - No Security header in message"
     
      Source="System.Web.Services"
     
      Actor=""
     
      Lang=""
     
      Node=""
     
      Role=""
     
      StackTrace:
     
           à System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
     
           à System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
     
           à WindowsApplication1.WebReference.ServicesService.operation(Int32 p1, Int32 p2, Int32 p3) dans E:\Mes documents\Visual Studio Projects\WindowsApplication1\WindowsApplication1\Web References\WebReference\Reference.cs:ligne 80
     
           à WindowsApplication1.Form1.button1_Click(Object sender, EventArgs e) dans E:\Mes documents\Visual Studio Projects\WindowsApplication1\WindowsApplication1\Form1.cs:ligne 41
     
           à System.Windows.Forms.Control.OnClick(EventArgs e)
     
           à System.Windows.Forms.Button.OnClick(EventArgs e)
     
           à System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
     
           à System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
     
           à System.Windows.Forms.Control.WndProc(Message& m)
     
           à System.Windows.Forms.ButtonBase.WndProc(Message& m)
     
           à System.Windows.Forms.Button.WndProc(Message& m)
     
           à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
     
           à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
     
           à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
     
           à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
     
           à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
     
           à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
     
           à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
     
           à System.Windows.Forms.Application.Run(Form mainForm)
     
           à WindowsApplication1.Program.Main() dans E:\Mes documents\Visual Studio Projects\WindowsApplication1\WindowsApplication1\Program.cs:ligne 17
     
           à System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
     
           à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
     
           à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
     
           à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
     
           à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
     
           à System.Threading.ThreadHelper.ThreadStart()
    Coté développement du web service sous netbeans, lorsque je suis la démarche rigoureuse de sécurisation, le fichier wsit-webservices.Services.xml change considérablement:

    wsit-webservices.Services.xml en contournant l'assistant visuel de netbeans (pas de détail pour l'encryptage des données, etc.):

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
     
    <?xml version="1.0" encoding="UTF-8"?> 
     <definitions 
     xmlns="http://schemas.xmlsoap.org/wsdl/" 
     xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="ServicesService" targetNamespace="http://webservices/" xmlns:tns="http://webservices/" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsaws="http://www.w3.org/2005/08/addressing" xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy" xmlns:sc="http://schemas.sun.com/2006/03/wss/server" xmlns:wspp="http://java.sun.com/xml/ns/wsit/policy" 
     >
        <message name="operation"/>
        <message name="operationResponse"/>
        <portType name="Services">
            <operation name="operation">
                <input message="tns:operation"/>
                <output message="tns:operationResponse"/>
            </operation>
        </portType>
        <binding name="ServicesPortBinding" type="tns:Services">
            <operation name="operation">
                <input></input>
                <output></output>
            </operation>
        </binding>
        <service name="ServicesService">
            <port name="ServicesPort" binding="tns:ServicesPortBinding"/>
        </service>
    </definitions>
    wsit-webservices.Services.xml en passant par l'assistant design Services de Netbeans:

    - Message authentication over SSL
    - Authentication token: Username
    - WSS Version: 1.0
    - Algorithm Suite: Basic 128 bits
    - Security Header layout: Lax
    - Establish secure session: non cochée
    - Encrypt signature: non cochée

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
     
    <?xml version="1.0" encoding="UTF-8"?> 
     <definitions 
     xmlns="http://schemas.xmlsoap.org/wsdl/" 
     xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="ServicesService" targetNamespace="http://webservices/" xmlns:tns="http://webservices/" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsaws="http://www.w3.org/2005/08/addressing" xmlns:sc="http://schemas.sun.com/2006/03/wss/server" xmlns:wspp="http://java.sun.com/xml/ns/wsit/policy" xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy" 
     >
        <message name="operation"/>
        <message name="operationResponse"/>
        <portType name="Services">
            <operation name="operation">
                <input message="tns:operation"/>
                <output message="tns:operationResponse"/>
            </operation>
        </portType>
        <binding name="ServicesPortBinding" type="tns:Services">
            <wsp:PolicyReference URI="#ServicesPortBindingPolicy"/>
            <operation name="operation">
                <input></input>
                <output></output>
            </operation>
        </binding>
        <service name="ServicesService">
            <port name="ServicesPort" binding="tns:ServicesPortBinding"/>
        </service>
        <wsp:Policy wsu:Id="ServicesPortBindingPolicy">
            <wsp:ExactlyOne>
                <wsp:All>
                    <wsaws:UsingAddressing xmlns:wsaws="http://www.w3.org/2006/05/addressing/wsdl"/>
                    <sp:TransportBinding>
                        <wsp:Policy>
                            <sp:TransportToken>
                                <wsp:Policy>
                                    <sp:HttpsToken RequireClientCertificate="false"/>
                                </wsp:Policy>
                            </sp:TransportToken>
                            <sp:Layout>
                                <wsp:Policy>
                                    <sp:Lax/>
                                </wsp:Policy>
                            </sp:Layout>
                            <sp:IncludeTimestamp/>
                            <sp:AlgorithmSuite>
                                <wsp:Policy>
                                    <sp:Basic128/>
                                </wsp:Policy>
                            </sp:AlgorithmSuite>
                        </wsp:Policy>
                    </sp:TransportBinding>
                    <sp:Wss10>
                        <wsp:Policy>
                            <sp:MustSupportRefKeyIdentifier/>
                        </wsp:Policy>
                    </sp:Wss10>
                    <sp:SignedSupportingTokens>
                        <wsp:Policy>
                            <sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
                                <wsp:Policy>
                                    <sp:WssUsernameToken10/>
                                </wsp:Policy>
                            </sp:UsernameToken>
                        </wsp:Policy>
                    </sp:SignedSupportingTokens>
                </wsp:All>
            </wsp:ExactlyOne>
        </wsp:Policy>
    </definitions>
    Je suis actuellement sur une piste qui consiste à installer XWSS ( XML and WebServices Security Project )
    https://xwss.dev.java.net/

    Je vous tiens au courant.

  3. #3
    oca
    oca est déconnecté
    Membre averti
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    354
    Détails du profil
    Informations personnelles :
    Âge : 51
    Localisation : Suisse

    Informations forums :
    Inscription : Octobre 2004
    Messages : 354
    Points : 421
    Points
    421
    Par défaut
    Citation Envoyé par Saitou-San Voir le message

    Je suis actuellement sur une piste qui consiste à installer XWSS ( XML and WebServices Security Project )
    https://xwss.dev.java.net/

    Je vous tiens au courant.
    J'y connais pas grand chose en securité, mais je sais qu'il existe aussi le framework wss4j http://ws.apache.org/wss4j/index.html (ou cas ou tu voudrais aussi essayer autre chose que xwss)
    A+

  4. #4
    Candidat au Club
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    6
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 6
    Points : 4
    Points
    4
    Par défaut
    Merci oca, je vais essayer de rester avec l'association netbeans + metro.
    Je ne comprends toujours pas, j'ai bel et bien installé la dernière version de metro, donc je dois disposer de WSIT et de tout ce qu'il me faut pour utiliser tomcat efficacement.

    Je fournis encore une fois mon wsit-webservices.[...].xml et aussi mon wsdl
    Au cas où quelqu'un aurait une idée...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
     
    <?xml version="1.0" encoding="UTF-8"?> 
     <definitions 
     xmlns="http://schemas.xmlsoap.org/wsdl/" 
     xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="ServicesService" targetNamespace="http://webservices/" xmlns:tns="http://webservices/" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsaws="http://www.w3.org/2005/08/addressing" xmlns:sc="http://schemas.sun.com/2006/03/wss/server" xmlns:wspp="http://java.sun.com/xml/ns/wsit/policy" xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy" 
     >
        <message name="operation"></message>
        <message name="operationResponse"/>
        <portType name="Services">
            <operation name="operation">
                <input message="tns:operation"/>
                <output message="tns:operationResponse"/>
            </operation>
        </portType>
        <binding name="ServicesPortBinding" type="tns:Services">
            <wsp:PolicyReference URI="#ServicesPortBindingPolicy"/>
            <operation name="operation">
                <input></input>
                <output></output>
            </operation>
        </binding>
        <service name="ServicesService">
            <port name="ServicesPort" binding="tns:ServicesPortBinding"/>
        </service>
        <wsp:Policy wsu:Id="ServicesPortBindingPolicy">
            <wsp:ExactlyOne>
                <wsp:All>
                    <wsaws:UsingAddressing xmlns:wsaws="http://www.w3.org/2006/05/addressing/wsdl"/>
                    <sp:TransportBinding>
                        <wsp:Policy>
                            <sp:TransportToken>
                                <wsp:Policy>
                                    <sp:HttpsToken RequireClientCertificate="false"/>
                                </wsp:Policy>
                            </sp:TransportToken>
                            <sp:Layout>
                                <wsp:Policy>
                                    <sp:Lax/>
                                </wsp:Policy>
                            </sp:Layout>
                            <sp:IncludeTimestamp/>
                            <sp:AlgorithmSuite>
                                <wsp:Policy>
                                    <sp:Basic128/>
                                </wsp:Policy>
                            </sp:AlgorithmSuite>
                        </wsp:Policy>
                    </sp:TransportBinding>
                    <sp:Wss10>
                        <wsp:Policy>
                            <sp:MustSupportRefKeyIdentifier/>
                        </wsp:Policy>
                    </sp:Wss10>
                    <sp:SignedSupportingTokens>
                        <wsp:Policy>
                            <sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
                                <wsp:Policy>
                                    <sp:WssUsernameToken10/>
                                </wsp:Policy>
                            </sp:UsernameToken>
                        </wsp:Policy>
                    </sp:SignedSupportingTokens>
                </wsp:All>
            </wsp:ExactlyOne>
        </wsp:Policy>
    </definitions>
    wsdl

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
     
    <!--
     Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.3-hudson-390-. 
    -->
    <!--
     Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.3-hudson-390-. 
    -->
    <definitions targetNamespace="http://webservices/" name="ServicesService">
    <ns1:Policy wsu:Id="ServicesPortBindingPolicy">
    <ns1:ExactlyOne>
    <ns1:All>
    <ns2:SignedSupportingTokens>
    <ns1:Policy>
    <ns1:ExactlyOne>
    <ns1:All>
    <ns2:UsernameToken ns2:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
    <ns1:Policy>
    <ns1:ExactlyOne>
    <ns1:All>
    <ns2:WssUsernameToken10/>
    </ns1:All>
    </ns1:ExactlyOne>
    </ns1:Policy>
    </ns2:UsernameToken>
    </ns1:All>
    </ns1:ExactlyOne>
    </ns1:Policy>
    </ns2:SignedSupportingTokens>
    <ns3:TransportBinding>
    <ns1:Policy>
    <ns1:ExactlyOne>
    <ns1:All>
    <ns3:AlgorithmSuite>
    <ns1:Policy>
    <ns1:ExactlyOne>
    <ns1:All>
    <ns3:Basic128/>
    </ns1:All>
    </ns1:ExactlyOne>
    </ns1:Policy>
    </ns3:AlgorithmSuite>
    <ns3:IncludeTimestamp/>
    <ns3:Layout>
    <ns1:Policy>
    <ns1:ExactlyOne>
    <ns1:All>
    <ns3:Lax/>
    </ns1:All>
    </ns1:ExactlyOne>
    </ns1:Policy>
    </ns3:Layout>
    <ns3:TransportToken>
    <ns1:Policy>
    <ns1:ExactlyOne>
    <ns1:All>
    <ns3:HttpsToken RequireClientCertificate="false"/>
    </ns1:All>
    </ns1:ExactlyOne>
    </ns1:Policy>
    </ns3:TransportToken>
    </ns1:All>
    </ns1:ExactlyOne>
    </ns1:Policy>
    </ns3:TransportBinding>
    <ns4:Wss10>
    <ns1:Policy>
    <ns1:ExactlyOne>
    <ns1:All>
    <ns4:MustSupportRefKeyIdentifier/>
    </ns1:All>
    </ns1:ExactlyOne>
    </ns1:Policy>
    </ns4:Wss10>
    <ns5:UsingAddressing/>
    </ns1:All>
    </ns1:ExactlyOne>
    </ns1:Policy>
    <types>
    <xsd:schema>
    <xsd:import namespace="http://webservices/" schemaLocation="https://localhost:8443/projet/Services?xsd=1"/>
    </xsd:schema>
    </types>
    <message name="operation">
    <part name="parameters" element="tns:operation"/>
    </message>
    <message name="operationResponse">
    <part name="parameters" element="tns:operationResponse"/>
    </message>
    <portType name="Services">
    <operation name="operation">
    <input message="tns:operation"/>
    <output message="tns:operationResponse"/>
    </operation>
    </portType>
    <binding name="ServicesPortBinding" type="tns:Services">
    <ns6:PolicyReference URI="#ServicesPortBindingPolicy"/>
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
    <operation name="operation">
    <soap:operation soapAction=""/>
    <input>
    <soap:body use="literal"/>
    </input>
    <output>
    <soap:body use="literal"/>
    </output>
    </operation>
    </binding>
    <service name="ServicesService">
    <port name="ServicesPort" binding="tns:ServicesPortBinding">
    <soap:address location="https://localhost:8443/projet/Services"/>
    </port>
    </service>
    </definitions>
    web.xml

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
     
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
        <listener>
            <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
        </listener>
        <servlet>
            <servlet-name>Services</servlet-name>
            <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
            </servlet>
        <servlet-mapping>
            <servlet-name>Services</servlet-name>
            <url-pattern>/Services</url-pattern>
        </servlet-mapping>
        <session-config>
            <session-timeout>
                30
            </session-timeout>
        </session-config>
        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
        <security-constraint>
            <display-name>SSL transport for ServicesService </display-name>
            <web-resource-collection>
                <web-resource-name>Secure Area</web-resource-name>
                <description/>
                <url-pattern> /Services/* </url-pattern>
                <http-method>GET</http-method>
                <http-method>POST</http-method>
                <http-method>HEAD</http-method>
                <http-method>PUT</http-method>
                <http-method>OPTIONS</http-method>
                <http-method>TRACE</http-method>
                <http-method>DELETE</http-method>
                </web-resource-collection>
            <auth-constraint>
                <role-name>wsclient</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>MemoryRealm</realm-name>
            </login-config>
        <security-role>
            <description/>
            <role-name>wsclient</role-name>
        </security-role>
        </web-app>
    Suis-je le seul à avoir ce genre de problème ? (et surtout le seul à utiliser apache tomcat avec metro ? )
    (Je rappelle que je ne peux pas accèder au web service depuis un client .NET, et un projet java netbeans refuse tout simplement de m'ajouter le webservice client...)

  5. #5
    oca
    oca est déconnecté
    Membre averti
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    354
    Détails du profil
    Informations personnelles :
    Âge : 51
    Localisation : Suisse

    Informations forums :
    Inscription : Octobre 2004
    Messages : 354
    Points : 421
    Points
    421
    Par défaut
    Je suis en train de faire des tests sur la sécurité aussi (avec tomcat et java 1.6.05 (donc metro...)), mais je ne suis pas aussi avancé que toi...
    pour le moment, j'en suis encore à écrire mes propres handler pour traiter la sécurité, sans passer par les policy...

    Je suis le livre SOA Security de Manning qui est très bien, mais j'en suis pas encore très loin...

    A+

  6. #6
    Candidat au Club
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    6
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 6
    Points : 4
    Points
    4
    Par défaut
    Hello oca,
    si tu pouvais partager avec moi une partie du code sur la création de handlers, tu me rendrais un chouette service. Ma solution temporaire un peu bidouillée n'est pas tellement satisfaisante, j'aimerai voir ce que cela peut donner en oubliant un moment les policies et je galère plutot ^^.

  7. #7
    oca
    oca est déconnecté
    Membre averti
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    354
    Détails du profil
    Informations personnelles :
    Âge : 51
    Localisation : Suisse

    Informations forums :
    Inscription : Octobre 2004
    Messages : 354
    Points : 421
    Points
    421
    Par défaut
    Je me suis basé sur cet article :
    http://www.javaworld.com/javaworld/j...er.html?page=2

    Il explique bien les handlers.

    côté client, il faut un handler HandlerResolver qui permet de définir
    une chaine de handler (dans mon cas, je n'en ai qu'un)

    Client
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
     
    	public static void main(String[] args) {
    		URL wsdlLocation = null;
    		try {
    			wsdlLocation = new URL("http://localhost:9083/hello?wsdl");
    		} catch (MalformedURLException e) {
    			e.printStackTrace();
    		}
    		QName serviceName = new QName("http://oca", "MonService");
    		Service s = Service.create(wsdlLocation, serviceName);
    		s.setHandlerResolver(new ServiceHandlerResolver());
     
    		MonPortType service = s.getPort(MonPortType.class);
     
    		// secu
    		Map requestContext = ((BindingProvider) service).getRequestContext();
    		requestContext.put("authn_userid", "user test");
    		requestContext.put("authn_password", "pwd test");
     
    		String rep = service.sayHello("Hi", "Oli");
     
    		System.out.println("=====================================");
    }
    ClientAuthenticationSOAPHandler doit implémenter javax.xml.ws.handler.Handler, qui impose quelques méthodes :
    comme

    public interface Handler<C extends MessageContext> {
    public boolean handleMessage(C context);
    public boolean handleFault(C context);
    public void close(MessageContext context);
    }


    dans ces méthodes, tu as accès a un context qui te donne lui accès
    au message SOAP.

    c'est ce handler qui va enrichir le message en ajoutant les infos de l'utilisateur dans le header du message soap

    Coté server :

    il faut aussi déclarer les handler, par exemple dans un fichier xml.
    le fichier xml peut être spécifié avec l'annotation @HandlerChain
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    @WebService(targetNamespace = "http://oca",portName="MonSOAP", serviceName="MonService", name="MonPortType")
    @HandlerChain(file="handler-chain.xml")
    public class MonService {
    handler-chain.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <javaee:handler-chains xmlns:javaee="http://java.sun.com/xml/ns/javaee" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <javaee:handler-chain>
       <javaee:handler>
          <javaee:handler-class>oca.ServiceAuthenticationSOAPHandler</javaee:handler-class>
       </javaee:handler>
       </javaee:handler-chain>
    </javaee:handler-chains>
    c'est ce handler qui contrôle les infos que j'ai mis dans le header du message SOAP.

    Il y a un exemple downloadable à la fin de l'article que j'ai mis en lien.

    J'ai aussi mis mes fichiers de tests en attachement pour le client et le server.
    c'est pas parfais mais sa tourne...
    pour démarrer le server : class oca.MonServer (ds server.zip)
    pour démarrer un client : class test.MonClientWS (ds client.zip)
    j'utilise java 1.6.05 sans lib additionelles


    Ma prochaine étape sera d'adapter cet exemple pour utiliser les tags de la norme WS-Security plutôt que des tags "maison"

    A+
    Fichiers attachés Fichiers attachés

Discussions similaires

  1. [Metro] WebService sécurisé par UsernameToken
    Par BloodyDark dans le forum Services Web
    Réponses: 1
    Dernier message: 21/10/2011, 16h13
  2. [Web Services] Appel de WebServices !
    Par cicolas dans le forum Spring
    Réponses: 4
    Dernier message: 30/06/2006, 11h44
  3. [VB5] appeler un webservice en VB5 ?
    Par marcsaker dans le forum VB 6 et antérieur
    Réponses: 1
    Dernier message: 08/06/2006, 17h47
  4. [SOAP] Client d'un webservice sécurisé par SSL
    Par tom91 dans le forum XML/XSL et SOAP
    Réponses: 1
    Dernier message: 24/03/2006, 10h29
  5. Appeler un webservice
    Par pcdingo dans le forum ASP
    Réponses: 5
    Dernier message: 11/01/2006, 14h30

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo