Example #1
0
        //
        // RPC
        //

        void AddAccessHeaders(HttpRequestMessage req, WebContext wc)
        {
            if (Clustered)
            {
                var cfg = Framework.Config;
//                req.Headers.TryAddWithoutValidation("X-Caller-Sign", Framework.sign);
//                req.Headers.TryAddWithoutValidation("X-Caller-Name", cfg.name);
//                req.Headers.TryAddWithoutValidation("X-Caller-Shard", cfg.shard);
            }

            var auth = wc?.Header("Authorization");

            if (auth != null)
            {
                req.Headers.TryAddWithoutValidation("Authorization", auth);
            }
        }
Example #2
0
        internal override async Task ExecuteAsync(WebContext wc)
        {
            // do access check
            //

            if (_roles != null)
            {
                var prin = wc.Principal;
                if (prin == null)
                {
                    throw new WebException {
                              Code = 401
                    };                                   // Unauthorized
                }

                for (int i = 0; i < _roles.Length; i++)
                {
                    if (prin.IsRole(_roles[i]))
                    {
                        goto Okay;
                    }
                }

                throw new WebException {
                          Code = 403
                };                                   // Forbidden
            }

Okay:

            if (IsAsync)
            {
                await _doAsync(wc);
            }
            else
            {
                _do(wc);
            }
        }
Example #3
0
 protected internal abstract Task HandleAsync(string rsc, WebContext wc);
Example #4
0
 /// <summary>
 ///
 /// </summary>
 internal abstract Task ExecuteAsync(WebContext wc);