Bonjour,

J'ai crée un service sur un projet web vs2010, il est utilisable sans soucis par le client.

Maintenant, je rajoute une couche d'authentification "custom", je surcharge donc Validate de UserNamePasswordValidator dans un objet.

Sur le client je prépare le service :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
 
           this._SuiviVolServiceClient = new SuiviVolServiceClient();
            this._SuiviVolServiceClient.ClientCredentials.UserName.UserName = "Truc";
            this._SuiviVolServiceClient.ClientCredentials.UserName.Password = "Much";
La dessus, le OperationContext.Current.ServiceSecurityContext du contract est toujours, null, j'imagine que cela ne suffit pas, en effet il faut brancher mon validator dans le fichier de config :

Sur le fichier de config Web.config généré par vs2010, j'ajoute donc un serviceCredentials :

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
 
<?xml version="1.0"?>
 
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
 
<configuration>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true">
            <add name="DomainServiceModule" preCondition="managedHandler" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        </modules>
        <validation validateIntegratedModeConfiguration="false" />
    </system.webServer>
    <system.web>
        <httpModules>
            <add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        </httpModules>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
 
 
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="false" />
                    <serviceCredentials>
                        <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="ComposanteSol_Web.SuiviVolAuthentication, ComposanteSol_Web"/>
                    </serviceCredentials>
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <bindings>
            <customBinding>
                <binding name="ComposanteSol_Web.SuiviVolService.customBinding0">
                    <binaryMessageEncoding />
                    <httpTransport />
                </binding>
            </customBinding>
        </bindings>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
            multipleSiteBindingsEnabled="true" />
        <services>
            <service name="ComposanteSol_Web.SuiviVolService" behaviorConfiguration="">
                <endpoint address="" binding="customBinding" bindingConfiguration="ComposanteSol_Web.SuiviVolService.customBinding0"
                    contract="ComposanteSol_Web.SuiviVolService" />
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            </service>
        </services>
    </system.serviceModel>
</configuration>
Malheureusement, le ServiceSecurityContext est toujours nul, et rien ne passe par ma classe validator :

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
 
  public class SuiviVolAuthentication : UserNamePasswordValidator
    {
        public override void Validate(string userName, string password)
        {
            if (null == userName || null == password)
            {
                throw new ArgumentNullException();
            }
 
            if ("toto".Equals(userName))
            {
                throw new SecurityTokenException("toto detected");
            }
 
            int a = 1;
 
            a++;
            a++;
        }

J'imagine que mon Web.config est pas bon, il y a une histoire de <security mode"..... à rajouter mais je ne sais pas ou le mettre.

Une piste ? Je m'y prends mal ?

Merci d'avance.