public static MembershipRebootConfiguration<HierarchicalUserAccount> Create()
        {
            var config = new MembershipRebootConfiguration<HierarchicalUserAccount>();
            //config.RequireAccountVerification = false;

            config.AddEventHandler(new DebuggerEventHandler<HierarchicalUserAccount>());

            var appinfo = new AspNetApplicationInformation("Test", "Test Email Signature",
                "UserAccount/Login",
                "UserAccount/ChangeEmail/Confirm/",
                "UserAccount/Register/Cancel/",
                "UserAccount/PasswordReset/Confirm/");
            var emailFormatter = new EmailMessageFormatter<HierarchicalUserAccount>(appinfo);
            // uncomment if you want email notifications -- also update smtp settings in web.config
            config.AddEventHandler(new EmailAccountEventsHandler<HierarchicalUserAccount>(emailFormatter));

            // uncomment to enable SMS notifications -- also update TwilloSmsEventHandler class below
            //config.AddEventHandler(new TwilloSmsEventHandler(appinfo));

            // uncomment to ensure proper password complexity
            //config.ConfigurePasswordComplexity();

            var debugging = false;
            #if DEBUG
            debugging = true;
            #endif
            // this config enables cookies to be issued once user logs in with mobile code
            config.ConfigureTwoFactorAuthenticationCookies(debugging);

            return config;
        }
        private static void ConfigureMembershipReboot(IAppBuilder app)
        {
            var cookieOptions = new CookieAuthenticationOptions
            {
                AuthenticationType = MembershipRebootOwinConstants.AuthenticationType
            };
            Func<IDictionary<string, object>, UserAccountService> uaFunc = env =>
            {
                var appInfo = new OwinApplicationInformation(
                    env,
                    "Test",
                    "Test Email Signature",
                    "/Login",
                    "/Register/Confirm/",
                    "/Register/Cancel/",
                    "/PasswordReset/Confirm/");

                var config = new MembershipRebootConfiguration();
                var emailFormatter = new EmailMessageFormatter(appInfo);
                // uncomment if you want email notifications -- also update smtp settings in web.config
                config.AddEventHandler(new EmailAccountEventsHandler(emailFormatter));

                var svc = new UserAccountService(config, new DefaultUserAccountRepository());
                svc.TwoFactorAuthenticationPolicy = new OwinCookieBasedTwoFactorAuthPolicy(env);
                return svc;
            };
            Func<IDictionary<string, object>, AuthenticationService> authFunc = env =>
            {
                return new OwinAuthenticationService(cookieOptions.AuthenticationType, uaFunc(env), env);
            };

            app.UseMembershipReboot(cookieOptions, uaFunc, authFunc);
        }
        public static void FromLegacy(
            this MembershipRebootConfiguration config,
            INotificationService notificationService,
            IPasswordPolicy passwordPolicy)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            if (notificationService != null)
            {
                config.AddEventHandler(new NotificationServiceEventHandler(notificationService));
                if (config.SecuritySettings.RequireAccountVerification)
                {
                    config.AddEventHandler(new NotificationServiceAccountCreatedEventHandler(notificationService));
                }
            }

            if (passwordPolicy != null)
            {
                config.RegisterPasswordValidator(new DelegateValidator(
                                                     (svc, acct, password) =>
                {
                    if (!passwordPolicy.ValidatePassword(password))
                    {
                        return(new ValidationResult("Invalid password: " + passwordPolicy.PolicyMessage));
                    }
                    return(null);
                }));
            }
        }
        private static void ConfigureMembershipReboot(IAppBuilder app)
        {
            System.Data.Entity.Database.SetInitializer(new System.Data.Entity.MigrateDatabaseToLatestVersion<DefaultMembershipRebootDatabase, BrockAllen.MembershipReboot.Ef.Migrations.Configuration>());

            var builder = new ContainerBuilder();

            var config = new MembershipRebootConfiguration();
            // just for giggles, we'll use the multi-tenancy to keep
            // client authentication separate from user authentication
            config.MultiTenant = true;
            config.RequireAccountVerification = false;
            
            builder.RegisterInstance(config);

            builder.RegisterType<DefaultUserAccountRepository>()
                .As<IUserAccountRepository>()
                .As<IUserAccountQuery>()
                .InstancePerLifetimeScope();

            builder.RegisterType<UserAccountService>()
                .InstancePerLifetimeScope();

            var container = builder.Build();
            app.Use(async (ctx, next) =>
            {
                using (var scope = container.BeginLifetimeScope())
                {
                    ctx.Environment.SetUserAccountService(() => scope.Resolve<UserAccountService>());
                    await next();
                }
            });

            PopulateTestData(container);
        }
        static UserManagerFactory()
        {
            System.Data.Entity.Database.SetInitializer(new System.Data.Entity.MigrateDatabaseToLatestVersion<DefaultMembershipRebootDatabase, BrockAllen.MembershipReboot.Ef.Migrations.Configuration>());

            config = new MembershipRebootConfiguration();
            config.PasswordHashingIterationCount = 10000;
            config.RequireAccountVerification = false;
        }
        public static MembershipRebootConfiguration<CustomUserAccount> Create()
        {
            var settings = SecuritySettings.Instance;

            var config = new MembershipRebootConfiguration<CustomUserAccount>(settings);

            return config;
        }
        public static MembershipRebootConfiguration CreateMembershipRebootConfiguration()
        {
            var settings = SecuritySettings.Instance;
            settings.MultiTenant = false;

            var config = new MembershipRebootConfiguration(settings, new DelegateFactory(() => new DefaultUserAccountRepository(settings.ConnectionStringName)));
            return config;
        }
        public GroupService(MembershipRebootConfiguration configuration, IGroupRepository groupRepository)
        {
            if (configuration == null) throw new ArgumentNullException("configuration");
            if (groupRepository == null) throw new ArgumentNullException("groupRepository");

            this.configuration = configuration;
            this.groupRepository = groupRepository;
        }
 public IdentityRepository()
 {
     var settings = SecuritySettings.FromConfiguration();
     settings.RequireAccountVerification = false;
     var config = new MembershipRebootConfiguration(settings);
     this.userSvc = new UserAccountService(config, new BrockAllen.MembershipReboot.Ef.DefaultUserAccountRepository());
     this.groupSvc = new GroupService(new BrockAllen.MembershipReboot.Ef.DefaultGroupRepository());
 }
