예제 #1
0
 internal static EndpointIdentity CreateWindowsIdentity(NetworkCredential serverCredential)
 {
     if (serverCredential != null && !NetworkCredentialHelper.IsDefault(serverCredential))
     {
         string upn;
         if (serverCredential.Domain != null && serverCredential.Domain.Length > 0)
         {
             upn = serverCredential.UserName + "@" + serverCredential.Domain;
         }
         else
         {
             upn = serverCredential.UserName;
         }
         return(EndpointIdentity.CreateUpnIdentity(upn));
     }
     else
     {
         return(SecurityUtils.CreateWindowsIdentity());
     }
 }
 public virtual EndpointIdentity GetIdentityOfSelf(SecurityTokenRequirement tokenRequirement)
 {
     if (tokenRequirement == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("tokenRequirement");
     }
     if (tokenRequirement is RecipientServiceModelSecurityTokenRequirement)
     {
         string tokenType = tokenRequirement.TokenType;
         if (tokenType == SecurityTokenTypes.X509Certificate ||
             tokenType == ServiceModelSecurityTokenTypes.AnonymousSslnego ||
             tokenType == ServiceModelSecurityTokenTypes.MutualSslnego)
         {
             if (parent.ServiceCertificate.Certificate != null)
             {
                 return(EndpointIdentity.CreateX509CertificateIdentity(parent.ServiceCertificate.Certificate));
             }
         }
         else if (tokenType == SecurityTokenTypes.Kerberos || tokenType == ServiceModelSecurityTokenTypes.Spnego)
         {
             return(SecurityUtils.CreateWindowsIdentity());
         }
         else if (tokenType == ServiceModelSecurityTokenTypes.SecureConversation)
         {
             SecurityBindingElement securityBindingElement = ((RecipientServiceModelSecurityTokenRequirement)tokenRequirement).SecureConversationSecurityBindingElement;
             if (securityBindingElement != null)
             {
                 if (securityBindingElement == null || securityBindingElement is TransportSecurityBindingElement)
                 {
                     return(null);
                 }
                 SecurityTokenParameters  bootstrapProtectionParameters = (securityBindingElement is SymmetricSecurityBindingElement) ? ((SymmetricSecurityBindingElement)securityBindingElement).ProtectionTokenParameters : ((AsymmetricSecurityBindingElement)securityBindingElement).RecipientTokenParameters;
                 SecurityTokenRequirement bootstrapRequirement          = new RecipientServiceModelSecurityTokenRequirement();
                 bootstrapProtectionParameters.InitializeSecurityTokenRequirement(bootstrapRequirement);
                 return(GetIdentityOfSelf(bootstrapRequirement));
             }
         }
     }
     return(null);
 }