我在XAF项目中使用新安全系统。我已经创建了自定义安全类" ExtendedSystemSecurityRole"和" SecuritySystemUser"。在Updater类中,我创建了一个名为" G1"及其权限如下。但是在跑步时,用户"约翰"看不到"买家"形式。
ExtendedSecuritySystemRole basicUserRole = ObjectSpace.FindObject<ExtendedSecuritySystemRole>(new BinaryOperator("Name", "G1"));
if (basicUserRole == null)
{
basicUserRole = ObjectSpace.CreateObject<ExtendedSecuritySystemRole>();
basicUserRole.Name = "G1";
SecuritySystemTypePermissionObject userTypePermission =
ObjectSpace.CreateObject<SecuritySystemTypePermissionObject>();
userTypePermission.TargetType = typeof(Buyer);
SecuritySystemObjectPermissionsObject currentUserObjectPermission =
ObjectSpace.CreateObject<SecuritySystemObjectPermissionsObject>();
currentUserObjectPermission.Criteria = "[Active] = True";
currentUserObjectPermission.AllowNavigate = true;
currentUserObjectPermission.AllowRead = true;
userTypePermission.ObjectPermissions.Add(currentUserObjectPermission);
basicUserRole.TypePermissions.Add(userTypePermission);
}
ExtendedSecuritySystemUser userJohn =
ObjectSpace.FindObject<ExtendedSecuritySystemUser>(
new BinaryOperator("UserName", "John"));
if (userJohn == null)
{
userJohn = ObjectSpace.CreateObject<ExtendedSecuritySystemUser>();
userJohn.UserName = "John";
userJohn.SetPassword("");
userJohn.Roles.Add(basicUserRole);
}
答案 0 :(得分:0)
您的条件是Buyer.Active = True
而非ExtendedSecuritySystemUser.Active = true
。
你可以 create your own function operator IsCurrentUserActive()
为此使用ViewController
会更简单。类似的东西:
public class InactiveUsersController : ViewController
{
public InactiveUsersController()
{
this.TargetViewNesting = Nesting.Any;
this.TargetViewType = ViewType.ListView;
this.TargetObjectType = typeof(Buyer);
}
protected override void OnActivated()
{
base.OnActivated();
ListView listView = View as ListView;
listView.CollectionSource.Criteria.Remove("InactiveUserFilter"); // clear the filter
var currentUser = SecuritySystem.CurrentUser as ExtendedSecuritySystemUser;
if (!currentUser.Active)
{
// return empty list if user is inactive
listView.CollectionSource.Criteria.Add("InactiveUserFilter", CollectionSource.EmptyCollectionCriteria);
}
}
}