コード例 #1
0
ファイル: Roles.cs プロジェクト: dox0/DotNet471RS3
        static public string[] GetRolesForUser(string username)
        {
            if (HostingEnvironment.IsHosted && EtwTrace.IsTraceEnabled(EtwTraceLevel.Information, EtwTraceFlags.AppSvc) && HttpContext.Current != null)
            {
                EtwTrace.Trace(EtwTraceType.ETW_TYPE_ROLE_BEGIN, HttpContext.Current.WorkerRequest);
            }

            EnsureEnabled();
            string[] roles           = null;
            bool     isRolePrincipal = false;

            try {
                SecUtility.CheckParameter(ref username, true, false, true, 0, "username");
                if (username.Length < 1)
                {
                    roles = new string[0];
                    return(roles);
                }
                IPrincipal user = GetCurrentUser();
                if (user != null && user is RolePrincipal && ((RolePrincipal)user).ProviderName == Provider.Name && StringUtil.EqualsIgnoreCase(username, user.Identity.Name))
                {
                    roles           = ((RolePrincipal)user).GetRoles();
                    isRolePrincipal = true;
                }
                else
                {
                    roles = Provider.GetRolesForUser(username);
                }
                return(roles);
            } finally {
                if (HostingEnvironment.IsHosted && EtwTrace.IsTraceEnabled(EtwTraceLevel.Information, EtwTraceFlags.AppSvc) && HttpContext.Current != null)
                {
                    if (EtwTrace.IsTraceEnabled(EtwTraceLevel.Verbose, EtwTraceFlags.AppSvc))
                    {
                        string roleNames = null;
                        if (roles != null && roles.Length > 0)
                        {
                            roleNames = roles[0];
                        }
                        for (int i = 1; i < roles.Length; i++)
                        {
                            roleNames += "," + roles[i];
                        }

                        EtwTrace.Trace(EtwTraceType.ETW_TYPE_ROLE_GET_USER_ROLES, HttpContext.Current.WorkerRequest, isRolePrincipal ? "RolePrincipal" : Provider.GetType().FullName, username, roleNames, null);
                    }
                    EtwTrace.Trace(EtwTraceType.ETW_TYPE_ROLE_END, HttpContext.Current.WorkerRequest, isRolePrincipal ? "RolePrincipal" : Provider.GetType().FullName, username);
                }
            }
        }
コード例 #2
0
        public static bool IsUserInRole(string username, string roleName)
        {
            bool flag3;

            if (HostingEnvironment.IsHosted && EtwTrace.IsTraceEnabled(4, 8))
            {
                EtwTrace.Trace(EtwTraceType.ETW_TYPE_ROLE_BEGIN, HttpContext.Current.WorkerRequest);
            }
            EnsureEnabled();
            bool flag  = false;
            bool flag2 = false;

            try
            {
                SecUtility.CheckParameter(ref roleName, true, true, true, 0, "roleName");
                SecUtility.CheckParameter(ref username, true, false, true, 0, "username");
                if (username.Length < 1)
                {
                    return(false);
                }
                IPrincipal currentUser = GetCurrentUser();
                if (((currentUser != null) && (currentUser is RolePrincipal)) && ((((RolePrincipal)currentUser).ProviderName == Provider.Name) && System.Web.Util.StringUtil.EqualsIgnoreCase(username, currentUser.Identity.Name)))
                {
                    flag = currentUser.IsInRole(roleName);
                }
                else
                {
                    flag = Provider.IsUserInRole(username, roleName);
                }
                flag3 = flag;
            }
            finally
            {
                if (HostingEnvironment.IsHosted && EtwTrace.IsTraceEnabled(4, 8))
                {
                    if (EtwTrace.IsTraceEnabled(5, 8))
                    {
                        string str = System.Web.SR.Resources.GetString(flag ? "Etw_Success" : "Etw_Failure", CultureInfo.InstalledUICulture);
                        EtwTrace.Trace(EtwTraceType.ETW_TYPE_ROLE_IS_USER_IN_ROLE, HttpContext.Current.WorkerRequest, flag2 ? "RolePrincipal" : Provider.GetType().FullName, username, roleName, str);
                    }
                    EtwTrace.Trace(EtwTraceType.ETW_TYPE_ROLE_END, HttpContext.Current.WorkerRequest, flag2 ? "RolePrincipal" : Provider.GetType().FullName, username);
                }
            }
            return(flag3);
        }
