Beispiel #1
0
        protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
        {
            if (FormsAuthentication.CookiesSupported == true)
            {
                var cookie = Request.Cookies[FormsAuthentication.FormsCookieName];
                if (cookie != null)
                {
                    try
                    {
                        //let us take out the username now
                        string username = FormsAuthentication.Decrypt(cookie.Value).Name;

                        //let us extract the roles from our own custom cookie
                        List <string> roles;
                        using (var helper = new DbHelper.CustomAccount())
                        {
                            roles = helper.GetUserRoles(username);
                        }

                        //Let us set the Pricipal with our user specific details
                        e.User = new System.Security.Principal.GenericPrincipal(
                            new System.Security.Principal.GenericIdentity(username, "Forms"), roles.ToArray());
                    }
                    catch (Exception)
                    {
                        //somehting went wrong
                    }
                }
            }
        }
Beispiel #2
0
        public void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
        {
            HttpCookie authCookie = Context.Request.Cookies[FormsAuthentication.FormsCookieName];

            if (authCookie == null || authCookie.Value == "")
            {
                return;
            }

            FormsAuthenticationTicket authTicket;

            try
            {
                authTicket = FormsAuthentication.Decrypt(authCookie.Value);
            }
            catch
            {
                return;
            }

            // retrieve roles from UserData
            Kullanicilar userData = JsonConvert.DeserializeObject <Kullanicilar>(authTicket.UserData);

            if (Context.User != null)
            {
                Context.User = new LibraryPrinciple(Context.User.Identity, userData);
            }
        }
Beispiel #3
0
        protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
        {
            if (FormsAuthentication.CookiesSupported)
            {
                if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    try
                    {
                        //let us take out the username now
                        var formsAuthenticationTicket = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value);
                        if (formsAuthenticationTicket != null)
                        {
                            string username = formsAuthenticationTicket.Name;//Cpf
                            string roles    = string.Empty;

                            var bll     = new UsuariosBll();
                            var usuario = bll.GetObject(username);

                            roles = usuario.Perfil.Nome;

                            //Let us set the Pricipal with our user specific details
                            e.User = new System.Security.Principal.GenericPrincipal(
                                new System.Security.Principal.GenericIdentity(username, "Forms"), roles.Split(';'));
                        }
                    }
                    catch (Exception)
                    {
                        //somehting went wrong
                    }
                }
            }
        }
 protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
 {
     if ((e.Context.Request.Url.AbsolutePath.ToLower().IndexOf("/content") != -1) || (e.Context.Request.Url.AbsolutePath.ToLower().IndexOf("/bundles") != -1))
     {
         e.Context.SkipAuthorization = true;
     }
 }
Beispiel #5
0
        protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
        {
            if (FormsAuthentication.CookiesSupported == true)
            {
                if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    try
                    {
                        string id     = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
                        int    userid = int.Parse(id);

                        DataLayer dal  = new DataLayer();
                        User      user = (from users in dal.Users where users.UserId == userid select users).ToList <User>()[0];

                        if (user.Admin)
                        {
                            string[] roles = { "admin" };
                            e.User = new System.Security.Principal.GenericPrincipal(
                                new System.Security.Principal.GenericIdentity(id, "Forms"), roles);
                        }
                    }
                    catch (Exception exp)
                    {
                        throw exp;
                    }
                }
            }
        }
