Sdílet prostřednictvím


EndpointIdentity.CreateUpnIdentity(String) Metoda

Definice

Vytvoří identitu hlavního názvu uživatele (UPN) se zadaným názvem.

public:
 static System::ServiceModel::EndpointIdentity ^ CreateUpnIdentity(System::String ^ upnName);
public static System.ServiceModel.EndpointIdentity CreateUpnIdentity (string upnName);
static member CreateUpnIdentity : string -> System.ServiceModel.EndpointIdentity
Public Shared Function CreateUpnIdentity (upnName As String) As EndpointIdentity

Parametry

upnName
String

Název identity hlavního názvu uživatele (UPN).

Návraty

EndpointIdentity

Hlavní název uživatele (UPN EndpointIdentity ) přidružený k zadanému upnName.

Výjimky

upnName je null.

Příklady

Následující kód ukazuje, jak tuto metodu volat.

namespace TestPrincipalPermission
{
    class PrincipalPermissionModeWindows
    {

        [ServiceContract]
        interface ISecureService
        {
            [OperationContract]
            string Method1();
        }

        class SecureService : ISecureService
        {
            [PrincipalPermission(SecurityAction.Demand, Role = "everyone")]
            public string Method1()
            {
                return String.Format("Hello, \"{0}\"", Thread.CurrentPrincipal.Identity.Name);
            }
        }

        public void Run()
        {
            Uri serviceUri = new Uri(@"http://localhost:8006/Service");
            ServiceHost service = new ServiceHost(typeof(SecureService));
            service.AddServiceEndpoint(typeof(ISecureService), GetBinding(), serviceUri);
            service.Authorization.PrincipalPermissionMode = PrincipalPermissionMode.UseAspNetRoles;
            service.Open();

            EndpointAddress sr = new EndpointAddress(
                serviceUri, EndpointIdentity.CreateUpnIdentity(WindowsIdentity.GetCurrent().Name));
            ChannelFactory<ISecureService> cf = new ChannelFactory<ISecureService>(GetBinding(), sr);
            ISecureService client = cf.CreateChannel();
            Console.WriteLine("Client received response from Method1: {0}", client.Method1());
            ((IChannel)client).Close();
            Console.ReadLine();
            service.Close();
        }

        public static Binding GetBinding()
        {
            WSHttpBinding binding = new WSHttpBinding(SecurityMode.Message);
            binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
            return binding;
        }
    }
}

Poznámky

Zabezpečený klient WCF, který se připojuje ke koncovému bodu s touto identitou, používá hlavní název uživatele (UPN) při ověřování SSPI s koncovým bodem.

Tato statická metoda vytvoří instanci UpnEndpointIdentity voláním jeho konstruktoru , UpnEndpointIdentitypomocí upnName jako vstupní parametr.

Pokud upnName je zadán prázdný řetězec, ověřování se vrátí z Kerberos do NTLM, pokud je to možné. Pokud AllowNtlm ano false, wcf se snaží vyvolat výjimku, pokud se používá PROTOKOL NTLM. Všimněte si, že nastavení této vlastnosti false nemusí bránit odesílání přihlašovacích údajů NTLM přes drát.

Platí pro