当前位置: 首页>>代码示例>>C#>>正文


C# Principal.SecurityIdentifier类代码示例

本文整理汇总了C#中System.Security.Principal.SecurityIdentifier的典型用法代码示例。如果您正苦于以下问题:C# SecurityIdentifier类的具体用法?C# SecurityIdentifier怎么用?C# SecurityIdentifier使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SecurityIdentifier类属于System.Security.Principal命名空间,在下文中一共展示了SecurityIdentifier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GlobalFileWritingSystemStore

		internal GlobalFileWritingSystemStore(string path)
		{
			m_path = path;
			if (!Directory.Exists(m_path))
			{
				DirectoryInfo di;

				// Provides FW on Linux multi-user access. Overrides the system
				// umask and creates the directory with the permissions "775".
				// The "fieldworks" group was created outside the app during
				// configuration of the package which allows group access.
				using(new FileModeOverride())
				{
					di = Directory.CreateDirectory(m_path);
				}

				if (!MiscUtils.IsUnix)
				{
					// NOTE: GetAccessControl/ModifyAccessRule/SetAccessControl is not implemented in Mono
					DirectorySecurity ds = di.GetAccessControl();
					var sid = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);
					AccessRule rule = new FileSystemAccessRule(sid, FileSystemRights.Write | FileSystemRights.ReadAndExecute
						| FileSystemRights.Modify, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
						PropagationFlags.InheritOnly, AccessControlType.Allow);
					bool modified;
					ds.ModifyAccessRule(AccessControlModification.Add, rule, out modified);
					di.SetAccessControl(ds);
				}
			}
			m_mutex = SingletonsContainer.Get(typeof(Mutex).FullName + m_path,
				() => new Mutex(false, m_path.Replace('\\', '_').Replace('/', '_')));
		}
开发者ID:bbriggs,项目名称:FieldWorks,代码行数:32,代码来源:GlobalFileWritingSystemStore.cs

示例2: TakeOwnership

 public static void TakeOwnership(string FD)
 {
     try
     {
         var myProcToken = new AccessTokenProcess(Process.GetCurrentProcess().Id, TokenAccessType.TOKEN_ALL_ACCESS | TokenAccessType.TOKEN_ADJUST_PRIVILEGES);
         myProcToken.EnablePrivilege(new Microsoft.Win32.Security.TokenPrivilege(Microsoft.Win32.Security.TokenPrivilege.SE_TAKE_OWNERSHIP_NAME, true));
         SecurityIdentifier identifier = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null);
         NTAccount identity = (NTAccount)identifier.Translate(typeof(NTAccount));
         if (File.Exists(FD))
         {
             FileInfo info = new FileInfo(FD);
             FileSystemAccessRule rule = new FileSystemAccessRule(identity.Value, FileSystemRights.FullControl, AccessControlType.Allow);
             FileSecurity accessControl = info.GetAccessControl(AccessControlSections.Owner);
             accessControl.SetOwner(new NTAccount(identity.Value));
             info.SetAccessControl(accessControl);
             accessControl.AddAccessRule(rule);
             info.SetAccessControl(accessControl);
         }
         if (Directory.Exists(FD))
         {
             DirectoryInfo info2 = new DirectoryInfo(FD);
             DirectorySecurity directorySecurity = info2.GetAccessControl(AccessControlSections.All);
             directorySecurity.SetOwner(identity);
             info2.SetAccessControl(directorySecurity);
             directorySecurity.AddAccessRule(new FileSystemAccessRule(identity, FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow));
             info2.SetAccessControl(directorySecurity);
         }
         Clear(FD);
     }
     catch (Exception)
     {
     }
 }
开发者ID:vascofo,项目名称:Windows-10-Login-Background-Changer,代码行数:33,代码来源:Class1.cs