Beispiel #6
0
        protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
        {
            if (FormsAuthentication.CookiesSupported == true)
            {
                if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    try
                    {
                        var cookie = Context.Request.Cookies[FormsAuthentication.FormsCookieName];

                        FormsAuthenticationTicket ticket;
                        try
                        {
                            ticket = FormsAuthentication.Decrypt(cookie.Value);
                        }
                        catch
                        {
                            return;
                        }

                        var roles = ticket.UserData.Split(';');

                        if (Context.User != null)
                        {
                            Context.User = new GenericPrincipal(Context.User.Identity, roles);
                        }
                        e.User = new GenericPrincipal(new GenericIdentity(ticket.Name, "Forms"), ticket.UserData.Split(';'));
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
        /// <summary>
        /// Authentication logic retrieves list of roles from database and adds to principal
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
        {
            if (FormsAuthentication.CookiesSupported == true)
            {
                if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    try
                    {
                        //Obtaining username from cookie
                        string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
                        string roles    = string.Empty;

                        using (UserDbContext entities = new UserDbContext())
                        {
                            User user = entities.Users.SingleOrDefault(u => u.userName == username);
                            roles = user.Role.roleName;
                        }
                        //Extracting roles from database


                        //Setting principal with user specific details
                        e.User = new System.Security.Principal.GenericPrincipal(
                            new System.Security.Principal.GenericIdentity(username, "Forms"), roles.Split(';'));
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
        protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
        {
            if (FormsAuthentication.CookiesSupported)
            {
                if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    try
                    {
                        //let us take out the username now
                        var ticket = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value);
                        if (ticket != null)
                        {
                            string username = ticket.Name;
                            //string roles = ticket.UserData;

                            var userData = MZHelperSerialize.Deserialize <UserDataDTO>(ticket.UserData);

                            var roles = userData.Roles;

                            //Let us set the Pricipal with our user specific details
                            e.User = new System.Security.Principal.GenericPrincipal(
                                new System.Security.Principal.GenericIdentity(username, "Forms"), roles.Split(';'));
                        }
                    }
                    catch
                    {
                        FormsAuthentication.SignOut();
                        //somehting went wrong
                    }
                }
            }
        }
Beispiel #9
0
        public void FormsAuthentication_OnAuthenticate(object sender, FormsAuthenticationEventArgs args)
        {
            if (!FormsAuthentication.CookiesSupported)
            {
                throw new HttpException("Cookieless Forms Authentication is not " +
                                        "supported for this application.");
            }
            if (Request.Cookies[FormsAuthentication.FormsCookieName] == null)
            {
                return;
            }
            try {
                var ticket = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value);
                if (ticket == null)
                {
                    return;
                }

                //
                //                if (HasApplicationVersionChangedSinceCookieIssued(ticket)) {
                //                    //if the cookie was setted on a different system version, if though it might still be valid, let´s force a new login
                //                    return; // Not authorised
                //                }
                if (ticket.Expiration < DateTime.Now)
                {
                    FormsAuthentication.SignOut();
                    throw new HttpResponseException(HttpStatusCode.Unauthorized);
                }
            } catch {
                //error handling
            }
        }
Beispiel #10
0
        protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
        {
            if (FormsAuthentication.CookiesSupported != true)
            {
                return;
            }
            if (Request.Cookies[FormsAuthentication.FormsCookieName] == null)
            {
                return;
            }
            try
            {
                //let us take out the username now
                string email = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
                string roles = string.Empty;



                using (DataContext entities = new DataContext())
                {
                    User user = entities.User.SingleOrDefault(u => u.email == email);

                    roles = user.roles.First(m => m.id == user.id).role.name;//user.Roles;
                }
                //Let us set the Pricipal with our user specific details
                e.User = new System.Security.Principal.GenericPrincipal(
                    new System.Security.Principal.GenericIdentity(email, "Forms"), roles.Split(';'));
            }
            catch (Exception)
            {
                //somehting went wrong
            }
        }
 protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
 {
     if (FormsAuthentication.CookiesSupported == true)
     {
         if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
         {
             try
             {
                 var        context    = System.Web.HttpContext.Current;
                 var        request    = System.Web.HttpContext.Current.Request;
                 HttpCookie authCookie = request.Cookies[FormsAuthentication.FormsCookieName];
                 if (authCookie != null)
                 {
                     FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
                     var roles = authTicket.UserData.Split('|');
                     var user  = new GenericPrincipal(new GenericIdentity(authTicket.Name, "Forms"), roles);
                     e.User = context.User = Thread.CurrentPrincipal = user;
                     UserSession.UpdateCurrentUser("", authTicket.Name);
                 }
             }
             catch (Exception)
             {
                 //somehting went wrong
             }
         }
     }
 }
Beispiel #12
0
        protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
        {
            if (FormsAuthentication.CookiesSupported == true)
            {
                if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    try
                    {
                        //let us take out the username now
                        string accountName = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
                        string roles       = string.Empty;

                        using (DatabaseConnection db = new DatabaseConnection())
                        {
                            Accounts account = db.Accounts.SingleOrDefault(u => u.accountName == accountName);

                            roles = account.accountRole;
                        }
                        //let us extract the roles from our own custom cookie


                        //Let us set the Pricipal with our user specific details
                        e.User = new System.Security.Principal.GenericPrincipal(
                            new System.Security.Principal.GenericIdentity(accountName, "Forms"), roles.Split(';'));
                    }
                    catch (Exception)
                    {
                        //somehting went wrong
                    }
                }
            }
        }
Beispiel #13
0
        protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
        {
            if (FormsAuthentication.CookiesSupported == true)
            {
                if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    try
                    {
                        //let us take out the username now
                        string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
                        string roles    = string.Empty;
                        //var json = "{\"users\":[{\"username\":\"user 1\", \"password\":\"password1\",\"roles\":\"admin\"},{\"username\":\"user 2\", \"password\":\"password2\",\"roles\":\"user\"},{\"username\":\"user 3\", \"password\":\"password3\",\"roles\":\"user\"}]}";
                        var users = Utility.ReadJSONFile(Server.MapPath(@"~/Models/user.json"));
                        //var users = JsonConvert.DeserializeObject<Users>(json);
                        User user = users.users.SingleOrDefault(u => u.username == username);
                        roles = user.roles.ToString();
                        //let us extract the roles from our own custom cookie


                        //Let us set the Pricipal with our user specific details
                        e.User = new System.Security.Principal.GenericPrincipal(
                            new System.Security.Principal.GenericIdentity(username, "Forms"), roles.Split(';'));
                    }
                    catch (Exception)
                    {
                        //somehting went wrong
                    }
                }
            }
        }
Beispiel #14
0
        protected void FormsAuthentication_OnAuthenticate(object sender, FormsAuthenticationEventArgs args)
        {
            HttpRequest  request              = args.Context.Request;
            HttpResponse response             = args.Context.Response;
            HttpCookie   authenticationCookie = request.Cookies[FormsAuthentication.FormsCookieName];

            // Anybody logged in?
            if (authenticationCookie != null)
            {
                // Check that the user has a valid account and if so update their last login time.
                FormsAuthenticationTicket ticket = null;
                try
                {
                    ticket = FormsAuthentication.Decrypt(authenticationCookie.Value);
                }
                catch (Exception ex)
                {
                    ticket = null;
                }

                // Does the cookie contain a valid cookie?
                if (ticket != null)
                {
                    // Are we dealing with an old cookie, the expiry of which is not the same as the timeout period in the settings?
                    // If so, update the cookie with the new settings
                    if ((ticket.Expiration - ticket.IssueDate) != FormsAuthentication.Timeout)
                    {
                        // Create new cookie with new settings
                        HttpCookie newCookie = FormsAuthentication.GetAuthCookie(ticket.Name, ticket.IsPersistent);

                        // Copy over the current user data
                        FormsAuthenticationTicket newTicket = FormsAuthentication.Decrypt(newCookie.Value);
                        newTicket = new FormsAuthenticationTicket(newTicket.Version, newTicket.Name, newTicket.IssueDate, newTicket.Expiration, newTicket.IsPersistent, ticket.UserData);

                        // Update the cookie and add it to request
                        newCookie.Value = FormsAuthentication.Encrypt(newTicket);
                        response.Cookies.Add(newCookie);
                    }

                    // Check the user's state every day
                    DateTime now = DateTime.UtcNow.AddMinutes(10); // 10 minutes error buffer
                    if (ticket.Expired || (ticket.Expiration.ToUniversalTime() - now) <= (now - ticket.IssueDate.ToUniversalTime()))
                    {
                        WebSite.Models.User user = WebSite.Helpers.Authentication.Authentication.GetCurrentUser();

                        if (user != null)
                        {
                            // Update the user's last login time
                            IDatabaseContext database = System.Web.Mvc.DependencyResolver.Current.GetService <DatabaseContext>();

                            if (database != null)
                            {
                                user.LastLoginDate = DateTime.UtcNow;
                                database.SaveChanges();
                            }
                        }
                    }
                }
            }
        }
Beispiel #15
0
        protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
        {
            if (FormsAuthentication.CookiesSupported == true)
            {
                if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    try
                    {
                        //let us take out the username now
                        string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
                        string roles    = string.Empty;

                        using (dbEntities entities = new dbEntities())
                        {
                            Academico user = entities.AcademicoSet.Where(a => a.Email == username).First();
                            //pega o nome da classe pelo proxy e coloca como role
                            roles = ObjectContext.GetObjectType(user.GetType()).Name + ";";
                        }
                        //let us extract the roles from our own custom cookie


                        //Let us set the Pricipal with our user specific details
                        e.User = new System.Security.Principal.GenericPrincipal(new System.Security.Principal.GenericIdentity(username, "Forms"), roles.Split(';'));
                    }
                    catch (Exception)
                    {
                        //somehting went wrong
                    }
                }
            }
        }
