void ReadElementsFromXml(EwsServiceXmlReader reader)
    {
        bool hasChanged = reader.ReadElementValue <bool>(XmlNamespace.Messages, XmlElementNames.HasChanged);

        reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.PictureData);
        Uint8List photoData = reader.ReadBase64ElementValue();

        // We only get a content type if we get a photo
        if (photoData.Length > 0)
        {
            this.Results.Photo       = photoData;
            this.Results.ContentType = reader.ReadElementValue(XmlNamespace.Messages, XmlElementNames.ContentType);
        }

        if (hasChanged)
        {
            if (this.Results.Photo.Length == 0)
            {
                this.Results.Status = GetUserPhotoStatus.PhotoOrUserNotFound;
            }
            else
            {
                this.Results.Status = GetUserPhotoStatus.PhotoReturned;
            }
        }
        else
        {
            this.Results.Status = GetUserPhotoStatus.PhotoUnchanged;
        }
    }
Exemple #2
0
    int Read(Uint8List buffer, int offset, int count)
    {
        int retVal = this.underlyingStream.Read(buffer, offset, count);

        if (HangingServiceRequestBase.LogAllWireBytes)
        {
            String readString = Encoding.UTF8.GetString(buffer, offset, retVal);
            String logMessage = String.Format(
                "HangingTraceStream ID [{0}] returned {1} bytes. Bytes returned: [{2}]",
                this.GetHashCode(),
                retVal,
                readString);

            this.service.TraceMessage(
                TraceFlags.DebugMessage,
                logMessage);
        }

        if (this.responseCopy != null)
        {
            this.responseCopy.Write(buffer, offset, retVal);
        }

        return(retVal);
    }
Exemple #3
0
    /// <summary>
    /// Loads from XML.
    /// </summary>
    /// <param name="reader">The reader.</param>
    void LoadFromXml(EwsServiceXmlReader reader)
    {
        EwsUtilities.Assert(
            reader != null,
            "UserConfiguration.LoadFromXml",
            "reader is null");

        reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.UserConfiguration);
        reader.Read();     // Position at first property element

        do
        {
            if (reader.NodeType == XmlNodeType.Element)
            {
                switch (reader.LocalName)
                {
                case XmlElementNames.UserConfigurationName:
                    String responseName = reader.ReadAttributeValue(XmlAttributeNames.Name);

                    EwsUtilities.Assert(
                        string.Compare(this.name, responseName, StringComparison.Ordinal) == 0,
                        "UserConfiguration.LoadFromXml",
                        "UserConfigurationName does not match: Expected: " + this.name + " Name in response: " + responseName);

                    reader.SkipCurrentElement();
                    break;

                case XmlElementNames.ItemId:
                    this.itemId = new ItemId();
                    this.itemId.LoadFromXml(reader, XmlElementNames.ItemId);
                    break;

                case XmlElementNames.Dictionary:
                    this.dictionary.LoadFromXml(reader, XmlElementNames.Dictionary);
                    break;

                case XmlElementNames.XmlData:
                    this.xmlData = Convert.FromBase64String(reader.ReadElementValue());
                    break;

                case XmlElementNames.BinaryData:
                    this.binaryData = Convert.FromBase64String(reader.ReadElementValue());
                    break;

                default:
                    EwsUtilities.Assert(
                        false,
                        "UserConfiguration.LoadFromXml",
                        "Xml element not supported: " + reader.LocalName);
                    break;
                }
            }

            // If XmlData was loaded, read is skipped because GetXmlData positions the reader at the next property.
            reader.Read();
        }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.UserConfiguration));
    }
Exemple #4
0
    /// <summary>
    /// Initializes properties.
    /// </summary>
    /// <param name="requestedProperties">The properties requested for this UserConfiguration.</param>
    /// <remarks>
    /// InitializeProperties is called in 3 cases:
    /// .  Create new object:  From the UserConfiguration constructor.
    /// .  Bind to existing object:  Again from the constructor.  The constructor is called eventually by the GetUserConfiguration request.
    /// .  Refresh properties:  From the Load method.
    /// </remarks>
    /* private */ void InitializeProperties(UserConfigurationProperties requestedProperties)
    {
        this.itemId     = null;
        this.dictionary = new UserConfigurationDictionary();
        this.xmlData    = null;
        this.binaryData = null;
        this.propertiesAvailableForAccess = requestedProperties;

        this.ResetIsDirty();
    }
