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


C# Permissions.Permission类代码示例

本文整理汇总了C#中Orchard.Security.Permissions.Permission的典型用法代码示例。如果您正苦于以下问题:C# Permission类的具体用法?C# Permission怎么用?C# Permission使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Permission类属于Orchard.Security.Permissions命名空间,在下文中一共展示了Permission类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetOwnerVariation

 private static Permission GetOwnerVariation(Permission permission) {
     if (permission.Name == Permissions.Management.Name)
         return Permissions.Lead;
     if (permission.Name == Orchard.Core.Contents.Permissions.ViewContent.Name)
         return Orchard.Core.Contents.Permissions.ViewOwnContent;
     return null;
 }
开发者ID:dioptre,项目名称:nkd,代码行数:7,代码来源:NKDAuthorizationEventHandler.cs

示例2: OnAuthorization

        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            if (String.IsNullOrEmpty(PermissionName))
            {
                throw new ApplicationException("No permission supplied");
            }

            //No authorization if permission is AllowAnonymous
            if (String.Equals(PermissionName, "AllowAnonymous", StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }

            WorkContext workContext = filterContext.GetWorkContext();
            IAuthorizer authorizer = workContext.Resolve<IAuthorizer>();
            Permission permission = new Permission {Name = PermissionName};

            if (authorizer.Authorize(permission,
                new LocalizedString("Access is denied")))
            {
                return;
            }

            //Access is denied
            filterContext.Result = new HttpUnauthorizedResult();
        }
开发者ID:rijkshuisstijl,项目名称:Orchard-Seeds,代码行数:26,代码来源:OrchardAuthorizationAttribute.cs

示例3: Authorize

        public new bool Authorize(Permission permission, IContent content, LocalizedString message) {
            var authorizerMessage = new AuthorizerMessage {PermissionName = permission.Name};

            if (content != null)
            {
                authorizerMessage.ContentId = content.Id;
                authorizerMessage.ContentType = content.ContentItem.ContentType;
                authorizerMessage.ContentName = content.GetContentName();
            }

            return _performanceMonitor.PublishTimedAction(() =>
            {
                if (permission == StandardPermissions.AccessFrontEnd)
                {
                    return true;
                }

                return base.Authorize(permission, content, message);
            }, (r, t) => { 
                authorizerMessage.Duration = t.Duration;
                authorizerMessage.UserIsAuthorized = r;

                return authorizerMessage;
            }, TimelineCategories.Authorization, "Authorize", permission.Name).ActionResult;
        }
开发者ID:pszmyd,项目名称:Glimpse.Orchard,代码行数:25,代码来源:GlimpseAuthorizer.cs

示例4: ConvertToDynamicPermission

        /// <summary>
        /// Returns a dynamic permission for a content type, based on a global content permission template
        /// </summary>
        public static Permission ConvertToDynamicPermission(Permission permission) {
            if (PermissionTemplates.ContainsKey(permission.Name)) {
                return PermissionTemplates[permission.Name];
            }

            return null;
        }
开发者ID:RasterImage,项目名称:Orchard,代码行数:10,代码来源:DynamicPermissions.cs

示例5: TryCheckAccess

        public bool TryCheckAccess(Permission permission, IUser user, IContent content) {
            var context = new CheckAccessContext { Permission = permission, User = user, Content = content };
            _authorizationServiceEventHandler.Checking(context);

            for (var adjustmentLimiter = 0; adjustmentLimiter != 3; ++adjustmentLimiter) {
                if (!context.Granted && context.User != null) {
                    if (String.Equals(context.User.UserName, "Administrator", StringComparison.OrdinalIgnoreCase) ||
                        ((!String.IsNullOrEmpty(CurrentSite.SuperUser) &&
                           String.Equals(context.User.UserName, CurrentSite.SuperUser, StringComparison.OrdinalIgnoreCase)))) {
                        context.Granted = true;
                    }
                }

                if (!context.Granted) {

                    // determine which set of permissions would satisfy the access check
                    var grantingNames = PermissionNames(context.Permission, Enumerable.Empty<string>()).ToArray();

                    // determine what set of roles should be examined by the access check
                    IEnumerable<string> rolesToExamine;
                    if (context.User == null) {
                        rolesToExamine = AnonymousRole;
                    }
                    else if (context.User.Has<IUserRoles>()) {
                        rolesToExamine = context.User.As<IUserRoles>().Roles.Concat(AuthenticatedRole);
                    }
                    else {
                        rolesToExamine = AuthenticatedRole;
                    }

                    foreach (var role in rolesToExamine) {
                        RoleRecord roleRecord = _roleService.GetRoleByName(role);
                        if ( roleRecord == null )
                            continue;
                        foreach (var permissionName in _roleService.GetPermissionsForRole(roleRecord.Id)) {
                            string possessedName = permissionName;
                            if (grantingNames.Any(grantingName => String.Equals(possessedName, grantingName, StringComparison.OrdinalIgnoreCase))) {
                                context.Granted = true;
                            }

                            if (context.Granted)
                                break;
                        }

                        if (context.Granted)
                            break;
                    }
                }

                context.Adjusted = false;
                _authorizationServiceEventHandler.Adjust(context);
                if (!context.Adjusted)
                    break;
            }

            _authorizationServiceEventHandler.Complete(context);

            return context.Granted;
        }
