本文整理汇总了C#中Principal.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Principal.GetType方法的具体用法?C# Principal.GetType怎么用?C# Principal.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Principal
的用法示例。
在下文中一共展示了Principal.GetType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PushChangesToNative
//
// Native <--> Principal
//
// For modified object, pushes any changes (including IdentityClaim changes)
// into the underlying store-specific object (e.g., DirectoryEntry) and returns the underlying object.
// For unpersisted object, creates a underlying object if one doesn't already exist (in
// Principal.UnderlyingObject), then pushes any changes into the underlying object.
internal override object PushChangesToNative(Principal p)
{
try
{
DirectoryEntry de = (DirectoryEntry)p.UnderlyingObject;
Type principalType = p.GetType();
GlobalDebug.WriteLineIf(GlobalDebug.Info, "SAMStoreCtx", "Entering PushChangesToNative, type={0}", p.GetType());
if (de == null)
{
// Must be a newly-inserted Principal for which PushChangesToNative has not yet
// been called.
// Determine the objectClass of the SAM entry we'll be creating
string objectClass;
if (principalType == typeof(UserPrincipal) || principalType.IsSubclassOf(typeof(UserPrincipal)))
objectClass = "user";
else if (principalType == typeof(GroupPrincipal) || principalType.IsSubclassOf(typeof(GroupPrincipal)))
objectClass = "group";
else
{
throw new InvalidOperationException(
String.Format(CultureInfo.CurrentCulture, StringResources.StoreCtxUnsupportedPrincipalTypeForSave, principalType.ToString()));
}
// 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,
//.........这里部分代码省略.........
示例2: ExceptionToWinNTConverter
//
// PAPI --> WinNT
//
private static void ExceptionToWinNTConverter(Principal p, string propertyName, DirectoryEntry de, string suggestedWinNTProperty, bool isLSAM)
{
throw new InvalidOperationException(
String.Format(CultureInfo.CurrentCulture,
StringResources.PrincipalUnsupportPropertyForType,
p.GetType().ToString(),
PropertyNamesExternal.GetExternalForm(propertyName)));
}
示例3: Load
internal override void Load(Principal p, string principalPropertyName)
{
Debug.Assert(p != null);
Debug.Assert(p.UnderlyingObject != null);
Debug.Assert(p.UnderlyingObject is DirectoryEntry);
DirectoryEntry de = (DirectoryEntry)p.UnderlyingObject;
Type principalType = p.GetType();
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;
}
ArrayList entries = (ArrayList)propertyMappingTableByProperty[principalPropertyName];
// We don't support this property and cannot load it. To maintain backward compatibility with the old code just return.
if (entries == null)
return;
try
{
foreach (PropertyMappingTableEntry entry in entries)
{
if (null != entry.winNTToPapiConverter)
{
GlobalDebug.WriteLineIf(GlobalDebug.Info, "SAMStoreCtx", "Load_PropertyName: loading {0}", entry.propertyName);
entry.winNTToPapiConverter(de, entry.suggestedWinNTPropertyName, p, entry.propertyName);
}
}
}
catch (System.Runtime.InteropServices.COMException e)
{
throw ExceptionHelper.GetExceptionFromCOMException(e);
}
}
示例4: 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;
}
示例5: IsValidProperty
internal override bool IsValidProperty(Principal p, string propertyName)
{
ObjectMask value = ObjectMask.None;
if (s_validPropertyMap.TryGetValue(propertyName, out value))
{
return ((s_maskMap[p.GetType()] & value) > 0 ? true : false);
}
else
{
Debug.Assert(false);
return false;
}
}
示例6: Load
internal override void Load(Principal p)
{
Hashtable hashtables;
ArrayList item = null;
try
{
DirectoryEntry underlyingObject = (DirectoryEntry)p.UnderlyingObject;
ICollection propertyNames = underlyingObject.Properties.PropertyNames;
Type type = p.GetType();
if (type != typeof(UserPrincipal))
{
if (type != typeof(GroupPrincipal))
{
hashtables = SAMStoreCtx.computerPropertyMappingTableByWinNT;
}
else
{
hashtables = SAMStoreCtx.groupPropertyMappingTableByWinNT;
}
}
else
{
hashtables = SAMStoreCtx.userPropertyMappingTableByWinNT;
}
foreach (string str in item)
{
item = (ArrayList)hashtables[str.ToLower(CultureInfo.InvariantCulture)];
if (item == null)
{
continue;
}
IEnumerator enumerator = item.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
SAMStoreCtx.PropertyMappingTableEntry propertyMappingTableEntry = (SAMStoreCtx.PropertyMappingTableEntry)str;
propertyMappingTableEntry.winNTToPapiConverter(underlyingObject, propertyMappingTableEntry.suggestedWinNTPropertyName, p, propertyMappingTableEntry.propertyName);
}
}
finally
{
IDisposable disposable = enumerator as IDisposable;
if (disposable != null)
{
disposable.Dispose();
}
}
}
}
catch (COMException cOMException1)
{
COMException cOMException = cOMException1;
throw ExceptionHelper.GetExceptionFromCOMException(cOMException);
}
}
示例7: IsValidProperty
internal override bool IsValidProperty(Principal p, string propertyName)
{
SAMStoreCtx.ObjectMask objectMask = SAMStoreCtx.ObjectMask.None;
if (!SAMStoreCtx.ValidPropertyMap.TryGetValue(propertyName, out objectMask))
{
return false;
}
else
{
if ((SAMStoreCtx.MaskMap[p.GetType()] & objectMask) > SAMStoreCtx.ObjectMask.None)
{
return true;
}
else
{
return false;
}
}
}
示例8: Load
// Loads the store values from p.UnderlyingObject into p, performing schema mapping as needed.
internal override void Load(Principal p)
{
Debug.Assert(p != null);
Debug.Assert(p.UnderlyingObject != null);
Debug.Assert(p.UnderlyingObject is DirectoryEntry);
DirectoryEntry de = (DirectoryEntry)p.UnderlyingObject;
Debug.Assert(de != null);
GlobalDebug.WriteLineIf(GlobalDebug.Info, "ADStoreCtx", "Entering Load, type={0}, path={1}", p.GetType(), de.Path);
Hashtable ldapMappingTable = (Hashtable)s_propertyMappingTableByLDAP[this.MappingTableIndex];
foreach (DictionaryEntry Dictentry in ldapMappingTable)
{
ArrayList entries = (ArrayList)Dictentry.Value;
try
{
foreach (PropertyMappingTableEntry entry in entries)
{
GlobalDebug.WriteLineIf(GlobalDebug.Info, "ADStoreCtx", "Load: loading {0}", entry.propertyName);
entry.ldapToPapiConverter(new dSPropertyCollection(de.Properties), entry.suggestedADPropertyName, p, entry.propertyName);
}
}
catch (System.Runtime.InteropServices.COMException e)
{
throw ExceptionHelper.GetExceptionFromCOMException(e);
}
}
p.Loaded = true;
}
示例9: PushChangesToNative
//
// Native <--> Principal
//
// For modified object, pushes any changes (including IdentityClaim changes)
// into the underlying store-specific object (e.g., DirectoryEntry) and returns the underlying object.
// For unpersisted object, creates a underlying object if one doesn't already exist (in
// Principal.UnderlyingObject), then pushes any changes into the underlying object.
internal override object PushChangesToNative(Principal p)
{
GlobalDebug.WriteLineIf(GlobalDebug.Info, "ADStoreCtx", "Entering PushChangesToNative, type={0}", p.GetType());
try
{
DirectoryEntry de = (DirectoryEntry)p.UnderlyingObject;
if (de == null)
{
// Must be a newly-inserted Principal for which PushChangesToNative has not yet
// been called.
// Determine the objectClass of the AD entry we'll be creating
string objectClass;
Type principalType = p.GetType();
// read the rdnPrefix off of the class attribute. This defaults to CN for the internal classes
string rdnPrefix = p.ExtensionHelper.RdnPrefix;
string rdnValue = null;
string baseObjectRdnPrefix = null;
if (principalType == typeof(UserPrincipal))
objectClass = "user";
else if (principalType == typeof(GroupPrincipal))
objectClass = "group";
else if (principalType == typeof(ComputerPrincipal))
objectClass = "computer";
else
{
objectClass = p.ExtensionHelper.StructuralObjectClass;
if (null == objectClass || null == rdnPrefix)
{
throw new InvalidOperationException(StringResources.ExtensionInvalidClassAttributes);
}
// We need to determine if this class is dervived from one of the base classes but has a different RdnPrefix
// For the base objects ( User, Computer and Group ) Their RDNPrefix is a required field along with the RDNPrefix for the
// derived object. This is only done for classes that derive from User, Computer or Group. If a user derives his own class from AuthPrincipal
// they are responsible for setting all required base class properties.
if (principalType.IsSubclassOf(typeof(GroupPrincipal)) ||
principalType.IsSubclassOf(typeof(UserPrincipal)) ||
principalType.IsSubclassOf(typeof(ComputerPrincipal)))
{
DirectoryRdnPrefixAttribute[] MyAttribute =
(DirectoryRdnPrefixAttribute[])Attribute.GetCustomAttributes(principalType.BaseType, typeof(DirectoryRdnPrefixAttribute), false);
if (MyAttribute == null)
throw new InvalidOperationException(StringResources.ExtensionInvalidClassAttributes);
string defaultRdn = null;
// Search for the rdn prefix. This will use either the prefix that has a context type
// that matches the principals context or the first rdnPrefix that has a null context type
for (int i = 0; i < MyAttribute.Length; i++)
{
if ((MyAttribute[i].Context == null && null == defaultRdn) ||
(p.ContextType == MyAttribute[i].Context))
{
defaultRdn = MyAttribute[i].RdnPrefix;
}
}
// If the base objects RDN prefix is not the same as the dervied class then we need to set both
if (defaultRdn != rdnPrefix)
{
baseObjectRdnPrefix = defaultRdn;
}
}
}
// Determine a RDN for the AD entry we'll be creating.
// In order, try:
// (1) The NAme is they set one.
// (2) The SAM account name if they set one
string rdn = null;
if (p.GetChangeStatusForProperty(PropertyNames.PrincipalName))
{
// They set a display name.
string name = (string)p.GetValueForProperty(PropertyNames.PrincipalName);
if ((name != null) && (name.Length > 0))
rdnValue = ADUtils.EscapeDNComponent(name);
}
if (rdnValue == null)
{
if (p.GetChangeStatusForProperty(PropertyNames.PrincipalSamAccountName))
{
// They set a sAMAccountName. If it's an invalid claim, we'll just ignore it here.
//.........这里部分代码省略.........