コード例 #1
0
ファイル: RavenModule.cs プロジェクト: OdeToCode/Memflex
        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" });
                }

            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
ファイル: IntegrationTest.cs プロジェクト: KennyBu/Memflex
 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);
 }
コード例 #4
0
        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))));
        }
コード例 #5
0
ファイル: IntegrationTest.cs プロジェクト: aknuds1/Memflex
 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);
 }
コード例 #6
0
 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);
 }