コード例 #3
0
ファイル: Roles.cs プロジェクト: dox0/DotNet471RS3
        // authorization

        static public bool IsUserInRole(string username, string roleName)
        {
            if (HostingEnvironment.IsHosted && EtwTrace.IsTraceEnabled(EtwTraceLevel.Information, EtwTraceFlags.AppSvc) && HttpContext.Current != null)
            {
                EtwTrace.Trace(EtwTraceType.ETW_TYPE_ROLE_BEGIN, HttpContext.Current.WorkerRequest);
            }

            EnsureEnabled();
            bool isUserInRole    = false;
            bool isRolePrincipal = false;

            try {
                SecUtility.CheckParameter(ref roleName, true, true, true, 0, "roleName");
                SecUtility.CheckParameter(ref username, true, false, true, 0, "username");
                if (username.Length < 1)
                {
                    return(false);
                }
                IPrincipal user = GetCurrentUser();
                if (user != null && user is RolePrincipal && ((RolePrincipal)user).ProviderName == Provider.Name && StringUtil.EqualsIgnoreCase(username, user.Identity.Name))
                {
                    isUserInRole = user.IsInRole(roleName);
                }
                else
                {
                    isUserInRole = Provider.IsUserInRole(username, roleName);
                }
                return(isUserInRole);
            } finally {
                if (HostingEnvironment.IsHosted && EtwTrace.IsTraceEnabled(EtwTraceLevel.Information, EtwTraceFlags.AppSvc) && HttpContext.Current != null)
                {
                    if (EtwTrace.IsTraceEnabled(EtwTraceLevel.Verbose, EtwTraceFlags.AppSvc))
                    {
                        string status = SR.Resources.GetString(isUserInRole ? SR.Etw_Success : SR.Etw_Failure, CultureInfo.InstalledUICulture);
                        EtwTrace.Trace(EtwTraceType.ETW_TYPE_ROLE_IS_USER_IN_ROLE, HttpContext.Current.WorkerRequest, isRolePrincipal ? "RolePrincipal" : Provider.GetType().FullName, username, roleName, status);
                    }

                    EtwTrace.Trace(EtwTraceType.ETW_TYPE_ROLE_END, HttpContext.Current.WorkerRequest, isRolePrincipal ? "RolePrincipal" : Provider.GetType().FullName, username);
                }
            }
        }
コード例 #4
0
        public static string[] GetRolesForUser(string username)
        {
            string[] strArray2;
            if (HostingEnvironment.IsHosted && EtwTrace.IsTraceEnabled(4, 8))
            {
                EtwTrace.Trace(EtwTraceType.ETW_TYPE_ROLE_BEGIN, HttpContext.Current.WorkerRequest);
            }
            EnsureEnabled();
            string[] roles = null;
            bool     flag  = false;

            try
            {
                SecUtility.CheckParameter(ref username, true, false, true, 0, "username");
                if (username.Length < 1)
                {
                    return(new string[0]);
                }
                IPrincipal currentUser = GetCurrentUser();
                if (((currentUser != null) && (currentUser is RolePrincipal)) && ((((RolePrincipal)currentUser).ProviderName == Provider.Name) && System.Web.Util.StringUtil.EqualsIgnoreCase(username, currentUser.Identity.Name)))
                {
                    roles = ((RolePrincipal)currentUser).GetRoles();
                    flag  = true;
                }
                else
                {
                    roles = Provider.GetRolesForUser(username);
                }
                strArray2 = roles;
            }
            finally
            {
                if (HostingEnvironment.IsHosted && EtwTrace.IsTraceEnabled(4, 8))
                {
                    if (EtwTrace.IsTraceEnabled(5, 8))
                    {
                        string str = null;
                        if ((roles != null) && (roles.Length > 0))
                        {
                            str = roles[0];
                        }
                        for (int i = 1; i < roles.Length; i++)
                        {
                            str = str + "," + roles[i];
                        }
                        EtwTrace.Trace(EtwTraceType.ETW_TYPE_ROLE_GET_USER_ROLES, HttpContext.Current.WorkerRequest, flag ? "RolePrincipal" : Provider.GetType().FullName, username, str, null);
                    }
                    EtwTrace.Trace(EtwTraceType.ETW_TYPE_ROLE_END, HttpContext.Current.WorkerRequest, flag ? "RolePrincipal" : Provider.GetType().FullName, username);
                }
            }
            return(strArray2);
        }