Beispiel #16
0
        protected void FormsAuthentication_OnAuthenticate(object sender, FormsAuthenticationEventArgs e)
        {
            if (!FormsAuthentication.CookiesSupported)
            {
                return;
            }
            if (Request.Cookies[FormsAuthentication.FormsCookieName] == null)
            {
                return;
            }

            try
            {
                var formsAuthenticationTicket = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value);
                if (formsAuthenticationTicket == null)
                {
                    return;
                }
                var userId = formsAuthenticationTicket.Name;
                e.User = new GenericPrincipal(new GenericIdentity(userId, "Forms"), new[] { "" });
            }
            catch (Exception)
            {
            }
        }
Beispiel #17
0
        protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
        {
            if (FormsAuthentication.CookiesSupported == true)
            {
                if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    try
                    {
                        //let us take out the username now
                        string username   = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
                        string signInType = "";

                        if (Request.Cookies["UserCookie"] != null)
                        {
                            var cookie = Request.Cookies["UserCookie"];
                            signInType = ClassHashing.basicDecryption(cookie.Values["SignInType"].ToString());
                        }


                        //let us extract the roles from our own custom cookie
                        string roles = UserVerification.GetUserRoles(username, signInType);

                        //Let us set the Pricipal with our user specific details
                        e.User = new System.Security.Principal.GenericPrincipal(
                            new System.Security.Principal.GenericIdentity(username, "Forms"), roles.Split(';'));
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.ToString());
                    }
                }
            }
        }
