Exemple #1
0
        /// <summary>
        /// Checks if given user is granted for given permission.
        /// </summary>
        /// <param name="powerChecker">Permission checker</param>
        /// <param name="userId">User</param>
        /// <param name="requiresAll">True, to require all given permissions are granted. False, to require one or more.</param>
        /// <param name="permissionCodes">Name of the permissions</param>
        public static async Task <bool> IsGrantedAsync(this IPowerChecker powerChecker, string userId, bool requiresAll, params string[] permissionCodes)
        {
            if (permissionCodes.IsNullOrEmpty())
            {
                return(true);
            }

            if (requiresAll)
            {
                foreach (var permissionCode in permissionCodes)
                {
                    if (!(await powerChecker.IsGrantedAsync(userId, permissionCode)))
                    {
                        return(false);
                    }
                }

                return(true);
            }
            else
            {
                foreach (var permissionCode in permissionCodes)
                {
                    if (await powerChecker.IsGrantedAsync(userId, permissionCode))
                    {
                        return(true);
                    }
                }

                return(false);
            }
        }
Exemple #2
0
 /// <summary>
 /// Checks if a user is granted for a permission.
 /// </summary>
 /// <param name="powerChecker">Permission checker</param>
 /// <param name="userId">User to check</param>
 /// <param name="permissionCode">Name of the permission</param>
 public static bool IsGranted(this IPowerChecker powerChecker, string userId, string permissionCode)
 {
     return(AsyncHelper.RunSync(() => powerChecker.IsGrantedAsync(userId, permissionCode)));
 }
Exemple #3
0
 public static async Task AuthorizeAsync(this IPowerChecker powerChecker, string absolutePath,
                                         HttpMethod method)
 {
     await powerChecker.IsGrantedAsync(absolutePath, method);
 }