public void ToXml() { HashMembershipCondition hash = new HashMembershipCondition(md5, digestMd5); SecurityElement se = hash.ToXml(); Assert.AreEqual("IMembershipCondition", se.Tag, "Tag"); Assert.IsTrue(se.Attribute("class").StartsWith("System.Security.Policy.HashMembershipCondition"), "class"); Assert.AreEqual("1", se.Attribute("version"), "version"); Assert.AreEqual(se.ToString(), hash.ToXml(null).ToString(), "ToXml(null)"); Assert.AreEqual(se.ToString(), hash.ToXml(PolicyLevel.CreateAppDomainLevel()).ToString(), "ToXml(PolicyLevel)"); }
public void ToXml() { DomainApplicationMembershipCondition domapp = new DomainApplicationMembershipCondition(); SecurityElement se = domapp.ToXml(); Assert.AreEqual("IMembershipCondition", se.Tag, "Tag"); Assert.IsTrue(se.Attribute("class").StartsWith("System.Security.Policy.DomainApplicationMembershipCondition"), "class"); Assert.AreEqual("1", se.Attribute("version"), "version"); Assert.AreEqual(se.ToString(), domapp.ToXml(null).ToString(), "ToXml(null)"); Assert.AreEqual(se.ToString(), domapp.ToXml(PolicyLevel.CreateAppDomainLevel()).ToString(), "ToXml(PolicyLevel)"); }
public void NameRole() { const string userName = "******"; const string roleName = "ThisIsARoleName"; PrincipalPermission p = new PrincipalPermission(userName, roleName); Assert.True(!p.IsUnrestricted()); SecurityElement pele = (SecurityElement)(p.ToXml().Children[0]); Assert.Contains(userName, pele.ToString()); Assert.Contains(roleName, pele.ToString()); }
public void ToXml () { MyCodeGroup cg = new MyCodeGroup (new AllMembershipCondition (), new PolicyStatement(new PermissionSet (PermissionState.None))); SecurityElement se = cg.ToXml (); string s = se.ToString (); Assert.IsTrue (s.StartsWith ("<CodeGroup class=\"MonoTests.System.Security.Policy.MyCodeGroup,"), "ToXml-Starts"); Assert.IsTrue (s.EndsWith ("version=\"1\"/>" + Environment.NewLine + "</CodeGroup>" + Environment.NewLine), "ToXml-Ends"); cg.AddChild (new MyCodeGroup (new AllMembershipCondition (), new PolicyStatement(new PermissionSet (PermissionState.Unrestricted)))); se = cg.ToXml (); s = se.ToString (); Assert.IsTrue (s.IndexOf ("<CodeGroup class=\"MonoTests.System.Security.Policy.MyCodeGroup,", 1) > 0, "ToXml-Child"); }
// Convert this object into a string. public override String ToString() { SecurityElement element = new SecurityElement ("System.Security.Policy.PermissionRequestEvidence"); SecurityElement child; element.AddAttribute("version", "1"); if (request != null) { child = new SecurityElement("Request"); child.AddChild(request.ToXml()); element.AddChild(child); } if (optional != null) { child = new SecurityElement("Optional"); child.AddChild(optional.ToXml()); element.AddChild(child); } if (denied != null) { child = new SecurityElement("Denied"); child.AddChild(denied.ToXml()); element.AddChild(child); } return(element.ToString()); }
/// <summary>Gets a string representation of the state of the <see cref="T:System.Security.Policy.PermissionRequestEvidence" />.</summary> /// <returns>A representation of the state of the <see cref="T:System.Security.Policy.PermissionRequestEvidence" />.</returns> /// <PermissionSet> /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" /> /// </PermissionSet> public override string ToString() { SecurityElement securityElement = new SecurityElement("System.Security.Policy.PermissionRequestEvidence"); securityElement.AddAttribute("version", "1"); if (this.requested != null) { SecurityElement securityElement2 = new SecurityElement("Request"); securityElement2.AddChild(this.requested.ToXml()); securityElement.AddChild(securityElement2); } if (this.optional != null) { SecurityElement securityElement3 = new SecurityElement("Optional"); securityElement3.AddChild(this.optional.ToXml()); securityElement.AddChild(securityElement3); } if (this.denied != null) { SecurityElement securityElement4 = new SecurityElement("Denied"); securityElement4.AddChild(this.denied.ToXml()); securityElement.AddChild(securityElement4); } return(securityElement.ToString()); }
// If a domain attribute is not found in the specified // FirstMatchCodeGroup, add a child XML element identifying a custom // membership condition. private static void addXmlMember(ref FirstMatchCodeGroup codeGroup) { //<Snippet10> SecurityElement xmlElement = codeGroup.ToXml(); //</Snippet10> SecurityElement rootElement = new SecurityElement("CodeGroup"); if (xmlElement.Attribute("domain") == null) { //<Snippet11> SecurityElement newElement = new SecurityElement("CustomMembershipCondition"); newElement.AddAttribute("class", "CustomMembershipCondition"); newElement.AddAttribute("version", "1"); newElement.AddAttribute("domain", "contoso.com"); rootElement.AddChild(newElement); codeGroup.FromXml(rootElement); //</Snippet11> } Console.WriteLine("Added a custom membership condition:"); Console.WriteLine(rootElement.ToString()); }
private ZoneMembershipCondition BasicTest(SecurityZone zone) { ZoneMembershipCondition zmc = new ZoneMembershipCondition(zone); Assert.AreEqual(zone, zmc.SecurityZone, "SecurityZone"); Assert.IsFalse(zmc.Check(null), "Check(null)"); Assert.IsFalse(zmc.Check(allEmpty), "Check(empty)"); Assert.IsFalse(zmc.Check(hostOther), "Check(hostOther)"); Assert.IsFalse(zmc.Check(assemblyOther), "Check(assemblyOther)"); ZoneMembershipCondition copy = (ZoneMembershipCondition)zmc.Copy(); Assert.IsTrue(zmc.Equals(copy), "Equals-1"); Assert.IsTrue(copy.Equals(zmc), "Equals-2"); Assert.IsFalse(Object.ReferenceEquals(zmc, copy), "!ReferenceEquals"); Assert.IsFalse(zmc.Equals(null), "Equals-3"); Assert.IsFalse(zmc.Equals(wrongEvidence), "Equals-4"); SecurityElement se = zmc.ToXml(); copy.FromXml(se); Assert.IsTrue(zmc.Equals(copy), "Equals-5"); Assert.AreEqual(se.ToString(), zmc.ToXml(null).ToString(), "Equals-6"); Assert.IsTrue(zmc.ToString().StartsWith("Zone - "), "ToString-1"); Assert.IsTrue(zmc.ToString().EndsWith(zmc.SecurityZone.ToString()), "ToString-2"); #if NET_2_0 Assert.AreEqual(zmc.SecurityZone.GetHashCode(), zmc.GetHashCode(), "GetHashCode"); #endif return(zmc); // for further tests }
public static bool SaveXml(string filepath, SecurityElement root) { if (string.IsNullOrEmpty(filepath) || root == null) { return(false); } if (File.Exists(filepath)) { File.Delete(filepath); } var stream = File.Open(filepath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write); if (stream != null) { StreamWriter writer = new StreamWriter(stream); if (writer != null) { writer.Write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"); writer.Write(root.ToString()); writer.Flush(); writer.Close(); } stream.Dispose(); stream.Close(); } return(true); }
public override string ToString() { SecurityElement se = new SecurityElement("System.Security.Policy.PermissionRequestEvidence"); se.AddAttribute("version", "1"); if (requested != null) { SecurityElement requestElement = new SecurityElement("Request"); requestElement.AddChild(requested.ToXml()); se.AddChild(requestElement); } if (optional != null) { SecurityElement optionalElement = new SecurityElement("Optional"); optionalElement.AddChild(optional.ToXml()); se.AddChild(optionalElement); } if (denied != null) { SecurityElement deniedElement = new SecurityElement("Denied"); deniedElement.AddChild(denied.ToXml()); se.AddChild(deniedElement); } return(se.ToString()); }
public override string ToString() { SecurityElement se = new SecurityElement(GetType().FullName); se.AddAttribute("version", "1"); return(se.ToString()); }
private static void SaveXML(object config, string path) { SecurityElement element = new SecurityElement("root"); element.AddChild(new SecurityElement("record")); SecurityElement element2 = element.Children[0] as SecurityElement; PropertyInfo[] properties = config.GetType().GetProperties(); foreach (PropertyInfo info in properties) { if (info.Name.Contains("GuideTimes")) { object obj2 = info.GetGetMethod().Invoke(config, null); string text = ""; foreach (KeyValuePair <ulong, string> pair in obj2 as Dictionary <ulong, string> ) { text = text + pair.Key.ToString() + ":" + pair.Value + ","; } element2.AddChild(new SecurityElement(info.Name, text)); } else { object obj3 = info.GetGetMethod().Invoke(config, null); element2.AddChild(new SecurityElement(info.Name, obj3.ToString())); } } XMLParser.SaveText(path, element.ToString()); }
private static void SaveXMLList <T>(string path, List <T> data, string attrName = "record") { SecurityElement element = new SecurityElement("root"); int num = 0; PropertyInfo[] properties = typeof(T).GetProperties(); foreach (T local in data) { SecurityElement child = new SecurityElement(attrName); foreach (PropertyInfo info in properties) { Type propertyType = info.PropertyType; string text = string.Empty; object obj2 = info.GetGetMethod().Invoke(local, null); if (propertyType.IsGenericType && (propertyType.GetGenericTypeDefinition() == typeof(Dictionary <,>))) { text = typeof(Utils).GetMethod("PackMap").MakeGenericMethod(propertyType.GetGenericArguments()).Invoke(null, new object[] { obj2, ':', ',' }).ToString(); } else if (propertyType.IsGenericType && (propertyType.GetGenericTypeDefinition() == typeof(List <>))) { text = typeof(Utils).GetMethod("PackList").MakeGenericMethod(propertyType.GetGenericArguments()).Invoke(null, new object[] { obj2, ',' }).ToString(); } else { text = obj2.ToString(); } child.AddChild(new SecurityElement(info.Name, text)); } element.AddChild(child); num++; } XMLParser.SaveText(path, element.ToString()); }
/// <summary>Returns a string representation of the current <see cref="T:System.Security.Policy.Url" />.</summary> /// <returns>A representation of the current <see cref="T:System.Security.Policy.Url" />.</returns> public override string ToString() { SecurityElement securityElement = new SecurityElement("System.Security.Policy.Url"); securityElement.AddAttribute("version", "1"); securityElement.AddChild(new SecurityElement("Url", this.origin_url)); return(securityElement.ToString()); }
/// <summary> /// //把一个xml节点写入文件中 /// </summary> /// <param name="element">xml节点</param> /// <param name="fileName">文件名</param> /// <param name="version">xml的版本</param> /// <param name="encoding">xml的编码格式</param> public static void WriteSecurityElementToFile(SecurityElement element, string fileName, string version = "1.0", string encoding = "utf-8") { var sb = StringUtils.NewStringBuilder; sb.AppendLine(string.Format(CN_XML_HEAD, version, encoding)); sb.AppendLine(element.ToString()); File.WriteAllText(fileName, sb.ToString()); }
public override string ToString() { SecurityElement element = new SecurityElement("System.Security.Policy.Site"); element.AddAttribute("version", "1"); element.AddChild(new SecurityElement("Name", origin_site)); return(element.ToString()); }
/// <summary>Returns a string representation of the current <see cref="T:System.Security.Policy.Zone" />.</summary> /// <returns>A representation of the current <see cref="T:System.Security.Policy.Zone" />.</returns> public override string ToString() { SecurityElement securityElement = new SecurityElement("System.Security.Policy.Zone"); securityElement.AddAttribute("version", "1"); securityElement.AddChild(new SecurityElement("Zone", this.zone.ToString())); return(securityElement.ToString()); }
public static void Main(String[] args) { FileIOPermission myPerm = new FileIOPermission(FileIOPermissionAccess.AllAccess, @"c:\Networking\Authentication\codetemp"); SecurityElement mySec = myPerm.ToXml(); Console.WriteLine(mySec.ToString()); }
/// <summary> /// 转换为string /// </summary> /// <returns></returns> public override string ToString() { if (_element != null) { return(_element.ToString()); } return(""); }
/// <summary>Gets a string representation of the state of the <see cref="T:System.Security.Policy.ApplicationDirectory" /> evidence object.</summary> /// <returns>A representation of the state of the <see cref="T:System.Security.Policy.ApplicationDirectory" /> evidence object.</returns> public override string ToString() { this.ThrowOnInvalid(this.Directory); SecurityElement securityElement = new SecurityElement("System.Security.Policy.ApplicationDirectory"); securityElement.AddAttribute("version", "1"); securityElement.AddChild(new SecurityElement("Directory", this.directory)); return(securityElement.ToString()); }
/// <summary> /// 保存新生成的版本 /// </summary> private void saveVersion() { SecurityElement ele = new SecurityElement("root"); SecurityElement version = new SecurityElement("CurrentVersion"); version.Text = m_newVersion; ele.AddChild(version); File.WriteAllText(FConst.F_INTERNAL_VERSION_LIST_PATH, ele.ToString()); }
[Category("NotWorking")] // MS bug: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=304583 public void FromString_Quote_Delimiter_MS() { const string xml = "<value name='Company'>Novell</value>"; SecurityElement se = SecurityElement.FromString(xml); Assert.AreEqual("'Company'", se.Attribute("name"), "#1"); Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "<value name=\"'Company'\">Novell</value>{0}", Environment.NewLine), se.ToString(), "#2"); }
/// <summary>Creates a string representation of the current <see cref="T:System.Security.Policy.StrongName" />.</summary> /// <returns>A representation of the current <see cref="T:System.Security.Policy.StrongName" />.</returns> public override string ToString() { SecurityElement securityElement = new SecurityElement(typeof(StrongName).Name); securityElement.AddAttribute("version", "1"); securityElement.AddAttribute("Key", this.publickey.ToString()); securityElement.AddAttribute("Name", this.name); securityElement.AddAttribute("Version", this.version.ToString()); return(securityElement.ToString()); }
public override string ToString() { SecurityElement element = new SecurityElement(typeof(System.Security.Policy.StrongName).Name); element.AddAttribute("version", "1"); element.AddAttribute("Key", publickey.ToString()); element.AddAttribute("Name", name); element.AddAttribute("Version", version.ToString()); return(element.ToString()); }
public override string ToString() { // MS "by design" behaviour (see FDBK14362) ThrowOnInvalid(Directory); SecurityElement element = new SecurityElement("System.Security.Policy.ApplicationDirectory"); element.AddAttribute("version", "1"); element.AddChild(new SecurityElement("Directory", directory)); return(element.ToString()); }
public void UnauthenticatedName() { const string userName = "******"; PrincipalPermission p = new PrincipalPermission(userName, null, false); Assert.True(!p.IsUnrestricted()); SecurityElement pele = (SecurityElement)(p.ToXml().Children[0]); Assert.Contains(userName, pele.ToString()); }
public void UnauthenticatedRole() { const string roleName = "ThisIsARoleName"; PrincipalPermission p = new PrincipalPermission(null, roleName, false); Assert.True(!p.IsUnrestricted()); SecurityElement pele = (SecurityElement)(p.ToXml().Children[0]); Assert.Contains(roleName, pele.ToString()); }
public void MultipleAttributes() { SecurityElement se = new SecurityElement("Multiple"); se.AddAttribute("Attribute1", "One"); se.AddAttribute("Attribute2", "Two"); string expected = string.Format("<Multiple Attribute1=\"One\"{0}Attribute2=\"Two\"/>{0}", Environment.NewLine); Assert.Equal(expected, se.ToString()); }
private static void SaveFingerPrint(String destFileName, FingerPrint fingerPrint) { String fingerPrintFileName = FileDownloadHelper.MakeFingerPrintFilePath(destFileName); SecurityElement finger_print = new SecurityElement("finger_print"); finger_print.AddAttribute("time_stamp", fingerPrint.timeStamp); finger_print.AddAttribute("file_size", fingerPrint.fileSize.ToString()); File.WriteAllText(fingerPrintFileName, finger_print.ToString()); }
private void SaveVersion(VersionManagerInfo version) { PropertyInfo[] properties = typeof(VersionManagerInfo).GetProperties(); SecurityElement element = new SecurityElement("root"); foreach (PropertyInfo info in properties) { element.AddChild(new SecurityElement(info.Name, info.GetGetMethod().Invoke(version, null) as string)); } XMLParser.SaveText(SystemConfig.VersionPath, element.ToString()); }
// Convert this object into a string. public override String ToString() { SecurityElement element = new SecurityElement ("System.Security.Policy.Url"); SecurityElement child; element.AddAttribute("version", "1"); child = new SecurityElement ("Url", SecurityElement.Escape(parser.URL)); element.AddChild(child); return element.ToString(); }
// Convert this object into a string. public override String ToString() { SecurityElement element = new SecurityElement("StrongName"); element.AddAttribute("version", "1"); element.AddAttribute("Key", blob.ToString()); element.AddAttribute ("Name", SecurityElement.Escape(name)); element.AddAttribute("Version", version.ToString()); return element.ToString(); }
// Convert this object into a string. public override String ToString() { SecurityElement element = new SecurityElement ("System.Security.Policy.Site"); SecurityElement child; element.AddAttribute("version", "1"); child = new SecurityElement ("Name", SecurityElement.Escape(name)); element.AddChild(child); return element.ToString(); }
// Convert this object into a string. public override String ToString() { SecurityElement element = new SecurityElement ("System.Security.Policy.PermissionRequestEvidence"); SecurityElement child; element.AddAttribute("version", "1"); if(request != null) { child = new SecurityElement("Request"); child.AddChild(request.ToXml()); element.AddChild(child); } if(optional != null) { child = new SecurityElement("Optional"); child.AddChild(optional.ToXml()); element.AddChild(child); } if(denied != null) { child = new SecurityElement("Denied"); child.AddChild(denied.ToXml()); element.AddChild(child); } return element.ToString(); }
public override string ToString () { SecurityElement se = new SecurityElement ("System.Security.Policy.PermissionRequestEvidence"); se.AddAttribute ("version", "1"); if (requested != null) { SecurityElement requestElement = new SecurityElement ("Request"); requestElement.AddChild (requested.ToXml ()); se.AddChild (requestElement); } if (optional != null) { SecurityElement optionalElement = new SecurityElement ("Optional"); optionalElement.AddChild (optional.ToXml ()); se.AddChild (optionalElement); } if (denied != null) { SecurityElement deniedElement = new SecurityElement ("Denied"); deniedElement.AddChild (denied.ToXml ()); se.AddChild (deniedElement); } return se.ToString (); }
public override string ToString () { // MS "by design" behaviour (see FDBK14362) ThrowOnInvalid (Directory); SecurityElement element = new SecurityElement ("System.Security.Policy.ApplicationDirectory"); element.AddAttribute ("version", "1"); element.AddChild (new SecurityElement ("Directory", directory)); return element.ToString (); }
private Boolean SaveRecord() { SecurityElement xmlRoot = new SecurityElement("expansion_pack_record"); lock (m_lock) { foreach (var item in m_packRecordMap) { String packId = item.Key; ExpansionPackRecord record = item.Value; SecurityElement xmlItem = new SecurityElement("item"); xmlRoot.AddChild(xmlItem); xmlItem.AddAttribute("id", packId); xmlItem.AddAttribute("state", ((Int32)record.state).ToString()); } } try { CreateDirectoryForFile(GetRecordFilePath()); File.WriteAllText(GetRecordFilePath(), xmlRoot.ToString()); return true; } catch (IOException e) { Debug.LogException(e); return false; } }
public override string ToString () { SecurityElement element = new SecurityElement (typeof (System.Security.Policy.StrongName).Name); element.AddAttribute ("version", "1"); element.AddAttribute ("Key", publickey.ToString ()); element.AddAttribute ("Name", name); element.AddAttribute ("Version", version.ToString ()); return element.ToString (); }
public override string ToString () { SecurityElement element = new SecurityElement ("System.Security.Policy.Site"); element.AddAttribute ("version", "1"); element.AddChild (new SecurityElement ("Name", origin_site)); return element.ToString (); }
public override string ToString () { SecurityElement se = new SecurityElement (GetType ().FullName); se.AddAttribute ("version", "1"); StringBuilder sb = new StringBuilder (); byte[] raw = GetData (); for (int i=0; i < raw.Length; i++) sb.Append (raw [i].ToString ("X2")); se.AddChild (new SecurityElement ("RawData", sb.ToString ())); return se.ToString (); }
// Convert this object into a string. public override String ToString() { SecurityElement element; element = new SecurityElement("System.Security.Policy.Hash"); element.AddAttribute("version", "1"); byte[] rawData = RawData; if(rawData != null && rawData.Length != 0) { element.AddChild(new SecurityElement ("RawData", StrongNamePublicKeyBlob.ToHex(rawData))); } return element.ToString(); }
public override string ToString () { SecurityElement se = new SecurityElement ("System.Security.Policy.Zone"); se.AddAttribute ("version", "1"); se.AddChild (new SecurityElement ("Zone", zone.ToString ())); return se.ToString (); }
// Convert this object into a string. public override String ToString() { SecurityElement element = new SecurityElement ("System.Security.Policy.Publisher"); SecurityElement child; element.AddAttribute("version", "1"); child = new SecurityElement ("X509v3Certificate", cert.GetRawCertDataString()); element.AddChild(child); return element.ToString(); }
public void Tag() { SecurityElement se = new SecurityElement("Values"); Assert.Equal("Values", se.Tag); Assert.Equal(string.Format(CultureInfo.InvariantCulture, "<Values/>{0}", Environment.NewLine), se.ToString()); se.Tag = "abc:Name"; Assert.Equal("abc:Name", se.Tag); Assert.Equal(string.Format(CultureInfo.InvariantCulture, "<abc:Name/>{0}", Environment.NewLine), se.ToString()); se.Tag = "Name&Address"; Assert.Equal("Name&Address", se.Tag); Assert.Equal(string.Format(CultureInfo.InvariantCulture, "<Name&Address/>{0}", Environment.NewLine), se.ToString()); se.Tag = string.Empty; Assert.Equal(string.Empty, se.Tag); Assert.Equal(string.Format(CultureInfo.InvariantCulture, "</>{0}", Environment.NewLine), se.ToString()); }
public override string ToString () { SecurityElement se = new SecurityElement ("System.Security.Policy.Publisher"); se.AddAttribute ("version", "1"); SecurityElement cert = new SecurityElement ("X509v3Certificate"); string data = m_cert.GetRawCertDataString (); if (data != null) cert.Text = data; se.AddChild (cert); return se.ToString (); }
public override string ToString () { SecurityElement se = new SecurityElement (GetType ().FullName); se.AddAttribute ("version", "1"); return se.ToString (); }