Пример #10
0
 public UserService(App.Common.Data.IRepository<NhUserAccount, Guid> userRepository, NhUserAccountService<NhUserAccount> userAccountService,
     MembershipRebootConfiguration<NhUserAccount> membershipConfiguration,IActivityLogService activityLogService)
 {
     _userRepository = userRepository;
     _userAccountService = userAccountService;
     _activityLogService = activityLogService;
     _membershipConfiguration = membershipConfiguration;
 }
        public static void RegisterPasswordValidator(this MembershipRebootConfiguration config, Func <UserAccountService, UserAccount, string, ValidationResult> func)

        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            config.RegisterPasswordValidator(new DelegateValidator <UserAccount>(func));
        }
        public static void ConfigurePasswordComplexity(this MembershipRebootConfiguration config)

        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            config.RegisterPasswordValidator(new PasswordComplexityValidator <UserAccount>());
        }
        static MembershipRebootUserServiceFactory()
        {
            System.Data.Entity.Database.SetInitializer(new System.Data.Entity.MigrateDatabaseToLatestVersion<DefaultMembershipRebootDatabase, BrockAllen.MembershipReboot.Ef.Migrations.Configuration>());

            config = new MembershipRebootConfiguration();
            config.PasswordHashingIterationCount = 50000;
            config.AllowLoginAfterAccountCreation = true;
            config.RequireAccountVerification = false;
        }
Пример #14
0
 public static void ConfigurePasswordComplexity <TAccount>(this MembershipRebootConfiguration <TAccount> config, int minimumLength, int minimumNumberOfComplexityRules)
     where TAccount : UserAccount
 {
     if (config == null)
     {
         throw new ArgumentNullException("config");
     }
     config.RegisterPasswordValidator(new PasswordComplexityValidator <TAccount>(minimumLength, minimumNumberOfComplexityRules));
 }