Exemple #5
0
    /// <summary>
    /// Writes a dictionary Object's value to Xml.
    /// </summary>
    /// <param name="writer">The writer.</param>
    /// <param name="dictionaryObject">The dictionary object to write.</param>
    /* private */ void WriteObjectValueToXml(EwsServiceXmlWriter writer, object dictionaryObject)
    {
        EwsUtilities.Assert(
            writer != null,
            "UserConfigurationDictionary.WriteObjectValueToXml",
            "writer is null");
        EwsUtilities.Assert(
            dictionaryObject != null,
            "UserConfigurationDictionary.WriteObjectValueToXml",
            "dictionaryObject is null");

        // This logic is based on Microsoft.Exchange.Services.Core.GetUserConfiguration.ConstructDictionaryObject().
        //
        // Object values are either:
        //   . an array of strings
        //   . a single value
        //
        // Single values can be:
        //   . base64 String (from a byte array)
        //   . datetime, boolean, byte, short, int, long, string, ushort, unint, ulong
        //
        // First check for a String array
        string[] dictionaryObjectAsStringArray = dictionaryObject as string[];
        if (dictionaryObjectAsStringArray != null)
        {
            this.WriteEntryTypeToXml(writer, UserConfigurationDictionaryObjectType.StringArray);

            for (String arrayElement in dictionaryObjectAsStringArray)
            {
                this.WriteEntryValueToXml(writer, arrayElement);
            }
        }
        else
        {
            // if not a String array, all other object values are returned as a single element
            UserConfigurationDictionaryObjectType dictionaryObjectType = UserConfigurationDictionaryObjectType.String;
            String valueAsString = null;

            Uint8List dictionaryObjectAsByteArray = dictionaryObject as Uint8List;
            if (dictionaryObjectAsByteArray != null)
            {
                // Convert byte array to base64 string
                dictionaryObjectType = UserConfigurationDictionaryObjectType.ByteArray;
                valueAsString        = Convert.ToBase64String(dictionaryObjectAsByteArray);
            }
            else
            {
                GetTypeCode(writer.Service, dictionaryObject, ref dictionaryObjectType, ref valueAsString);
            }

            this.WriteEntryTypeToXml(writer, dictionaryObjectType);
            this.WriteEntryValueToXml(writer, valueAsString);
        }
    }
Exemple #6
0
 /// <summary>
 /// Gets the base64 property value.
 /// </summary>
 /// <param name="bytes">The bytes.</param>
 /// <returns></returns>
 /* private */ String GetBase64PropertyValue(Uint8List bytes)
 {
     if (bytes == null ||
         bytes.Length == 0)
     {
         return(String.Empty);
     }
     else
     {
         return(Convert.ToBase64String(bytes));
     }
 }
Exemple #7
0
    /// <summary>
    /// Writes a byte array to Xml.
    /// </summary>
    /// <param name="writer">The writer.</param>
    /// <param name="byteArray">Byte array to write.</param>
    /// <param name="xmlElementName">Name of the Xml element.</param>
    /* private */ static void WriteByteArrayToXml(
        EwsServiceXmlWriter writer,
        Uint8List byteArray,
        String xmlElementName)
    {
        EwsUtilities.Assert(
            writer != null,
            "UserConfiguration.WriteByteArrayToXml",
            "writer is null");
        EwsUtilities.Assert(
            xmlElementName != null,
            "UserConfiguration.WriteByteArrayToXml",
            "xmlElementName is null");

        writer.WriteStartElement(XmlNamespace.Types, xmlElementName);

        if (byteArray != null && byteArray.Length > 0)
        {
            writer.WriteValue(Convert.ToBase64String(byteArray), xmlElementName);
        }

        writer.WriteEndElement();
    }
