一:关于前台权限

1:只允许自己看到

首先,我们需要确定在 Role 设置页面,用户所对应的 View Page by others 和 View all content 未被选中。备注,我们首先和得设置 Anonymous 和 Authenticated 的这两个的权限,这两项也未被选中。

这样一来,我们可以达到整个站点,我们只能看到自己的东西,如下:

而如果是 Admin 等全权限登录的,应该是这样的:

2:只允许某个角色看到

同理1。

二:关于自定义权限

首先,我们需要在模块的根目录下创建文件 Permissions:

public class Permissions : IPermissionProvider {
    public static readonly Permission ManageBlogs = new Permission { Description = "Manage blogs for others", Name = "ManageBlogs" };
    public static readonly Permission ManageOwnBlogs = new Permission { Description = "Manage own blogs", Name = "ManageOwnBlogs", ImpliedBy = new[] { ManageBlogs } };

public static readonly Permission PublishBlogPost = new Permission { Description = "Publish or unpublish blog post for others", Name = "PublishBlogPost", ImpliedBy = new[] { ManageBlogs } };
    public static readonly Permission PublishOwnBlogPost = new Permission { Description = "Publish or unpublish own blog post", Name = "PublishOwnBlogPost", ImpliedBy = new[] { PublishBlogPost, ManageOwnBlogs } };
    public static readonly Permission EditBlogPost = new Permission { Description = "Edit blog posts for others", Name = "EditBlogPost", ImpliedBy = new[] { PublishBlogPost } };
    public static readonly Permission EditOwnBlogPost = new Permission { Description = "Edit own blog posts", Name = "EditOwnBlogPost", ImpliedBy = new[] { EditBlogPost, PublishOwnBlogPost } };
    public static readonly Permission DeleteBlogPost = new Permission { Description = "Delete blog post for others", Name = "DeleteBlogPost", ImpliedBy = new[] { ManageBlogs } };
    public static readonly Permission DeleteOwnBlogPost = new Permission { Description = "Delete own blog post", Name = "DeleteOwnBlogPost", ImpliedBy = new[] { DeleteBlogPost, ManageOwnBlogs } };

public static readonly Permission MetaListBlogs = new Permission { ImpliedBy = new[] { EditBlogPost, PublishBlogPost, DeleteBlogPost }, Name = "MetaListBlogs"};
    public static readonly Permission MetaListOwnBlogs = new Permission { ImpliedBy = new[] { EditOwnBlogPost, PublishOwnBlogPost, DeleteOwnBlogPost }, Name = "MetaListOwnBlogs" };

public virtual Feature Feature { get; set; }

public IEnumerable<Permission> GetPermissions() {
        return new[] {
            ManageOwnBlogs,
            ManageBlogs,
            EditOwnBlogPost,
            EditBlogPost,
            PublishOwnBlogPost,
            PublishBlogPost,
            DeleteOwnBlogPost,
            DeleteBlogPost,
        };
    }

public IEnumerable<PermissionStereotype> GetDefaultStereotypes() {
        return new[] {
            new PermissionStereotype {
                Name = "Administrator",
                Permissions = new[] {ManageBlogs}
            },
            new PermissionStereotype {
                Name = "Editor",
                Permissions = new[] {PublishBlogPost,EditBlogPost,DeleteBlogPost}
            },
            new PermissionStereotype {
                Name = "Moderator",
            },
            new PermissionStereotype {
                Name = "Author",
                Permissions = new[] {ManageOwnBlogs}
            },
            new PermissionStereotype {
                Name = "Contributor",
                Permissions = new[] {EditOwnBlogPost}
            },
        };
    }

}

其次,我们需要在控制器中,为服务设定权限,如:

public AdminController(IMyService myService, IOrchardServices orchardServices) { _myService = myService; Services = orchardServices; }

。。。

Services.Authorizer.Authorize(Permissions.SomeModulePermission, T("Some operation failed"));

三:获取当前登录用户的角色信息

四:对 PART 设定权限

至此,ORCHARD 已经完全控制了所以的显式和功能权限,包括页面上的 PART部分。

参考:

http://docs.orchardproject.net/Documentation/Developer-FAQ

http://orchard.codeplex.com/discussions/547703

http://orchard.codeplex.com/discussions/390754

