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


C# Principal.GetValueForProperty方法代码示例

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


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

示例1: LogonHoursToWinNTConverter

		private static void LogonHoursToWinNTConverter(Principal p, string propertyName, DirectoryEntry de, string suggestedWinNTProperty, bool isLSAM)
		{
			byte[] valueForProperty = (byte[])p.GetValueForProperty(propertyName);
			if (!p.unpersisted || valueForProperty != null)
			{
				if (valueForProperty == null || (int)valueForProperty.Length == 0)
				{
					byte[] numArray = new byte[] { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 };
					byte[] numArray1 = numArray;
					de.Properties[suggestedWinNTProperty].Value = numArray1;
					return;
				}
				else
				{
					de.Properties[suggestedWinNTProperty].Value = valueForProperty;
					return;
				}
			}
			else
			{
				return;
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:23,代码来源:SAMStoreCtx.cs

示例2: PushChangesToNative

		internal override object PushChangesToNative(Principal p)
		{
			string str;
			ArrayList value = null;
			object obj;
			try
			{
				DirectoryEntry underlyingObject = (DirectoryEntry)p.UnderlyingObject;
				Type type = p.GetType();
				if (underlyingObject == null)
				{
					if (type == typeof(UserPrincipal) || type.IsSubclassOf(typeof(UserPrincipal)))
					{
						str = "user";
					}
					else
					{
						if (type == typeof(GroupPrincipal) || type.IsSubclassOf(typeof(GroupPrincipal)))
						{
							str = "group";
						}
						else
						{
							object[] objArray = new object[1];
							objArray[0] = type.ToString();
							throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, StringResources.StoreCtxUnsupportedPrincipalTypeForSave, objArray));
						}
					}
					string samAccountName = this.GetSamAccountName(p);
					if (samAccountName != null)
					{
						lock (this.ctxBaseLock)
						{
							underlyingObject = this.ctxBase.Children.Add(samAccountName, str);
						}
						p.UnderlyingObject = underlyingObject;
						if (type.IsSubclassOf(typeof(AuthenticablePrincipal)))
						{
							this.InitializeUserAccountControl((AuthenticablePrincipal)p);
						}
					}
					else
					{
						throw new InvalidOperationException(StringResources.NameMustBeSetToPersistPrincipal);
					}
				}
				if (type != typeof(UserPrincipal))
				{
					if (type != typeof(GroupPrincipal))
					{
					}
					else
					{
					}
				}
				else
				{
				}
				foreach (DictionaryEntry dictionaryEntry in value)
				{
					value = (ArrayList)dictionaryEntry.Value;
					IEnumerator enumerator = value.GetEnumerator();
					try
					{
						while (enumerator.MoveNext())
						{
							SAMStoreCtx.PropertyMappingTableEntry propertyMappingTableEntry = (SAMStoreCtx.PropertyMappingTableEntry)dictionaryEntry;
							if (propertyMappingTableEntry.papiToWinNTConverter == null || !p.GetChangeStatusForProperty(propertyMappingTableEntry.propertyName))
							{
								continue;
							}
							propertyMappingTableEntry.papiToWinNTConverter(p, propertyMappingTableEntry.propertyName, underlyingObject, propertyMappingTableEntry.suggestedWinNTPropertyName, this.IsLSAM);
						}
					}
					finally
					{
						IDisposable disposable = enumerator as IDisposable;
						if (disposable != null)
						{
							disposable.Dispose();
						}
					}
				}
				if (p.GetChangeStatusForProperty("AuthenticablePrincipal.PasswordInfo.Password"))
				{
					string valueForProperty = (string)p.GetValueForProperty("AuthenticablePrincipal.PasswordInfo.Password");
					SDSUtils.SetPassword(underlyingObject, valueForProperty);
				}
				obj = underlyingObject;
			}
			catch (COMException cOMException1)
			{
				COMException cOMException = cOMException1;
				throw ExceptionHelper.GetExceptionFromCOMException(cOMException);
			}
			return obj;
		}
