public void Test_WebUserIdentityTest() { var identity = new WebUserIdentity(new FormsAuthenticationTicket("Test", false, 1000), true) { Session = new UserSession { Id = 1, Name = "Test" } }; Assert.AreEqual(1, identity.Id, "Id"); Assert.AreEqual("Test", identity.Name, "Name"); Assert.IsTrue(identity.IsAuthenticated, "IsAuthenticated"); Assert.IsNotNull(identity.Session, "Session"); }
public void Test_DateExtension_Personalize_Adjust() { var identity = new WebUserIdentity(new FormsAuthenticationTicket("Test", false, 1000), true) { Session = new UserSession { Id = 1, TimeZone = "Eastern Standard Time" } }; Assert.AreEqual("Aug 8, 2010 9:08 AM", new DateTime(2010, 8, 8, 8, 8, 0).Adjust(identity).Personalize(null)); }
public void Test_DateExtension_Personalize_Extended() { var identity = new WebUserIdentity(new FormsAuthenticationTicket("Test", false, 1000), true) { Session = new UserSession { Id = 1, TimeZone = "Central Standard Time", TimeFormat = UserPreferenceTimeFormat.Extended } }; Assert.AreEqual("Aug 8, 2010 8:08 AM", new DateTime(2010, 8, 8, 8, 8, 0).Personalize(identity)); }
public void Test_WebPrivilegePrincipal_DetermineRolePrivileges() { var privileges = new List<UserRoleRelation> { new UserRoleRelation { Id = 1, Privilege = Privileges.Create, User = new User { Id = 1 }, Role = new UserRole { Id = 1, Title = "test" } } }; var identity = new WebUserIdentity(new FormsAuthenticationTicket("Test", false, 1000), true) { Session = new UserSession(privileges) { Id = 1, Name = "Test" } }; var principal = new WebPrivilegePrincipal(identity); principal.DetermineRolePrivileges(); Assert.AreEqual(1, principal.Privileges.Count, "Count"); }
/// <summary> /// Creates the user session. /// </summary> /// <param name="context">The context.</param> /// <param name="principal">The principal.</param> /// <param name="identity">The identity.</param> public void Create(HttpContextBase context, PrivilegePrincipal principal, WebUserIdentity identity) { if (context == null) { throw new ArgumentNullException("context"); } if (principal == null) { throw new ArgumentNullException("principal"); } if (identity == null) { throw new ArgumentNullException("identity"); } if (context.Session == null) { throw new InvalidOperationException("The http context session is null"); } identity.Session = context.Session[SessionKey] as UserSession; if (identity.Session == null) { identity.Session = this.Create(identity.Name); context.Session[SessionKey] = identity.Session; this.UserHostService.Capture(); } principal.DetermineRolePrivileges(); }
/// <summary> /// Creates the principal. /// </summary> /// <param name="ticket">The ticket.</param> /// <param name="authenticated">if set to <c>true</c> [authenticated].</param> private void CreatePrincipal(FormsAuthenticationTicket ticket, bool authenticated) { var identity = new WebUserIdentity(ticket, authenticated); Context.User = new WebPrivilegePrincipal(identity); Thread.CurrentPrincipal = Context.User; }