Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

OBSOLETE - How to extend the security strategy to provide object access control, based on encrypted license data

$
0
0

Although you can create a new security strategy from scratch, here we'll extend the SecuritySimple strategy.
First, create an interface to declare the user's license.


[C#]
publicinterfaceILicensedUser:ISimpleUser{stringLicense{get;}}

Then, create a custom user class and implement this interface, or extend the existing SimpleUser class.
Now, create a SecuritySimple descendant, and override the ReloadPermissions method to assign permissions, based on license data.

[C#]
protectedoverridePermissionSetReloadPermissions(){PermissionSetset=base.ReloadPermissions();if(this.User.IsActive){base.IsGrantedForNonExistentPermission=true;set.AddPermission(newObjectAccessPermission(typeof(object),ObjectAccess.AllAccess));set.AddPermission(newObjectAccessPermission(typeof(IPropertyBag),ObjectAccess.AllAccess));set.AddPermission(newObjectAccessPermission(typeof(IXPSimpleObject),ObjectAccess.NoAccess));set.AddPermission(newObjectAccessPermission(this.UserType,ObjectAccess.AllAccess));set.AddPermission(newEditModelPermission(this.User.IsAdministrator?ModelAccessModifier.Allow:ModelAccessModifier.Deny));if(!this.User.IsAdministrator){set.AddPermission(newObjectAccessPermission(this.UserType,ObjectAccess.ChangeAccess,ObjectAccessModifier.Deny));if(!this.AllowNonAdministratorNavigateToUsers){set.AddPermission(newObjectAccessPermission(this.UserType,ObjectAccess.Navigate,ObjectAccessModifier.Deny));}}ILicensedUserluser=this.UserasILicensedUser;if(luser!=null&&!string.IsNullOrEmpty(luser.License)){AddLicensedPermissions(set,DecryptLicense(luser.License));}returnset;}base.IsGrantedForNonExistentPermission=false;returnset;}privatevoidAddLicensedPermissions(PermissionSetset,stringlicense){if(license==null)return;string[]items=license.Split(';');foreach(stringiteminitems){Typetype=Type.GetType(item);if(type!=null){ObjectAccessPermissionp=newObjectAccessPermission(type,ObjectAccess.AllAccess);set.AddPermission(p);}}}

Here we implement additive permissions, based on the list of classes encoded in the license. This part can be implemented in different ways, including subtractive permissions, or any other complex scheme. You should additionally implement the DecryptLicense method according to your security requirements.
To use this security strategy, open the WinApplication or WebApplication module, and replace the existing security strategy with this one. Then, set the SecuritySimpleEx.UserType property to your new user class, and add some authentication type.


Viewing all articles
Browse latest Browse all 7205

Latest Images

Trending Articles



Latest Images