Esempio n. 1
0
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            string debugMode = ConfigurationManager.AppSettings["debugMode"];

            if (debugMode == "true")
            {
                GenericIdentity testIdentity = new GenericIdentity(@"textile\jsucco");
                string[]        groups       = { "Admin" };
                HttpContext.Current.User = new GenericPrincipal(testIdentity, groups);

                Helpers.AdminService service = new Helpers.AdminService();

                service.AddAdmin(new Models.AdminsGridView()
                {
                    Address = "test",
                    Status  = false
                });

                return;
            }

            //if (HttpContext.Current.Request.Url.AbsolutePath.Contains("api"))
            //{
            //    return;
            //}

            HttpCookie authcookie = Request.Cookies[FormsAuthentication.FormsCookieName];

            if (authcookie == null)
            {
                UnAuthorized();
                return;
            }

            try
            {
                FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authcookie.Value);

                if (ticket != null)
                {
                    string[] groups = { "" };
                    HttpContext.Current.User = new GenericPrincipal(new FormsIdentity(ticket), groups);

                    if (!ValidateAdminPriv())
                    {
                        RedirectToMenu();
                    }
                }
                else
                {
                    UnAuthorized();
                }
            }
            catch (Exception ex)
            {
                UnAuthorized();
            }
        }
Esempio n. 2
0
        private bool ValidateAdminPriv()
        {
            string debugMode = ConfigurationManager.AppSettings["debugMode"];

            if (debugMode == "true")
            {
                return(true);
            }

            HttpCookie authcookie = Request.Cookies[FormsAuthentication.FormsCookieName];

            if (authcookie == null)
            {
                RedirectToMenu();
            }

            FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authcookie.Value);

            if (ticket == null)
            {
                RedirectToMenu();
            }

            Helpers.AdminService service = new Helpers.AdminService();

            service.AddAdmin(new Models.AdminsGridView()
            {
                Address = ticket.Name,
                Status  = false
            });

            HashSet <string> admins = service.GetAdminHash();

            var rawUserName = service.ParseRawUserName(ticket.Name);

            if (admins.Contains(rawUserName.ToUpper()))
            {
                Session["username"] = rawUserName;
                return(true);
            }


            return(false);
        }