CSLA.NET 5.4.2
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
Csla.Validation.Shared/AuthorizationRules.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="AuthorizationRules.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Provides consistent context information between the client</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections.Generic;
10using System.Linq;
11using System.Text;
12using System.Threading.Tasks;
13using Csla.Rules;
15
17{
21 public class AuthorizationRules
22 {
23 #region Object Level Roles
30 public static void AllowGet(Type objectType, params string[] roles)
31 {
32 BusinessRules.AddRule(objectType, new IsInRole(AuthorizationActions.GetObject, roles));
33 }
34
41 public static void DenyGet(Type objectType, params string[] roles)
42 {
43 BusinessRules.AddRule(objectType, new IsNotInRole(AuthorizationActions.GetObject, roles));
44 }
45
52 public static void AllowEdit(Type objectType, params string[] roles)
53 {
54 BusinessRules.AddRule(objectType, new IsInRole(AuthorizationActions.EditObject, roles));
55 }
56
63 public static void DenyEdit(Type objectType, params string[] roles)
64 {
65 BusinessRules.AddRule(objectType, new IsNotInRole(AuthorizationActions.EditObject, roles));
66 }
67
74 public static void AllowCreate(Type objectType, params string[] roles)
75 {
76 BusinessRules.AddRule(objectType, new IsInRole(AuthorizationActions.CreateObject, roles));
77 }
78
85 public static void DenyCreate(Type objectType, params string[] roles)
86 {
87 BusinessRules.AddRule(objectType, new IsNotInRole(AuthorizationActions.CreateObject, roles));
88 }
89
96 public static void AllowDelete(Type objectType, params string[] roles)
97 {
98 BusinessRules.AddRule(objectType, new IsInRole(AuthorizationActions.DeleteObject, roles));
99 }
100
107 public static void DenyDelete(Type objectType, params string[] roles)
108 {
109 BusinessRules.AddRule(objectType, new IsNotInRole(AuthorizationActions.DeleteObject, roles));
110 }
111
112 #endregion
113
114 #region Check Object Level Roles
115
122 public static bool CanCreateObject(Type objectType)
123 {
124 return BusinessRules.HasPermission(AuthorizationActions.CreateObject, objectType);
125 }
126
133 public static bool CanGetObject(Type objectType)
134 {
135 return BusinessRules.HasPermission(AuthorizationActions.GetObject, objectType);
136 }
137
144 public static bool CanEditObject(Type objectType)
145 {
146 return BusinessRules.HasPermission(AuthorizationActions.EditObject, objectType);
147 }
148
155 public static bool CanDeleteObject(Type objectType)
156 {
157 return BusinessRules.HasPermission(AuthorizationActions.DeleteObject, objectType);
158 }
159
160 #endregion
161 }
162}
Tracks the business rules for a business object.
static bool HasPermission(AuthorizationActions action, Type objectType)
Checks per-type authorization rules.
void AddRule(IBusinessRuleBase rule)
Associates a business rule with the business object.
static void AllowDelete(Type objectType, params string[] roles)
Specify the roles allowed to delete a given type of business object.
static bool CanDeleteObject(Type objectType)
Gets a value indicating whether the current user is allowed to delete an instance of the business obj...
static void AllowEdit(Type objectType, params string[] roles)
Specify the roles allowed to edit (save) a given type of business object.
static bool CanGetObject(Type objectType)
Gets a value indicating whether the current user is allowed to get (fetch) an instance of the busines...
static void DenyDelete(Type objectType, params string[] roles)
Specify the roles not allowed to delete a given type of business object.
static void DenyEdit(Type objectType, params string[] roles)
Specify the roles not allowed to edit (save) a given type of business object.
static void AllowCreate(Type objectType, params string[] roles)
Specify the roles allowed to create a given type of business object.
static void DenyGet(Type objectType, params string[] roles)
Specify the roles not allowed to get (fetch) a given type of business object.
static void AllowGet(Type objectType, params string[] roles)
Specify the roles allowed to get (fetch) a given type of business object.
static bool CanCreateObject(Type objectType)
Gets a value indicating whether the current user is allowed to create an instance of the business obj...
static void DenyCreate(Type objectType, params string[] roles)
Specify the roles not allowed to create a given type of business object.
static bool CanEditObject(Type objectType)
Gets a value indicating whether the current user is allowed to edit (save) an instance of the busines...
AuthorizationActions
Authorization actions.