private void CheckForCoreData(IDocumentStore ds, IContext context) { // In case the versioning bundle is installed, make sure it will version // only what we opt-in to version using (IDocumentSession s = ds.OpenSession()) { var store = new FlexMembershipUserStore<User, Role>(s); var membership = new FlexMembershipProvider<User>(store, new AspnetEnvironment()); var roles = new FlexRoleProvider(store); if (!membership.HasLocalAccount("sallen")) { membership.CreateAccount(new User { Username = "******", Password = "******", FavoriteNumber = 24 }); } if (!roles.RoleExists("admin")) { roles.CreateRole("admin"); } if (!roles.IsUserInRole("sallen", "admin")) { roles.AddUsersToRoles(new[] { "sallen" }, new[] { "admin" }); } } }
public void OnAuthorization(AuthorizationContext filterContext) { var user = filterContext.HttpContext.User; if (!user.Identity.IsAuthenticated) { HandleUnauthorizedRequest(filterContext); return; } if (_usersSplit.Length > 0) { if (_usersSplit.Contains(user.Identity.Name, StringComparer.OrdinalIgnoreCase)) { return; } } if (_rolesSplit.Length > 0) { RoleProvider = new FlexRoleProvider(new RoleRepository<MjrAppRole, User>()); if (_rolesSplit.Any(role => RoleProvider.IsUserInRole(user.Identity.Name, role))) { return; } } if (_rolesSplit.Length > 0 || _usersSplit.Length > 0) { HandleUnauthorizedRequest(filterContext); } }
public IntegrationTest() { var context = new SomeDb("name=Default"); _db = new TestDb(); UserStore = new UserStore(context); RoleStore = new RoleStore(context); Environment = new FakeApplicationEnvironment(); RoleProvider = new FlexRoleProvider(RoleStore); MembershipProvider = new FlexMembershipProvider(UserStore, Environment); }
protected override bool AuthorizeCore(System.Web.HttpContextBase httpContext) { //todo: this is not pretty since this project should not know about these things at all... consider DI so the project using this project will be the one sending in whats needed EvercateContext efcontext = new EvercateContext("EvercateConnection"); IFlexRoleProvider roleProvider = new FlexRoleProvider(new FlexRoleStore<Role, User>(efcontext)); return !_isHandlerDisabled && (!_requiresAuthentication || (httpContext.Request.IsAuthenticated && _allowedRoles.Any(r => r == "*" || roleProvider.IsUserInRole(httpContext.User.Identity.Name, r, null)))); //httpContext.User.IsInRole(r)))); }
public IntegrationTest() { DocumentStore = new EmbeddableDocumentStore() { RunInMemory = true }; DocumentStore.Conventions.DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites; DocumentStore.Initialize(); UserStore = new FlexMembershipUserStore<User, Role>(DocumentStore); Environment = new FakeApplicationEnvironment(); RoleProvider = new FlexRoleProvider(UserStore); MembershipProvider = new FlexMembershipProvider(UserStore, Environment); }
public IntegrationTest() { DocumentStore = new EmbeddableDocumentStore() { RunInMemory = true , UseEmbeddedHttpServer = true }; DocumentStore.RegisterListener(new NoStaleQueries()); DocumentStore.Initialize(); Session = DocumentStore.OpenSession(); UserStore = new FlexMembershipUserStore<User, Role>(Session); Environment = new FakeApplicationEnvironment(); RoleProvider = new FlexRoleProvider(UserStore); MembershipProvider = new FlexMembershipProvider(UserStore, Environment); }