Пример #15
0
 public static void RegisterEmailValidator <TAccount>(this MembershipRebootConfiguration <TAccount> config, Func <UserAccountService <TAccount>, TAccount, string, ValidationResult> func)
     where TAccount : UserAccount
 {
     if (config == null)
     {
         throw new ArgumentNullException("config");
     }
     config.RegisterEmailValidator(new DelegateValidator <TAccount>(func));
 }
        public static void ConfigureAspNetCookieBasedTwoFactorAuthPolicy(this MembershipRebootConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            config.ConfigureCookieBasedTwoFactorAuthPolicy(new AspNetCookieBasedTwoFactorAuthPolicy());
        }
Пример #17
0
 public static void AddEventHandler <TAccount, TEvent>(this MembershipRebootConfiguration <TAccount> config, Action <TEvent> action)
     where TAccount : UserAccount
     where TEvent : IEvent
 {
     if (config == null)
     {
         throw new ArgumentNullException("config");
     }
     config.AddEventHandler(new DelegateEventHandler <TEvent>(action));
 }
Пример #18
0
 public static void AddCommandHandler <TAccount, TCommand>(this MembershipRebootConfiguration <TAccount> config, Action <TCommand> action)
     where TAccount : UserAccount
     where TCommand : ICommand
 {
     if (config == null)
     {
         throw new ArgumentNullException("config");
     }
     config.AddCommandHandler(new DelegateCommandHandler <TCommand>(action));
 }
        public static void ConfigureCookieBasedTwoFactorAuthPolicy(this MembershipRebootConfiguration config, CookieBasedTwoFactorAuthPolicy policy)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            config.TwoFactorAuthenticationPolicy = policy;
            config.AddEventHandler(policy);
        }
Пример #20
0
 public static void ConfigureCookieBasedTwoFactorAuthPolicy <TAccount>(this MembershipRebootConfiguration <TAccount> config, CookieBasedTwoFactorAuthPolicy <TAccount> policy)
     where TAccount : UserAccount
 {
     if (config == null)
     {
         throw new ArgumentNullException("config");
     }
     config.TwoFactorAuthenticationPolicy = policy;
     config.AddEventHandler(policy);
 }
 protected override IIdentityManagerService CreateIdentityManager()
 {
     var config = new MembershipRebootConfiguration<TestUserAccount>();
     config.RequireAccountVerification = false;
     config.PasswordHashingIterationCount = 100;
     
     var repository = new TestUserAccountRepository();
     userAccountService = new UserAccountService<TestUserAccount>(config, repository);
     return new IdentityManagerService<TestUserAccount>(userAccountService, repository);
 }
        public UserAccountService(
            IUserAccountRepository userAccountRepository,
            INotificationService notificationService,
            IPasswordPolicy passwordPolicy)
        {
            if (userAccountRepository == null) throw new ArgumentNullException("userAccountRepository");

            var config = new MembershipRebootConfiguration();
            config.FromLegacy(notificationService, passwordPolicy);
            this.InitFromConfiguration(config, userAccountRepository);
        }
        public UserAccountService(MembershipRebootConfiguration configuration, IUserAccountRepository userRepository)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }
            if (userRepository == null)
            {
                throw new ArgumentNullException("userRepository");
            }

            this.Configuration = configuration;

            var validationEventBus = new EventBus();

            validationEventBus.Add(new UserAccountValidator(this));
            this.userRepository = new EventBusUserAccountRepository(userRepository,
                                                                    new AggregateEventBus {
                validationEventBus, configuration.ValidationBus
            },
                                                                    configuration.EventBus);

            this.usernameValidator = new Lazy <AggregateValidator>(() =>
            {
                var val = new AggregateValidator();
                if (!this.SecuritySettings.EmailIsUsername)
                {
                    val.Add(UserAccountValidation.UsernameDoesNotContainAtSign);
                }
                val.Add(UserAccountValidation.UsernameMustNotAlreadyExist);
                val.Add(configuration.UsernameValidator);
                return(val);
            });

            this.emailValidator = new Lazy <AggregateValidator>(() =>
            {
                var val = new AggregateValidator();
                val.Add(UserAccountValidation.EmailIsValidFormat);
                val.Add(UserAccountValidation.EmailMustNotAlreadyExist);
                val.Add(configuration.EmailValidator);
                return(val);
            });

            this.passwordValidator = new Lazy <AggregateValidator>(() =>
            {
                var val = new AggregateValidator();
                val.Add(UserAccountValidation.PasswordMustBeDifferentThanCurrent);
                val.Add(configuration.PasswordValidator);
                return(val);
            });
        }
