Ejemplo n.º 1
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");
            }

            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));
            }
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Meldet einen Client am Applikationserver an.
        /// </summary>
        /// <param name="sessionID">Sitzungsschlüssel (wird vom Client erstellt)</param>
        /// <param name="credentials">Anmeldeinformationen</param>
        public void Logon(Guid sessionID, Hashtable credentials)
        {
            // Wenn kein eindeutiger Sitzungsschlüssel angegeben wurde ...
            if (sessionID == Guid.Empty)
            {
                // Ausnahme werfen
                throw new ArgumentException(LanguageResource.ArgumentException_EmptySessionIDIsNotAllowed, "sessionID");
            }

            // Wenn noch keine Sitzung mit dem angegebenen Sitzungsschlüssel existiert ...
            if (!_host.SessionManager.ExistSession(sessionID))
            {
                // Authentifizieren
                AuthResponseMessage authResponse = _host.Authenticate(new AuthRequestMessage()
                {
                    Credentials = credentials
                });

                // Wenn die Authentifizierung fehlgeschlagen ist ...
                if (!authResponse.Success)
                {
                    // Ausnahme werfen
                    throw new SecurityException(authResponse.ErrorMessage);
                }

                // Sitzungsvariablen-Adapter erzeugen
                SessionVariableAdapter sessionVariableAdapter = new SessionVariableAdapter(_host.SessionManager, sessionID);

                // Neue Sitzung erstellen
                ServerSession session = new ServerSession(sessionID, authResponse.AuthenticatedIdentity, sessionVariableAdapter);

                // Sitzung speichern
                _host.SessionManager.StoreSession(session);

                // Aktuelle Sitzung im Threadspeicher ablegen
                ServerSession.CurrentSession = session;
            }
        }