Beispiel #1
0
 public override ACLVerdict Apply(UserContext ctx, DataOperation op)
 {
     return (op == DataOperation.Retreive) ? ACLVerdict.Allowed : ACLVerdict.None;
 }
Beispiel #2
0
        public ACLVerdict Apply(UserContext ctx, DataOperation op)
        {
            ACLVerdict current = ACLVerdict.Denied;

            foreach (IACLEntry entry in _accessControlList)
            {
                ACLVerdict result = entry.Apply(ctx, op);
                switch (result)
                {
                    case ACLVerdict.Denied:
                        return ACLVerdict.Denied;
                    case ACLVerdict.Allowed:
                        current = ACLVerdict.Allowed;
                        break;
                }
            }

            return current;
        }
Beispiel #3
0
        public override ACLVerdict Apply(UserContext ctx, DataOperation op)
        {
            if (op == DataOperation.Retreive && ctx.AccountId != 0)
            {
                return ACLVerdict.Allowed;
            }

            return ACLVerdict.None;
        }
Beispiel #4
0
 public abstract ACLVerdict Apply(UserContext ctx, DataOperation op);
Beispiel #5
0
        public override ACLVerdict Apply(UserContext ctx, DataOperation op)
        {
            if ((op == DataOperation.Create || op == DataOperation.Delete) && ctx.AccountId != 0)
            {
                return ACLVerdict.Allowed;
            }

            return ACLVerdict.None;
        }
Beispiel #6
0
        public override ACLVerdict Apply(UserContext ctx, DataOperation op)
        {
            if (ctx.AccountId == 0)
                return ACLVerdict.None;

            if (ctx.AccountId != _accountId)
                return ACLVerdict.None;

            if ((_operation & (int)op) == 0)
                return ACLVerdict.None;

            return _permission == DataOperationPermission.Allow
                ? ACLVerdict.Allowed
                : ACLVerdict.Denied;
        }
Beispiel #7
0
        public bool TryCheck(UserContext ctx, DataOperation op)
        {
            ACLVerdict result = Apply(ctx, op);
            switch (result)
            {
                case ACLVerdict.Denied:
                case ACLVerdict.None:
                    return false;
            }

            return true;
        }
Beispiel #8
0
 public void Check(UserContext ctx, DataOperation op)
 {
     if (!TryCheck(ctx, op))
     {
         throw new AccessDeniedException();
     }
 }
Beispiel #9
0
        /// <summary>
        /// Try to login a user.
        /// </summary>
        /// <param name="username">user name</param>
        /// <param name="password">user password</param>
        /// <param name="ctx">user context</param>
        /// <returns>a user security context</returns>
        public bool TryLogin(string username, string password, out UserContext ctx)
        {
            ctx = null;

            // find an account by username/passsword
            Account account = _session.CreateCriteria(typeof(Account))
                .Add(Expression.Eq("Name", username))
                .Add(Expression.Eq("Password", password))
                .UniqueResult<Account>();

            if (account != null)
            {
                ctx = new UserContext(account);
                return true;
            }

            return false;
        }