Пример #24
0
        public GroupService(MembershipRebootConfiguration configuration, IGroupRepository groupRepository)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }
            if (groupRepository == null)
            {
                throw new ArgumentNullException("groupRepository");
            }

            this.configuration   = configuration;
            this.groupRepository = groupRepository;
        }
        public IdentityRepository()
        {
            var settings = SecuritySettings.FromConfiguration();
            settings.RequireAccountVerification = false;
            settings.PasswordHashingIterationCount = 50000;
            var config = new MembershipRebootConfiguration(settings);
            var uarepo = new BrockAllen.MembershipReboot.Ef.DefaultUserAccountRepository();
            this.userSvc = new UserAccountService(config, uarepo);
            this.userQuery = uarepo;

            var grpRepo = new BrockAllen.MembershipReboot.Ef.DefaultGroupRepository();
            this.groupSvc = new GroupService(config.DefaultTenant, grpRepo);
            this.groupQuery = grpRepo;
        }
        void InitFromConfiguration(MembershipRebootConfiguration configuration, IUserAccountRepository userAccountRepository = null)
        {
            this.configuration = configuration;
            this.userRepository =
                new UserAccountRepository(
                    userAccountRepository ?? configuration.CreateUserAccountRepository(), 
                    configuration.EventBus);
            this.securitySettings = configuration.SecuritySettings;

            ConfigureRequiredValidation();
            usernameValidator.Add(configuration.UsernameValidator);
            emailValidator.Add(configuration.EmailValidator);
            passwordValidator.Add(configuration.PasswordValidator);
        }
        static MembershipRebootConfiguration ConfigFromDeprecatedInterfaces(
            IUserAccountRepository userAccountRepository,
            INotificationService notificationService,
            IPasswordPolicy passwordPolicy)
        {
            if (userAccountRepository == null)
            {
                throw new ArgumentNullException("userAccountRepository");
            }

            var config = new MembershipRebootConfiguration(SecuritySettings.Instance, new DelegateFactory(() => userAccountRepository));

            config.FromLegacy(notificationService, passwordPolicy);
            return(config);
        }
        public async Task Invoke(IDictionary<string, object> env)
        {
            var ctx = new OwinContext(env);

            using (var db = new BrockAllen.MembershipReboot.Ef.DefaultUserAccountRepository())
            {
                var settings = SecuritySettings.FromConfiguration();
                var mrConfig = new MembershipRebootConfiguration(settings);
                mrConfig.ConfigureCookieBasedTwoFactorAuthPolicy(new OwinCookieBasedTwoFactorAuthPolicy(env));

                var appInfo = new OwinApplicationInformation(env,
                    "Test", "Test Email Signature",
                    "UserAccount/Login",
                    "UserAccount/Register/Confirm/",
                    "UserAccount/Register/Cancel/",
                    "UserAccount/PasswordReset/Confirm/",
                    "UserAccount/ChangeEmail/Confirm/");

                var emailFormatter = new EmailMessageFormatter(appInfo);
                if (settings.RequireAccountVerification)
                {
                    // uncomment if you want email notifications -- also update smtp settings in web.config
                    //config.AddEventHandler(new EmailAccountCreatedEventHandler(emailFormatter));
                }
                // uncomment if you want email notifications -- also update smtp settings in web.config
                //config.AddEventHandler(new EmailAccountEventsHandler(emailFormatter));

                var uaSvc = new UserAccountService(mrConfig, db);
                var anSvc = new OwinAuthenticationService(uaSvc, env);
                try
                {
                    ctx.SetUserAccountService(uaSvc);
                    ctx.SetAuthenticationService(anSvc);
                    
                    await next(env);
                }
                finally
                {
                    ctx.SetUserAccountService(null);
                    ctx.SetAuthenticationService(null);
                }
            }
        }
        public UserAccountService(MembershipRebootConfiguration configuration, IUserAccountRepository userRepository)
        {
            if (configuration == null) throw new ArgumentNullException("configuration");
            if (userRepository == null) throw new ArgumentNullException("userRepository");
            
            this.Configuration = configuration;

            var validationEventBus = new EventBus();
            validationEventBus.Add(new UserAccountValidator(this));
            this.userRepository = new EventBusUserAccountRepository(userRepository,
                new AggregateEventBus { validationEventBus, configuration.ValidationBus },
                configuration.EventBus);

            this.usernameValidator = new Lazy<AggregateValidator>(()=>
            {
                var val = new AggregateValidator();
                if (!this.SecuritySettings.EmailIsUsername)
                {
                    val.Add(UserAccountValidation.UsernameDoesNotContainAtSign);
                }
                val.Add(UserAccountValidation.UsernameMustNotAlreadyExist);
                val.Add(configuration.UsernameValidator);
                return val;
            });

            this.emailValidator = new Lazy<AggregateValidator>(() =>
            {
                var val = new AggregateValidator();
                val.Add(UserAccountValidation.EmailIsValidFormat);
                val.Add(UserAccountValidation.EmailMustNotAlreadyExist);
                val.Add(configuration.EmailValidator);
                return val;
            });

            this.passwordValidator = new Lazy<AggregateValidator>(() =>
            {
                var val = new AggregateValidator();
                val.Add(UserAccountValidation.PasswordMustBeDifferentThanCurrent);
                val.Add(configuration.PasswordValidator);
                return val;
            });
        }
        private static void ConfigureMembershipReboot(IAppBuilder app)
        {
            System.Data.Entity.Database.SetInitializer(new System.Data.Entity.MigrateDatabaseToLatestVersion<DefaultMembershipRebootDatabase, BrockAllen.MembershipReboot.Ef.Migrations.Configuration>());
            var cookieOptions = new CookieAuthenticationOptions
            {
                AuthenticationType = MembershipRebootOwinConstants.AuthenticationType
            };

            var appInfo = new OwinApplicationInformation(
                app,
                "Test",
                "Test Email Signature",
                "/Login",
                "/Register/Confirm/",
                "/Register/Cancel/",
                "/PasswordReset/Confirm/");

            var config = new MembershipRebootConfiguration();
            var emailFormatter = new EmailMessageFormatter(appInfo);
            // uncomment if you want email notifications -- also update smtp settings in web.config
            config.AddEventHandler(new EmailAccountEventsHandler(emailFormatter));

            Func<IDictionary<string, object>, UserAccountService> uaFunc = env =>
            {
                var svc = new UserAccountService(config, new DefaultUserAccountRepository());
                var debugging = false;
#if DEBUG
                debugging = true;
#endif
                svc.ConfigureTwoFactorAuthenticationCookies(env, debugging);
                return svc;
            };
            Func<IDictionary<string, object>, AuthenticationService> authFunc = env =>
            {
                return new OwinAuthenticationService(cookieOptions.AuthenticationType, uaFunc(env), env);
            };

            app.UseMembershipReboot(cookieOptions, uaFunc, authFunc);
        }
