Guest User

Untitled

a guest
Aug 9th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <configuration>
  3. <startup>
  4. <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
  5. </startup>
  6. <system.serviceModel>
  7. <bindings>
  8. <wsHttpBinding>
  9. <binding name="TestAuthWCF.SecretServiceBinding">
  10. <!-- Укажем Security Mode -->
  11. <security mode="Message">
  12. <!-- Тип аутентификации -->
  13. <message clientCredentialType="UserName"/>
  14. </security>
  15. </binding>
  16. </wsHttpBinding>
  17. </bindings>
  18. <services>
  19. <service behaviorConfiguration="TestAuthWCF.SecretServiceBehavior"
  20. name="TestAuthWCF.TestAuthWCF">
  21. <endpoint address="http://localhost/service" binding="wsHttpBinding"
  22. bindingConfiguration="TestAuthWCF.SecretServiceBinding" contract="TestAuthWCF.ITestAuthWCF" />
  23. <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  24. <host>
  25. <baseAddresses>
  26. <add baseAddress="http://localhost/service" />
  27. </baseAddresses>
  28. </host>
  29. </service>
  30. </services>
  31. <behaviors>
  32. <serviceBehaviors>
  33. <behavior name="TestAuthWCF.SecretServiceBehavior">
  34. <serviceMetadata httpGetEnabled="true" />
  35. <serviceDebug includeExceptionDetailInFaults="true" />
  36. <serviceCredentials>
  37. <serviceCertificate findValue="Фамилия Имя Отчество" storeLocation="CurrentUser"
  38. x509FindType="FindBySubjectName" />
  39. <userNameAuthentication userNamePasswordValidationMode="Custom"
  40. customUserNamePasswordValidatorType="TestAuthWCF.CustomUserNameValidator, TestAuthWCF" />
  41. </serviceCredentials>
  42. </behavior>
  43. </serviceBehaviors>
  44. </behaviors>
  45. </system.serviceModel>
  46. </configuration>
  47.  
  48. public class CustomUserNameValidator : UserNamePasswordValidator
  49. {
  50. public override void Validate(string userName, string password)
  51. {
  52. // Доступ разрешен только пользователю "ilya" по паролю "pass"
  53. if (!(userName == "ilya" && password == "pass"))
  54. {
  55. throw new FaultException("Неверный логин или пароль");
  56. }
  57. }
  58. }
Add Comment
Please, Sign In to add comment