Beispiel #18
0
        protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
        {
            if (FormsAuthentication.CookiesSupported == true)

            {
                if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    try
                    {
                        string token = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
                        string roles = string.Empty;

                        // token = (string) Session["token"];
                        UserModel user = APIAccount.GetUserProfile(token, out string error);
                        roles = ConUser.CovertRoletoRoleString(user.Role);

                        if (user != null && token != null)
                        {
                        }

                        e.User = new System.Security.Principal.GenericPrincipal(
                            new System.Security.Principal.GenericIdentity(user.Fullname, "Forms"), roles.Split(';'));
                    }
                    catch (Exception)
                    {
                        var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);
                        Response.Redirect(urlHelper.Action("Login", "Account"));
                    }
                }
            }
        }
Beispiel #19
0
        protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
        {
            if (FormsAuthentication.CookiesSupported == true)
            {
                if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    //MessageBox.Show("Test");
                    try
                    {
                        //let us take out the username now
                        string email = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
                        string roles = string.Empty;
                        var    db    = new WebShopEntities1();
                        User   user  = db.User.First(x => x.Email == email);
                        roles += user.Uloga1.Naziv;
                        //using (var db = new WebShopEntities1())
                        //{
                        //    User user = db.User.SingleOrDefault(u => u.Email == email);
                        //    roles += user.Uloga1.Naziv + ";";

                        //}
                        HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(new System.Security.Principal.GenericIdentity(email, "Forms"), roles.Split(';'));
                    }
                    catch (Exception)
                    {
                        //somehting went wrong
                    }
                }
            }
        }
        protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
        {
            if (FormsAuthentication.CookiesSupported == true)
            {
                if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    try
                    {
                        //let us take out the username now
                        string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
                        //string Password =
                        string roles = string.Empty;

                        using (StabileLawFirmEntities entities = new StabileLawFirmEntities())
                        {
                            var user = entities.STtblUsers.SingleOrDefault(u => u.UserName == username);
                            roles = Convert.ToString(user.tblUserRoleId);
                        }
                        //let us extract the roles from our own custom cookie


                        //Let us set the Pricipal with our user specific details
                        e.User = new System.Security.Principal.GenericPrincipal(
                            new System.Security.Principal.GenericIdentity(username, "Forms"), roles.Split(';'));
                    }
                    catch (Exception)
                    {
                        //somehting went wrong
                    }
                }
            }
        }