Пример #31
0
        public static MembershipRebootConfiguration Create()
        {
            var settings = SecuritySettings.FromConfiguration();
            var config = new MembershipRebootConfiguration(settings);

            var appinfo = new AspNetApplicationInformation("Test", "Test Email Signature",
                "UserAccount/Login",
                "UserAccount/Register/Confirm/",
                "UserAccount/Register/Cancel/",
                "UserAccount/PasswordReset/Confirm/",
                "UserAccount/ChangeEmail/Confirm/");
            var emailFormatter = new EmailMessageFormatter(appinfo);
            if (settings.RequireAccountVerification)
            {
                // uncomment if you want email notifications -- also update smtp settings in web.config
                //config.AddEventHandler(new EmailAccountCreatedEventHandler(emailFormatter));
            }
            // uncomment if you want email notifications -- also update smtp settings in web.config
            //config.AddEventHandler(new EmailAccountEventsHandler(emailFormatter));
            config.AddEventHandler(new TwilloSmsEventHandler(appinfo));
            config.ConfigureAspNetCookieBasedTwoFactorAuthPolicy();

            return config;
        }
Пример #32
0
        private static MembershipRebootConfiguration CreateMembershipRebootConfiguration(IAppBuilder app)
        {
            var config = new MembershipRebootConfiguration();
            config.EmailIsUsername = true;
            config.RequireAccountVerification = true;
            config.AddEventHandler(new DebuggerEventHandler());

            var appInfo = new OwinApplicationInformation(
                app: app,
                appName: "Test",
                emailSig: "Test Email Signature",
                relativeLoginUrl: "/useraccount/login",
                relativeConfirmChangeEmailUrl: "/useraccount/changeemail/confirm/",
                relativeCancelNewAccountUrl: "/useraccount/register/cancel/",
                relativeConfirmPasswordResetUrl: "/useraccount/passwordreset/confirm/");

            var emailFormatter = new EmailMessageFormatter(appInfo);
            // uncomment if you want email notifications -- also update smtp settings in web.config
            config.AddEventHandler(new EmailAccountEventsHandler(emailFormatter));
            // uncomment to enable SMS notifications -- also update TwilloSmsEventHandler class below
            //config.AddEventHandler(new TwilloSmsEventHandler(appinfo));

            // uncomment to ensure proper password complexity
            //config.ConfigurePasswordComplexity();

            return config;
        }
