本文整理汇总了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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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))
};
}
示例8: PermissionRequirement
public PermissionRequirement(Permission permission)
{
if (permission == null)
{
throw new ArgumentNullException(nameof(permission));
}
Permission = permission;
}
示例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;
}
示例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;
}
示例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
};
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}