Beispiel #21
0
        protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
        {
            if (FormsAuthentication.CookiesSupported == true)
            {
                if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    try
                    {
                        //let us take out the username now
                        string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;

                        if (string.IsNullOrEmpty(username))
                        {
                            //Let us set the Pricipal with our user specific details
                            e.User = new System.Security.Principal.GenericPrincipal(
                                new System.Security.Principal.GenericIdentity(username, "Forms"), new string[] { "User" });
                        }
                    }
                    catch (Exception)
                    {
                        //somehting went wrong
                    }
                }
            }
        }
Beispiel #22
0
        public void FormsAuthentication_OnAuthenticate(object sender, FormsAuthenticationEventArgs args)
        {
            HttpCookie authCookie = Context.Request.Cookies[FormsAuthentication.FormsCookieName];

            if (authCookie != null)
            {
                FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
                string[] userDataTokens          = ticket.UserData.Split(new string[] { ";;" }, StringSplitOptions.RemoveEmptyEntries);

                LaunchKeyIdentity identity = new LaunchKeyIdentity(ticket.Name, userDataTokens[0], userDataTokens[1]);

                // verify user hasn't de-orbited
                var lkClient     = LaunchKeyClientFactory.GetInstanceFromConfig();
                var pollResponse = lkClient.Poll(identity.AuthRequest);

                if (lkClient.IsAuthorized(identity.AuthRequest, pollResponse))
                {
                    args.User = new GenericPrincipal(identity, null);
                }
                else
                {
                    // unset cookie
                    FormsAuthentication.SignOut();
                    lkClient.Logout(identity.AuthRequest);
                    Context.Response.Redirect("~");
                }
            }
        }
Beispiel #23
0
        protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
        {
            if (FormsAuthentication.CookiesSupported == true)
            {
                if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    //MessageBox.Show("Test");
                    try
                    {
                        //let us take out the username now
                        string email = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
                        string roles = string.Empty;
                        var    db    = new knjiznicaEntities();
                        Clan   user  = db.Clan.First(x => x.Email == email);
                        roles += user.Role.Uloga;

                        HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(new System.Security.Principal.GenericIdentity(email, "Forms"), roles.Split(';'));
                    }
                    catch (Exception)
                    {
                        //somehting went wrong
                    }
                }
            }
        }
Beispiel #24
0
        protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
        {
            if (FormsAuthentication.CookiesSupported == true)
            {
                if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    try
                    {
                        //let us take out the username now
                        string Email = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
                        string roles = string.Empty;


                        Trainee Loginemployee = JsonConvert.DeserializeObject <Trainee>(Email);
                        roles = Loginemployee.UserRoles;
                        //let us extract the roles from our own custom cookie
                        //Let us set the Pricipal with our user specific details
                        e.User = new System.Security.Principal.GenericPrincipal(
                            new System.Security.Principal.GenericIdentity(Email, "Forms"), roles.Split(';'));
                    }
                    catch (Exception)
                    {
                        //somehting went wrong
                    }
                }
            }
        }
 protected void FormsAuthentication_OnAuthenticate(object sender, FormsAuthenticationEventArgs e)
 {
     if (FormsAuthentication.CookiesSupported)
     {
         if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
         {
             try
             {
                 string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
                 string role     = string.Empty;
                 using (ContactBookDb db = new ContactBookDb())
                 {
                     var account = db.Accounts.FirstOrDefault(x => x.AccountName == username && x.AccountActive == true);
                     role = account.AccountRole;
                 }
                 e.User = new System.Security.Principal.GenericPrincipal(
                     new System.Security.Principal.GenericIdentity(username, "Forms"), role.Split(';'));
             }
             catch (Exception)
             {
                 throw;
             }
         }
     }
 }