开发者ID:mofashi2011,项目名称:orchardcms,代码行数:59,代码来源:RolesBasedAuthorizationService.cs

示例6: TryCheckAccess

        public bool TryCheckAccess(Permission permission, IUser user, IContent content) {
            var context = new CheckAccessContext { Permission = permission, User = user, Content = content };
            _authorizationServiceEventHandler.Checking(context);

            for (var adjustmentLimiter = 0; adjustmentLimiter != 3; ++adjustmentLimiter) {
                if (!context.Granted && context.User != null) {
                    if (!String.IsNullOrEmpty(_workContextAccessor.GetContext().CurrentSite.SuperUser) &&
                           String.Equals(context.User.UserName, _workContextAccessor.GetContext().CurrentSite.SuperUser, StringComparison.Ordinal)) {
                        context.Granted = true;
                    }
                }

                if (!context.Granted) {

                    // determine which set of permissions would satisfy the access check
                    var grantingNames = PermissionNames(context.Permission, Enumerable.Empty<string>()).Distinct().ToArray();

                    // determine what set of roles should be examined by the access check
                    IEnumerable<string> rolesToExamine;
                    if (context.User == null) {
                        rolesToExamine = AnonymousRole;
                    } 
                    else if (user.As<IUserRoles>().Roles.Any()) {
                        

                        // the current user is not null, so get his roles and add "Authenticated" to it
                        rolesToExamine = user.As<IUserRoles>().Roles.Union(AuthenticatedRole);

                    } else {
                        // the user is not null and has no specific role, then it's just "Authenticated"
                        rolesToExamine = AuthenticatedRole;
                    }

                    foreach (var role in rolesToExamine) {
                        foreach (var permissionName in _roleService.GetPermissionsForRoleByName(role)) {
                            string possessedName = permissionName;
                            if (grantingNames.Any(grantingName => String.Equals(possessedName, grantingName, StringComparison.OrdinalIgnoreCase))) {
                                context.Granted = true;
                            }

                            if (context.Granted)
                                break;
                        }

                        if (context.Granted)
                            break;
                    }
                }

                context.Adjusted = false;
                _authorizationServiceEventHandler.Adjust(context);
                if (!context.Adjusted)
                    break;
            }

            _authorizationServiceEventHandler.Complete(context);

            return context.Granted;
        }
开发者ID:NIKASoftwareDevs,项目名称:Orchard,代码行数:59,代码来源:CASAuthorizationService.cs

示例7: CreateDynamicPermission

 /// <summary>
 /// Generates a permission dynamically for a content type
 /// </summary>
 public static Permission CreateDynamicPermission(Permission template, ContentTypeDefinition typeDefinition) {
     return new Permission {
         Name = String.Format(template.Name, typeDefinition.Name),
         Description = String.Format(template.Description, typeDefinition.DisplayName),
         Category = typeDefinition.DisplayName,
         ImpliedBy = (template.ImpliedBy ?? new Permission[0]).Select(t => CreateDynamicPermission(t, typeDefinition))
     };
 }
开发者ID:RasterImage,项目名称:Orchard,代码行数:11,代码来源:DynamicPermissions.cs

示例8: PermissionRequirement

        public PermissionRequirement(Permission permission)
        {
            if (permission == null)
            {
                throw new ArgumentNullException(nameof(permission));
            }

            Permission = permission;
        }
