private static void ShowClaimSetHtml(ClaimSet set, bool isIssuer, bool verbose) { if (set.HasIssuer()) { ShowClaimSetHtml(set.Issuer, true, verbose); } string setType = set.GetType().Name; string setName = isIssuer ? "Issuer" : "Issued"; HeadingHtml(String.Format("\n{0} Claims ({1})\n", setName, setType)); foreach (Claim claim in set) { bool isIdentity = claim.Right.Equals(Rights.Identity); WriteLineHtml(claim.ClaimType, isIdentity); if (verbose) { WriteLineHtml(claim.Resource.GetType().FullName, isIdentity); WriteLineHtml(claim.Stringify(), isIdentity); } else { WriteLineHtml(claim.Resource.ToString(), isIdentity); } WriteLineHtml(claim.Right, isIdentity); WriteLineHtml("", false); Console.ResetColor(); } }
/// <summary> /// Serializes a claim set using the DataContractSerializer. /// </summary> /// <param name="set">the claim set to serialize</param> /// <param name="knownTypes">known serialization types</param> /// <returns></returns> public static XElement Serialize(this ClaimSet set, IEnumerable <Type> knownTypes) { // make sure lazy loading has been done before serialization var dlset = set as DeferredLoadClaimSet; if (dlset != null) { dlset.Load(); } DataContractSerializer dcs = new DataContractSerializer( set.GetType(), knownTypes, int.MaxValue, false, true, null); MemoryStream ms = new MemoryStream(); dcs.WriteObject(ms, set); ms.Seek(0, SeekOrigin.Begin); return(XElement.Load(new XmlTextReader(ms))); }
internal override void WriteTo(XmlWriter xml) { if (((this.message != null) && (this.message.State != MessageState.Closed)) && (this.message.Headers != null)) { try { xml.WriteStartElement("MessageProperties"); if (this.message.Properties.Encoder != null) { xml.WriteElementString("Encoder", this.message.Properties.Encoder.ToString()); } xml.WriteElementString("AllowOutputBatching", this.message.Properties.AllowOutputBatching.ToString()); if ((this.message.Properties.Security != null) && (this.message.Properties.Security.ServiceSecurityContext != null)) { xml.WriteStartElement("Security"); xml.WriteElementString("IsAnonymous", this.message.Properties.Security.ServiceSecurityContext.IsAnonymous.ToString()); xml.WriteElementString("WindowsIdentityUsed", ((this.message.Properties.Security.ServiceSecurityContext.WindowsIdentity != null) && !string.IsNullOrEmpty(this.message.Properties.Security.ServiceSecurityContext.WindowsIdentity.Name)).ToString()); if (DiagnosticUtility.ShouldTraceVerbose) { xml.WriteStartElement("Claims"); AuthorizationContext authorizationContext = this.message.Properties.Security.ServiceSecurityContext.AuthorizationContext; for (int j = 0; j < authorizationContext.ClaimSets.Count; j++) { ClaimSet set = authorizationContext.ClaimSets[j]; xml.WriteStartElement("ClaimSet"); xml.WriteAttributeString("ClrType", base.XmlEncode(set.GetType().AssemblyQualifiedName)); for (int k = 0; k < set.Count; k++) { SecurityTraceRecordHelper.WriteClaim(xml, set[k]); } xml.WriteEndElement(); } xml.WriteEndElement(); } xml.WriteEndElement(); } if (this.message.Properties.Via != null) { xml.WriteElementString("Via", this.message.Properties.Via.ToString()); } xml.WriteEndElement(); xml.WriteStartElement("MessageHeaders"); for (int i = 0; i < this.message.Headers.Count; i++) { this.message.Headers.WriteHeader(i, xml); } xml.WriteEndElement(); } catch (CommunicationException exception) { if (DiagnosticUtility.ShouldTraceInformation) { TraceUtility.TraceEvent(TraceEventType.Information, 0x2000a, System.ServiceModel.SR.GetString("TraceCodeDiagnosticsFailedMessageTrace"), (Exception)exception, this.message); } } } }
private static void ShowClaimSet(ClaimSet set, bool isIssuer, bool verbose) { if (set.HasIssuer()) { ShowClaimSet(set.Issuer, true, verbose); } string setType = set.GetType().Name; string setName = isIssuer ? "Issuer" : "Issued"; Heading(String.Format("\n{0} Claims ({1})\n", setName, setType), ConsoleColor.Green); if (set.Count == 0) { Console.WriteLine("(anonymous)\n"); } foreach (Claim claim in set) { if (claim.Right.Equals(Rights.Identity)) { Console.ForegroundColor = ConsoleColor.White; } Console.WriteLine(claim.ClaimType); if (verbose) { Console.WriteLine(claim.Resource.GetType().FullName); Console.WriteLine(claim.Stringify()); } else { Console.WriteLine(claim.Resource); } Console.WriteLine(claim.Right); Console.WriteLine(); Console.ResetColor(); } }
private static void ShowClaimSet(ClaimSet set, bool isIssuer, bool verbose) { if (set.HasIssuer()) { ShowClaimSet(set.Issuer, true, verbose); } string setType = set.GetType().Name; string setName = isIssuer ? "Issuer" : "Issued"; Heading(String.Format("\n{0} Claims ({1})\n", setName, setType), ConsoleColor.Green); if (set.Count == 0) { Console.WriteLine("(anonymous)\n"); } foreach (Claim claim in set) { if (claim.Right.Equals(Rights.Identity)) { Console.ForegroundColor = ConsoleColor.White; } Console.WriteLine(claim.ClaimType); if (verbose) { Console.WriteLine(claim.Resource.GetType().FullName); Console.WriteLine(claim.Stringify()); } else { Console.WriteLine(claim.Resource); } Console.WriteLine(claim.Right); Console.WriteLine(); Console.ResetColor(); } }
private static void ShowClaimSetHtml(ClaimSet set, bool isIssuer, bool verbose) { if (set.HasIssuer()) { ShowClaimSetHtml(set.Issuer, true, verbose); } string setType = set.GetType().Name; string setName = isIssuer ? "Issuer" : "Issued"; HeadingHtml(String.Format("\n{0} Claims ({1})\n", setName, setType)); foreach (Claim claim in set) { bool isIdentity = claim.Right.Equals(Rights.Identity); WriteLineHtml(claim.ClaimType, isIdentity); if (verbose) { WriteLineHtml(claim.Resource.GetType().FullName, isIdentity); WriteLineHtml(claim.Stringify(), isIdentity); } else { WriteLineHtml(claim.Resource.ToString(), isIdentity); } WriteLineHtml(claim.Right, isIdentity); WriteLineHtml("", false); Console.ResetColor(); } }
internal override void WriteTo(XmlWriter xml) { if ((this.message != null) && (this.message.State != MessageState.Closed) && (this.message.Headers != null)) { try { xml.WriteStartElement("MessageProperties"); if (message.Properties.Encoder != null) { xml.WriteElementString("Encoder", message.Properties.Encoder.ToString()); } xml.WriteElementString("AllowOutputBatching", message.Properties.AllowOutputBatching.ToString()); if (message.Properties.Security != null && message.Properties.Security.ServiceSecurityContext != null) { xml.WriteStartElement("Security"); xml.WriteElementString("IsAnonymous", message.Properties.Security.ServiceSecurityContext.IsAnonymous.ToString()); bool windowsIdentityUsed = message.Properties.Security.ServiceSecurityContext.WindowsIdentity != null && !string.IsNullOrEmpty(message.Properties.Security.ServiceSecurityContext.WindowsIdentity.Name); xml.WriteElementString("WindowsIdentityUsed", windowsIdentityUsed.ToString()); if (DiagnosticUtility.ShouldTraceVerbose) { xml.WriteStartElement("Claims"); AuthorizationContext authContext = message.Properties.Security.ServiceSecurityContext.AuthorizationContext; for (int i = 0; i < authContext.ClaimSets.Count; ++i) { ClaimSet claimSet = authContext.ClaimSets[i]; xml.WriteStartElement("ClaimSet"); xml.WriteAttributeString("ClrType", base.XmlEncode(claimSet.GetType().AssemblyQualifiedName)); for (int j = 0; j < claimSet.Count; ++j) { Fx.Assert(null != claimSet[j], "Claim cannot be null"); SecurityTraceRecordHelper.WriteClaim(xml, claimSet[j]); } xml.WriteEndElement(); } xml.WriteEndElement(); } xml.WriteEndElement(); } if (message.Properties.Via != null) { xml.WriteElementString("Via", message.Properties.Via.ToString()); } xml.WriteEndElement(); xml.WriteStartElement(MessageLogTraceRecord.MessageHeadersElementName); for (int i = 0; i < this.message.Headers.Count; i++) { this.message.Headers.WriteHeader(i, xml); } xml.WriteEndElement(); } catch (CommunicationException e) { if (DiagnosticUtility.ShouldTraceInformation) { TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.DiagnosticsFailedMessageTrace, SR.GetString(SR.TraceCodeDiagnosticsFailedMessageTrace), e, message); } } } }