/// <summary>
        /// Processes logon.
        /// </summary>
        /// <param name="sessionID">Unique session key (created on client side)</param>
        /// <param name="credentials">Logon credentials</param>
        public void Logon(Guid sessionID, Hashtable credentials)
        {
            if (sessionID == Guid.Empty)
            {
                throw new ArgumentException(LanguageResource.ArgumentException_EmptySessionIDIsNotAllowed, "sessionID");
            }

            if (!_host.SessionManager.ExistSession(sessionID))
            {
                // reset current session before authentication is complete
                ServerSession.CurrentSession = null;

                AuthResponseMessage authResponse = _host.Authenticate(new AuthRequestMessage()
                {
                    Credentials = credentials
                });
                if (!authResponse.Success)
                {
                    var exception = authResponse.Exception ?? new SecurityException(authResponse.ErrorMessage);
                    throw exception.PreserveStackTrace();
                }

                var sessionVariableAdapter = new SessionVariableAdapter(_host.SessionManager, sessionID);
                var session = new ServerSession(sessionID, authResponse.AuthenticatedIdentity, sessionVariableAdapter);
                _host.SessionManager.StoreSession(session);
                ServerSession.CurrentSession = session;
                PutClientAddressToCurrentSession();

                _host.OnClientLoggedOn(new LoginEventArgs(LoginEventType.Logon, session.Identity, session.ClientAddress, session.Timestamp));
            }
        }
示例#2
0
        /// <summary>
        /// Processes logon.
        /// </summary>
        /// <param name="sessionID">Unique session key (created on client side)</param>
        /// <param name="credentials">Logon credentials</param>
        public void Logon(Guid sessionID, Hashtable credentials)
        {
            if (sessionID == Guid.Empty)
            {
                throw new ArgumentException(LanguageResource.ArgumentException_EmptySessionIDIsNotAllowed, "sessionID");
            }

            // prepare client IP address
            var clientAddress = GetCallingClientIPAddress();

            try
            {
                if (!_host.SessionManager.ExistSession(sessionID))
                {
                    // reset current session before authentication is complete
                    _host.SessionManager.SetCurrentSession(null);

                    // authenticate
                    var authResponse = _host.Authenticate(new AuthRequestMessage
                    {
                        Credentials   = credentials,
                        ClientAddress = clientAddress
                    });

                    if (!authResponse.Success)
                    {
                        var exception = authResponse.Exception ?? new SecurityException(authResponse.ErrorMessage);
                        throw exception.PreserveStackTrace();
                    }

                    // create a new session
                    var session = _host.SessionManager.CreateServerSession(sessionID, DateTime.Now, authResponse.AuthenticatedIdentity);
                    session.ClientAddress = clientAddress;
                    _host.SessionManager.StoreSession(session);
                    _host.SessionManager.SetCurrentSession(session);

                    _host.OnClientLoggedOn(new LoginEventArgs(LoginEventType.Logon, session.Identity, session.ClientAddress, session.Timestamp));
                }
            }
            catch (Exception ex)
            {
                var args = new LoginEventArgs(LoginEventType.Logon, null, clientAddress, DateTime.Now);
                args.Exception = ex;
                _host.OnClientLogonCanceled(args);
                if (args.Exception != null)
                {
                    // this exception may be translated
                    throw args.Exception.PreserveStackTrace();
                }

                throw;
            }
        }