Esempio n. 1
0
 public void Delete(
     string urlPattern,
     MiddlewareFunc middlewareFunc,
     HandlerWithParamsFunc handlerFunc)
 {
     Delete(urlPattern, new [] { middlewareFunc }, handlerFunc);
 }
Esempio n. 2
0
 public void Delete(
     string urlPattern,
     MiddlewareFunc middlewareFunc,
     HandlerFunc handlerFunc)
 {
     Delete(urlPattern, new [] { middlewareFunc }, (environment, @params, next) => handlerFunc(environment, next));
 }
Esempio n. 3
0
 public void Put(
     string urlPattern,
     MiddlewareFunc middlewareFunc,
     HandlerFunc handler)
 {
     Put(urlPattern, new[] { middlewareFunc }, (environment, @params, next) => handler(environment, next));
 }
        public void HostMiddlewareFunc()
        {
            MiddlewareFunc testCode = (env, next) => {
                OwinContext.Get(env)
                .TraceOutput.Write("Middleware");
                return(next(env));
            };
            var host = new TestHostAndServer(testCode);

            host.ProcessGet("/");
            host.TraceOutputValue.ShouldEqual("Middleware");
        }
Esempio n. 5
0
 public IPipeline Use(MiddlewareFunc middleware, SetupAction setup = null) {
     _components.Add(new DelegateComponent(middleware, setup));
     return this;
 }
Esempio n. 6
0
 public MiddleWareDelegateComponent(MiddlewareFunc middleware, SetupAction setup = null)
 {
     _middleware = middleware;
     _setup      = setup;
 }
 public void When(Func <Env, bool> shouldHandle, MiddlewareFunc middlewareFunc, SetupAction setup = null)
 {
     When(shouldHandle, new DelegateComponent(middlewareFunc, setup));
 }
Esempio n. 8
0
 public IPipeline Use(MiddlewareFunc middleware, SetupAction setup = null)
 {
     _components.Add(new MiddleWareDelegateComponent(middleware, setup));
     return(this);
 }
 public static void IsGet(this ControlComponent component, string pathRegex, MiddlewareFunc middlewareFunc, SetupAction setup = null)
 {
     component.When(BuildGetFilter(pathRegex), middlewareFunc, setup);
 }
Esempio n. 10
0
 public TestHostAndServer(MiddlewareFunc middleware, AppFunc next = null, IEnumerable<IOwinHostService> hostServices = null) {
     _host = BuildHost(hostServices);
     _host.SetApp(environment => middleware(environment, next ?? Pipeline.ReturnDone));
 }