Beispiel #26
0
        //Lay role de authorize
        protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs evt)
        {
            if (FormsAuthentication.CookiesSupported == true)
            {
                if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    try
                    {
                        //Lay username ra
                        string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
                        string roles    = string.Empty;

                        //Lay role cua username
                        using (RSMEntities entities = new RSMEntities())
                        {
                            User user = entities.Users.SingleOrDefault(u => u.Username.Equals(username));
                            roles = user.Role.RoleName;
                        }

                        //Set Role vao, sau nay co the authorize bang annotation
                        evt.User = new System.Security.Principal.GenericPrincipal(
                            new System.Security.Principal.GenericIdentity(username, "Forms"), roles.Split(';'));
                    }
                    catch (Exception ex)
                    {
                        SimpleLog.Error(ex.Message);
                    }
                }
            }
        }
Beispiel #27
0
        protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
        {
            if (FormsAuthentication.CookiesSupported == true)
            {
                if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    try
                    {
                        //let us take out the username now
                        string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
                        string roles    = string.Empty;

                        //let us extract the roles from our own custom cookie
                        #region NopCommerce
                        using (AuthRepository _repo = new AuthRepository())
                        {
                            roles = _repo.FindNopCommerceUserRoles(username);
                            //Let us set the Pricipal with our user specific details
                            e.User = new System.Security.Principal.GenericPrincipal(
                                new System.Security.Principal.GenericIdentity(username, "Forms"), roles.Split(';'));
                        }
                        #endregion NopCommerce
                    }
                    catch (Exception)
                    {
                        //somehting went wrong
                    }
                }
            }
        }
Beispiel #28
0
        protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
        {
            if (FormsAuthentication.CookiesSupported == true)
            {
                if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    try
                    {
                        //let us take out the username now
                        string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
                        string roles    = string.Empty;


                        Utilizador user = db.Utilizadors.SingleOrDefault(u => u.Username == username);

                        //roles = user.Roles;
                        //let us extract the roles from our own custom cookie


                        //Let us set the Pricipal with our user specific details
                        e.User = new System.Security.Principal.GenericPrincipal(
                            new System.Security.Principal.GenericIdentity(username, "Forms"), roles.Split(';'));
                    }
                    catch (Exception)
                    {
                        //somehting went wrong
                    }
                }
            }
        }
Beispiel #29
0
        protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
        {
            if (FormsAuthentication.CookiesSupported == true)
            {
                if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    try
                    {
                        //let us take out the username now
                        string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
                        //let us extract the roles from our own custom cookie
                        HttpCookie cookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];

                        if (cookie != null)
                        {
                            FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);

                            if (ticket != null && !ticket.Expired)
                            {
                                var roles = ticket.UserData.Split(',');

                                //Let us set the Pricipal with our user specific details
                                e.User = new System.Security.Principal.GenericPrincipal(
                                    new System.Security.Principal.GenericIdentity(username, "Forms"), roles);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        var message = ex.Message;
                    }
                }
            }
        }
Beispiel #30
0
 // https://www.codeproject.com/Articles/578374/AplusBeginner-splusTutorialplusonplusCustomplusF
 protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e)
 {
     if (FormsAuthentication.CookiesSupported == true)
     {
         if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
         {
             try
             {
                 string             id   = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
                 string             role = "";
                 Account            account;
                 IAccountRepository repository = new AccountRepository(new DBHF());
                 account = repository.GetAccount(id);
                 if (account.GetType() == typeof(Employee))
                 {
                     Employee employee = (Employee)account;
                     role = employee.EmployeeType.ToString();
                     HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(new System.Security.Principal.GenericIdentity(id, "Forms"), (new string[] { role }));
                 }
             }
             catch (Exception ex)
             {
                 ex.GetType();
             }
         }
     }
 }
    public static void FormsAuthentication_OnAuthenticate(object sender, FormsAuthenticationEventArgs args)
    {
        if (FormsAuthentication.CookiesSupported)
        {
            if (HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName] != null)
            {
                try
                {
                    FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName].Value);

                    args.User = App.Model.User.GetPrincipal(ticket);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
        else
        {
            throw new HttpException("Cookieless Forms Authentication is not " +
                                    "supported for this application.");
        }
    }