When your application offers a login feature, you may want to restrict who can see
and edit various tables and even their columns. The DESDA.ColumnRestrictionAttribute
and DESDA.TableRestrictionAttribute describe how much access a user with a specific
security role has. BLD's user interface automatically conforms to these attributes
when setup.
BLD provides support for ASP.NET Forms Authentication. If you use a different
security model, you can support it by subclassing from PeterBlum.DES.BLD.BaseRestrictionManager.
These attributes define their restrictions with the PeterBlum.DES.DataAnnotations.DenyAccess type. It has
these values:
- None – This does not impose a security restriction. It is often used as a way for methods in this system indicate that there is no security error.
- View – Cannot view the data in single record or list views. Can still edit, insert, or delete. If you do not want to view, edit, insert or delete, choose DenyAccess.All.
- Edit – Cannot go into edit mode on an existing record or edit the DataField. You can still insert. If you want to prevent edit and insert, choose DenyAccess.Write.
- Insert – Cannot go into insert mode (create a new record)
- Delete – Cannot delete a record. Not supported by DESDA.ColumnRestrictionAttribute.
- Identify – Cannot see any presence of this table or DataField, even in a list of available tables or through a foreign key.
- Write – Cannot go into edit or insert modes. Effectively the same as DenyAccess.Edit OR DenyAccess.Insert (a bitset OR)
- AllActions – Cannot take any of the actions: View, Edit, Insert, or Delete. Can still see the presence of the table or DataField. (The DenyAcess.Identity restriction is not imposed.) Not supported by DESDA.ColumnRestrictionAttribute.
- All – Cannot take any action with the table or DataField, including viewing it.
Here are DESDA.ColumnRestrictionAttributes and DESDA.TableRestrictionAttributes
associated with the Product Entity class.
[DESDA.TableRestriction("Admin", DESDA.DenyAccess.None)]
[DESDA.TableRestriction("Customer", DESDA.DenyAccess.Edit | DESDA.DenyAccess.Delete | DESDA.DenyAccess.Insert)]
public class ProductMetadata
{
[DESDA.ColumnRestriction("Customer", DESDA.DenyAccess.View)]
public object UnitsInStock { get; set; }
[DESDA.ColumnRestriction("Customer", DESDA.DenyAccess.View)]
public object UnitsOnOrder { get; set; }
[DESDA.ColumnRestriction("Customer", DESDA.DenyAccess.View)]
public object ReorderLevel { get; set; }
[DESDA.ColumnRestriction("Customer", DESDA.DenyAccess.All)]
public object Order_Details { get; set; }
}
The Source Code Browser shows completed DataAnnotations. The DESDA.ColumnRestrictionAttributes
and DESDA.TableRestrictionAttributes have been highlighted.
The attributes are meaningless without the user interface supplying
a login system. Run this sample application. It reflects modifications
to the Page Templates and Master Page. Explore the code using it's Source
Code Browser and explore the files of the BLD Templates folder. You will
see that none of their BLD features have changed.
Instead, new code handles FormsAuthentication logins and redirects to other
pages if the user role does not permit access.
Open the Source Code Browser (C# only)