开发者ID:nickchal,项目名称:pash,代码行数:97,代码来源:SAMStoreCtx.cs

示例3: AcctExpirDateToNTConverter

        private static void AcctExpirDateToNTConverter(Principal p, string propertyName, DirectoryEntry de, string suggestedWinNTProperty, bool isLSAM)
        {
            Nullable<DateTime> value = (Nullable<DateTime>)p.GetValueForProperty(propertyName);

            if (p.unpersisted && value == null)
                return;

            // ADSI's WinNT provider uses 1/1/1970 to represent "never expires" when setting the property
            if (value.HasValue)
                de.Properties[suggestedWinNTProperty].Value = (DateTime)value;
            else
                de.Properties[suggestedWinNTProperty].Value = new DateTime(1970, 1, 1);
        }
开发者ID:chcosta,项目名称:corefx,代码行数:13,代码来源:SAMStoreCtx_LoadStore.cs

示例4: BinaryToLdapConverter

        protected static void BinaryToLdapConverter(Principal p, string propertyName, DirectoryEntry de, string suggestedAdProperty)
        {
            byte[] value = (byte[])p.GetValueForProperty(propertyName);

            if (p.unpersisted && value == null)
                return;

            if (value != null && value.Length != 0)
                de.Properties[suggestedAdProperty].Value = value;
            else
                de.Properties[suggestedAdProperty].Value = null;
        }
开发者ID:chcosta,项目名称:corefx,代码行数:12,代码来源:ADStoreCtx_LoadStore.cs

示例5: PushChangesToNative


//.........这里部分代码省略.........

                    // Determine the SAM account name for the entry we'll be creating.  Use the name from the NT4 IdentityClaim.
                    string samAccountName = GetSamAccountName(p);

                    if (samAccountName == null)
                    {
                        // They didn't set a NT4 IdentityClaim.
                        throw new InvalidOperationException(StringResources.NameMustBeSetToPersistPrincipal);
                    }

                    lock (_ctxBaseLock)
                    {
                        de = _ctxBase.Children.Add(samAccountName, objectClass);
                    }

                    GlobalDebug.WriteLineIf(
                        GlobalDebug.Info, "SAMStoreCtx", "PushChangesToNative: created fresh DE, oc={0}, name={1}, path={2}",
                        objectClass, samAccountName, de.Path);

                    p.UnderlyingObject = de;

                    // set the default user account control bits for authenticable principals
                    if (principalType.IsSubclassOf(typeof(AuthenticablePrincipal)))
                    {
                        InitializeUserAccountControl((AuthenticablePrincipal)p);
                    }
                }

                // Determine the mapping table to use, based on the principal type
                Hashtable propertyMappingTableByProperty;

                if (principalType == typeof(UserPrincipal))
                {
                    propertyMappingTableByProperty = s_userPropertyMappingTableByProperty;
                }
                else if (principalType == typeof(GroupPrincipal))
                {
                    propertyMappingTableByProperty = s_groupPropertyMappingTableByProperty;
                }
                else
                {
                    Debug.Assert(principalType == typeof(ComputerPrincipal));
                    propertyMappingTableByProperty = s_computerPropertyMappingTableByProperty;
                }

                // propertyMappingTableByProperty has entries for all writable properties,
                // including writable properties which we don't support in SAM for some or
                // all principal types.
                // If we don't support the property, the PropertyMappingTableEntry will map
                // it to a converter which will throw an appropriate exception.
                foreach (DictionaryEntry dictEntry in propertyMappingTableByProperty)
                {
                    ArrayList propertyEntries = (ArrayList)dictEntry.Value;

                    foreach (PropertyMappingTableEntry propertyEntry in propertyEntries)
                    {
                        if (null != propertyEntry.papiToWinNTConverter)
                        {
                            if (p.GetChangeStatusForProperty(propertyEntry.propertyName))
                            {
                                GlobalDebug.WriteLineIf(GlobalDebug.Info, "SAMStoreCtx", "PushChangesToNative: pushing {0}", propertyEntry.propertyName);

                                // The property was set.  Write it to the DirectoryEntry.
                                Debug.Assert(propertyEntry.propertyName == (string)dictEntry.Key);
                                propertyEntry.papiToWinNTConverter(
                                                    p,
                                                    propertyEntry.propertyName,
                                                    de,
                                                    propertyEntry.suggestedWinNTPropertyName,
                                                    this.IsLSAM
                                                    );
                            }
                        }
                    }
                }

                // Unlike AD, where password sets on newly-created principals must be handled after persisting the principal,
                // in SAM they get set before persisting the principal, and ADSI's WinNT provider saves off the operation
                // until the SetInfo() is performed.

                if (p.GetChangeStatusForProperty(PropertyNames.PwdInfoPassword))
                {
                    GlobalDebug.WriteLineIf(GlobalDebug.Info, "SAMStoreCtx", "PushChangesToNative: setting password");

                    // Only AuthenticablePrincipals can have PasswordInfo
                    Debug.Assert(p is AuthenticablePrincipal);

                    string password = (string)p.GetValueForProperty(PropertyNames.PwdInfoPassword);
                    Debug.Assert(password != null); // if null, PasswordInfo should not have indicated it was changed

                    SDSUtils.SetPassword(de, password);
                }

                return de;
            }
            catch (System.Runtime.InteropServices.COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(e);
            }
        }
