public void ThrowsForDuplicateId()
            {
                var sut = new StuntmanOptions();
                var user = new StuntmanUser("user-1", "User 1");

                sut.AddUser(user);

                var exception = Assert.Throws<ApplicationException>(() =>
                    {
                        sut.AddUser(user);
                    });

                Assert.Equal("user must have unique Id.", exception.Message);
            }
            public void ThrowsForDuplicateId()
            {
                var sut  = new StuntmanOptions();
                var user = new StuntmanUser("user-1", "User 1");

                sut.AddUser(user);

                var exception = Assert.Throws <Exception>(() =>
                {
                    sut.AddUser(user);
                });

                Assert.Equal("user must have unique Id.", exception.Message);
            }
Exemple #3
0
        public void Configuration(IAppBuilder app)
        {
            StuntmanOptions
            .AddUser(new StuntmanUser("user-1", "User 1")
                     .AddClaim("Awesome", "yes")
                     .AddClaim(ClaimTypes.Role, "Administrator")
                     .SetAccessToken("test-token"));

            var httpConfiguration = new HttpConfiguration();

            httpConfiguration.MapHttpAttributeRoutes();

            var builder = new ContainerBuilder();

            builder.RegisterModule(new WebApiModule(httpConfiguration));
            builder.RegisterModule(new AbilitiesModule(typeof(Startup).Assembly));

            var container = builder.Build();

            httpConfiguration.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            app.UseStuntman(StuntmanOptions);

            app.UseAutofacMiddleware(container)
            .UseAutofacWebApi(httpConfiguration)
            .UseWebApi(httpConfiguration);
        }
 public void CreateStuntUsers()
 {
     StuntmanOptions
     .AddUser(
         new StuntmanUser("user-1", "User 1")
         .AddClaim("name", "John Doe"));
 }
        public Startup(IConfiguration configuration)
        {
            StuntmanOptions
            .AddUser("John", "Doe")
            .AddUser("Mary", "Smith");

            Configuration = configuration;
        }
            public void SetsSourceToLocalSource()
            {
                var sut = new StuntmanOptions();

                sut.AddUser(new StuntmanUser("user-1", "User 1"));

                var user = sut.Users.Single();

                Assert.Equal(Constants.StuntmanOptions.LocalSource, user.Source);
            }
            public void AddsUser()
            {
                var sut = new StuntmanOptions();

                sut.AddUser(new StuntmanUser("user-1", "User 1"));

                var user = sut.Users.Single();

                Assert.Equal("user-1", user.Id);
                Assert.Equal("User 1", user.Name);
            }
            public void AddsUser()
            {
                var sut = new StuntmanOptions();

                sut.AddUser(new StuntmanUser("user-1", "User 1"));

                var user = sut.Users.Single();

                Assert.Equal("user-1", user.Id);
                Assert.Equal("User 1", user.Name);
            }
Exemple #9
0
        public Startup(IConfiguration configuration)
        {
            StuntmanOptions
            .AddUser(new StuntmanUser("user-1", "User 1")
                     .AddClaim("given_name", "John")
                     .AddClaim("family_name", "Doe"))
            .AddUser(new StuntmanUser("user-2", "User 2")
                     .AddClaim("given_name", "Jane")
                     .AddClaim("family_name", "Doe"));

            Configuration = configuration;
        }
Exemple #10
0
        public static StuntmanOptions AddUser(this StuntmanOptions options, string name, string surname)
        {
            var user = new StuntmanUser($"{name}.{surname}", $"{name} {surname}", ClaimTypes.Name, ClaimTypes.Role)
                       .SetAccessToken(Guid.NewGuid().ToString())
                       .AddClaim("given_name", name)
                       .AddClaim("family_name", surname)
                       .AddClaim("role", "MDA")
                       .AddClaim("role", "MPIR");

            options.AddUser(user);
            return(options);
        }
Exemple #11
0
        public void Configuration(IAppBuilder app)
        {
            StuntmanOptions
            .AddUser(new StuntmanUser("user-1", "User 1")
                     .AddClaim("given_name", "John")
                     .AddClaim("family_name", "Doe"));

            if (System.Web.HttpContext.Current.IsDebuggingEnabled)
            {
                app.UseStuntman(StuntmanOptions);
            }
        }
            public void SetsSourceToLocalSource()
            {
                var sut = new StuntmanOptions();

                sut.AddUser(new StuntmanUser("user-1", "User 1"));

                var user = sut.Users.Single();

                Assert.Equal(Constants.StuntmanOptions.LocalSource, user.Source);
            }
Exemple #13
0
        public void Configuration(IAppBuilder app)
        {
            StuntmanOptions
            .AddUser(new StuntmanUser("user-1", "User 1")
                     .SetAccessToken("user-1-token")
                     .AddClaim("given_name", "John")
                     .AddClaim("family_name", "Doe"))
            .AddUser(new StuntmanUser("user-2", "User 2")
                     .AddClaim("given_name", "Jane")
                     .AddClaim("family_name", "Doe"))
            .AddUser(new StuntmanUser("user-3", "User 3")
                     .AddClaim("given_name", "Sam")
                     .AddClaim("family_name", "Smith"))
            .AddUsersFromJson("https://raw.githubusercontent.com/ritterim/stuntman/master/samples/UsageSample/test-users-1.json")     // Tried this using OWIN locally, didn't get it working.
            .AddUsersFromJson(Path.Combine(GetBinPath(), "test-users-2.json"));

            if (System.Web.HttpContext.Current.IsDebuggingEnabled)
            {
                app.UseStuntman(StuntmanOptions);
            }

            app.Map("/secure", secure =>
            {
                AuthenticateAllRequests(secure, new[] { "StuntmanAuthentication" });

                secure.Run(context =>
                {
                    var userName = context.Request.User.Identity.Name;

                    if (string.IsNullOrEmpty(userName))
                    {
                        userName = "******";
                    }

                    context.Response.ContentType = "text/html";
                    context.Response.WriteAsync(
                        $"Hello, {userName}. This is the /secure endpoint.");

                    if (System.Web.HttpContext.Current.IsDebuggingEnabled)
                    {
                        context.Response.WriteAsync(
                            StuntmanOptions.UserPicker(context.Request.User));
                    }

                    return(Task.FromResult(true));
                });
            });

            app.Map("/logout", logout =>
            {
                logout.Run(context =>
                {
                    context.Authentication.SignOut();
                    return(Task.FromResult(true));
                });
            });

            app.Map("", nonSecure =>
            {
                nonSecure.Run(context =>
                {
                    var userName = context.Request.User.Identity.Name;

                    if (string.IsNullOrEmpty(userName))
                    {
                        userName = "******";
                    }

                    context.Response.ContentType = "text/html";

                    context.Response.WriteAsync(
                        @"<!DOCTYPE html>
<html>
    <head>
        <meta charset=""utf-8"">
        <title>Stuntman - UsageSample</title>
    </head>
<body>");

                    context.Response.WriteAsync(
                        $"Hello, {userName}.");

                    if (System.Web.HttpContext.Current.IsDebuggingEnabled)
                    {
                        context.Response.WriteAsync(
                            StuntmanOptions.UserPicker(context.Request.User));
                    }

                    context.Response.WriteAsync(
                        @"</body>
</html>");

                    return(Task.FromResult(true));
                });
            });
        }