本文整理汇总了C#中System.Security.PermissionSet.ToXml方法的典型用法代码示例。如果您正苦于以下问题:C# PermissionSet.ToXml方法的具体用法?C# PermissionSet.ToXml怎么用?C# PermissionSet.ToXml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.PermissionSet
的用法示例。
在下文中一共展示了PermissionSet.ToXml方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PermissionStateUnrestricted
public void PermissionStateUnrestricted ()
{
PermissionSet ps = new PermissionSet (PermissionState.Unrestricted);
Assert ("PermissionStateUnrestricted.IsUnrestricted", ps.IsUnrestricted ());
Assert ("PermissionStateUnrestricted.IsEmpty", !ps.IsEmpty ());
Assert ("PermissionStateUnrestricted.IsReadOnly", !ps.IsReadOnly);
AssertEquals ("PermissionStateUnrestricted.ToXml().ToString()==ToString()", ps.ToXml ().ToString (), ps.ToString ());
}
示例2: PermissionStateUnrestricted
public void PermissionStateUnrestricted ()
{
PermissionSet ps = new PermissionSet (PermissionState.Unrestricted);
Assert.IsTrue (ps.IsUnrestricted (), "PermissionStateUnrestricted.IsUnrestricted");
Assert.IsTrue (!ps.IsEmpty (), "PermissionStateUnrestricted.IsEmpty");
Assert.IsTrue (!ps.IsReadOnly, "PermissionStateUnrestricted.IsReadOnly");
Assert.AreEqual (ps.ToXml ().ToString (), ps.ToString (), "PermissionStateUnrestricted.ToXml().ToString()==ToString()");
Assert.IsTrue (!ps.ContainsNonCodeAccessPermissions (), "ContainsNonCodeAccessPermissions");
}
示例3: PermissionSetNull
public void PermissionSetNull ()
{
// no exception is thrown
PermissionSet ps = new PermissionSet (null);
Assert.IsTrue (!ps.IsUnrestricted (), "PermissionStateNull.IsUnrestricted");
Assert.IsTrue (ps.IsEmpty (), "PermissionStateNull.IsEmpty");
Assert.IsTrue (!ps.IsReadOnly, "PermissionStateNull.IsReadOnly");
Assert.AreEqual (ps.ToXml ().ToString (), ps.ToString (), "PermissionStateNull.ToXml().ToString()==ToString()");
Assert.IsTrue (!ps.ContainsNonCodeAccessPermissions (), "ContainsNonCodeAccessPermissions");
}
示例4: PermissionSetNull
public void PermissionSetNull ()
{
// no exception is thrown
PermissionSet ps = new PermissionSet (null);
#if NET_2_0
Assert ("PermissionStateNull.IsUnrestricted", !ps.IsUnrestricted ());
Assert ("PermissionStateNull.IsEmpty", ps.IsEmpty ());
#else
Assert ("PermissionStateNull.IsUnrestricted", ps.IsUnrestricted ());
Assert ("PermissionStateNull.IsEmpty", !ps.IsEmpty ());
#endif
Assert ("PermissionStateNull.IsReadOnly", !ps.IsReadOnly);
AssertEquals ("PermissionStateNull.ToXml().ToString()==ToString()", ps.ToXml ().ToString (), ps.ToString ());
}
示例5: FromXmlEmpty
public void FromXmlEmpty ()
{
PermissionSet ps = new PermissionSet (PermissionState.None);
SecurityElement se = ps.ToXml ();
AssertNotNull ("Empty.ToXml()", se);
AssertEquals ("Empty.Count", 0, ps.Count);
PermissionSet ps2 = (PermissionSet) ps.Copy ();
ps2.FromXml (se);
Assert ("FromXml-Copy.IsUnrestricted", !ps2.IsUnrestricted ());
se.AddAttribute ("Unrestricted", "true");
ps2.FromXml (se);
Assert ("FromXml-Unrestricted.IsUnrestricted", ps2.IsUnrestricted ());
}
示例6: FromXmlEmpty
public void FromXmlEmpty ()
{
PermissionSet ps = new PermissionSet (PermissionState.None);
SecurityElement se = ps.ToXml ();
Assert.IsNotNull (se, "Empty.ToXml()");
Assert.AreEqual (0, ps.Count, "Empty.Count");
PermissionSet ps2 = (PermissionSet) ps.Copy ();
ps2.FromXml (se);
Assert.IsTrue (!ps2.IsUnrestricted () , "FromXml-Copy.IsUnrestricted");
se.AddAttribute ("Unrestricted", "true");
ps2.FromXml (se);
Assert.IsTrue (ps2.IsUnrestricted (), "FromXml-Unrestricted.IsUnrestricted");
}
示例7: FromXmlInvalidPermission
public void FromXmlInvalidPermission ()
{
PermissionSet ps = new PermissionSet (PermissionState.None);
SecurityElement se = ps.ToXml ();
// can't modify - so we create our own
SecurityElement se2 = new SecurityElement ("InvalidPermissionSet", se.Text);
se2.AddAttribute ("class", se.Attribute ("class"));
se2.AddAttribute ("version", se.Attribute ("version"));
ps.FromXml (se2);
}
示例8: AddPermissionRequests
internal void AddPermissionRequests (PermissionSet required, PermissionSet optional, PermissionSet refused)
{
#if !NET_2_1
if (created)
throw new InvalidOperationException ("Assembly was already saved.");
// required for base Assembly class (so the permissions
// can be used even if the assembly isn't saved to disk)
_minimum = required;
_optional = optional;
_refuse = refused;
// required to reuse AddDeclarativeSecurity support
// already present in the runtime
if (required != null) {
permissions_minimum = new RefEmitPermissionSet [1];
permissions_minimum [0] = new RefEmitPermissionSet (
SecurityAction.RequestMinimum, required.ToXml ().ToString ());
}
if (optional != null) {
permissions_optional = new RefEmitPermissionSet [1];
permissions_optional [0] = new RefEmitPermissionSet (
SecurityAction.RequestOptional, optional.ToXml ().ToString ());
}
if (refused != null) {
permissions_refused = new RefEmitPermissionSet [1];
permissions_refused [0] = new RefEmitPermissionSet (
SecurityAction.RequestRefuse, refused.ToXml ().ToString ());
}
#endif
}
示例9: SecurityException
[System.Security.SecuritySafeCritical] // auto-generated
public SecurityException(string message, AssemblyName assemblyName, PermissionSet grant, PermissionSet refused, MethodInfo method, SecurityAction action, Object demanded, IPermission permThatFailed, Evidence evidence)
: base(message)
{
PermissionSet.s_fullTrust.Assert();
SetErrorCode(System.__HResults.COR_E_SECURITY);
Action = action;
if(permThatFailed != null)
m_typeOfPermissionThatFailed = permThatFailed.GetType();
FirstPermissionThatFailed = permThatFailed;
Demanded = demanded;
m_granted = (grant == null ? "" : grant.ToXml().ToString());
m_refused = (refused == null ? "" : refused.ToXml().ToString());
m_denied = "";
m_permitOnly = "";
m_assemblyName = assemblyName;
Method = method;
m_url = "";
m_zone = SecurityZone.NoZone;
if(evidence != null)
{
Url url = evidence.GetHostEvidence<Url>();
if(url != null)
m_url = url.GetURLString().ToString();
Zone zone = evidence.GetHostEvidence<Zone>();
if(zone != null)
m_zone = zone.SecurityZone;
}
m_debugString = this.ToString(true, false);
}
示例10: CheckHelper
[System.Security.SecurityCritical] // auto-generated
#pragma warning disable 618
internal static bool CheckHelper(PermissionSet grantedSet,
#pragma warning restore 618
PermissionSet refusedSet,
CodeAccessPermission demand,
PermissionToken permToken,
RuntimeMethodHandleInternal rmh,
Object assemblyOrString,
SecurityAction action,
bool throwException)
{
// We should never get here with a null demand
Contract.Assert(demand != null, "Should not reach here with a null demand");
#if _DEBUG && FEATURE_CAS_POLICY
if (debug)
{
DEBUG_OUT("Granted: ");
DEBUG_OUT(grantedSet.ToXml().ToString());
DEBUG_OUT("Refused: ");
DEBUG_OUT(refusedSet != null ? refusedSet.ToXml().ToString() : "<null>");
DEBUG_OUT("Demanded: ");
DEBUG_OUT(demand.ToString());
}
#endif // _DEBUG && FEATURE_CAS_POLICY
if (permToken == null)
permToken = PermissionToken.GetToken(demand);
if (grantedSet != null)
grantedSet.CheckDecoded(permToken.m_index);
if (refusedSet != null)
refusedSet.CheckDecoded(permToken.m_index);
// If PermissionSet is null, then module does not have Permissions... Fail check.
bool bThreadSecurity = SecurityManager._SetThreadSecurity(false);
try
{
if (grantedSet == null)
{
if (throwException)
ThrowSecurityException(assemblyOrString, grantedSet, refusedSet, rmh, action, demand, demand);
else
return false;
}
else if (!grantedSet.IsUnrestricted())
{
// If we aren't unrestricted, there is a refused set, or our permission is not of the unrestricted
// variety, we need to do the proper callback.
Contract.Assert(demand != null,"demand != null");
// Find the permission of matching type in the permission set.
CodeAccessPermission grantedPerm =
(CodeAccessPermission)grantedSet.GetPermission(permToken);
// Make sure the demand has been granted
if (!demand.CheckDemand( grantedPerm ))
{
if (throwException)
ThrowSecurityException(assemblyOrString, grantedSet, refusedSet, rmh, action, demand, demand);
else
return false;
}
}
// Make the sure the permission is not refused.
if (refusedSet != null)
{
CodeAccessPermission refusedPerm =
(CodeAccessPermission)refusedSet.GetPermission(permToken);
if (refusedPerm != null)
{
if (!refusedPerm.CheckDeny(demand))
{
#if _DEBUG
if (debug)
DEBUG_OUT( "Permission found in refused set" );
#endif
if (throwException)
ThrowSecurityException(assemblyOrString, grantedSet, refusedSet, rmh, action, demand, demand);
else
return false;
}
}
if (refusedSet.IsUnrestricted())
{
if (throwException)
ThrowSecurityException(assemblyOrString, grantedSet, refusedSet, rmh, action, demand, demand);
else
return false;
}
//.........这里部分代码省略.........
示例11: ConvertPermissionSet
ConvertPermissionSet(String inFormat,
byte[] inData,
String outFormat)
{
if(inData == null)
return null;
if(inFormat == null)
throw new ArgumentNullException("inFormat");
if(outFormat == null)
throw new ArgumentNullException("outFormat");
PermissionSet permSet = new PermissionSet( false );
inFormat = String.SmallCharToUpper(inFormat);
outFormat = String.SmallCharToUpper(outFormat);
if (inFormat.Equals( "XMLASCII" ) || inFormat.Equals( "XML" ))
{
permSet.FromXml( new Parser( inData, Tokenizer.ByteTokenEncoding.ByteTokens ).GetTopElement() );
}
else if (inFormat.Equals( "XMLUNICODE" ))
{
permSet.FromXml( new Parser( inData, Tokenizer.ByteTokenEncoding.UnicodeTokens ).GetTopElement() );
}
else if (inFormat.Equals( "BINARY" ))
{
permSet.DecodeUsingSerialization( inData );
}
else
{
return null;
}
if (outFormat.Equals( "XMLASCII" ) || outFormat.Equals( "XML" ))
{
MemoryStream ms = new MemoryStream();
StreamWriter writer = new StreamWriter( ms, Encoding.ASCII );
writer.Write( permSet.ToXml().ToString() );
writer.Flush();
return ms.ToArray();
}
else if (outFormat.Equals( "XMLUNICODE" ))
{
MemoryStream ms = new MemoryStream();
StreamWriter writer = new StreamWriter( ms, Encoding.Unicode );
writer.Write( permSet.ToXml().ToString() );
writer.Flush();
ms.Position = 2;
int countBytes = (int)ms.Length - 2;
byte[] retval = new byte[countBytes];
ms.Read( retval, 0, retval.Length );
return retval;
}
else if (outFormat.Equals( "BINARY" ))
{
return permSet.EncodeUsingSerialization();
}
else
{
return null;
}
}
示例12: RemoveNonReferencedPermissions
private static PermissionSet RemoveNonReferencedPermissions(string[] setToFilter, ITaskItem[] dependencies)
{
PermissionSet set = new PermissionSet(PermissionState.None);
if (((dependencies == null) || (setToFilter == null)) || (setToFilter.Length == 0))
{
return set;
}
List<string> list = new List<string>();
foreach (ITaskItem item in dependencies)
{
AssemblyName assemblyName = AssemblyName.GetAssemblyName(item.ItemSpec);
list.Add(assemblyName.Name + ", " + assemblyName.Version.ToString());
}
SecurityElement permissionSetXml = set.ToXml();
foreach (string str in setToFilter)
{
string str2;
string str3;
string str4;
if ((!string.IsNullOrEmpty(str) && ParseElementForAssemblyIdentification(SecurityElement.FromString(str), out str3, out str2, out str4)) && list.Contains(str2 + ", " + str4))
{
permissionSetXml.AddChild(SecurityElement.FromString(str));
}
}
return new ReadOnlyPermissionSet(permissionSetXml);
}
示例13: ToXmlUnrestricted
public void ToXmlUnrestricted ()
{
PermissionSet ps = new PermissionSet (PermissionState.Unrestricted);
SecurityElement se = ps.ToXml ();
Assert ("Unrestricted.ToString().StartsWith", ps.ToString().StartsWith ("<PermissionSet"));
AssertEquals ("Unrestricted.class", "System.Security.PermissionSet", (se.Attributes ["class"] as string));
AssertEquals ("Unrestricted.version", "1", (se.Attributes ["version"] as string));
AssertEquals ("Unrestricted.Unrestricted", "true", (se.Attributes ["Unrestricted"] as string));
}
示例14: PermissionSetPermissionSet
public void PermissionSetPermissionSet ()
{
FileDialogPermission fdp = new FileDialogPermission (FileDialogPermissionAccess.Open);
PermissionSet ps1 = new PermissionSet (PermissionState.None);
ps1.AddPermission (fdp);
Assert ("ps1.IsEmpty", !ps1.IsEmpty ());
PermissionSet ps = new PermissionSet (ps1);
Assert ("PermissionSetPermissionSet.IsUnrestricted", !ps.IsUnrestricted ());
Assert ("PermissionSetPermissionSet.IsEmpty", !ps.IsEmpty ());
Assert ("PermissionSetPermissionSet.IsReadOnly", !ps.IsReadOnly);
AssertEquals ("PermissionSetPermissionSet.ToXml().ToString()==ToString()", ps.ToXml ().ToString (), ps.ToString ());
}
示例15: RemoveNonReferencedPermissions
private static PermissionSet RemoveNonReferencedPermissions(string[] setToFilter, ITaskItem[] dependencies)
{
PermissionSet retSet = new PermissionSet(PermissionState.None);
if (dependencies == null || setToFilter == null || setToFilter.Length == 0)
return retSet;
List<string> assemblyNameList = new List<string>();
foreach (ITaskItem dependency in dependencies)
{
AssemblyName dependentAssemblyName = AssemblyName.GetAssemblyName(dependency.ItemSpec);
assemblyNameList.Add(dependentAssemblyName.Name + ", " + dependentAssemblyName.Version.ToString());
}
SecurityElement retSetElement = retSet.ToXml();
foreach (string permissionXml in setToFilter)
{
if (!String.IsNullOrEmpty(permissionXml))
{
string permissionAssemblyName;
string className;
string assemblyVersion;
SecurityElement permission = SecurityElement.FromString(permissionXml);
if (!ParseElementForAssemblyIdentification(permission, out className, out permissionAssemblyName, out assemblyVersion))
continue;
if (assemblyNameList.Contains(permissionAssemblyName + ", " + assemblyVersion))
{
retSetElement.AddChild(SecurityElement.FromString(permissionXml));
}
}
}
retSet = new ReadOnlyPermissionSet(retSetElement);
return retSet;
}