expressappframework-devexpress-dot-persistent-dot-baseimpl-dot-ef-78f06089.md
An XAF user who has a list of associated security roles.
Namespace : DevExpress.Persistent.BaseImpl.EF
Assembly : DevExpress.ExpressApp.Security.EF6.v25.1.dll
NuGet Package : DevExpress.ExpressApp.Security.EF6
[RuleCriteria("SecuritySystemUser_EF_Prevent_delete_logged_in_user", DefaultContexts.Delete, "[ID] != CurrentUserId()", "Cannot delete the current logged-in user. Please log in using another user account and retry.")]
public class User :
ISecurityUser,
IAuthenticationActiveDirectoryUser,
IAuthenticationStandardUser,
IOperationPermissionProvider,
ISecurityUserWithRoles,
INotifyPropertyChanged,
ICanInitialize
<RuleCriteria("SecuritySystemUser_EF_Prevent_delete_logged_in_user", DefaultContexts.Delete, "[ID] != CurrentUserId()", "Cannot delete the current logged-in user. Please log in using another user account and retry.")>
Public Class User
Implements ISecurityUser,
IAuthenticationActiveDirectoryUser,
IAuthenticationStandardUser,
IOperationPermissionProvider,
ISecurityUserWithRoles,
INotifyPropertyChanged,
ICanInitialize
Note
It is recommended to use the Allow/Deny Permission Policy. For this purpose, migrate from User to PermissionPolicyUser. If you use Entity Framework as the ORM system, you may also need to perform a migration.
Associated roles are exposed via the SecuritySystemUser.Roles property. To get the complete list of permissions granted to the current user via their associated roles, use the IOperationPermissionProvider.GetPermissions method.
Inherit this class when you use the SecurityStrategyComplex Security Strategy and want to replace the default User with a custom type that exposes additional properties.
using DevExpress.Persistent.BaseImpl.EF;
// ...
public class Employee : User {
[Browsable(false)]
public virtual int ID { get; protected set; }
public virtual string FullName {get; set; }
public virtual Department Department { get; set; }
public virtual IList<Task> Tasks { get; set; }
}
public class Task {
// ...
}
// Make sure that you use options.UseChangeTrackingProxies() in your DbContext settings.
Imports DevExpress.Persistent.BaseImpl.EF
' ...
Public Class Employee
Inherits User
Private privateID As Int32
<Browsable(False)> _
Public Property ID() As Int32
Get
Return privateID
End Get
Protected Set(ByVal value As Int32)
privateID = value
End Set
End Property
Public Property FullName() As String
Public Overridable Property Department() As Department
Public Overridable Property Tasks() As IList(Of Task)
End Class
Public Class Task
' ...
End Class
Then, invoke the Application Designer, focus the SecurityStrategyComplex component and change the SecurityStrategy.UserType value in the Properties window.
Alternativaly, you can specify the user type in code. In a Windows Forms application project, modify the Program.cs (Program.vb) file in the following manner.
public static void Main(string[] arguments) {
MySolutionWinApplication winApplication = new MySolutionWinApplication();
winApplication.Security =
new SecurityStrategyComplex(typeof(Employee), typeof(Role),
new AuthenticationStandard());
// ...
}
Public Shared Sub Main(ByVal arguments() As String)
Dim winApplication As New MySolutionWinApplication()
winApplication.Security = _
New SecurityStrategyComplex(GetType(Employee), GetType(Role), _
New AuthenticationStandard())
' ...
End Sub
In an ASP.NET Web Forms application project, modify the Global.asax.cs (Global.asax.vb) file in the following manner.
protected void Session_Start(Object sender, EventArgs e) {
WebApplication.SetInstance(Session, new MySolutionAspNetApplication());
WebApplication.Instance.Security =
new SecurityStrategyComplex(typeof(Employee), typeof(Role),
new AuthenticationStandard());
// ...
}
Protected Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
WebApplication.SetInstance(Session, New MySolutionAspNetApplication())
WebApplication.Instance.Security = _
New SecurityStrategyComplex(GetType(Employee), GetType(Role), _
New AuthenticationStandard())
' ...
End Sub
Tip
You can use the UserWithRolesExtensions.IsUserInRole extension method with User objects because User implements ISecurityUserWithRoles.
IAuthenticationActiveDirectoryUser
Object User
See Also