Exemplo n.º 1
0
        public HttpResponse Process(RequestInfo requestInfo)
        {
            var ctx = requestInfo.Context;

            if (ctx.Request.Url.AbsolutePath.Contains("private"))
            {
                string auth = ctx.Request.Headers["Authorization"];
                if (auth == null)
                {
                    var resp = new HttpResponse(401, new TextContent("Not Authorized"));

                    resp.WithHeader("WWW-Authenticate", "Basic realm=\"Private Area\"");
                    return(resp);
                }

                auth = auth.Replace("Basic ", "");
                string    userPassDecoded = Encoding.UTF8.GetString(Convert.FromBase64String(auth));
                string [] userPasswd      = userPassDecoded.Split(':');
                string    user            = userPasswd[0];
                string    passwd          = userPasswd[1];
                requestInfo.User = new GenericPrincipal(new GenericIdentity(user), null);

                Console.WriteLine("Authentication: {0} - {1}", auth, userPassDecoded);
            }

            return(_nextFilter.Process(requestInfo));
        }
Exemplo n.º 2
0
        public HttpResponse Process(RequestInfo requestInfo)
        {
            var ctx = requestInfo.Context;

            Trace.TraceInformation("[LogFilter]: Request for URI '{0}'", ctx.Request.Url);
            var resp = _nextFilter.Process(requestInfo);

            Trace.TraceInformation("[LogFilter]: User '{0}'", requestInfo.User != null ? requestInfo.User.Identity.Name : String.Empty);
            return(resp);
        }