Exemplo n.º 1
0
        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" });
                }

            }
        }
Exemplo n.º 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);
            }
        }
        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))));
        }