Orchard 前台权限与自定义权限
一:关于前台权限
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 前台权限与自定义权限的更多相关文章
- DRF认证、自定义认证和权限、自定义权限
源码分析 """ 1)APIView的dispath(self, request, *args, **kwargs) 2)dispath方法内 self.initial( ...
- 【转】 Pro Android学习笔记(六五):安全和权限(2):权限和自定义权限
目录(?)[-] 进程边界 声明和使用权限 AndroidManifestxml的许可设置 自定义权限 运行安全通过两个层面进行保护.进程层面:不同应用运行在不同的进程,每个应用有独自的user ID ...
- Salesforce自定义权限简介
自定义权限(Custom Permission) Salesforce默认提供了多种方式设定用户的权限,比如简档.权限集等.在这些设定中,已经包括了系统中的对象.应用.字段.页面布局等组件,管理员或开 ...
- Orchard Core 自定义权限配置
在我们为Orchard Core配置了一个新的Module之后,我们要考虑的是谁可以访问这个Module,那么这里就涉及到了一个权限的配置.如下图,添加了自定义的权限: Orchard Core源码: ...
- Android自定义权限和使用权限
本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 自定义权限,主要用于保护被赋予权限的组件.如无权限与有权限,正如public与private的对类保 ...
- Android权限安全(3)权限的分级和自定义权限
Android的不同权限分级 Normal 一般apk都可以用, Dangerous 一般apk都可以用,但有提示 SignatureOrSystem 特定的private key签名的或系统的apk ...
- android - 解决“应用自定义权限重名”
背景 现场的开发今天跟我说,测试包装不上!报错"应用自定义权限重名"!!! 网上百度下关键字,发现魅族手机有这个毛病,顺藤摸瓜:"http://bbs.flyme.cn/ ...
- 关于 DotNetCore 的自定义权限管理
1.自定义权限需要扩展 Microsoft.AspNetCore.Authentication 实现一套接口 IAuthenticationHandler, IAuthenticationSignIn ...
- SharePoint REST API - 使用REST接口对列表设置自定义权限
博客地址:http://blog.csdn.net/FoxDave SharePoint网站.列表和列表项都属于SecurableObject类型.默认情况下,一个安全对象继承父级的权限.对一个对 ...
随机推荐
- 002.KVM环境部署
一 环境准备 1.1 查看是否支持虚拟化 [root@kvm-host ~]# grep -E 'vmx|svm' /proc/cpuinfo 注意:intel为vmx,amd为svm. 1.2 确定 ...
- Codeforces.1041F.Ray in the tube(思路)
题目链接 \(Description\) 有两条平行于\(x\)轴的直线\(A,B\),每条直线上的某些位置有传感器.你需要确定\(A,B\)轴上任意两个整点位置\(x_A,x_B\),使得一条光线沿 ...
- BZOJ.2716.[Violet3]天使玩偶(CDQ分治 坐标变换)
题目链接 考虑对于两个点a,b,距离为|x[a]-x[b]|+|y[a]-y[b]|,如果a在b的右上,那我们可以把绝对值去掉,即x[a]+y[a]-(x[b]+y[b]). 即我们要求满足x[b]& ...
- BZOJ.1879.[SDOI2009]Bill的挑战(状压DP)
题目链接 f定义和下面的思路一样,转移时枚举填什么字符,去更新f并算出有哪些字符串可以匹配某个状态(见code吧...). 预处理出有哪些字符串在第i位可以转移到某个字符c,dp时&一下状态即 ...
- Xcode6 iOS7模拟器和Xcode7 iOS8模拟器离线下载
Xcode6 只支持iOS7和iOS8的模拟器 Xcode7 只支持iOS9和iOS8的模拟器 Xcode 并不会识别 SDKs 目录下的模拟器,我经过一些尝试以后,发现要放在这个目录下: /Libr ...
- c# RSA 加密解密 java.net公钥私钥转换 要解密的模块大于128字节
有一个和接口对接的任务,对方使用的是java,我方使用的是c#,接口加密类型为RSA,公钥加密私钥解密. 然后就是解决各种问题. 1.转换对方的密钥字符串 由于c#里面需要使用的是xml各式的密钥字符 ...
- 面试必会函数源代码 strcpy/memcpy/atoi/kmp/quicksort
http://blog.csdn.net/liuqiyao_01/article/details/26967813 二.stl模板函数 1.strcpy char * strcpy( char *st ...
- LPC-Link2 CMSIS-DAP firmware source
LPC-Link2 CMSIS-DAP firmware source Hi, I'm using the CMSIS-DAP firmware with the LPC-Link2. I'd lik ...
- a标签连接空标签的方法
在写页面时,想把a标签设置成空链接,方便后面数据的连接可以有几种方法. 1. <a herf=""></a> 这种方法会默认打开本页面,重新刷新一次页面. ...
- 作为互联网人,你必须知道的一些IT类网站