public static SerializedClientSecurityContext CreateFromClientSecurityContext(ClientSecurityContext clientSecurityContext, string logonName, string authenticationType) { SerializedClientSecurityContext serializedClientSecurityContext = new SerializedClientSecurityContext(); clientSecurityContext.SetSecurityAccessToken(serializedClientSecurityContext); serializedClientSecurityContext.LogonName = logonName; serializedClientSecurityContext.AuthenticationType = authenticationType; return(serializedClientSecurityContext); }
protected override void AddProtocolSpecificHeadersToServerRequest(WebHeaderCollection headers) { if (base.ProxyToDownLevel) { using (StringWriter stringWriter = new StringWriter()) { using (XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter)) { SerializedClientSecurityContext serializedClientSecurityContext = base.HttpContext.GetSerializedClientSecurityContext(); serializedClientSecurityContext.Serialize(xmlTextWriter); stringWriter.Flush(); headers["X-OwaLanguageProxySerializedSecurityContext"] = stringWriter.ToString(); } } } base.AddProtocolSpecificHeadersToServerRequest(headers); }
// Token: 0x0600038D RID: 909 RVA: 0x00014168 File Offset: 0x00012368 internal static SerializedClientSecurityContext Deserialize(Stream input) { XmlTextReader xmlTextReader = null; SerializedClientSecurityContext result; try { xmlTextReader = new XmlTextReader(input); xmlTextReader.WhitespaceHandling = WhitespaceHandling.All; result = SerializedClientSecurityContext.Deserialize(xmlTextReader); } finally { if (xmlTextReader != null) { xmlTextReader.Dispose(); } } return(result); }
public void Serialize(XmlTextWriter writer) { writer.WriteStartElement(SerializedClientSecurityContext.RootElementName); writer.WriteAttributeString(SerializedClientSecurityContext.AuthenticationTypeAttributeName, this.authenticationType); writer.WriteAttributeString(SerializedClientSecurityContext.LogonNameAttributeName, this.logonName); SerializedClientSecurityContext.WriteSid(writer, this.UserSid, 0U, SerializedClientSecurityContext.SidType.User); if (this.GroupSids != null) { for (int i = 0; i < this.GroupSids.Length; i++) { SerializedClientSecurityContext.WriteSid(writer, this.GroupSids[i].SecurityIdentifier, this.GroupSids[i].Attributes, SerializedClientSecurityContext.SidType.Group); } } if (this.RestrictedGroupSids != null) { for (int j = 0; j < this.RestrictedGroupSids.Length; j++) { SerializedClientSecurityContext.WriteSid(writer, this.RestrictedGroupSids[j].SecurityIdentifier, this.RestrictedGroupSids[j].Attributes, SerializedClientSecurityContext.SidType.RestrictedGroup); } } writer.WriteEndElement(); }
public static SerializedClientSecurityContext GetSerializedClientSecurityContext(this HttpContext httpContext) { if (httpContext == null) { throw new ArgumentNullException("httpContext"); } SerializedClientSecurityContext result = null; try { IIdentity callerIdentity = httpContext.GetCallerIdentity(); using (ClientSecurityContext clientSecurityContext = callerIdentity.CreateClientSecurityContext(true)) { result = SerializedClientSecurityContext.CreateFromClientSecurityContext(clientSecurityContext, callerIdentity.GetSafeName(true), callerIdentity.AuthenticationType); } } catch (AuthzException ex) { throw new HttpException(401, ex.Message); } return(result); }
// Token: 0x060003FD RID: 1021 RVA: 0x000173B4 File Offset: 0x000155B4 public static SerializedClientSecurityContext GetSerializedClientSecurityContext(this IRequestContext requestContext) { if (requestContext == null) { throw new ArgumentNullException("requestContext"); } SerializedClientSecurityContext result = null; try { IIdentity callerIdentity = requestContext.GetCallerIdentity(); using (ClientSecurityContext clientSecurityContext = IdentityUtils.ClientSecurityContextFromIdentity(callerIdentity, true)) { result = SerializedClientSecurityContext.CreateFromClientSecurityContext(clientSecurityContext, IIdentityExtensions.GetSafeName(callerIdentity, true), callerIdentity.AuthenticationType); } } catch (AuthzException ex) { throw new HttpException(401, ex.Message); } return(result); }
internal static SerializedClientSecurityContext Deserialize(XmlTextReader reader) { SerializedClientSecurityContext serializedClientSecurityContext = new SerializedClientSecurityContext(); serializedClientSecurityContext.UserSid = null; serializedClientSecurityContext.GroupSids = null; serializedClientSecurityContext.RestrictedGroupSids = null; try { List <SidStringAndAttributes> list = new List <SidStringAndAttributes>(); List <SidStringAndAttributes> list2 = new List <SidStringAndAttributes>(); if (!reader.Read() || XmlNodeType.Element != reader.NodeType || StringComparer.OrdinalIgnoreCase.Compare(reader.Name, SerializedClientSecurityContext.RootElementName) != 0) { SerializedClientSecurityContext.ThrowParserException(reader, "Missing or invalid root node"); } if (reader.MoveToFirstAttribute()) { do { if (StringComparer.OrdinalIgnoreCase.Compare(reader.Name, SerializedClientSecurityContext.AuthenticationTypeAttributeName) == 0) { if (serializedClientSecurityContext.authenticationType != null) { SerializedClientSecurityContext.ThrowParserException(reader, string.Format("Duplicated attribute {0}", SerializedClientSecurityContext.AuthenticationTypeAttributeName)); } serializedClientSecurityContext.authenticationType = reader.Value; } else if (StringComparer.OrdinalIgnoreCase.Compare(reader.Name, SerializedClientSecurityContext.LogonNameAttributeName) == 0) { if (serializedClientSecurityContext.logonName != null) { SerializedClientSecurityContext.ThrowParserException(reader, string.Format("Duplicated attribute {0}", SerializedClientSecurityContext.LogonNameAttributeName)); } serializedClientSecurityContext.logonName = reader.Value; } else { SerializedClientSecurityContext.ThrowParserException(reader, "Found invalid attribute in root element"); } }while (reader.MoveToNextAttribute()); } if (serializedClientSecurityContext.authenticationType == null || serializedClientSecurityContext.logonName == null) { SerializedClientSecurityContext.ThrowParserException(reader, "Auth type or logon name attributes are missing"); } bool flag = false; int num = 0; while (reader.Read()) { if (XmlNodeType.EndElement == reader.NodeType && StringComparer.OrdinalIgnoreCase.Compare(reader.Name, SerializedClientSecurityContext.RootElementName) == 0) { flag = true; break; } if (XmlNodeType.Element != reader.NodeType || StringComparer.OrdinalIgnoreCase.Compare(reader.Name, SerializedClientSecurityContext.SidElementName) != 0) { SerializedClientSecurityContext.ThrowParserException(reader, "Expecting SID node"); } SerializedClientSecurityContext.SidType sidType = SerializedClientSecurityContext.SidType.User; uint num2 = 0U; if (reader.MoveToFirstAttribute()) { do { if (StringComparer.OrdinalIgnoreCase.Compare(reader.Name, SerializedClientSecurityContext.SidTypeAttributeName) == 0) { int num3 = int.Parse(reader.Value); if (num3 == 1) { sidType = SerializedClientSecurityContext.SidType.Group; } else if (num3 == 2) { sidType = SerializedClientSecurityContext.SidType.RestrictedGroup; } else { SerializedClientSecurityContext.ThrowParserException(reader, "Invalid SID type"); } } else if (StringComparer.OrdinalIgnoreCase.Compare(reader.Name, SerializedClientSecurityContext.SidAttributesAttributeName) == 0) { num2 = uint.Parse(reader.Value); } else { SerializedClientSecurityContext.ThrowParserException(reader, "Found invalid attribute in SID element"); } }while (reader.MoveToNextAttribute()); } if (sidType == SerializedClientSecurityContext.SidType.User) { if (num2 != 0U) { SerializedClientSecurityContext.ThrowParserException(reader, "'Attributes' shouldn't be set in an user SID"); } else if (serializedClientSecurityContext.UserSid != null) { SerializedClientSecurityContext.ThrowParserException(reader, "There can only be one user SID in the XML document"); } } if (!reader.Read() || XmlNodeType.Text != reader.NodeType || string.IsNullOrEmpty(reader.Value)) { SerializedClientSecurityContext.ThrowParserException(reader, "Expecting SID value in SDDL format"); } string value = reader.Value; if (sidType == SerializedClientSecurityContext.SidType.User) { serializedClientSecurityContext.UserSid = value; } else if (sidType == SerializedClientSecurityContext.SidType.Group) { SidStringAndAttributes item = new SidStringAndAttributes(value, num2); list.Add(item); } else if (sidType == SerializedClientSecurityContext.SidType.RestrictedGroup) { SidStringAndAttributes item2 = new SidStringAndAttributes(value, num2); list2.Add(item2); } if (!reader.Read() || XmlNodeType.EndElement != reader.NodeType) { SerializedClientSecurityContext.ThrowParserException(reader, "Expected end of SID node"); } num++; if (num > SerializedClientSecurityContext.MaximumSidsPerContext) { throw new Exception(string.Format("Too many SID nodes in the request, maximum is {0}", SerializedClientSecurityContext.MaximumSidsPerContext)); } } if (serializedClientSecurityContext.UserSid == null) { SerializedClientSecurityContext.ThrowParserException(reader, "Serialized context should at least contain an user SID"); } if (!flag) { SerializedClientSecurityContext.ThrowParserException(reader, "Parsing error"); } if (list.Count > 0) { serializedClientSecurityContext.GroupSids = list.ToArray(); } if (list2.Count > 0) { serializedClientSecurityContext.RestrictedGroupSids = list2.ToArray(); } } catch (XmlException ex) { SerializedClientSecurityContext.ThrowParserException(reader, string.Format("Parser threw an XML exception: {0}", ex.Message)); } return(serializedClientSecurityContext); }