成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

WCF認(rèn)證之UserName認(rèn)證方法

開發(fā) 開發(fā)工具
WCF認(rèn)證在實(shí)際應(yīng)用中是一個(gè)比較重要的部分。其中的UserName認(rèn)證機(jī)制比較簡(jiǎn)單,我們可以使用X509證書密鑰對(duì)用戶名密碼進(jìn)行加密。

WCF認(rèn)證的主要作用是幫助我們實(shí)現(xiàn)安全的開發(fā)環(huán)境。在這里我們就為大家介紹一下WCF認(rèn)證中的一個(gè)叫做UserName認(rèn)證的實(shí)現(xiàn)方法。#t#

UserName認(rèn)證機(jī)制很簡(jiǎn)單,客戶端提供用戶名密碼信息,到服務(wù)器端通過UserName驗(yàn)證類進(jìn)行驗(yàn)證。在此過程中,需要X509證書的支持,使用X509證書并不是用于證書認(rèn)證而是使用X509證書的密鑰對(duì)用戶名密碼進(jìn)行加密以防在服務(wù)器上以明文方式傳遞。

 

測(cè)試時(shí)我們可以通過VS命令行創(chuàng)建測(cè)試使用的證書,如下:
C:\Program Files\Microsoft Visual Studio 9.0\VC>makecert.exe -sr LocalMachine -s
s My -a sha1 -n CN=SecurityTest -sky exchange –pe

然后我們需要編寫一個(gè)驗(yàn)證用戶名密碼的類,如下:

 

  1. Imports System.IdentityModel.Selectors  
  2. Public Class MyCustomValidator  
  3. Inherits UserNamePasswordValidator  
  4. Public Overrides Sub Validate
    (ByVal userName As String, 
    ByVal password As String)  
  5. ''驗(yàn)證過程  
  6. End Sub  
  7. End Class 

 

服務(wù)器端的web.config文件還需要增加一些配置,如下:

 

  1. <system.serviceModel> 
  2. <bindings> 
  3. <wsHttpBinding> 
  4. <!-- 設(shè)置綁定名稱 --> 
  5. <binding name="mySecureBinding"> 
  6. <security mode="Message"> 
  7. <!-- 設(shè)置客戶端身份類型 --> 
  8. <message clientCredentialType="UserName"/> 
  9. </security> 
  10. </binding> 
  11. </wsHttpBinding> 
  12. </bindings> 
  13. <services> 
  14. <service behaviorConfiguration=
    "SecurityHost.Service1Behavior" 
  15. name="SecurityHost.Service1"> 
  16. <endpoint address="" binding=
    "wsHttpBinding" bindingConfiguration
    ="mySecureBinding" 
  17. contract="SecurityHost.IService1"> 
  18. <identity> 
  19. <!-- 使用以證書一致的DNS名稱 --> 
  20. <dns value="SecurityTest" /> 
  21. </identity> 
  22. </endpoint> 
  23. <endpoint address="mex" binding=
    "mexHttpBinding" contract=
    "IMetadataExchange" /> 
  24. </service> 
  25. </services> 
  26. <behaviors> 
  27. <serviceBehaviors> 
  28. <behavior name="SecurityHost.Service1Behavior"> 
  29. <serviceMetadata httpGetEnabled="true" /> 
  30. <serviceDebug includeException
    DetailInFaults
    ="false" /> 
  31. <!-- 配置服務(wù)器身份 --> 
  32. <serviceCredentials> 
  33. <!-- 證書類型 --> 
  34. <serviceCertificate findValue=
    "SecurityTest" storeLocation="LocalMachine" 
  35. storeName="My" x509FindType=
    "FindBySubjectName" /> 
  36. <!-- 自定義驗(yàn)證類 --> 
  37. <userNameAuthentication 
    userNamePasswordValidationMode="Custom" 
  38. customUserNamePasswordValidatorType=
    "ClassLibrary1.MyCustomValidator,ClassLibrary1" /> 
  39. </serviceCredentials> 
  40. </behavior> 
  41. </serviceBehaviors> 
  42. </behaviors> 
  43. </system.serviceModel> 

