【发布时间】:2013-11-20 21:55:54
【问题描述】:
我查看了this question 并使用 WMI 界面创建了一个存储库并为用户添加了权限。我现在遇到的问题是:如果我尝试更新我创建的存储库并将 another 用户添加到存储库,它会清除当前使用(将其完全从存储库中删除)和只添加一个人。
所以,我需要弄清楚如何做两件事:
- 将用户添加到现有存储库
- 从现有存储库中删除用户
我想一旦我有了它,我就能弄清楚我的其余互动。我参考了 wof 文件并找到了我认为我需要实现的这些条目:
类 VisualSVN_Repository
[provider("VisualSVNWMIProvider"), dynamic]
class VisualSVN_Repository
{
[Description ("Repository name"), key]
string Name;
...
[implemented] void GetSecurity([in] string Path,
[out] VisualSVN_PermissionEntry Permissions[]);
[implemented] void SetSecurity([in] string Path,
[in] VisualSVN_PermissionEntry Permissions[],
[in] boolean ResetChildren = false);
}
我正在像这样实现集合安全性:
static public void UpdatePermissions(string sid, string repository, AccessLevel level, bool isAdmin = false)
{
ManagementClass repoClass = new ManagementClass("root\\VisualSVN", "VisualSVN_Repository", null);
ManagementObject repoObject = repoClass.CreateInstance();
repoObject.SetPropertyValue("Name", repository);
ManagementBaseObject inParams =
repoClass.GetMethodParameters("SetSecurity");
inParams["Path"] = "/";
inParams["Permissions"] = new object[] { permObject };
ManagementBaseObject outParams =
repoObject.InvokeMethod("SetSecurity", inParams, null);
}
这可行,但就像我说的那样,仅适用于一个用户。似乎它清除了那里的任何东西,只添加了一个用户对象。
我认为我需要与之交互的另一种方法是“GetSecurity”,它看起来返回一个 VisualSVN_PermissionEntry 数组
VisualSVN_PermissionEntry
class VisualSVN_PermissionEntry
{
VisualSVN_Account Account;
uint32 AccessLevel;
};
所以这个有一个 AccessLevel 属性和 VisualSVN_Account 对象
VisualSVN_Account(我使用的是 Windows 身份验证,所以我需要使用那个)
[provider("VisualSVNWMIProvider"), dynamic, abstract]
class VisualSVN_Account
{
};
class VisualSVN_WindowsAccount : VisualSVN_Account
{
[key] string SID;
};
所以这就是我迷路的地方。我假设我需要调用“GetSecurity”,然后遍历这些结果并将它们添加到“SetSecurity”输入参数的对象数组中。我似乎无法让它发挥作用。我玩过一些伪代码,但遇到各种错误(主要是对象引用错误):
ManagementBaseObject inSecParams=
repoClass.GetMethodParameters("GetSecurity");
inSecParams["Path"] = "/";
ManagementBaseObject existingPerms =
repoObject.InvokeMethod("GetSecurity");
//now I need to loop through the array existingPerms and add them to an array of VisualSVN_PermissionEntry object.
--or--
//can I take this result and just add the users I need to add to it somehow.
【问题讨论】:
-
您可以使用 PowerShell cmdlet(适用于 VisualSVN Server 3.4 及更高版本)管理权限:visualsvn.com/support/topic/00088
标签: c# svn wmi visualsvn-server