Exemplo n.º 1
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            httpContext.Response.Clear();
            httpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);

            _result = ShopConnectorAuthResult.FailedForUnknownReason;

            var controllingData = ConnectionCache.ControllingData();
            var now             = DateTime.UtcNow;

            try
            {
                _result = IsAuthenticated(httpContext, now, controllingData);
            }
            catch (Exception ex)
            {
                ex.Dump();
            }

            if (_result == ShopConnectorAuthResult.Success)
            {
                var response = httpContext.Response;

                response.AddHeader(ShopConnectorCore.Header.Version, controllingData.Version);
                response.AddHeader(ShopConnectorCore.Header.Date, now.ToString("o"));
            }
            else
            {
                var headers = httpContext.Response.Headers;

                headers.Add("WWW-Authenticate", ShopConnectorCore.Header.WwwAuthenticate);

                headers.Add(ShopConnectorCore.Header.Date, now.ToString("o"));

                headers.Add(ShopConnectorCore.Header.AuthResultId, ((int)_result).ToString());
                headers.Add(ShopConnectorCore.Header.AuthResultDescription, _result.ToString());

                if (controllingData.LogUnauthorized)
                {
                    LogUnauthorized(httpContext);
                }
            }

            return(_result == ShopConnectorAuthResult.Success);
        }
Exemplo n.º 2
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            httpContext.Response.Clear();
            httpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);

            int    version = 0;
            var    rawVersion = httpContext.Request.Headers[ShopConnectorCore.Header.Version];
            string connectorVersion, pluginVersion;

            if (rawVersion.SplitToPair(out connectorVersion, out pluginVersion, " "))
            {
                version = connectorVersion.ToInt();
            }

            if (version == ShopConnectorCore.ConnectorVersion)
            {
                _result  = ShopConnectorAuthResult.Success;
                _message = null;
            }
            else
            {
                _result = ShopConnectorAuthResult.IncompatibleVersion;

                var key = (version > ShopConnectorCore.ConnectorVersion ? "Plugins.SmartStore.ShopConnector.PluginOutOfDateMe" : "Plugins.SmartStore.ShopConnector.PluginOutOfDateHe");

                _message = EngineContext.Current.Resolve <ILocalizationService>().GetResource(key);
            }

            if (_result != ShopConnectorAuthResult.Success)
            {
                var headers = httpContext.Response.Headers;

                headers.Add(ShopConnectorCore.Header.Date, DateTime.UtcNow.ToString("o"));
                headers.Add(ShopConnectorCore.Header.AuthResultId, ((int)_result).ToString());
                headers.Add(ShopConnectorCore.Header.AuthResultDescription, _result.ToString());
            }

            return(_result == ShopConnectorAuthResult.Success);
        }
Exemplo n.º 3
0
        public static OperationResultModel CreateAuthErrorModel(this ShopConnectorAuthResult result, ILocalizationService localize, HttpContextBase httpContext, string message = null)
        {
            var model = new OperationResultModel();

            string[] descriptions = localize.GetResource("Plugins.SmartStore.ShopConnector.ShopConnectorAuthResults").SplitSafe(";");
            var      description  = descriptions.SafeGet((int)result);

            model.HasError     = true;
            model.ShortMessage = "{0}: {1} ({2}).".FormatInvariant(localize.GetResource("Plugins.SmartStore.ShopConnector.UnauthorizedRequest"), description, result.ToString());

            if (message.HasValue())
            {
                model.ShortMessage = string.Concat(model.ShortMessage, " ", message);
            }

            model.Description = HttpUtility.UrlDecode(httpContext.Request.Headers.ToString().EmptyNull()).Replace("&", "\r\n");

            return(model);
        }