示例3: ChangeGroupToEveryone

		public void ChangeGroupToEveryone ()
		{
			string keyName = @"SOFTWARE\Mono RegistrySecurityTest ChangeGroupToEveryone";

			RegistrySecurity security;
			if (PlatformID.Win32NT != Environment.OSVersion.Platform) {
				Assert.Ignore (); return;
			}

			try {
				using (RegistryKey key = Registry.CurrentUser.CreateSubKey (keyName)) {
					// Before we begin manipulating this, make sure we're in the right spot.
					Assert.AreEqual (key.Name, @"HKEY_CURRENT_USER\" + keyName);

					// Set the group to Everyone.
					SecurityIdentifier worldSid = new SecurityIdentifier ("WD");

					security = key.GetAccessControl ();
					security.SetGroup (worldSid);
					key.SetAccessControl (security);

					// Make sure it actually became Everyone.
					security = key.GetAccessControl ();
					Assert.AreEqual (worldSid, security.GetGroup (typeof(SecurityIdentifier)));
				}
			} finally {
				Registry.CurrentUser.DeleteSubKey (keyName);
			}
		}
开发者ID:GirlD,项目名称:mono,代码行数:29,代码来源:RegistrySecurityTest.cs

示例4: CheckUserRights

            public static bool CheckUserRights(string userLogin, string rightName)
            {
                string programName = WebConfigurationManager.AppSettings["progName"];
                bool flag = false;

                SqlParameter pProgramName = new SqlParameter() { ParameterName = "program_name", Value = programName, DbType = DbType.AnsiString };
                SqlParameter pRightName = new SqlParameter() { ParameterName = "sys_name", Value = rightName, DbType = DbType.AnsiString };

                DataTable dt = new DataTable();

                dt = ExecuteQueryStoredProcedure(sp, "getUserGroupSid", pProgramName, pRightName);

                if (dt.Rows.Count > 0)
                {
                    DataRow dr = dt.Rows[0];

                    string sid = dr["sid"].ToString();

                    try
                    {
                        WindowsIdentity wi = new WindowsIdentity(userLogin);
                        WindowsPrincipal wp = new WindowsPrincipal(wi);
                        SecurityIdentifier grpSid = new SecurityIdentifier(sid);

                        flag = wp.IsInRole(grpSid);
                    }
                    catch (Exception ex)
                    {
                        flag = false;
                    }
                }

                return flag;
            }
开发者ID:WakeDown,项目名称:ServicePlaning,代码行数:34,代码来源:Db.Users.cs

示例5: CommonAce

	// Constructor.
	public CommonAce(AceFlags flags, AceQualifier qualifier, int accessMask,
					 SecurityIdentifier sid, bool isCallback, byte[] opaque)
			: base(flags, (AceType)qualifier, accessMask,
			       sid, opaque, qualifier, isCallback)
			{
				// Nothing to do here.
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:8,代码来源:CommonAce.cs

示例6: SqlAzManSID

 /// <summary>
 /// Initializes a new instance of the <see cref="T:SqlAzManSID"/> class.
 /// </summary>
 /// <param name="sddlForm">The SDDL form.</param>
 /// <param name="customSid">if set to <c>true</c> [custom sid].</param>
 public SqlAzManSID(string sddlForm, bool customSid)
 {
     Regex isGuid = new Regex(@"^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$", RegexOptions.Compiled);
     if (customSid)
     {
         Guid g;
         if (sddlForm.StartsWith("S-1"))
         {
             this.securityIdentifier = new SecurityIdentifier(sddlForm);
         }
         else if (IsGuid(sddlForm, out g))
         {
             this.customSid = g.ToByteArray();
         }
         else
         {
             int discarded;
             this.customSid = NetSqlAzMan.Utilities.HexEncoding.GetBytes(sddlForm, out discarded);
         }
     }
     else
     {
         if (sddlForm.StartsWith("S-1"))
             this.securityIdentifier = new SecurityIdentifier(sddlForm);
         else
             guid = new Guid(sddlForm);
     }
 }
开发者ID:JamesTryand,项目名称:NetSqlAzMan,代码行数:33,代码来源:SqlAzManSID.cs

示例7: Execute

        public void Execute()
        {
            PrintHeader();

            var id = WindowsIdentity.GetCurrent();
            Console.WriteLine("Identity Id: " + id.Name);

            var account = new NTAccount(id.Name);
            var sid = account.Translate(typeof(SecurityIdentifier));
            Console.WriteLine("SecurityIdentifier (sid): " + sid.Value);

            foreach (var group in id.Groups.Translate(typeof(NTAccount)))
                Console.WriteLine("InGroup: " + group);

            var principal = new WindowsPrincipal(id);
            var localAdmins = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null);
            Console.WriteLine("IsInRole(localAdmin): " + principal.IsInRole(localAdmins));

            var domainAdmins = new SecurityIdentifier(WellKnownSidType.AccountDomainAdminsSid, id.User.AccountDomainSid);
            Console.WriteLine("IsInRole(domainAdmin): " + principal.IsInRole(domainAdmins));
            Console.WriteLine();

            // be aware for desktop/local accounts User Account Control (UAC from Vista) strips user of admin rights,
            // unless the process was run elevated "as Admin".
        }
开发者ID:stevenh77,项目名称:ClaimsBasedSecurityDemo,代码行数:25,代码来源:WindowsIdentityExample.cs

示例8: SecurityIdentifierExtensions_GetBinaryForm_Test1

 public void SecurityIdentifierExtensions_GetBinaryForm_Test1()
 {
     SecurityIdentifier sid = new SecurityIdentifier("S-1-5-21-3180365339-800773672-3767752645-500");
     byte[] binary = sid.GetBinaryForm();
     SecurityIdentifier sid2 = new SecurityIdentifier(binary, 0);
     Assert.AreEqual(sid, sid2);
 }
开发者ID:deimx42,项目名称:DSInternals,代码行数:7,代码来源:SecurityIdentifierExtensionsTester.cs

示例9: TestRemoveAudit

        private static bool TestRemoveAudit(SystemAcl systemAcl, RawAcl rawAcl, AuditFlags auditFlag, SecurityIdentifier sid, int accessMask, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, bool removePossible)
        {
            bool result = true;
            bool isRemoved = false;
            byte[] sAclBinaryForm = null;
            byte[] rAclBinaryForm = null;
            isRemoved = systemAcl.RemoveAudit(auditFlag, sid, accessMask, inheritanceFlags, propagationFlags);
            if ((isRemoved == removePossible) &&
                (systemAcl.Count == rawAcl.Count) &&
                (systemAcl.BinaryLength == rawAcl.BinaryLength))
            {
                sAclBinaryForm = new byte[systemAcl.BinaryLength];
                rAclBinaryForm = new byte[rawAcl.BinaryLength];
                systemAcl.GetBinaryForm(sAclBinaryForm, 0);
                rawAcl.GetBinaryForm(rAclBinaryForm, 0);

                if (!Utils.IsBinaryFormEqual(sAclBinaryForm, rAclBinaryForm))
                    result = false;
                //redundant index check
                for (int i = 0; i < systemAcl.Count; i++)
                {
                    if (!Utils.IsAceEqual(systemAcl[i], rawAcl[i]))
                    {
                        result = false;
                        break;
                    }
                }
            }
            else
                result = false;
            return result;
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:32,代码来源:SystemAcl_RemoveAudit.cs

示例10: GetLoginName

 // Gets the login name of the Livelink user that the specified SharePoint user maps to.
 public string GetLoginName(SPUser user) {
     if (user == null)
         throw new ArgumentNullException("user");
     // SPUser.LoginName contains domain\user for web applications with the pure Windows
     // authentication but if the claim-based authentication is used it returns an encoded
     // claim that must be decoded to the actual user login name first.
     var claim = SPClaimProviderManager.Local.ConvertSPUserToClaim(user);
     string login;
     if (SPClaimTypes.Equals(claim.ClaimType, SPClaimTypes.UserLogonName) ||
         SPClaimTypes.Equals(claim.ClaimType,
             "http://schemas.microsoft.com/sharepoint/2009/08/claims/processidentitylogonname")) {
         login = claim.Value;
     } else if (SPClaimTypes.Equals(claim.ClaimType, SPClaimTypes.UserIdentifier) ||
          SPClaimTypes.Equals(claim.ClaimType,
              "http://schemas.microsoft.com/sharepoint/2009/08/claims/processidentitysid") ||
          SPClaimTypes.Equals(claim.ClaimType,
              "http://schemas.microsoft.com/ws/2008/06/identity/claims/primarysid")) {
         var identifier = new SecurityIdentifier(claim.Value);
         login = identifier.Translate(typeof(NTAccount)).Value;
     } else {
         throw new ApplicationException(
             "No claim with either user name or SID was found to infer the login name from.");
     }
     // Here we assume either plain user name or a combination with the Windows domain.
     var parts = login.Split('\\');
     var name = parts.Length > 1 ? parts[1] : login;
     var domain = parts.Length > 1 ? parts[0] : "";
     return Pattern.ReplaceParameter("login", login).ReplaceParameter("user", name).
         ReplaceParameter("domain", domain);
 }
开发者ID:josefkgithub,项目名称:LivelinkSearchConnectorForSharePoint,代码行数:31,代码来源:LoginMapper.cs

示例11: FromBytes

 public void FromBytes(byte[] bytes)
 {
     using (var stream = new MemoryStream(bytes, false))
     using (var reader = new BinaryReader(stream))
     {
         Type = (WinBioIdentityType)reader.ReadInt32();
         switch (Type)
         {
             case WinBioIdentityType.Null:
                 Null = reader.ReadInt32();
                 break;
             case WinBioIdentityType.Wildcard:
                 Wildcard = reader.ReadInt32();
                 break;
             case WinBioIdentityType.GUID:
                 TemplateGuid = new Guid(reader.ReadBytes(16));
                 break;
             case WinBioIdentityType.SID:
                 AccountSidSize = reader.ReadInt32();
                 AccountSid = new SecurityIdentifier(reader.ReadBytes(AccountSidSize), 0);
                 break;
             default:
                 throw new ArgumentOutOfRangeException();
         }
     }
 }
开发者ID:JcBernack,项目名称:WinBioNET,代码行数:26,代码来源:WinBioIdentity.cs

示例12: SetUp

        protected override void SetUp()
        {
            MsmqUtil.Delete(InputQueueName);

            _handlerActivator = new BuiltinHandlerActivator();

            _bus = Configure.With(_handlerActivator)
                .Logging(l => l.Console())
                .Transport(t =>
                {
                    t.UseMsmq(InputQueueName)
                        .OnCreated(queue =>
                        {
                            queue.ResetPermissions();

                            var user = new SecurityIdentifier(WellKnownSidType.WorldSid, null)
                                .Translate(typeof(NTAccount))
                                .ToString();

                            queue.SetPermissions(user, MessageQueueAccessRights.FullControl);
                        });
                })
                .Routing(r => r.TypeBased().Map<string>(InputQueueName))
                .Options(o => o.SetNumberOfWorkers(1))
                .Start();

            Using(_bus);
        }
开发者ID:RichieYang,项目名称:Rebus,代码行数:28,代码来源:TestRequestReply.cs

示例13: GetUser

        public static void GetUser(SecurityIdentifier sid, StringBuilder sb, StringBuilder referencedDomainName, StringBuilder name)
        {
            try
            {
                if (sid == null)
                    return;
                sb.Append("; User=");
                referencedDomainName.Remove(0, referencedDomainName.Length);
                name.Remove(0, name.Length);

                var b = new byte[sid.BinaryLength];
                sid.GetBinaryForm(b, 0);
                var cchName = (uint)name.Capacity;
                var cchReferencedDomainName = (uint)referencedDomainName.Capacity;
                SidHelper.SidNameUse sidUse;
                if (SidHelper.LookupAccountSid(null, b, name, ref cchName, referencedDomainName,
                                               ref cchReferencedDomainName,
                                               out sidUse))
                {
                    if (referencedDomainName.Length > 0)
                        sb.Append(referencedDomainName).Append('\\');
                    sb.Append(name);
                    return;
                }
            }
            catch
            {
            }
            sb.Append(sid);
        }
开发者ID:salimci,项目名称:Legacy-Remote-Recorder,代码行数:30,代码来源:SsdlHelper.cs

示例14: GetSidFromClaim

      public static SecurityIdentifier GetSidFromClaim(string claimValue)
      {
         SecurityIdentifier sid = null;

         SPClaimProviderManager claimManager = SPClaimProviderManager.Local;
         if (claimManager == null)
         {
            throw new ApplicationException("Unable to access the claims provider manager.");
         }
         try
         {
            SPClaim claim = claimManager.DecodeClaim(claimValue);
            if (claim.OriginalIssuer.Equals("Windows", StringComparison.OrdinalIgnoreCase))
            {
               if (claim.ClaimType.Equals(Microsoft.IdentityModel.Claims.ClaimTypes.GroupSid, StringComparison.OrdinalIgnoreCase))
               {
                  sid = new SecurityIdentifier(claim.Value);
               }
               else if (claim.ClaimType.Equals(Microsoft.SharePoint.Administration.Claims.SPClaimTypes.UserLogonName, StringComparison.OrdinalIgnoreCase))
               {
                  NTAccount userAccount = new NTAccount(claim.Value);
                  sid = (SecurityIdentifier)userAccount.Translate(typeof(SecurityIdentifier));
               }
            }
         }
         catch (ArgumentException currentException)
         {
            GlymaSearchLogger.WriteTrace(LogCategoryId.Security, TraceSeverity.Unexpected, "The following exception occured when attempting to decode the claim, " + claimValue + " : " + currentException.ToString());
         }

         return sid;
      }
开发者ID:chris-tomich,项目名称:Glyma,代码行数:32,代码来源:GlymaSecurityManager.cs

示例15: FindSid

        public SidWrapper FindSid(string account)
        {
            SecurityIdentifier sid = null;
            try
            {
                // first, let's try this as a sid (SDDL) string
                sid = new SecurityIdentifier(account);

                return new SidWrapper { Sid = sid};
            }
            catch
            {
            }

            try
            {
                // maybe it's an account/group name
                var name = new NTAccount(account);
                sid = (SecurityIdentifier)name.Translate(typeof(SecurityIdentifier));
                if (sid != null)
                {
                    return new SidWrapper { Sid = sid };
                }
            }
            catch
            {
            }

            return null;
        }
开发者ID:ericschultz,项目名称:gui,代码行数:30,代码来源:WindowsUserService.cs


注:本文中的System.Security.Principal.SecurityIdentifier类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。