Esempio n. 11
0
        public static void ConfigureBuilder(IAppBuilder builder)
        {
            var forbidIfNotSignedIn = new MiddlewareFunc(next => env =>
            {
                var principal = env.Get <IPrincipal>("server.User");
                if (principal == null || !principal.Identity.IsAuthenticated)
                {
                    env.SetStatusCode(403);
                    return(env.GetCompleted());
                }

                return(next(env));
            });

            var forbidIfSignedIn = new MiddlewareFunc(next => env =>
            {
                var principal = env.Get <IPrincipal>("server.User");
                if (principal != null && principal.Identity.IsAuthenticated)
                {
                    env.SetStatusCode(403);
                    return(env.GetCompleted());
                }

                return(next(env));
            });

            var forbidIfNotAdministrator = new MiddlewareFunc(next => env =>
            {
                var user = env.GetUser();
                if (user == null || !user.IsAdministrator)
                {
                    env.SetStatusCode(403);
                    return(env.GetCompleted());
                }

                return(next(env));
            });

            var challengeIfNotAdministrator = new MiddlewareFunc(next => env =>
            {
                var user = env.GetUser();
                if (user == null || !user.IsAdministrator)
                {
                    env.SetStatusCode(401);
                    return(env.GetCompleted());
                }

                return(next(env));
            });

            builder.Use(ContentType.Create());

            builder.Use(MethodOverrideMiddleware.Create());

            builder.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationMode = AuthenticationMode.Active,
                AuthenticationType = "Session",
                CookieName         = "Fnord",
                LoginPath          = new PathString("/forms/sign-in"),
                LogoutPath         = new PathString("/forms/sign-out")
            });

            builder.Use(Mustache.Create(
                            templateRootDirectoryName: "MustacheTemplates",
                            layoutTemplateName: "_layout",
                            layoutDataFunc: environment =>
                            environment.GetUser().To(user => new
            {
                isAdministrator = user.IsAdministrator,
                user            = new { username = user.Username }
            })));

            builder.Use(DispatcherMiddleware.Create(dispatcher =>
            {
                dispatcher.Get("/", Handlers.GetHome);
                dispatcher.Get("/users", challengeIfNotAdministrator, Handlers.GetUsers);
                dispatcher.Patch("/users/{username}", forbidIfNotAdministrator, Handlers.PatchUser);
                dispatcher.Post("/events/push", Handlers.PostPushEvent);
                dispatcher.Post("/events/force", forbidIfNotAdministrator, Handlers.PostForceEvent);
                dispatcher.Get("/forms/sign-up", forbidIfSignedIn, Handlers.GetSignUpForm);
                dispatcher.Get("/forms/sign-in", forbidIfSignedIn, Handlers.GetSignInForm);
                dispatcher.Put("/session", forbidIfSignedIn, Handlers.PutSession);
                dispatcher.Post("/users", forbidIfSignedIn, Handlers.PostUsers);
                dispatcher.Delete("/session", forbidIfNotSignedIn, Handlers.DeleteSession);
                dispatcher.Get("/{owner}/{name}", Handlers.GetBuilds);
                dispatcher.Get("/{owner}/{name}/builds/{id}", Handlers.GetBuild);
                dispatcher.Post("/{owner}/{name}/builds", forbidIfNotAdministrator, Handlers.PostBuild);
            }));
        }
 public void When(Func<Env, bool> shouldHandle, MiddlewareFunc middlewareFunc, SetupAction setup = null) {
     When(shouldHandle, new DelegateComponent(middlewareFunc, setup));
 }
Esempio n. 13
0
        /// <summary>
        /// 関数をミドルウェア コンポーネントでラップします。
        /// </summary>
        /// <typeparam name="T">関数のパラメーターの型。</typeparam>
        /// <typeparam name="TResult">関数の戻り値の型。</typeparam>
        /// <param name="onionFunc">ラップ対象の関数。</param>
        /// <param name="middleware">関数をラップするミドルウェア コンポーネント。</param>
        /// <returns>ミドルウェア コンポーネントでラップされた新しい関数。常に非 <c>null</c>。</returns>
        /// <exception cref="ArgumentNullException"><paramref name="onionFunc"/> or <paramref name="middleware"/> is <c>null</c>.</exception>
        public static Func <T, TResult> Layer <T, TResult>(this Func <T, TResult> onionFunc, MiddlewareFunc <T, TResult> middleware)
        {
            if (onionFunc == null)
            {
                throw new ArgumentNullException(nameof(onionFunc));
            }
            if (middleware == null)
            {
                throw new ArgumentNullException(nameof(middleware));
            }

            return(middleware(onionFunc));
        }
 public DelegateComponent(MiddlewareFunc middleware, SetupAction setup = null) {
     _middleware = middleware;
     _setup = setup;
 }
Esempio n. 15
0
 public MiddlewareWinder(IEnumerable <TMiddleware> commands, MiddlewareFunc invoke)
 {
     _commands       = commands.ToArray();
     _actionWrappers = _commands.Select((c, i) => ActionWrapper(i)).ToArray();
     _invoke         = invoke;
 }
 public static void IsGet(this ControlComponent component, string pathRegex, MiddlewareFunc middlewareFunc, SetupAction setup = null) {
     component.When(BuildGetFilter(pathRegex), middlewareFunc, setup);
 }
Esempio n. 17
0
 public TestHostAndServer(MiddlewareFunc middleware, AppFunc next = null, IEnumerable <IOwinHostService> hostServices = null)
 {
     _host = BuildHost(hostServices);
     _host.SetApp(environment => middleware(environment, next ?? Pipeline.ReturnDone));
 }