public void GivenIdentity_WhenIGetIdentity_ThenIdentityMatchesOriginal()
 {
     EducationSecurityIdentity expected = new EducationSecurityIdentity(new ClaimsIdentity(), new User());
     EducationSecurityPrincipal target = new EducationSecurityPrincipal(expected);
     Assert.AreEqual(expected, target.Identity);
     Assert.AreEqual(expected, ((IPrincipal)target).Identity);
 }
        public void GivenIdentity_WhenIGetIdentity_ThenIdentityMatchesOriginal()
        {
            EducationSecurityIdentity  expected = new EducationSecurityIdentity(new ClaimsIdentity(), new User());
            EducationSecurityPrincipal target   = new EducationSecurityPrincipal(expected);

            Assert.AreEqual(expected, target.Identity);
            Assert.AreEqual(expected, ((IPrincipal)target).Identity);
        }
 public static string FindUserKey(ClaimsPrincipal claimsPrincipal)
 {
     if (claimsPrincipal == null)
     {
         throw new ArgumentNullException("claimsPrincipal");
     }
     return(EducationSecurityIdentity.FindUserKey((ClaimsIdentity)claimsPrincipal.Identity));
 }
 public EducationSecurityPrincipal(EducationSecurityIdentity identity)
 {
     if (identity == null)
     {
         throw new ArgumentNullException("identity");
     }
     Identity = identity;
     Configuration = new DefaultSecurityConfiguration();
 }
 public EducationSecurityPrincipal(EducationSecurityIdentity identity)
 {
     if (identity == null)
     {
         throw new ArgumentNullException("identity");
     }
     Identity      = identity;
     Configuration = new DefaultSecurityConfiguration();
 }
        public void GivenClaimsIdentityWithNameIdentifierClaim_WhenIFindUserKey_ThenGetNameIdentifierClaimValue()
        {
            string expected = "this is the user key";

            BaseIdentity.AddClaim(new Claim(ClaimTypes.NameIdentifier, expected));

            string actual = EducationSecurityIdentity.FindUserKey(BaseIdentity);

            Assert.AreEqual(expected, actual);
        }
        public void GivenBaseIdentityHasName_AndUserHasDisplayName_WhenGetIdentityName_ThenReturnBaseIdentityNameInsteadOfUserName()
        {
            string expected = "this is the name I expect";
            string notExpected = "this is the name of the user, but defer to base identity for name";
            Users[0].DisplayName = notExpected;
            BaseIdentity = new GenericIdentity(expected, "Federated");
            Target = new EducationSecurityIdentity(BaseIdentity, Users[0]);

            string actual = Target.Name;

            Assert.AreEqual(expected, actual);
        }
        public void GivenBaseIdentityHasName_AndUserHasDisplayName_WhenGetIdentityName_ThenReturnBaseIdentityNameInsteadOfUserName()
        {
            string expected    = "this is the name I expect";
            string notExpected = "this is the name of the user, but defer to base identity for name";

            Users[0].DisplayName = notExpected;
            BaseIdentity         = new GenericIdentity(expected, "Federated");
            Target = new EducationSecurityIdentity(BaseIdentity, Users[0]);

            string actual = Target.Name;

            Assert.AreEqual(expected, actual);
        }
 public EducationSecurityPrincipal(User userEntity)
 {
     if (userEntity == null)
     {
         throw new ArgumentNullException("userEntity");
     }
     if (userEntity.UserKey == null)
     {
         throw new ArgumentException("UserKey property cannot be null.", "userEntity");
     }
     Claim claim = new Claim(ClaimTypes.NameIdentifier, userEntity.UserKey);
     Identity = new EducationSecurityIdentity(new ClaimsIdentity(new List<Claim> { claim }, "Custom"), userEntity);
     Configuration = new DefaultSecurityConfiguration();
 }
 public void InitializeTest()
 {
     Users = new List <User> {
         new User {
             Id = 20, UserKey = "3u2e2"
         }, new User {
             Id = 30, UserKey = "29e8r2fj"
         }, new User {
             Id = 40, UserKey = "w8iw2j2"
         }
     };
     MockUserRepository = MockRepository.GenerateMock <IUserRepository>();
     MockUserRepository.Expect(r => r.Items).Return(Users.AsQueryable());
     BaseIdentity = new ClaimsIdentity("Federated");
     Target       = new EducationSecurityIdentity(BaseIdentity, Users[0]);
 }
        public EducationSecurityPrincipal(User userEntity)
        {
            if (userEntity == null)
            {
                throw new ArgumentNullException("userEntity");
            }
            if (userEntity.UserKey == null)
            {
                throw new ArgumentException("UserKey property cannot be null.", "userEntity");
            }
            Claim claim = new Claim(ClaimTypes.NameIdentifier, userEntity.UserKey);

            Identity = new EducationSecurityIdentity(new ClaimsIdentity(new List <Claim> {
                claim
            }, "Custom"), userEntity);
            Configuration = new DefaultSecurityConfiguration();
        }
 private static EducationSecurityPrincipal CreateEducationSecurityPrincipal(AuthorizationContext filterContext, System.Security.Claims.ClaimsPrincipal claimsPrincipal)
 {
     System.Security.Claims.ClaimsIdentity claimsIdentity = (System.Security.Claims.ClaimsIdentity)claimsPrincipal.Identity;
     IAccountManager manager = DependencyResolver.Current.GetService<IAccountManager>();
     User userEntity = manager.EnsureUserEntity(claimsIdentity);
     EducationSecurityIdentity identity = new EducationSecurityIdentity(claimsIdentity, userEntity);
     EducationSecurityPrincipal principal = new EducationSecurityPrincipal(identity);
     if (_AuditOnMapCollection.Contains(userEntity.UserKey))
     {
         _AuditOnMapCollection.Remove(userEntity.UserKey);
         manager.AuditLogin(principal);
     }
     if (!(filterContext.RequestContext.RouteData.Values["action"].ToString() == "Index" && filterContext.RequestContext.RouteData.Values["controller"].ToString() == "Agreement"))
     {
         manager.ValidateEulaAccepted(principal.Identity.User);
     }
     return principal;
 }
 public void GivenClaimsIdentityWithNoNameIdentifierClaim_WhenIFindUserKey_ThenThrowException()
 {
     Target.ExpectException <InvalidOperationException>(() => EducationSecurityIdentity.FindUserKey(new ClaimsIdentity()));
 }
 public void InitializeTest()
 {
     Users = new List<User> { new User { Id = 20, UserKey = "3u2e2" }, new User { Id = 30, UserKey = "29e8r2fj" }, new User { Id = 40, UserKey = "w8iw2j2" } };
     MockUserRepository = MockRepository.GenerateMock<IUserRepository>();
     MockUserRepository.Expect(r => r.Items).Return(Users.AsQueryable());
     BaseIdentity = new ClaimsIdentity("Federated");
     Target = new EducationSecurityIdentity(BaseIdentity, Users[0]);
 }
 public void GivenClaimsIdentityHasNoClaims_WhenIGetIsAuthenticated_ThenReturnTrue()
 {
     Target = new EducationSecurityIdentity(new ClaimsIdentity(), Users[0]);
     Assert.IsFalse(Target.IsAuthenticated);
 }
 public void GivenClaimsIdentityHasNoClaims_WhenIGetIsAuthenticated_ThenReturnTrue()
 {
     Target = new EducationSecurityIdentity(new ClaimsIdentity(), Users[0]);
     Assert.IsFalse(Target.IsAuthenticated);
 }
 public void GivenNullClaimsIdentity_WhenIFindUserKey__ThenThrowException()
 {
     Target.ExpectException <ArgumentNullException>(() => EducationSecurityIdentity.FindUserKey(null));
 }