简体   繁体   English

将安全组添加到文件夹问题/ System.Security.Principal.IdentityNotMappedException:

[英]add security groups to folder issue / System.Security.Principal.IdentityNotMappedException:

I am struggling with strange issue and I wonder if some one can help me please. 我正在努力解决奇怪的问题,我想知道是否有人可以帮助我。 At some point of my program I like to add security groups with appropriate permissions to folder. 在我的程序的某些时候,我喜欢添加对文件夹具有适当权限的安全组。 Steps look like that. 步骤看起来像那样。

  1. Create Folder 创建文件夹
  2. Create Domain Local Security Group 创建域本地安全组
  3. Create Global Security group 创建全局安全组
  4. Add Global Group to local group 将全局组添加到本地组
  5. Add Domain Local security group to folder "\\domain\\dfs\\folder" 将域本地安全组添加到文件夹“\\ domain \\ dfs \\ folder”

I got below piece of code to do this from Microsoft page 我从Microsoft页面下面得到了一段代码

 public static void AddDirectorySecurity(string DirectoryName, string Group, FileSystemRights Rights, InheritanceFlags iFlag, PropagationFlags pFlag, AccessControlType ControlType)
{
    // Create a new DirectoryInfo object.
    DirectoryInfo dInfo = new DirectoryInfo(DirectoryName);

    // Get a DirectorySecurity object that represents the  
    // current security settings.
    DirectorySecurity dSecurity = dInfo.GetAccessControl();

    // Add the FileSystemAccessRule to the security settings. 
    dSecurity.AddAccessRule(new FileSystemAccessRule(Group,Rights,iFlag,pFlag,ControlType));

    // Set the new access settings.
    dInfo.SetAccessControl(dSecurity); // 

}

procedure of adding looks like that: 添加的过程看起来像这样:

path = @"\\domain\dfs\folder"

gRDL_RW = "RDL-group-RW"

    AddDirectorySecurity(path, gRDL_RW, FileSystemRights.Modify, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow);

It is working fine in my test environment but when I like to run it in production environment I am getting error: 它在我的测试环境中工作正常,但是当我想在生产环境中运行它时,我收到错误:

************** Exception Text **************
System.Security.Principal.IdentityNotMappedException: Some or all identity references could not be translated.
at System.Security.Principal.NTAccount.Translate(IdentityReferenceCollection sourceAccounts, Type targetType, Boolean forceSuccess)
at System.Security.Principal.NTAccount.Translate(Type targetType)
at System.Security.AccessControl.CommonObjectSecurity.ModifyAccess(AccessControlModification modification, AccessRule rule, Boolean& modified)
at System.Security.AccessControl.CommonObjectSecurity.AddAccessRule(AccessRule rule)
at Program_dev_1.Form1.button1_Click(Object sender, EventArgs e) in  c:\Users\?????????\Documents\Visual Studio 2012\Projects\brite_dev_1\brite_dev_1\Form1.cs:line 191
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Is it a problem with "Admin rights"? 这是“管理员权限”的问题吗? I have God like permissions in production environment. 我在生产环境中拥有上帝的权限。 So what is going on? 那么发生了什么?

I have feeling that for some reason all those user friendly names such as "FileSystemRights.Modify" can not be translated. 我觉得由于某种原因,所有那些用户友好的名称,如“FileSystemRights.Modify”无法翻译。 I check locale on test and prod environment and both are this same. 我在测试和prod环境中检查locale,两者都是一样的。

Is it possible to use raw numbers that are hiding behind those user friendly names? 是否可以使用隐藏在这些用户友好名称后面的原始数字?

Maybe there is a other way to add security groups to folder? 也许还有另一种方法可以将安全组添加到文件夹中? All I really like to have is a working solution. 我真正想拥有的只是一个有效的解决方案。

Application was crushing when groups were tried to be add to folder because newly created groups were not know to all domain controllers immediately. 当尝试将组添加到文件夹时,应用程序正在崩溃,因为新创建的组立即不知道所有域控制器。 I had to create procedure that check if newly create groups have been synchronized across whole estate before progressing with the rest of the code. 在进行其余代码之前,我必须创建一个过程来检查新创建的组是否已在整个属性中同步。 It is not possible or I could not find a method of specifying domain controller used when adding groups to folder permission. 在将文件夹权限添加到文件夹权限时,我无法找到指定域控制器的方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.Security.Principal.WindowsIdentity.GetCurrent()。Name在服务器上的问题 - System.Security.Principal.WindowsIdentity.GetCurrent().Name Issue on Server WindowsIdentity类未在System.Security.Principal命名空间中显示 - WindowsIdentity Class not shown in System.Security.Principal Namespace 如何在 .NET461 中填充 System.Security.Principal.WindowsIdentity? - How to Shim System.Security.Principal.WindowsIdentiy in .NET461? System.Security.SecurityException:请求主体权限失败 - System.Security.SecurityException: Request for principal permission failed 无法加载文件或程序集“System.Security.Principal.Windows” - Could not load file or assembly 'System.Security.Principal.Windows' 无法将类型“ CustomPrincipal”转换为“ System.Security.Principal.IPrincipal” - Cannot convert type 'CustomPrincipal' to 'System.Security.Principal.IPrincipal' 无法将类型为“ System.Security.Claims.ClaimsIdentity”的对象转换为类型为“ System.Security.Principal.WindowsIdentity”的对象 - Unable to cast object of type 'System.Security.Claims.ClaimsIdentity' to type 'System.Security.Principal.WindowsIdentity' 无法将类型为“System.Security.Principal.GenericIdentity”的对象强制转换为“System.Web.Security.FormsIdentity” - Unable to cast object of type 'System.Security.Principal.GenericIdentity' to type 'System.Web.Security.FormsIdentity' System.Security.Principal.WindowsIdentity的使用是否合理安全? - Is this use of System.Security.Principal.WindowsIdentity reasonably secure? Security.Principal和Security.Permissions示例 - Security.Principal and Security.Permissions Samples
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM