Exemplo n.º 1
0
 public override void TearDown()
 {
     DeleteUser(_user);
     _user = null;
     SessionManager.CurrentSessionContext = new GuestUserContext();
     base.TearDown();
 }
Exemplo n.º 2
0
        public void TestCreateDeleteAnyone()
        {
            // an account can be created by anyone
            Account account = new Account();
            account.Created = DateTime.UtcNow;
            account.Name = Guid.NewGuid().ToString();
            account.Password = "******";
            Session.Save(account);
            Session.Flush();

            // an account cannot be deleted by guest
            try
            {
                Session.Delete(account);
                Session.Flush();
            }
            finally
            {
                using (new Impersonator(new UserContext(account)))
                {
                    Account accountCopy = Session.Load<Account>(account.Id);
                    Session.Delete(accountCopy);
                    Session.Flush();
                }
            }
        }
Exemplo n.º 3
0
 public override void SetUp()
 {
     base.SetUp();
     SessionManager.Initialize(new ThreadSessionSource(), ServiceDataEventListeners.Instance);
     _user = CreateUser();
     SessionManager.CurrentSessionContext = new UserContext(_user);
 }
Exemplo n.º 4
0
 public void DeleteUser(Account instance)
 {
     using (new Impersonator(new UserContext(instance)))
     {
         Session.Delete(instance);
         Session.Flush();
     }
 }
Exemplo n.º 5
0
 public AccountClassACL(Account instance)
 {
     // allow everyone to create an account
     this.Add(new ACLEveryoneAllowCreate());
     // everyone can see accounts
     this.Add(new ACLEveryoneAllowRetrieve());
     // owner can do everything with his own account
     this.Add(new ACLAccount(instance, DataOperation.All));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Create a user.
 /// </summary>
 /// <param name="username">username</param>
 /// <param name="password">password</param>
 public Account CreateUser(string username, string password)
 {
     Account account = new Account();
     account.Created = DateTime.UtcNow;
     account.Name = username;
     account.Password = password;
     _session.Save(account);
     _session.Flush();
     return account;
 }
Exemplo n.º 7
0
 protected Account CreateUser()
 {
     using (new Impersonator(new GuestUserContext()))
     {
         Account instance = new Account();
         instance.Created = DateTime.UtcNow;
         instance.Name = Guid.NewGuid().ToString();
         instance.Password = "******";
         Session.Save(instance);
         Session.Flush();
         return instance;
     }
 }
Exemplo n.º 8
0
        public void TestCreateDelete()
        {
            // create a new account, this can be done by anyone
            Account account = new Account();
            account.Created = DateTime.UtcNow;
            account.Name = Guid.NewGuid().ToString();
            account.Password = "******";
            Session.Save(account);
            Session.Flush();

            // switch context to self and delete the account, this can be done by the account owner himself
            using (new Impersonator(new UserContext(account)))
            {
                Account accountCopy = Session.Load<Account>(account.Id);
                // the owner can update his own account
                accountCopy.Name = Guid.NewGuid().ToString();
                Session.Save(accountCopy);
                // an account can be deleted by self
                Session.Delete(accountCopy);
                Session.Flush();
            }
        }
Exemplo n.º 9
0
 public ACLAccount(Account value, int op, DataOperationPermission perm)
     : base(op, perm)
 {
     _account = value;
 }
Exemplo n.º 10
0
 public ACLAccount(Account value, DataOperation op)
     : this(value, (int)op, DataOperationPermission.Allow)
 {
 }
Exemplo n.º 11
0
 public UserContext(Account account)
 {
     _accountId = account.Id;
 }