Exemple #8
0
    SecurityTimestamp(DateTime creationTimeUtc, DateTime expiryTimeUtc, String id, String digestAlgorithm, Uint8List digest)
    {
        EwsUtilities.Assert(
            creationTimeUtc.Kind == DateTimeKind.Utc,
            "SecurityTimestamp.ctor",
            "creation time must be in UTC");
        EwsUtilities.Assert(
            expiryTimeUtc.Kind == DateTimeKind.Utc,
            "SecurityTimestamp.ctor",
            "expiry time must be in UTC");

        if (creationTimeUtc > expiryTimeUtc)
        {
            throw new ArgumentOutOfRangeException("recordedExpiryTime");
        }

        this.creationTimeUtc = creationTimeUtc;
        this.expiryTimeUtc   = expiryTimeUtc;
        this.id = id;

        this.digestAlgorithm = digestAlgorithm;
        this.digest          = digest;
    }
Exemple #9
0
    /// <summary>
    /// Custom implementaion of basic auth for non ascii email address.
    /// This is very similar to the .Net's Basic/default Authenticate implementation in ...\Net\System\Net\_BasicClient.cs, the only differenece here is the UTF8 encoding part
    /// </summary>
    /// <param name="httpWebRequest">httpweb request object</param>
    /// <param name="credentials">user credential</param>
    /// <returns></returns>
    /* private */ Authorization Authenticate(HttpWebRequest httpWebRequest, ICredentials credentials)
    {
        if (credentials == null)
        {
            return(null);
        }

        // Get the username and password from the credentials
        NetworkCredential nc = credentials.GetCredential(httpWebRequest.RequestUri, AuthenticationTypeName);

        if (nc == null)
        {
            return(null);
        }

        ICredentialPolicy policy = AuthenticationManager.CredentialPolicy;

        if (policy != null && !policy.ShouldSendCredential(httpWebRequest.RequestUri, httpWebRequest, nc, this))
        {
            return(null);
        }

        String username = nc.UserName;
        String domain   = nc.Domain;

        if (StringUtils.IsNullOrEmpty(username))
        {
            return(null);
        }

        String    basicTicket    = (!StringUtils.IsNullOrEmpty(domain) ? (domain + "\\") : "") + username + ":" + nc.Password;
        Uint8List bytes          = Encoding.UTF8.GetBytes(basicTicket);
        String    responseHeader = AuthenticationTypeName + " " + Convert.ToBase64String(bytes);

        return(new Authorization(responseHeader, true));
    }
    /// <summary>
    /// Function that sends the token request to Windows Live.
    /// </summary>
    /// <param name="uriForTokenEndpointReference">The Uri to use for the endpoint reference for our token</param>
    /// <returns>Response to token request.</returns>
    /* private */ HttpWebResponse EmitTokenRequest(Uri uriForTokenEndpointReference)
    {
        const String TokenRequest =
            "<?xml version='1.0' encoding='UTF-8'?>" +
            "<s:Envelope xmlns:s='http://www.w3.org/2003/05/soap-envelope' " +
            "            xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd' " +
            "            xmlns:saml='urn:oasis:names:tc:SAML:1.0:assertion' " +
            "            xmlns:wsp='http://schemas.xmlsoap.org/ws/2004/09/policy' " +
            "            xmlns:wsu='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd' " +
            "            xmlns:wsa='http://www.w3.org/2005/08/addressing' " +
            "            xmlns:wssc='http://schemas.xmlsoap.org/ws/2005/02/sc' " +
            "            xmlns:wst='http://schemas.xmlsoap.org/ws/2005/02/trust' " +
            "            xmlns:ps='http://schemas.microsoft.com/Passport/SoapServices/PPCRL'>" +
            "  <s:Header>" +
            "    <wsa:Action s:mustUnderstand='1'>http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue</wsa:Action>" +
            "    <wsa:To s:mustUnderstand='1'>{0}</wsa:To>" +
            "    <ps:AuthInfo Id='PPAuthInfo'>" +
            "      <ps:HostingApp>{{63f179af-8bcd-49a0-a3e5-1154c02df090}}</ps:HostingApp>" +     //// NOTE: I generated a new GUID for the EWS API
            "      <ps:BinaryVersion>5</ps:BinaryVersion>" +
            "      <ps:UIVersion>1</ps:UIVersion>" +
            "      <ps:Cookies></ps:Cookies>" +
            "      <ps:RequestParams>AQAAAAIAAABsYwQAAAAxMDMz</ps:RequestParams>" +
            "    </ps:AuthInfo>" +
            "    <wsse:Security>" +
            "      <wsse:UsernameToken wsu:Id='user'>" +
            "        <wsse:Username>{1}</wsse:Username>" +
            "        <wsse:Password>{2}</wsse:Password>" +
            "      </wsse:UsernameToken>" +
            "      <wsu:Timestamp Id='Timestamp'>" +
            "        <wsu:Created>{3}</wsu:Created>" +
            "        <wsu:Expires>{4}</wsu:Expires>" +
            "      </wsu:Timestamp>" +
            "    </wsse:Security>" +
            "  </s:Header>" +
            "  <s:Body>" +
            "    <ps:RequestMultipleSecurityTokens Id='RSTS'>" +
            "      <wst:RequestSecurityToken Id='RST0'>" +
            "        <wst:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</wst:RequestType>" +
            "        <wsp:AppliesTo>" +
            "          <wsa:EndpointReference>" +
            "            <wsa:Address>http://Passport.NET/tb</wsa:Address>" +
            "          </wsa:EndpointReference>" +
            "        </wsp:AppliesTo>" +
            "      </wst:RequestSecurityToken>" +
            "      <wst:RequestSecurityToken Id='RST1'>" +
            "        <wst:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</wst:RequestType>" +
            "        <wsp:AppliesTo>" +
            "          <wsa:EndpointReference>" +
            "            <wsa:Address>{5}</wsa:Address>" +
            "          </wsa:EndpointReference>" +
            "        </wsp:AppliesTo>" +
            "        <wsp:PolicyReference URI='LBI_FED_SSL'></wsp:PolicyReference>" +
            "      </wst:RequestSecurityToken>" +
            "    </ps:RequestMultipleSecurityTokens>" +
            "  </s:Body>" +
            "</s:Envelope>";

        // Create a security timestamp valid for 5 minutes to send with the request.
        DateTime          now = DateTime.UtcNow;
        SecurityTimestamp securityTimestamp = new SecurityTimestamp(now, now.AddMinutes(5), "Timestamp");

        // Format the request String to send to the server, filling in all the bits.
        String requestToSend = String.Format(
            TokenRequest,
            this.windowsLiveUrl,
            this.windowsLiveId,
            this.password,
            securityTimestamp.GetCreationTimeChars(),
            securityTimestamp.GetExpiryTimeChars(),
            uriForTokenEndpointReference.ToString());

        // Create and send the request.
        HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(this.windowsLiveUrl);

        webRequest.Method      = "POST";
        webRequest.ContentType = "text/xml; charset=utf-8";
        Uint8List requestBytes = Encoding.UTF8.GetBytes(requestToSend);

        webRequest.ContentLength = requestBytes.Length;

        // NOTE: We're not tracing the request to Windows Live here because it has the user name and
        // password in it.

        {
            requestStream.Write(requestBytes, 0, requestBytes.Length);
        }

        return((HttpWebResponse)webRequest.GetResponse());
    }
Exemple #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MimeContentUTF8"/> class.
 /// </summary>
 /// <param name="content">The content.</param>
 MimeContentUTF8(Uint8List content)
 {
     this.CharacterSet = Encoding.UTF8.BodyName;
     this.Content      = content;
 }
Exemple #12
0
 void Write(Uint8List buffer, int offset, int count)
 {
     throw new NotSupportedException();
 }