Exemple #1
0
        /// <summary>
        /// Handles the AuthenticateRequest event of the Application control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            var authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];

            if (authCookie != null)
            {
                try
                {
                    var authTicket = FormsAuthentication.Decrypt(authCookie.Value);
                    if (authTicket != null)
                    {
                        var identity  = new GenericIdentity(authTicket.Name, "Forms");
                        var roles     = authTicket.UserData.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToArray();
                        var principal = new GenericPrincipal(identity, roles);
                        Context.User = principal;
                    }
                }
                catch
                {
                    Session.Clear();
                    FormsAuthentication.SignOut();
                }
            }

            cmsHost.OnAuthenticateRequest(this);
        }
Exemple #2
0
        /// <summary>
        /// Handles the AuthenticateRequest event of the Application control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            // Users module covers it:

            //var authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
            //var roleCokie = Request.Cookies[Roles.CookieName];

            //if (authCookie != null)
            //{
            //    try
            //    {
            //        var authTicket = FormsAuthentication.Decrypt(authCookie.Value);
            //        if (authTicket != null)
            //        {
            //            var identity = new FormsIdentity(authTicket);
            //            var principal = roleCokie == null ? new RolePrincipal("BetterCmsRoleProvider", identity) : new RolePrincipal(identity, roleCokie.Value);
            //            Context.User = principal;
            //        }
            //    }
            //    catch
            //    {
            //        Session.Clear();
            //        FormsAuthentication.SignOut();
            //    }
            //}

            cmsHost.OnAuthenticateRequest(this);
        }
Exemple #3
0
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            var roles = new[] { "BcmsEditContent",
                                "BcmsPublishContent", "BcmsDeleteContent", "BcmsAdministration" };

            var principal = new GenericPrincipal(new GenericIdentity("TestUser"), roles);

            HttpContext.Current.User = principal;

            cmsHost.OnAuthenticateRequest(this);
        }
Exemple #4
0
        /// <summary>
        /// Handles the AuthenticateRequest event of the Application control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            // Users module covers it:

            //var authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
            //var roleCokie = Request.Cookies[Roles.CookieName];

            //if (authCookie != null)
            //{
            //    try
            //    {
            //        var authTicket = FormsAuthentication.Decrypt(authCookie.Value);
            //        if (authTicket != null)
            //        {
            //            var identity = new FormsIdentity(authTicket);
            //            var principal = roleCokie == null ? new RolePrincipal("BetterCmsRoleProvider", identity) : new RolePrincipal(identity, roleCokie.Value);
            //            Context.User = principal;
            //        }
            //    }
            //    catch
            //    {
            //        Session.Clear();
            //        FormsAuthentication.SignOut();
            //    }
            //}

            // Super simple example how to force deleted user reauthentication.
            if (User != null && usersToForceRelogin.Contains(User.Identity.Name))
            {
                if (HttpContext.Current.Session != null)
                {
                    HttpContext.Current.Session.Clear();
                }

                if (Roles.Enabled)
                {
                    Roles.DeleteCookie();
                }

                if (FormsAuthentication.IsEnabled)
                {
                    FormsAuthentication.SignOut();
                }

                Response.Redirect(FormsAuthentication.LoginUrl);
            }

            cmsHost.OnAuthenticateRequest(this);
        }
Exemple #5
0
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            // [YOUR CODE]

            // Uncomment following source code for a quick Better CMS test if you don't have implemented users authentication.
            // Do not use this code for production!

            /*
             * var roles = new[] { "BcmsEditContent", "BcmsPublishContent", "BcmsDeleteContent", "BcmsAdministration" };
             * var principal = new GenericPrincipal(new GenericIdentity("TestUser"), roles);
             * HttpContext.Current.User = principal;
             */

            cmsHost.OnAuthenticateRequest(this);
        }
Exemple #6
0
        protected void Application_AuthenticateRequest()
        {
            using (var container = ContextScopeProvider.CreateChildContainer())
            {
                var installService = container.Resolve <IInstallService>();

                var dbShouldBeSet = installService.ShoulDatabaseBeSet();

                if (!dbShouldBeSet)
                {
                    cmsHost.OnAuthenticateRequest(this);
                }
                else
                {
                    installService.NavigateToDatabaseSetup();
                }
            }
        }