当前位置: 首页>>代码示例>>C#>>正文


C# ISecurityContext.CurrenUserRoles方法代码示例

本文整理汇总了C#中ISecurityContext.CurrenUserRoles方法的典型用法代码示例。如果您正苦于以下问题:C# ISecurityContext.CurrenUserRoles方法的具体用法?C# ISecurityContext.CurrenUserRoles怎么用?C# ISecurityContext.CurrenUserRoles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ISecurityContext的用法示例。


在下文中一共展示了ISecurityContext.CurrenUserRoles方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Enforce

        public PolicyResult Enforce(ISecurityContext context)
        {
            if (context.CurrenUserAuthenticated() == false)
                return PolicyResult.CreateFailureResult(this, "Anonymous access denied");

            if (context.CurrenUserRoles() == null || context.CurrenUserRoles().Any() == false)
                return PolicyResult.CreateFailureResult(this, "Access denied");

            if (_requiredRoles.Any(requiredRole => context.CurrenUserRoles().Contains(requiredRole) == false))
            {
                const string message = "Access requires all of the following roles: {0}.";
                var formattedMessage = string.Format(message, GetRoles());
                return PolicyResult.CreateFailureResult(this, formattedMessage);
            }

            return PolicyResult.CreateSuccessResult(this);
        }
开发者ID:protechdm,项目名称:CloudCompare,代码行数:17,代码来源:RequireAllRolesPolicy.cs

示例2: Enforce

        public PolicyResult Enforce(ISecurityContext context)
        {
            if (context.CurrenUserAuthenticated() == false)
                return PolicyResult.CreateFailureResult(this, "Anonymous access denied");

            if (context.CurrenUserRoles() == null || context.CurrenUserRoles().Any() == false)
                return PolicyResult.CreateFailureResult(this, "Access denied");

            foreach (var requiredRole in _requiredRoles)
            {
                foreach (var role in context.CurrenUserRoles())
                {
                    if (requiredRole.ToString() == role.ToString())
                    {
                        return PolicyResult.CreateSuccessResult(this);
                    }
                }
            }

            const string message = "Access requires one of the following roles: {0}.";
            var formattedMessage = string.Format(message, GetRoles());
            return PolicyResult.CreateFailureResult(this, formattedMessage);
        }
开发者ID:cguedes,项目名称:FluentSecurity,代码行数:23,代码来源:RequireRolePolicy.cs

示例3: Enforce

 public PolicyResult Enforce(ISecurityContext context)
 {
     var authenticated = context.CurrenUserAuthenticated();
     var roles = context.CurrenUserRoles();
     return PolicyResult.CreateSuccessResult(this);
 }
开发者ID:dsekar,项目名称:FluentSecurity,代码行数:6,代码来源:PolicyContainerSpec.cs


注:本文中的ISecurityContext.CurrenUserRoles方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。