Beispiel #1
0
        public void From_should_add_role_based_on_UserType()
        {
            // Arrange
            var member = new Member { UserType = UserType.Member };

            // Act
            var identity = new UserIdentity().From(member);

            // Assert
            Assert.That(identity.Roles.Contains("Member"));
        }
Beispiel #2
0
        public void UserIdentity_Deserialize_should_return_nonAuthenticated_UserIdentity_for_null()
        {
            // Arrange
            const string data = null;
            var identity = new UserIdentity();

            // Act
            var result = identity.Deserialize(data);

            // Assert
            Assert.That(result.IsAuthenticated, Is.False);
        }
Beispiel #3
0
        void GlobalApplication_AuthenticateRequest(object sender, EventArgs e)
        {
            var cookie = Context.Request.Cookies[FormsAuthentication.FormsCookieName];

            var principal = new UserPrincipal();

            if (cookie != null)
            {
                var ticket = FormsAuthentication.Decrypt(cookie.Value);

                var userIdentity = new UserIdentity().Deserialize(ticket.UserData);

                principal.With(userIdentity);

            }

            Context.User = principal;
        }