Inheritance: ISerializable
        private bool VerifySecurity(ClientInfo client)
        {
            if ((object)client == null)
                throw new ArgumentNullException(nameof(client));

            // Set current thread principal to remote client's user principal.
            if (!(Thread.CurrentPrincipal is WindowsPrincipal) && (object)client.ClientUser != null)
                Thread.CurrentPrincipal = client.ClientUser;

            // Retrieve previously initialized security provider of the remote client's user.
            SecurityProviderCache.ValidateCurrentProvider();

            // Initialize security provider for the remote client's user from specified credentials.
            if ((!Thread.CurrentPrincipal.Identity.IsAuthenticated || (object)client.ClientUser == null) && !string.IsNullOrEmpty(client.ClientUserCredentials))
            {
                string[] credentialParts = client.ClientUserCredentials.Split(':');

                if (credentialParts.Length == 2)
                {
                    ISecurityProvider provider = SecurityProviderUtility.CreateProvider(credentialParts[0]);

                    if (provider.Authenticate(credentialParts[1]))
                        SecurityProviderCache.CurrentProvider = provider;
                }
            }

            // Save the initialized security provider of remote client's user for subsequent uses.
            if (client.ClientUser != Thread.CurrentPrincipal)
                client.SetClientUser(Thread.CurrentPrincipal);

            return (object)client.ClientUser != null && client.ClientUser.Identity.IsAuthenticated;
        }
 /// <summary>
 /// Raises the <see cref="ReceivedClientRequest"/> event.
 /// </summary>
 /// <param name="request">The <see cref="ClientRequest"/> that was received.</param>
 /// <param name="requestSender">The <see cref="ClientInfo"/> object of the <paramref name="request"/> sender.</param>
 protected virtual void OnReceivedClientRequest(ClientRequest request, ClientInfo requestSender)
 {
     if ((object)ReceivedClientRequest != null)
         ReceivedClientRequest(this, new EventArgs<Guid, ClientRequest>(requestSender.ClientID, request));
 }
        private bool TrySetCurrentThreadPrincipal(ClientInfo client)
        {
            if ((object)client == null)
                throw new ArgumentNullException(nameof(client));

            WindowsPrincipal clientPrincipal;

            // Attempt to find the TryGetClientPrincipal method using reflection - remoting server could be a TCP or TLS server
            if ((object)m_remotingServer != null && (object)m_tryGetClientPrincipalFunction == null)
            {
                MethodInfo tryGetClientPrincipalInfo = m_remotingServer.GetType().GetMethod("TryGetClientPrincipal", new[] { typeof(Guid), typeof(WindowsPrincipal).MakeByRefType() });

                if ((object)tryGetClientPrincipalInfo != null && tryGetClientPrincipalInfo.ReturnType == typeof(bool))
                    m_tryGetClientPrincipalFunction = (TryGetClientPrincipalFunctionSignature)Delegate.CreateDelegate(typeof(TryGetClientPrincipalFunctionSignature), m_remotingServer, tryGetClientPrincipalInfo);
            }

            // Attempt to get the client principal from the remoting server
            if ((object)m_tryGetClientPrincipalFunction != null && m_tryGetClientPrincipalFunction(client.ClientID, out clientPrincipal))
            {
                if ((object)clientPrincipal != null)
                    Thread.CurrentPrincipal = clientPrincipal;
                else if ((object)client.ClientUser != null)
                    Thread.CurrentPrincipal = client.ClientUser;

                return true;
            }

            return false;
        }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ClientRequestInfo"/> class.
 /// </summary>
 /// <param name="sender"><see cref="ClientInfo"/> object of the <paramref name="request"/> sender.</param>
 /// <param name="request"><see cref="ClientRequest"/> object sent by the <paramref name="sender"/>.</param>
 public ClientRequestInfo(ClientInfo sender, ClientRequest request)
 {
     Request = request;
     Sender = sender;
     ReceivedAt = DateTime.UtcNow;
 }