/// <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); }
/// <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); } }
/// <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); }
/// <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 }); } }
/// <summary> /// Creates the account. /// </summary> /// <param name="session">The session.</param> /// <returns>AccountItem.</returns> private Account GetAccountForSession(WulkaSession session) { return (AuthenticationProvider .Accounts .GetAccountForSession(session)); }
/// <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(); } }
/// <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); } }
/// <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); }
/// <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); } }
/// <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); } }
/// <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()); }
/// <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)); }
/// <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); }
/// <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(); } }
/// <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); }
/// <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); } }
/// <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(); }
/// <summary> /// Starts the session. /// </summary> /// <param name="session">The session.</param> /// <returns>WulkaSession.</returns> public WulkaSession StartSession(WulkaSession session) { return(Client.StartSession(session)); }
/// <summary> /// Ends the session. /// </summary> /// <param name="session">The session.</param> /// <returns>WulkaSession.</returns> public WulkaSession EndSession(WulkaSession session) { return(Client.EndSession(session)); }
/// <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)); }
/// <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)); }
/// <summary> /// Terminates the session. /// </summary> /// <param name="session">The session.</param> /// <returns>WulkaSession.</returns> public WulkaSession TerminateSession(WulkaSession session) { return(SessionProxyPortal .SessionProxy .EndSession(session)); }