2

我有一个在服务器端使用 WCF 的 WPF 客户端/服务器应用程序。它目前不安全,我希望为我的 Active Directory 上的用户群保护它。应用程序应该托管它自己的角色/权限数据库,该数据库可以通过引用他们的活动目录帐户(SID、SAM 等等)附加到用户的配置文件。

我需要了解一些实施安全性的步骤,然后是我的用户在我的应用程序中拥有的角色/权限:

  1. 如何让我的 WPF 应用程序只允许我的 Active Directory 授权的身份?如果有人使用某个本地用户帐户登录到他们的本地计算机,他们显然仍然有权运行 WPF 可执行文件 - 那么我如何确保登录确实是 Active Directory 登录,而不是本地登录?app.config 中的配置选项是否与 asp.net web.config 中的配置选项相同,我所做的只是将身份验证设置为 Windows,其余的只是处理?
  2. 一旦用户被证明是有效的活动目录用户,将用户的 WindowsIdentity 绑定到我的数据库表中的角色的最佳方法是什么?这是使用自定义 RoleProvider 最好的方法吗?

是否有任何好的文档可以帮助连接这些点?由于我读过的所有 WIF 文档和我看过的所有教程,这些是唯一对我没有意义并且似乎没有在任何地方解释的部分。

我知道我需要保护 WCF,但我的理解是这相对简单,就像在 ASP.NET 中一样,它实际上只是正确配置它的问题,其余的就发生了。

4

1 回答 1

1

关于问题1:

您可以在公开的 WCF 方法上使用PrincipalPermissionAttribute :

    [PrincipalPermission(SecurityAction.Demand, Role = "ProjectManagers")]
    [PrincipalPermission(SecurityAction.Demand, Role = "Developers")]
    [PrincipalPermission(SecurityAction.Demand, Role = "Operations")]
    [PrincipalPermission(SecurityAction.Demand, Role = "Clients OU Admins")]
    public string CreateUser(string strFName, string strLName, string strPassword, string strOUName)
    {
        return CreateADAccount(strFName, strLName, strPassword, strOUName);
    }

这将仅授权属于上述四个组之一的用户执行该方法。

对于问题 2,在我的脑海中,您可以执行以下操作:

以下代码未经测试且不完整。它仅用于概念化。

public class ControlAuthenticator
{
    Dictionary<string, ControlRule> ControlRules { get; set; } 
    public ControlAuthenticator()
    {
        ControlRules = new Dictionary<string, ControlRule>();
    }

    public bool UserCanRead(string controlName)
    {
        var user = MainViewModel.Current.CurrentUserPrincipal;

        return ControlRules[controlName].ReadPermission.Split(Convert.ToChar(","))
                                     .Intersect(user.GetGroups().Select(g => g.Name))
                                     .Any();
    }
}

public class ControlRule
{
    public string ControlName { get; set; }
    public string ReadPermission { get; set; }
    public string WritePermission { get; set; }
}

这个想法是,在您的 ViewModel 上,您调用提供控件名称的 userCanRead(或我没有创建的 write)方法。你得到一个布尔值。UserCanRead 方法检查 ReadPermission 属性中是否有与当前用户所属的组相关的条目(我认为它可能是一个逗号分隔的授权组字符串)。如果有任何相关性,则返回 true。

在您的 ViewModel 上,如果为 true,则显示值(或允许编辑),否则显示不同的值,或禁止任何编辑。

于 2013-04-16T21:19:31.773 回答