开发者ID:jchenga,项目名称:Orchard2,代码行数:9,代码来源:PermissionRequirement.cs

示例9: GetOwnerVariation

 private static Permission GetOwnerVariation(Permission permission) {
     if (permission.Name == Permissions.PublishOthersPages.Name)
         return Permissions.PublishPages;
     if (permission.Name == Permissions.EditOthersPages.Name)
         return Permissions.EditPages;
     if (permission.Name == Permissions.DeleteOthersPages.Name)
         return Permissions.DeletePages;
     return null;
 }
开发者ID:mofashi2011,项目名称:orchardcms,代码行数:9,代码来源:AuthorizationEventHandler.cs

示例10: GetOwnerVariation

 private static Permission GetOwnerVariation(Permission permission) {
     if (permission.Name == Permissions.PublishTimetableAppointment.Name)
         return Permissions.PublishOwnTimetableAppointment;
     if (permission.Name == Permissions.EditTimetableAppointment.Name)
         return Permissions.EditOwnTimetableAppointment;
     if (permission.Name == Permissions.DeleteTimetableAppointment.Name)
         return Permissions.DeleteOwnTimetableAppointment;
     return null;
 }
开发者ID:dminik,项目名称:voda_code,代码行数:9,代码来源:TimetableAuthorizationEventHandler.cs

示例11: CheckAccess

 public void CheckAccess(Permission permission, IUser user, IContent content) {
     if (!TryCheckAccess(permission, user, content)) {
         throw new OrchardSecurityException(T("A security exception occurred in the content management system.")) {
             PermissionName = permission.Name,
             User = user,
             Content = content
         };
     }
 }
开发者ID:githubzwj,项目名称:Orchard.Platform,代码行数:9,代码来源:RolesBasedAuthorizationService.cs

示例12: GetOwnerVariation

 private static Permission GetOwnerVariation(Permission permission) {
     if (permission.Name == Permissions.PublishBlogPost.Name)
         return Permissions.PublishOwnBlogPost;
     if (permission.Name == Permissions.EditBlogPost.Name)
         return Permissions.EditOwnBlogPost;
     if (permission.Name == Permissions.DeleteBlogPost.Name)
         return Permissions.DeleteOwnBlogPost;
     return null;
 }
开发者ID:rupertwhitlock,项目名称:IncreasinglyAbsorbing,代码行数:9,代码来源:BlogAuthorizationEventHandler.cs

示例13: GetOwnerVariation

 private static Permission GetOwnerVariation(Permission permission) {
     if (permission.Name == Permissions.PublishContent.Name)
         return Permissions.PublishOwnContent;
     if (permission.Name == Permissions.EditContent.Name)
         return Permissions.EditOwnContent;
     if (permission.Name == Permissions.DeleteContent.Name)
         return Permissions.DeleteOwnContent;
     return null;
 }
开发者ID:Vinna,项目名称:DeepInSummer,代码行数:9,代码来源:AuthorizationEventHandler.cs

示例14: GetOwnerVariation

 private static Permission GetOwnerVariation(Permission permission)
 {
     if (permission.Name == Permissions.DeletePost.Name)
         return Permissions.DeleteOwnPost;
     if (permission.Name == Permissions.EditPost.Name)
         return Permissions.EditOwnPost;
     if (permission.Name == Permissions.MarkPostAsAnswer.Name)
         return Permissions.MarkPostInOwnThreadAsAnswer;
     return null;
 }
开发者ID:Trifectgaming,项目名称:Trifect-CMS,代码行数:10,代码来源:ForumAuthorizationEventHandler.cs

示例15: GetOwnerVariation

 private static Permission GetOwnerVariation(Permission permission) {
     if (permission.Name == Permissions.ManageForums.Name)
         return Permissions.ManageOwnForums;
     if (permission.Name == Permissions.MoveThread.Name)
         return Permissions.MoveOwnThread;
     if (permission.Name == Permissions.StickyThread.Name)
         return Permissions.StickyOwnThread;
     if (permission.Name == Permissions.CloseThread.Name)
         return Permissions.CloseOwnThread;
     return null;
 }
开发者ID:WoB-OSS,项目名称:NGM.Forum,代码行数:11,代码来源:ForumAuthorizationEventHandler.cs


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