开发者ID:chcosta,项目名称:corefx,代码行数:101,代码来源:SAMStoreCtx_LoadStore.cs

示例6: LogonHoursToWinNTConverter

        private static void LogonHoursToWinNTConverter(Principal p, string propertyName, DirectoryEntry de, string suggestedWinNTProperty, bool isLSAM)
        {
            Debug.Assert(propertyName == PropertyNames.AcctInfoPermittedLogonTimes);

            byte[] value = (byte[])p.GetValueForProperty(propertyName);

            if (p.unpersisted && value == null)
                return;

            if (value != null && value.Length != 0)
            {
                de.Properties[suggestedWinNTProperty].Value = value;
            }
            else
            {
                byte[] allHours = new byte[]{0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
                                             0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
                                             0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
                                             0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
                                             0xff};

                de.Properties[suggestedWinNTProperty].Value = allHours;
            }
        }
开发者ID:chcosta,项目名称:corefx,代码行数:24,代码来源:SAMStoreCtx_LoadStore.cs

示例7: ExtensionCacheToLdapConverter

        // Supported types
        // ICollection where an item of the collection is not an ICollection or IList
        // object[]
        // object
        protected static void ExtensionCacheToLdapConverter(Principal p, string propertyName, DirectoryEntry de, string suggestedAdProperty)
        {
            ExtensionCache cacheValues = (ExtensionCache)p.GetValueForProperty(propertyName);
            GlobalDebug.WriteLineIf(GlobalDebug.Info, "ADStoreCtx", "ExtensionCacheToLdapConverter");

            foreach (KeyValuePair<string, ExtensionCacheValue> kvp in cacheValues.properties)
            {
                if (!kvp.Value.Filter && null != kvp.Value.Value && kvp.Value.Value.Length != 0)
                {
                    // array of objects   ( .Length > 1 && typeof(array[0] != ICollection or IList )
                    // Single collection ( .Length == 1 ) &&  typeof(array[0] == ICollection ) && typeof(array[0][0] != ICollection or IList )

                    GlobalDebug.WriteLineIf(GlobalDebug.Info, "ADStoreCtx", "ExtensionCacheToLdapConverter - Value Type " + kvp.Value.Value.GetType().ToString());

                    if ((kvp.Value.Value.Length == 1 && kvp.Value.Value[0] is ICollection) || (kvp.Value.Value.Length > 1))
                    {
                        if (kvp.Value.Value.Length > 1 && (kvp.Value.Value[0] is ICollection))
                            throw new ArgumentException(StringResources.InvalidExtensionCollectionType);

                        GlobalDebug.WriteLineIf(GlobalDebug.Info, "ADStoreCtx", "ExtensionCacheToLdapConverter - Value implements ICollection");

                        ICollection valueCollection;

                        // byte[] gets special treatment (following S.DS and ADSI) - we don't treat it as ICollection but rather as a whole
                        if (kvp.Value.Value.Length == 1 && kvp.Value.Value[0] is ICollection && !(kvp.Value.Value[0] is byte[]))
                        {
                            valueCollection = (ICollection)kvp.Value.Value[0];
                        }
                        else
                        {
                            valueCollection = (ICollection)kvp.Value.Value;
                        }

                        foreach (object oVal in valueCollection)
                        {
                            if (null != oVal)
                            {
                                if ((oVal is ICollection || oVal is IList) && !(oVal is byte[]))
                                    throw new ArgumentException(StringResources.InvalidExtensionCollectionType);

                                GlobalDebug.WriteLineIf(GlobalDebug.Info, "ADStoreCtx", "ExtensionCacheToLdapConverter - Element Value Type " + oVal.GetType().ToString());
                                GlobalDebug.WriteLineIf(GlobalDebug.Info, "ADStoreCtx", "ExtensionCacheToLdapConverter - Adding  Element " + oVal.ToString());
                            }

                            // Do nothing if we are not persisted and the value is null.  We can't delete a property that
                            // has not already been set.
                            if (p.unpersisted && null == oVal)
                                continue;

                            de.Properties[kvp.Key].Add(oVal);
                        }
                        GlobalDebug.WriteLineIf(GlobalDebug.Info, "ADStoreCtx", "ExtensionCacheToLdapConverter - Collection complete");
                    }
                    else
                    {
                        GlobalDebug.WriteLineIf(GlobalDebug.Info, "ADStoreCtx", "ExtensionCacheToLdapConverter - Adding " + kvp.Value.Value.ToString());
                        // Do nothing if we are not persisted and the value is null.  We can't delete a property that
                        // has not already been set.
                        if (p.unpersisted && (null == kvp.Value.Value[0]))
                            continue;

                        de.Properties[kvp.Key].Value = kvp.Value.Value[0];
                    }
                }
            }
        }
