Example #1
0
        internal bool IsAuthorized(Oid userId, Oid entityId, EAuthorizations authorizations)
        {
            var isAuthorized = Context.Authorizations.Values.Any(a => ((a.UserId == userId) &&
                                                                       (a.EntityId == entityId) &&
                                                                       ((a.Authorizations & authorizations) == authorizations)));

            return(isAuthorized);
        }
Example #2
0
        //----------------------------------------------------------------------------------------------

        internal Authorization AddAuthorization(Oid userId, Oid entityId, EAuthorizations authorizations)
        {
            var authorization = new Authorization(userId, entityId, authorizations);

            Context.Authorizations.Add(authorization.UserId, authorization);

            return(authorization);
        }
Example #3
0
        //----------------------------------------------------------------------------------------------

        public bool AssertIsUserAuthorized(string username, Oid entityId, EAuthorizations authorizations)
        {
            var user = GetUserByUsername(username);

            if (!(user.IsAdmin || IsAuthorized(user.Id, entityId, authorizations)))
            {
                throw new AuthorizationException($"User '{user.Username}' is not authorized for this operation.");
            }

            return(true);
        }
Example #4
0
 public Authorization(Oid userId, Oid entityId, EAuthorizations authorizations)
 {
     UserId         = userId;
     EntityId       = entityId;
     Authorizations = authorizations;
 }