Пример #1
0
        /// <summary>
        /// Checking credential parameters for HTTP authentication, which are necessary for an xServer configuration running in an Azure environment.
        /// After registering in the Customer Centre, you received your personal account data. This data needed for authentication consists of the
        /// username, password and a token. Meanwhile the username and password is needed for every authentication aspect, the token is restricted
        /// to programming reasons. We recommend to use the token only in your further development steps.
        /// </summary>
        /// <param name="user">User name of the HTTP authentication. In combination with the usage of the token, this parameter has to be set to 'xtok'.</param>
        /// <param name="password">Password of the HTTP authentication. The token value can be used here in combination with the user 'xtok'.</param>
        public void CheckCredentials(string user, string password)
        {
            string baseUrl = Url;

            if (baseUrl.ToUpper().EndsWith("/XMAP/WS/XMAP"))
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - "/XMAP/WS/XMAP".Length);
            }

            if (XServerUrl.IsXServerInternet(baseUrl) && CheckSampleRequest(baseUrl, password))
            {
                return; // Check OK
            }
            if (new XServer2Version(Url, password).IsValidUrl())
            {
                throw new ArgumentException("The XMap url addresses an XServer 2 service. This is currently not supported.");
            }

            if (!CheckSampleRequest(baseUrl, null))
            {
                throw new ArgumentException("The XMap url is not configured correctly. Maybe the corresponding server does not exist or is currently not available.");
            }

            if (XServerUrl.IsXServerInternet(baseUrl))
            {
                // The token-free request works, but the token-request failed --> Token is not valid
                throw new AuthenticationException("The specified authentication data does not validate against the specified url. The url itself is working as expected. " +
                                                  "Please note that the pre-supplied access token (15-day-test-license) may have expired.");
            }
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XMapMetaInfo"/> class by requesting the xmap .properties file,
        /// initializing the <see cref="CopyrightText"/> and <see cref="MaxRequestSize"/>, if this file could be requested.
        /// The <see cref="User"/> and <see cref="Password"/> remains empty.
        /// </summary>
        /// <param name="baseUrl"> The base url for the xMapServer. It consists of the first part of the complete XMapServer URL,
        /// for example eu-n-test.</param>
        public XMapMetaInfo(string baseUrl) : this()
        {
            Url = baseUrl = XServerUrl.Complete(baseUrl, "XMap");

            if (baseUrl.ToUpper().EndsWith("/XMAP/WS/XMAP"))
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - "/XMAP/WS/XMAP".Length);
            }

            try // Customers get Index-out-of-range
            {
                var jspFound = false;
                try
                {
                    if (WebRequest.Create(baseUrl + "/server-info.jsp") is HttpWebRequest request)
                    {
                        request.Timeout = 10000;

                        using (var response = request.GetResponse())
                            using (var reader =
                                       new StreamReader(response.GetResponseStream() ?? throw new InvalidOperationException(),
                                                        Encoding.ASCII))
                            {
                                var content = reader.ReadToEnd();

                                var copyrightResult = content;
                                jspFound = SearchValueInJSON(
                                    new[] { "\"modules\"", "\"xmap\"", "\"map\"", "\"copyright\" : \"" },
                                    ref copyrightResult);
                                if (!jspFound)
                                {
                                    copyrightResult = content;
                                    jspFound        = SearchValueInJSON(
                                        new[]
                                    {
                                        "\"modules\"", "\"xmap\"", "\"profiles\"", "\"default\"", "\"map\"",
                                        "\"copyright\" : \""
                                    }, ref copyrightResult);
                                }

                                if (jspFound)
                                {
                                    CopyrightText = copyrightResult;
                                }

                                ///////

                                var maxSizeResult = content;
                                if (SearchValueInJSON(
                                        new[]
                                {
                                    "\"modules\"", "\"xmap\"", "\"profiles\"", "\"default\"", "\"image\"",
                                    "\"maxSize\" : \""
                                }, ref maxSizeResult))
                                {
                                    var values = maxSizeResult.Split(',');
                                    MaxRequestSize = new Size(int.Parse(values[0]), int.Parse(values[1]));
                                    jspFound       = true;
                                }
                            }
                    }
                }
                catch (WebException) { }

                if (jspFound)
                {
                    return;
                }
                string defaultPropertiesUrl = baseUrl + "/pages/viewConfFile.jsp?name=xmap-default.properties";
                try
                {
                    var request = (HttpWebRequest)WebRequest.Create(defaultPropertiesUrl);
                    request.Timeout   = 10000;
                    request.KeepAlive = false;

                    string metaInfo;
                    using (var response = request.GetResponse())
                        using (var stream = response.GetResponseStream())
                        {
                            if (stream == null)
                            {
                                return;
                            }
                            using (var reader = new StreamReader(stream))
                                metaInfo = reader.ReadToEnd();
                        }

                    // copyright
                    const string copyrightTag = "doNotEdit.map.copyright=";
                    // The tag in the configuration for the copyright text.
                    var i1 = metaInfo.IndexOf(copyrightTag, StringComparison.Ordinal) + copyrightTag.Length;
                    if (i1 > -1)
                    {
                        CopyrightText = "© " + metaInfo.Substring(i1, metaInfo.IndexOf('\r', i1) - i1);
                    }

                    // max size
                    const string maxSizeTag = "doNotEdit.image.maxSize=";
                    // The tag in the configuration for the max size value.
                    i1 = metaInfo.IndexOf(maxSizeTag, StringComparison.Ordinal) + maxSizeTag.Length;
                    if (i1 <= -1)
                    {
                        return;
                    }

                    var i2     = metaInfo.IndexOf('\r', i1);
                    var values = metaInfo.Substring(i1, i2 - i1).Split(',');
                    MaxRequestSize = new Size(Convert.ToInt32(values[0]), Convert.ToInt32(values[1]));
                }
                catch (WebException exception)
                {
                    logger.Writeline(TraceEventType.Error, defaultPropertiesUrl + ":" + Environment.NewLine + exception.Message);
                }
            }
            catch { }
        }