客戶端進(jìn)行服務(wù)引用之后,可通過如下代碼指定身份信息:

 

  1. Dim client As New ServiceReference1.Service1Client  
  2. '' 我們是使用X509證書密鑰加密并非進(jìn)行證書認(rèn)證
     
    client.ClientCredentials.Service
    Certificate.Authentication.Certificate
    ValidationMode
     = ServiceModel.
    Security.X509CertificateValidationMode.None  
  3. '' 指定客戶端身份:用戶名、密碼  
  4. client.ClientCredentials.UserName
    .UserName
     = Guid.NewGuid.ToString  
  5. client.ClientCredentials.UserName
    .Password
     = Guid.NewGuid.ToString  
  6. '' 執(zhí)行服務(wù)方法 

Dim str As String = client.GetData(1)
 

這樣我們就可以進(jìn)行WCF服務(wù)的UserName認(rèn)證了。

責(zé)任編輯:曹凱 來(lái)源: 博客園
相關(guān)推薦

2009-12-21 14:58:57

WCF用戶密碼認(rèn)證

2011-07-14 11:12:39

Cisco限制BT

2011-07-14 11:03:22

2011-07-14 11:12:47

限制BT

2009-08-31 09:03:54

思科認(rèn)證初級(jí)認(rèn)證思科CCDA認(rèn)證

2009-09-08 09:25:46

思科認(rèn)證學(xué)習(xí)方法思科認(rèn)證

2009-08-31 09:14:31

思科認(rèn)證思科CCIE認(rèn)證思科認(rèn)證高級(jí)認(rèn)證

2010-08-19 11:50:47

思科華為認(rèn)證

2009-08-24 10:22:17

思科認(rèn)證思科認(rèn)證分類介紹

2023-06-16 08:13:57

2009-08-26 10:37:49

思科認(rèn)證CCNA思科認(rèn)證

2013-08-15 13:41:53

Nginx用戶認(rèn)證

2010-08-19 11:54:38

思科華為認(rèn)證

2009-08-20 12:35:12

思科認(rèn)證思科認(rèn)證種類思科認(rèn)證資料

2011-09-15 14:21:38

2009-08-22 11:06:58

思科認(rèn)證介紹思科認(rèn)證注冊(cè)方法思科認(rèn)證

2009-12-07 14:47:21

Juniper認(rèn)證

2009-08-28 09:45:07

最新思科認(rèn)證CCNA Securi

2009-09-07 09:28:00

思科認(rèn)證CCSPCCSP認(rèn)證過程

2009-09-04 09:37:49

思科認(rèn)證CCNA學(xué)習(xí)方法
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: 国产精品视频久久久 | 亚洲精品一区二区在线观看 | 中文字幕亚洲区 | 亚洲成人精品久久 | www.色.com| 精品综合久久 | 天堂网avav| 久久99精品久久久久久国产越南 | 国产日韩欧美一区 | 欧美日韩三级在线观看 | 成人国产免费视频 | 亚洲人成在线观看 | 国产麻豆乱码精品一区二区三区 | 国产精品视频一二三区 | 亚洲天堂精品久久 | 午夜不卡一区二区 | 一区二区三区国产好 | 日韩中文视频 | 亚洲自拍偷拍免费视频 | 久久国产美女视频 | 欧美激情亚洲 | 在线观看国产视频 | 日日噜噜噜夜夜爽爽狠狠视频, | 国产精品99久久久久久宅男 | 久热电影 | 久久久亚洲成人 | 日日夜夜草 | 午夜电影福利 | 久久久精品网 | 精品久久影院 | 日韩一区二区三区在线 | 色小姐综合网 | 国产一区二区影院 | 中文字幕在线观看视频一区 | 午夜精品影院 | 黑色丝袜三级在线播放 | 国产一区二区三区四区 | 欧美日韩在线观看一区 | 在线播放中文字幕 | 国产美女在线观看 | 欧美性生活网 |