GetCurrentUserRoles() public static method

Helper method that returns the correct roles based on authentication.
public static GetCurrentUserRoles ( ) : string[]
return string[]
Beispiel #1
0
        /// <summary>
        /// Returns whether the current user passes authorization on the rights based on the given AuthorizationCheck.
        /// </summary>
        /// <param name="authCheck"></param>
        /// <param name="rights"></param>
        /// <returns></returns>
        public static bool IsAuthorizedTo(AuthorizationCheck authCheck, IEnumerable <Rights> rights)
        {
            if (rights.Count() == 0)
            {
                // Always return false for this. If there's a mistake where authorization
                // is being checked for on an empty collection, we don't want to return
                // true.
                return(false);
            }
            else
            {
                var roles = Security.GetCurrentUserRoles();

                if (authCheck == AuthorizationCheck.HasAny)
                {
                    foreach (var right in rights)
                    {
                        if (Right.HasRight(right, roles))
                        {
                            return(true);
                        }
                    }

                    return(false);
                }
                else if (authCheck == AuthorizationCheck.HasAll)
                {
                    bool authCheckPassed = true;

                    foreach (var right in rights)
                    {
                        if (!Right.HasRight(right, roles))
                        {
                            authCheckPassed = false;
                            break;
                        }
                    }
                    return(authCheckPassed);
                }
                else
                {
                    throw new NotSupportedException();
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Returns whether or not the current user has the passed in Right.
 /// </summary>
 /// <param name="right"></param>
 /// <returns></returns>
 public static bool IsAuthorizedTo(Rights right)
 {
     return(Right.HasRight(right, Security.GetCurrentUserRoles()));
 }
Beispiel #3
0
 /// <summary>
 /// Returns an IEnumerable of Rights that belong to the ecurrent user.
 /// </summary>
 /// <returns></returns>
 public static IEnumerable <Right> CurrentUserRights()
 {
     return(Right.GetRights(Security.GetCurrentUserRoles()));
 }