Orchard 前台权限与自定义权限的更多相关文章

  1. DRF认证、自定义认证和权限、自定义权限

    源码分析 """ 1)APIView的dispath(self, request, *args, **kwargs) 2)dispath方法内 self.initial( ...

  2. 【转】 Pro Android学习笔记(六五):安全和权限(2):权限和自定义权限

    目录(?)[-] 进程边界 声明和使用权限 AndroidManifestxml的许可设置 自定义权限 运行安全通过两个层面进行保护.进程层面:不同应用运行在不同的进程,每个应用有独自的user ID ...

  3. Salesforce自定义权限简介

    自定义权限(Custom Permission) Salesforce默认提供了多种方式设定用户的权限,比如简档.权限集等.在这些设定中,已经包括了系统中的对象.应用.字段.页面布局等组件,管理员或开 ...

  4. Orchard Core 自定义权限配置

    在我们为Orchard Core配置了一个新的Module之后,我们要考虑的是谁可以访问这个Module,那么这里就涉及到了一个权限的配置.如下图,添加了自定义的权限: Orchard Core源码: ...

  5. Android自定义权限和使用权限

    本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 自定义权限,主要用于保护被赋予权限的组件.如无权限与有权限,正如public与private的对类保 ...

  6. Android权限安全(3)权限的分级和自定义权限

    Android的不同权限分级 Normal 一般apk都可以用, Dangerous 一般apk都可以用,但有提示 SignatureOrSystem 特定的private key签名的或系统的apk ...

  7. android - 解决“应用自定义权限重名”

    背景 现场的开发今天跟我说,测试包装不上!报错"应用自定义权限重名"!!! 网上百度下关键字,发现魅族手机有这个毛病,顺藤摸瓜:"http://bbs.flyme.cn/ ...

  8. 关于 DotNetCore 的自定义权限管理

    1.自定义权限需要扩展 Microsoft.AspNetCore.Authentication 实现一套接口 IAuthenticationHandler, IAuthenticationSignIn ...

  9. SharePoint REST API - 使用REST接口对列表设置自定义权限

    博客地址:http://blog.csdn.net/FoxDave SharePoint网站.列表和列表项都属于SecurableObject类型.默认情况下,一个安全对象继承父级的权限.对一个对 ...

随机推荐

  1. Codeforces Round #189 (Div. 1) C - Kalila and Dimna in the Logging Industry 斜率优化dp

    C - Kalila and Dimna in the Logging Industry 很容易能得到状态转移方程 dp[ i ] = min( dp[ j ] + b[ j ] * a[ i ] ) ...

  2. rhev 虚拟化

    引用自:https://blog.csdn.net/Jmilk/article/details/50964121#rhev-hhypervisor-%E8%99%9A%E6%8B%9F%E6%9C%B ...

  3. 谈谈MySQL中的降序索引 order by id DESC / ASC

    今天这篇主要讲order by 语句中的多个字段asc desc的问题.mysql5中,索引存储的排序方式是ASC的,没有DESC的索引.现在能够理解为啥order by 默认是按照ASC来排序的了吧 ...

  4. pymysql模块 执行sql封装

    封装pymysql模块执行sql class HandCost(object): """ 处理数据库中的数据 """ def __init_ ...

  5. 001.NTP简介

    一 NTP简介 ntp服务器顾名思义就是时间同步服务器(Network Time Protocol),时间同步对于计划备份.入侵检测记录.分布式任务调度或者事务订单管理来说都是非常有必要的日常任务. ...

  6. AngularJs指令配置参数scope详解

    AngularJs最重要也是最难理解的模块之一就是它的指令(directive)了,自定义指令配置有很多个参数,下面我只说说其中scope的配置极其含义. scope表示指令的作用域,它有三个可选值: ...

  7. 通过css属性hack完成select样式美化,并兼容IE

    最近在重构时遇到了select样式问题,并且需要在不影响语义化的情况下,兼容IE8. 经过一番的百度后始终没有找到合适的纯CSS解决方案,最后换了一下思路,大胆使用了属性hack: 在chrome和F ...

  8. 初识thinkphp(3)

    这篇内容主要涉及请求相应内容. 该系列主要是个人笔记,且内容是连贯的,其中涉及到的自己写的模块或者方法在前面文章中有介绍咋来的,如果您看得云里雾里,给您带来不便,真的不好意思. 0x01:请求对象 官 ...

  9. 求有向图的强连通分量个数 之 Kosaraju算法

    代码: #include<cstdio> #include<cstring> #include<iostream> using namespace std; ][] ...

  10. Codeforces.959E.Mahmoud and Ehab and the xor-MST(思路)

    题目链接 \(Description\) 有一张\(n\)个点的完全图,从\(0\)到\(n-1\)标号,每两点\(i,j\)间的边权为\(i\oplus j\).求其最小生成树边权之和. \(Sol ...