Ejemplo n.º 1
0
        /// <summary>
        /// Creates the valid Wulka session.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="mode">The mode.</param>
        /// <returns>WulkaSession.</returns>
        private WulkaSession CreateValidWulkaSession(string name, string mode)
        {
            var session = new WulkaSession()
            {
                Username              = name,
                AuthenticationMode    = mode,
                ApplicationFunctionId = AuthenticationDefaults.ServiceCode
            };

            try
            {
                var acc = GetAccountForSession(session);
                if (acc != null)
                {
                    session.IsKnown   = !String.IsNullOrEmpty(acc.Email);
                    session.AccountId = acc.Id;
                    session.FirstName = acc.FirstName;
                    session.LastName  = acc.LastName;
                }
                session = StartSession(session);
            }
            catch (Exception ex)
            {
                _logger.Error("A Valid Session could not be created. Message: {0}", ex.GetCombinedMessages());
            }
            return(session);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the account for session.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <returns>AccountItem.</returns>
        public Account GetAccountForSession(WulkaSession session)
        {
            var acc = GetAccountForUser(session.Username);

            if (acc != null)
            {
                return(acc);
            }
            else
            {
                var result = new Account
                {
                    Username   = session.Username,
                    FirstName  = "New",
                    LastName   = "User",
                    SessionId  = session.SessionId,
                    AuthModeId = session.AuthenticationMode,
                    DtStart    = DateTime.Now,
                    DtEnd      = DateTime.Now.AddDays(10),
                    Email      = String.Empty
                };
                Provider <Account> .Save(result);

                return(result);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Decorates the specified session.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <returns>WulkaSession.</returns>
        private WulkaSession Decorate(WulkaSession session)
        {
            PrintSession(session, "Decorating");
            WulkaSession result = session;

            result.SessionId = session.Id;
            switch (session.AuthenticationMode)
            {
            case AuthenticationMode.Windows:
            {
                if (Validate(session.Username, session.Id))
                {
                    result = ActiveSessions[session.Id];
                }
                else
                {
                    result.Id                 = session.Id;
                    result.SessionId          = session.Id;
                    result.LastRequest        = DateTime.Now;
                    result.Username           = session.Username;
                    result.IsKnown            = session.IsKnown;
                    result.AuthenticationMode = session.AuthenticationMode;
                    result.ConnectionTime     = DateTime.Now;
                }
                break;
            }

            default:
            {
                break;
            }
            }
            PrintSession(result, "Decorated");
            return(result);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Called when [native authentication completed].
 /// </summary>
 /// <param name="session">The session.</param>
 private void OnNativeAuthenticationCompleted(WulkaSession session)
 {
     if (session == null)
     {
         Feedback             = String.Format("Authentication for user '{0}' failed!", Request.UserName);
         WulkaSession.Current = null;
         Thread.Sleep(5000);
     }
     else
     {
         Feedback                 = String.Format("User '{0}' is authenticated!", Request.UserName);
         WulkaSession.Current     = session;
         WulkaCredentials.Current = new ExtendedCredentials(
             WulkaSession.Current.Username,
             WulkaSession.Current.Id,
             WulkaSession.Current.ApplicationFunctionId);
         WulkaContext.Current.Add(WulkaContextKey.UserName, WulkaSession.Current.Username);
         WulkaContext.Current.Add(WulkaContextKey.SessionId, WulkaSession.Current.Id);
         WulkaContext.Current.Add(WulkaContextKey.ServiceCode, WulkaSession.Current.ApplicationFunctionId);
         Messenger.Default.Send(new AuthenticationResultMessage()
         {
             Session = session
         });
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates the account.
 /// </summary>
 /// <param name="session">The session.</param>
 /// <returns>AccountItem.</returns>
 private Account GetAccountForSession(WulkaSession session)
 {
     return
         (AuthenticationProvider
          .Accounts
          .GetAccountForSession(session));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Called when [guest logon completed].
 /// </summary>
 /// <param name="session">The session.</param>
 static void OnGuestLogonCompleted(WulkaSession session)
 {
     WulkaSession.Current = session;
     if (_postLogoffAction != null)
     {
         _postLogoffAction();
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Prints the session.
 /// </summary>
 /// <param name="nfo">The nfo.</param>
 /// <param name="verb">The verb.</param>
 private void PrintSession(WulkaSession nfo, string verb)
 {
     if (nfo == null)
     {
         Logger.Debug("Calling PrintSession with no info....");
     }
     else
     {
         Logger.Info("{0} Session: [{1}] - User = {2}", verb, nfo.Id, nfo.Username);
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Terminates the session async completed.
 /// </summary>
 /// <param name="session">The session.</param>
 static void TerminateSessionAsyncCompleted(WulkaSession session)
 {
     WulkaSession.Current     = session;
     WulkaCredentials.Current = new ExtendedCredentials(
         WulkaSession.Current.Username,
         WulkaSession.Current.Id,
         WulkaSession.Current.ApplicationFunctionId);
     AuthenticationPortal
     .Authentication
     .AuthenticateByUserNameAndPasswordAsync(AuthenticationDefaults.GuestUserName, AuthenticationDefaults.GuestEncPwd, OnGuestLogonCompleted);
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets the account for session.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <returns>AccountItem.</returns>
        public Account GetAccountForSession(WulkaSession session)
        {
            var clt = CreateClient();

            try
            {
                return(clt.GetAccountForSession(session));
            }
            finally
            {
                CloseClient(clt);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Terminates the session.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <returns>WulkaSession.</returns>
        public WulkaSession TerminateSession(WulkaSession session)
        {
            var clt = CreateClient();

            try
            {
                return(clt.TerminateSession());
            }
            finally
            {
                CloseClient(clt);
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Removes the session.
 /// </summary>
 /// <param name="session">The session.</param>
 /// <returns>WulkaSession.</returns>
 internal WulkaSession RemoveSession(WulkaSession session)
 {
     if (session == null)
     {
         session = SessionFactory.CreateDefaultWulkaSession();
     }
     PrintSession(session, "Removing");
     lock (ActiveSessions)
     {
         ActiveSessions.Remove(session.Id);
     }
     PrintSession(session, "Removed");
     return(SessionFactory.CreateDefaultWulkaSession());
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Ends the session.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <returns></returns>
        public WulkaSession EndSession(WulkaSession session)
        {
            if (session == null)
            {
                _logger.Error("No Session to End.");
                return(null);
            }
            if (session.Username == AuthenticationDefaults.GuestUserName)
            {
                return(SessionCache.Instance.RemoveSession(session));
            }
            var ss = SessionCache.Instance.RemoveSession(session);

            return(StartSession(ss));
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Adds the session.
 /// </summary>
 /// <param name="session">The nfo.</param>
 /// <returns>WulkaSession.</returns>
 internal WulkaSession AddSession(WulkaSession session)
 {
     if (session == null)
     {
         session = SessionFactory.CreateDefaultWulkaSession();
     }
     session.SessionId = Guid.Empty.ToString();
     PrintSession(session, "Adding");
     lock (ActiveSessions)
     {
         session = Decorate(session);
         RemoveSession(session);
         ActiveSessions.Add(session.Id, session);
     }
     PrintSession(session, "Added");
     return(session);
 }
Ejemplo n.º 14
0
        /// <summary>
        ///     Ends the session async.
        /// </summary>
        /// <param name="session">The session.</param>
        public void EndSessionAsync(WulkaSession session)
        {
            var ss = (WulkaSession)null;

            using (var wrk = new BackgroundWorker())
            {
                wrk.DoWork             += (s, e) => { ss = Client.EndSession(session); };
                wrk.RunWorkerCompleted += (s, e) =>
                {
                    if (EndSessionCompleted != null)
                    {
                        EndSessionCompleted(ss);
                    }
                };
                wrk.RunWorkerAsync();
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Authenticates the user credentials.
        /// </summary>
        /// <returns>WulkaSession.</returns>
        public WulkaSession AuthenticateUserCredentials()
        {
            if (Identity == null)
            {
                _logger.Error("Identity is null! Check infrastructure!");
                return(SessionFactory.CreateDefaultWulkaSession());
            }
            _logger.Info("Authenticating user {0}", Identity.Name);
            if (!Identity.IsAuthenticated)
            {
                return(SessionFactory.CreateDefaultWulkaSession());
            }
            WulkaSession sess = null;

            using (var spc = new TransactionScope())
            {
                sess = CreateValidWulkaSession(Identity.Name, (Identity is WindowsIdentity) ? AuthenticationMode.Windows : AuthenticationMode.Native);
                GetAccountForSession(sess);
                spc.Complete();
            }
            return(sess);
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Starts the session.
 /// </summary>
 /// <param name="session">The session.</param>
 /// <returns>WulkaSession.</returns>
 private WulkaSession StartSession(WulkaSession session)
 {
     try
     {
         _logger.Info("Starting Session for {0}", session.Username);
         var res = SessionProxyPortal
                   .SessionProxy
                   .StartSession(session);
         if (res == null)
         {
             _logger.Info("Returned null session");
             return(session);
         }
         _logger.Info("Session [{0}] created for user [{1}]. Known user: {2}", res.Id, res.Username,
                      res.IsKnown);
         return(res);
     }
     catch (Exception ex)
     {
         _logger.Error("Failed to start Session for {0}", session.Username);
         _logger.Error(ex.GetCombinedMessages);
         return(session);
     }
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Gets the account for session.
 /// </summary>
 /// <param name="session">The session.</param>
 /// <returns>Account.</returns>
 /// <exception cref="NotImplementedException"></exception>
 public Account GetAccountForSession(WulkaSession session)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 18
0
 /// <summary>
 ///     Starts the session.
 /// </summary>
 /// <param name="session">The session.</param>
 /// <returns>WulkaSession.</returns>
 public WulkaSession StartSession(WulkaSession session)
 {
     return(Client.StartSession(session));
 }
Ejemplo n.º 19
0
 /// <summary>
 ///     Ends the session.
 /// </summary>
 /// <param name="session">The session.</param>
 /// <returns>WulkaSession.</returns>
 public WulkaSession EndSession(WulkaSession session)
 {
     return(Client.EndSession(session));
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Starts the session.
 /// </summary>
 /// <param name="session">The session.</param>
 /// <returns></returns>
 public WulkaSession StartSession(WulkaSession session)
 {
     _logger.Info("Starting Session for user [{0}]", session.Username);
     return(SessionCache.Instance.AddSession(session));
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Starts the session.
 /// </summary>
 /// <param name="session">The session.</param>
 /// <returns>WulkaSession.</returns>
 /// <exception cref="System.NotImplementedException"></exception>
 public WulkaSession StartSession(WulkaSession session)
 {
     return(SessionProxyPortal
            .SessionProxy
            .StartSession(session));
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Terminates the session.
 /// </summary>
 /// <param name="session">The session.</param>
 /// <returns>WulkaSession.</returns>
 public WulkaSession TerminateSession(WulkaSession session)
 {
     return(SessionProxyPortal
            .SessionProxy
            .EndSession(session));
 }