开发者ID:chcosta,项目名称:corefx,代码行数:70,代码来源:ADStoreCtx_LoadStore.cs

示例8: AcctExpirDateToNTConverter

		private static void AcctExpirDateToNTConverter(Principal p, string propertyName, DirectoryEntry de, string suggestedWinNTProperty, bool isLSAM)
		{
			DateTime? valueForProperty = (DateTime?)p.GetValueForProperty(propertyName);
			if (!p.unpersisted || valueForProperty.HasValue)
			{
				if (!valueForProperty.HasValue)
				{
					de.Properties[suggestedWinNTProperty].Value = new DateTime(0x7b2, 1, 1);
					return;
				}
				else
				{
					de.Properties[suggestedWinNTProperty].Value = valueForProperty.Value;
					return;
				}
			}
			else
			{
				return;
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:21,代码来源:SAMStoreCtx.cs

示例9: CertToLdap

        protected static void CertToLdap(Principal p, string propertyName, DirectoryEntry de, string suggestedAdProperty)
        {
            X509Certificate2Collection certificates = (X509Certificate2Collection)p.GetValueForProperty(propertyName);

            if (certificates.Count == 0)
            {
                // Clear out the certificates
                de.Properties[suggestedAdProperty].Value = null;
            }
            else
            {
                // Replace the existing certs with the modified certs.  Note that this replaces all the certs ---
                // X509CertificateExCollection doesn't expose a finer-grained change-tracking mechanism
                byte[][] rawCerts = new byte[certificates.Count][];

                for (int i = 0; i < certificates.Count; i++)
                {
                    rawCerts[i] = certificates[i].RawData;
                }

                de.Properties[suggestedAdProperty].Value = null;        // remove the old
                de.Properties[suggestedAdProperty].Value = rawCerts;    // and put in the new
            }
        }
开发者ID:chcosta,项目名称:corefx,代码行数:24,代码来源:ADStoreCtx_LoadStore.cs

示例10: AcctExpirToLdapConverter

        protected static void AcctExpirToLdapConverter(Principal p, string propertyName, DirectoryEntry de, string suggestedAdProperty)
        {
            Nullable<DateTime> dt = (Nullable<DateTime>)p.GetValueForProperty(propertyName);

            if (p.unpersisted && dt == null)
                return;

            UnsafeNativeMethods.ADsLargeInteger largeIntObj = new UnsafeNativeMethods.ADsLargeInteger();
            UnsafeNativeMethods.IADsLargeInteger largeInt = (UnsafeNativeMethods.IADsLargeInteger)largeIntObj;

            if (!dt.HasValue)
            {
                // no expiration date
                largeInt.LowPart = unchecked((int)0xffffffff);
                largeInt.HighPart = (int)0x7fffffff;
            }
            else
            {
                Int64 filetime = ADUtils.DateTimeToADFileTime(dt.Value);

                uint lowPart = (uint)(((ulong)filetime) & ((ulong)0x00000000ffffffff));
                uint highPart = (uint)((((ulong)filetime) & ((ulong)0xffffffff00000000)) >> 32);

                largeInt.LowPart = (int)lowPart;
                largeInt.HighPart = (int)highPart;
            }

            de.Properties[suggestedAdProperty].Value = largeInt;
        }
开发者ID:chcosta,项目名称:corefx,代码行数:29,代码来源:ADStoreCtx_LoadStore.cs

示例11: CommaStringToLdapConverter

        protected static void CommaStringToLdapConverter(Principal p, string propertyName, DirectoryEntry de, string suggestedAdProperty)
        {
            PrincipalValueCollection<string> trackingList = (PrincipalValueCollection<string>)p.GetValueForProperty(propertyName);

            StringBuilder sb = new StringBuilder();

            foreach (string value in trackingList)
            {
                // Preexisting values that have not been removed.
                // This also includes inserted values.
                sb.Append(value);
                sb.Append(",");
            }

            // We have an extra comma at the end (assuming we added any values to the string).  Remove it.
            if (sb.Length > 0)
                sb.Remove(sb.Length - 1, 1);

            string s = (sb.Length > 0) ? sb.ToString() : null;

            if (p.unpersisted && s == null)
                return;

            de.Properties[suggestedAdProperty].Value = s;
        }
开发者ID:chcosta,项目名称:corefx,代码行数:25,代码来源:ADStoreCtx_LoadStore.cs

示例12: AcctDisabledToLdapConverter

 // This function is converting the disabled directory status into the enabled principal property
 // the boolan value needs to be negated
 protected static void AcctDisabledToLdapConverter(Principal p, string propertyName, DirectoryEntry de, string suggestedAdProperty)
 {
     // Only modify disabled property if we are talking to an already persisted user.
     // We need to set the password before we can enable the user on new objects.
     if (!p.unpersisted)
     {
         object value = (bool)p.GetValueForProperty(propertyName);
         if (value != null)
             de.Properties[suggestedAdProperty].Value = !(bool)value;
         else
             de.Properties[suggestedAdProperty].Value = null;
     }
 }
开发者ID:chcosta,项目名称:corefx,代码行数:15,代码来源:ADStoreCtx_LoadStore.cs

示例13: BoolToLdapConverter

        protected static void BoolToLdapConverter(Principal p, string propertyName, DirectoryEntry de, string suggestedAdProperty)
        {
            object value = (bool)p.GetValueForProperty(propertyName);

            if (p.unpersisted && value == null)
                return;

            if (value != null)
                de.Properties[suggestedAdProperty].Value = (bool)value;
            else
                de.Properties[suggestedAdProperty].Value = null;
        }
开发者ID:chcosta,项目名称:corefx,代码行数:12,代码来源:ADStoreCtx_LoadStore.cs

示例14: StringToWinNTConverter

		private static void StringToWinNTConverter(Principal p, string propertyName, DirectoryEntry de, string suggestedWinNTProperty, bool isLSAM)
		{
			string valueForProperty = (string)p.GetValueForProperty(propertyName);
			if (!p.unpersisted || valueForProperty != null)
			{
				if (valueForProperty == null || valueForProperty.Length <= 0)
				{
					de.Properties[suggestedWinNTProperty].Value = "";
					return;
				}
				else
				{
					de.Properties[suggestedWinNTProperty].Value = valueForProperty;
					return;
				}
			}
			else
			{
				return;
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:21,代码来源:SAMStoreCtx.cs

示例15: GroupTypeToLdapConverter

        protected static void GroupTypeToLdapConverter(Principal p, string propertyName, DirectoryEntry de, string suggestedAdProperty)
        {
            Debug.Assert(propertyName == PropertyNames.GroupIsSecurityGroup || propertyName == PropertyNames.GroupGroupScope);

            int groupTypeCombined;

            // We want to get the current value, so we can flip the appropriate bit while leaving the other bits as-is.
            // If this is a to-be-inserted Principal, we may not have an existing groupType, so we'll use AD's default value
            // for new groups.
            if (de.Properties[suggestedAdProperty].Count > 0)
            {
                Debug.Assert(de.Properties[suggestedAdProperty].Count == 1);

                groupTypeCombined = (int)de.Properties[suggestedAdProperty][0];
            }
            else
            {
                if (!p.unpersisted)
                {
                    // It's not an unpersisted principal, so we should have the property.  Perhaps we don't have access
                    // to it.  In that case, we don't want to blindly overwrite whatever other bits might be there.
                    throw new PrincipalOperationException(
                                    StringResources.ADStoreCtxUnableToReadExistingGroupTypeFlagsForUpdate);
                }

                // initial default value
                groupTypeCombined = unchecked((int)(0x80000000 | 0x00000002));  //  GROUP_TYPE_SECURITY_ENABLED | GROUP_TYPE_ACCOUNT_GROUP
            }

            switch (propertyName)
            {
                case PropertyNames.GroupIsSecurityGroup:
                    bool groupEnabled = (bool)p.GetValueForProperty(propertyName);

                    // Flip the bit without touching the other bits.
                    if (!groupEnabled)
                        Utils.ClearBit(ref groupTypeCombined, 0x80000000);   // disabled --> clear GROUP_TYPE_SECURITY_ENABLED
                    else
                        Utils.SetBit(ref groupTypeCombined, 0x80000000);     // enabled --> set GROUP_TYPE_SECURITY_ENABLED

                    break;

                case PropertyNames.GroupGroupScope:

                    GroupScope groupType = (GroupScope)p.GetValueForProperty(propertyName);

                    // Remove the bits indicating the group type it currently is...
                    Utils.ClearBit(ref groupTypeCombined, ADGroupScope.Local);
                    Utils.ClearBit(ref groupTypeCombined, ADGroupScope.Global);
                    Utils.ClearBit(ref groupTypeCombined, ADGroupScope.Universal);

                    // ...and set the bit for the group type we want it to be
                    if (groupType == GroupScope.Local)
                    {
                        Utils.SetBit(ref groupTypeCombined, ADGroupScope.Local);
                    }
                    else if (groupType == GroupScope.Global)
                    {
                        Utils.SetBit(ref groupTypeCombined, ADGroupScope.Global);
                    }
                    else
                    {
                        Debug.Assert(groupType == GroupScope.Universal);
                        Utils.SetBit(ref groupTypeCombined, ADGroupScope.Universal);
                    }

                    break;

                default:
                    Debug.Fail("ADStoreCtx.GroupTypeToLdapConverter: Fell off end looking for " + propertyName);
                    break;
            }

            de.Properties[suggestedAdProperty].Value = groupTypeCombined;
        }
开发者ID:chcosta,项目名称:corefx,代码行数:75,代码来源:ADStoreCtx_LoadStore.cs


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