本文整理汇总了VB.NET中System.IdentityModel.Claims.ClaimTypes类的典型用法代码示例。如果您正苦于以下问题:VB.NET ClaimTypes类的具体用法?VB.NET ClaimTypes怎么用?VB.NET ClaimTypes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ClaimTypes类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: EchoService
' 导入命名空间
Imports System.Collections.Generic
Imports System.Security.Cryptography.X509Certificates
Imports System.IdentityModel.Claims
Imports System.IdentityModel.Policy
Imports System.IdentityModel.Tokens
Imports System.IdentityModel.Selectors
Imports System.ServiceModel
' Service class that implements the service contract.
<ServiceBehavior(IncludeExceptionDetailInFaults:=True)> _
Public Class EchoService
Implements IEchoService
<ServiceContract()> _
Public Interface IEchoService
: Inherits IDisposable
<OperationContract()> _
Function Echo() As String
End Interface 'IEchoService
Public Function Echo() As String Implements IEchoService.Echo
Dim userName As String = String.Empty
Dim certificateSubjectName As String = String.Empty
GetCallerIdentities(OperationContext.Current.ServiceSecurityContext, userName, certificateSubjectName)
Return String.Format("Hello {0}, {1}", userName, certificateSubjectName)
End Function 'Echo
Public Sub Dispose() Implements IDisposable.Dispose
End Sub
Function TryGetClaimValue(Of TClaimResource)(ByVal claimSet As ClaimSet, ByVal claimType As String, ByRef resourceValue As TClaimResource) As Boolean
Dim matchingClaims As IEnumerable(Of Claim) = claimSet.FindClaims(claimType, Rights.PossessProperty)
If matchingClaims Is Nothing Then
Return False
End If
Dim enumerator As IEnumerator(Of Claim) = matchingClaims.GetEnumerator()
If enumerator.MoveNext() Then
If enumerator.Current.Resource Is Nothing Then
resourceValue = Nothing
Else
resourceValue = CType(enumerator.Current.Resource, TClaimResource)
End If
Return True
Else
Return False
End If
End Function
Sub GetCallerIdentities(ByVal callerSecurityContext As ServiceSecurityContext, ByRef userName As String, ByRef certificateSubjectName As String)
' Returns the username and certificate subject name provided by the client.
userName = Nothing
certificateSubjectName = Nothing
' Look in all the claimsets in the authorization context.
Dim claimSet As ClaimSet
For Each claimSet In callerSecurityContext.AuthorizationContext.ClaimSets
' Try to find a Upn claim. This has been generated from the Windows username.
Dim tmpName As String = String.Empty
If TryGetClaimValue(Of String)(claimSet, ClaimTypes.Upn, tmpName) Then
userName = tmpName
Else
' Try to find an X500DistinguishedName claim. This has been generated from the client certificate.
Dim tmpDistinguishedName As X500DistinguishedName = Nothing
If TryGetClaimValue(Of X500DistinguishedName)(claimSet, ClaimTypes.X500DistinguishedName, tmpDistinguishedName) Then
certificateSubjectName = tmpDistinguishedName.Name
End If
End If
Next claimSet
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System.IdentityModel.Claims,代码行数:78,代码来源:ClaimTypes
注:本文中的System.IdentityModel.Claims.ClaimTypes类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论