Пример #33
0
 public UserController()
 {
     _userService = IoC.GetService<IUserService>();
     _roleService = IoC.GetService<IRoleService>();
     _membershipConfiguration = IoC.GetService<MembershipRebootConfiguration<NhUserAccount>>();
 }
Пример #34
0
        private static MembershipRebootConfiguration CreateMembershipRebootConfiguration(IAppBuilder app)
        {
            var appInfo = new OwinApplicationInformation(
                app,
                "Test",
                "Test Email Signature",
                "/Login",
                "/Register/Confirm/",
                "/Register/Cancel/",
                "/PasswordReset/Confirm/");

            var config = new MembershipRebootConfiguration();
            var emailFormatter = new EmailMessageFormatter(appInfo);
            // uncomment if you want email notifications -- also update smtp settings in web.config
            config.AddEventHandler(new EmailAccountEventsHandler(emailFormatter));
            return config;
        }
        static MembershipRebootConfiguration ConfigFromDeprecatedInterfaces(
            IUserAccountRepository userAccountRepository,
            INotificationService notificationService,
            IPasswordPolicy passwordPolicy)
        {
            if (userAccountRepository == null) throw new ArgumentNullException("userAccountRepository");

            var config = new MembershipRebootConfiguration(SecuritySettings.Instance, new DelegateFactory(() => userAccountRepository));
            config.FromLegacy(notificationService, passwordPolicy);
            return config;
        }
 public static MembershipRebootConfiguration Create()
 {
     var settings = SecuritySettings.FromConfiguration();
     var config = new MembershipRebootConfiguration(settings);
     return config;
 }
        private static MembershipRebootConfiguration CreateMembershipRebootConfiguration(IAppBuilder app)
        {
            var config = new MembershipRebootConfiguration();
            config.RequireAccountVerification = false;
            config.AddEventHandler(new DebuggerEventHandler());

            var appInfo = new OwinApplicationInformation(
                app,
                "Test",
                "Test Email Signature",
                "/UserAccount/Login",
                "/UserAccount/ChangeEmail/Confirm/",
                "/UserAccount/Register/Cancel/",
                "/UserAccount/PasswordReset/Confirm/");

            var emailFormatter = new EmailMessageFormatter(appInfo);
            // uncomment if you want email notifications -- also update smtp settings in web.config
            config.AddEventHandler(new EmailAccountEventsHandler(emailFormatter));
            // uncomment to enable SMS notifications -- also update TwilloSmsEventHandler class below
            //config.AddEventHandler(new TwilloSmsEventHandler(appinfo));

            // uncomment to ensure proper password complexity
            //config.ConfigurePasswordComplexity();
            
            return config;
        }
 public UserAccountService(MembershipRebootConfiguration configuration)
 {
     InitFromConfiguration(configuration);
 }