/// <summary>
 /// Clear out everything except the admin user
 /// </summary>
 private void DoFullReset()
 {
     foreach (var repository in Repository.GetAllRepositories())
     {
         Repository.Delete(repository.Id);
     }
     foreach (var team in TeamRepository.GetAllTeams())
     {
         TeamRepository.Delete(team.Id);
     }
     foreach (var user in Users.GetAllUsers())
     {
         if (!user.Username.Equals("Admin", StringComparison.OrdinalIgnoreCase))
         {
             Users.DeleteUser(user.Id);
         }
     }
     foreach (var role in RoleProvider.GetAllRoles())
     {
         if (role != Definitions.Roles.Administrator)
         {
             RoleProvider.DeleteRole(role, true);
         }
     }
 }
Exemplo n.º 2
0
        public ActionResult Edit(Guid id)
        {
            if (id != User.Id() && !User.IsInRole(Definitions.Roles.Administrator))
            {
                return(RedirectToAction("Unauthorized", "Home"));
            }

            if (MembershipService.IsReadOnly())
            {
                return(RedirectToAction("Detail", "Account", new { id = id }));
            }

            var user = MembershipService.GetUserModel(id);

            if (user != null)
            {
                var model = new UserEditModel
                {
                    Id            = user.Id,
                    Username      = user.Username,
                    Name          = user.GivenName,
                    Surname       = user.Surname,
                    Email         = user.Email,
                    Roles         = RoleProvider.GetAllRoles(),
                    SelectedRoles = RoleProvider.GetRolesForUser(user.Id)
                };
                return(View(model));
            }
            return(View());
        }
Exemplo n.º 3
0
        internal static void CreateRoles(RoleProvider provider)
        {
            ProviderRoles = provider.GetAllRoles().ToList <string>().FindAll(roleName => roleName.ToLower().Contains("test_"));
            foreach (string role in ProviderRoles)
            {
                if (provider.RoleExists(role))
                {
                    string[] usersInRoles = provider.GetUsersInRole(role);
                    if (usersInRoles.Length != 0)
                    {
                        provider.RemoveUsersFromRoles(usersInRoles, new string[] { role }); //remove users from role
                    }
                    provider.DeleteRole(role, false);                                       //remove role
                }
            }

            ProviderRoles.Clear();
            for (int x = 0; x < 20; x++)
            {
                string roleName = string.Format("TEST_ROLE:{0:000}", x);
                ProviderRoles.Add(roleName);
                provider.CreateRole(roleName);
            }

            //NOTE:  roles 0-9 are reserved for query type operations and should be considered read only
            //       roles 10-19 may be used for C-U-D operations
            addUserToRole(Users[0], ProviderRoles[0], provider);  // several users in one role
            addUserToRole(Users[2], ProviderRoles[0], provider);
            addUserToRole(Users[4], ProviderRoles[0], provider);

            addUserToRole(Users[6], ProviderRoles[1], provider); // same user in multiple roles
            addUserToRole(Users[6], ProviderRoles[2], provider);
            addUserToRole(Users[6], ProviderRoles[3], provider);

            addUserToRole(Users[10], ProviderRoles[1], provider); // same user in multiple roles
            addUserToRole(Users[10], ProviderRoles[2], provider);
            addUserToRole(Users[10], ProviderRoles[3], provider);

            addUserToRole(Users[8], ProviderRoles[1], provider);
            addUserToRole(Users[8], ProviderRoles[2], provider);

/*
 * TEST_ROLE:000
 *  Users[0]
 *  Users[2]
 *  Users[4]
 * TEST_ROLE:001
 *  Users[6]
 *  Users[8]
 * TEST_ROLE:002
 *  Users[6]
 *  Users[8]
 * TEST_ROLE:003
 *  Users[6]
 * TEST_ROLE:004
 *  -- no users
 *
 */
        }
Exemplo n.º 4
0
        public override string[] GetAllRoles()
        {
            LogDebug("Entering CachedProvider.GetAllRoles");
            string[] roles;
            roles = _provider.GetAllRoles();

            return(roles);
        }
Exemplo n.º 5
0
        public ActionResult Edit(UserEditModel model)
        {
            if (User.Id() != model.Id && !User.IsInRole(Definitions.Roles.Administrator))
            {
                return(RedirectToAction("Unauthorized", "Home"));
            }

            if (AuthenticationSettings.DemoModeActive && User.IsInRole(Definitions.Roles.Administrator) && User.Id() == model.Id)
            {
                // Don't allow the admin user to be changed in demo mode
                return(RedirectToAction("Unauthorized", "Home"));
            }

            if (ModelState.IsValid)
            {
                bool valid = true;

                if (!User.IsInRole(Definitions.Roles.Administrator) && (model.OldPassword == null && model.NewPassword != null))
                {
                    ModelState.AddModelError("OldPassword", Resources.Account_Edit_OldPasswordEmpty);
                    valid = false;
                }

                if (model.OldPassword != null && MembershipService.ValidateUser(model.Username, model.OldPassword) != ValidationResult.Success)
                {
                    ModelState.AddModelError("OldPassword", Resources.Account_Edit_OldPasswordIncorrect);
                    valid = false;
                }

                if (User.IsInRole(Definitions.Roles.Administrator) && model.Id == User.Id() && !(model.PostedSelectedRoles != null && model.PostedSelectedRoles.Contains(Definitions.Roles.Administrator)))
                {
                    ModelState.AddModelError("Roles", Resources.Account_Edit_CannotRemoveYourselfFromAdminRole);
                    valid = false;
                }

                if (valid)
                {
                    MembershipService.UpdateUser(model.Id, model.Username, model.Name, model.Surname, model.Email, model.NewPassword);
                    // Only Administrators can make any changes to roles
                    if (User.IsInRole(Definitions.Roles.Administrator))
                    {
                        RoleProvider.RemoveUserFromRoles(model.Id, RoleProvider.GetAllRoles());
                        if (model.PostedSelectedRoles != null)
                        {
                            RoleProvider.AddUserToRoles(model.Id, model.PostedSelectedRoles);
                        }
                    }
                    ViewBag.UpdateSuccess = true;
                }
            }

            model.Roles         = RoleProvider.GetAllRoles();
            model.SelectedRoles = model.PostedSelectedRoles;

            return(View(model));
        }
Exemplo n.º 6
0
        public void Can_Get_All_Roles()
        {
            RoleProvider.CreateRole("admin");
            RoleProvider.CreateRole("engineering");
            RoleProvider.CreateRole("sales");

            var result = RoleProvider.GetAllRoles();

            Assert.Equal(3, result.Length);
        }
Exemplo n.º 7
0
        public void GetAllRoles_GetAllRolesForExistingUser_UsersRolesInAllRoles()
        {
            var roles         = provider.GetAllRoles();
            var rolesForUsers = provider.GetRolesForUser(ExistingUserName);

            foreach (var userRole in rolesForUsers)
            {
                Assert.IsTrue(roles.Contains(userRole), "Can not find role '" + userRole + "' in roles.");
            }
        }
        public void MembershipRole_GetAllRolesTests()
        {
            //-------------------------------------------------------
            // no parameters.  just execute
            //-------------------------------------------------------
            string[] roleNames;

            roleNames = _provider.GetAllRoles();
            Assert.IsNotNull(roleNames);
            Assert.AreEqual <int>(20, roleNames.Length);
        }
        private void CreateRoles(Dictionary <string, string> usersToCreate)
        {
            var roles = _roleProvider.GetAllRoles();

            foreach (var u in usersToCreate)
            {
                if (!roles.Contains(u.Value))
                {
                    _roleProvider.CreateRole(u.Value);
                }
            }
        }
Exemplo n.º 10
0
        public IList <RoleModel> GetAllRoles()
        {
            IList <RoleModel> roleModels = new List <RoleModel>();
            var roles = roleProvider.GetAllRoles();

            foreach (var role in roles)
            {
                var roleModel = new RoleModel {
                    RoleModelName = role
                };
                roleModels.Add(roleModel);
            }

            return(roleModels);
        }
        public override string[] GetAllRoles()
        {
            List <string> allRoles = new List <string>();

            foreach (string providerName in m_ProviderList)
            {
                RoleProvider rp    = Roles.Providers[providerName];
                string[]     roles = rp.GetAllRoles();
                foreach (string role in roles)
                {
                    allRoles.Add(role);
                }
            }
            return(allRoles.ToArray());
        }
        /// <summary>
        /// The GetRoleNonMembers method returns a list of roles that doesn´t have any members.
        /// </summary>
        /// <param name="roleId">The role id.</param>
        /// <param name="portalAlias">The portal alias</param>
        public IList <RainbowRole> GetRoleNonMembers(Guid roleId, string portalAlias)
        {
            IList <RainbowRole> res = new List <RainbowRole>();

            IList <RainbowRole> allRoles = RoleProvider.GetAllRoles(portalAlias);

            foreach (RainbowRole s in allRoles)
            {
                if (RoleProvider.GetUsersInRole(portalAlias, s.Id).Length == 0)
                {
                    res.Add(s);
                }
            }
            return(res);
        }
Exemplo n.º 13
0
        public override string[] GetAllRoles()
        {
            if (!Initialized)
            {
                return(_prevProvider.GetAllRoles());
            }

            using (MySqlDatabaseWrapper dbConn = new MySqlDatabaseWrapper(ConnectionString))
            {
                var roles = dbConn.ExecuteQuery(string.Format("select rolename from {0};", _rolesTable));
                if (roles.Count() > 0)
                {
                    return(roles.Select(role => role[0].ToString()).ToArray());
                }
            }
            return(null);
        }
Exemplo n.º 14
0
        public ActionResult Edit(UserEditModel model)
        {
            if (!User.Id().Equals(model.Username, StringComparison.OrdinalIgnoreCase) && !User.IsInRole(Definitions.Roles.Administrator))
            {
                return(RedirectToAction("Unauthorized", "Home"));
            }

            if (ModelState.IsValid)
            {
                bool valid = true;

                if (!User.IsInRole(Definitions.Roles.Administrator) && (model.OldPassword == null && model.NewPassword != null))
                {
                    ModelState.AddModelError("OldPassword", Resources.Account_Edit_OldPasswordEmpty);
                    valid = false;
                }

                if (model.OldPassword != null && MembershipService.ValidateUser(model.Username, model.OldPassword) != ValidationResult.Success)
                {
                    ModelState.AddModelError("OldPassword", Resources.Account_Edit_OldPasswordIncorrect);
                    valid = false;
                }

                if (User.IsInRole(Definitions.Roles.Administrator) && model.Username.Equals(User.Id(), StringComparison.OrdinalIgnoreCase) && !(model.Roles != null && model.Roles.Contains(Definitions.Roles.Administrator)))
                {
                    ModelState.AddModelError("Roles", Resources.Account_Edit_CannotRemoveYourselfFromAdminRole);
                    valid = false;
                }

                if (valid)
                {
                    MembershipService.UpdateUser(model.Username, model.Name, model.Surname, model.Email, model.NewPassword);
                    RoleProvider.RemoveUserFromRoles(model.Username, RoleProvider.GetAllRoles());
                    if (model.Roles != null)
                    {
                        RoleProvider.AddUserToRoles(model.Username, model.Roles);
                    }
                    ViewBag.UpdateSuccess = true;
                }
            }

            PopulateRoles();
            return(View(model));
        }
Exemplo n.º 15
0
 /// <summary>
 /// Finds all.
 /// </summary>
 /// <returns></returns>
 public IEnumerable <string> FindAll()
 {
     return(_roleProvider.GetAllRoles());
 }
Exemplo n.º 16
0
 public List <string> GetAllRoles()
 {
     return(_provider.GetAllRoles().ToList <string>());
 }
 public IEnumerable <string> GetAllRoles()
 {
     return(roleProvider.GetAllRoles());
 }
Exemplo n.º 18
0
 public string[] GetAllRoles()
 {
     return(roleProvider.GetAllRoles());
 }
Exemplo n.º 19
0
 public static string[] GetAllNonAdminRoles(this RoleProvider providerInstance)
 {
     return((from role in providerInstance.GetAllRoles()
             where !role.Equals("Admin", StringComparison.InvariantCultureIgnoreCase)
             select role).ToArray());
 }
Exemplo n.º 20
0
 public IEnumerable <string> GetRoles()
 {
     return((IEnumerable <string>)_provider.GetAllRoles());
 }
Exemplo n.º 21
0
 private void PopulateRoles()
 {
     ViewData["AvailableRoles"] = RoleProvider.GetAllRoles();
 }
Exemplo n.º 22
0
 public override string[] GetAllRoles()
 {
     return(_Provider.GetAllRoles());
 }
Exemplo n.º 23
0
        public string Process(string[] args)
        {
            var sb = new StringBuilder();

            var p = new OptionSet()
            {
                { "c|create", "create a role\nUSAGE: role --create rolename",
                  v => _command = Command.Create },
                { "d|delete", "delete a role\nUSAGE: role --delete rolename",
                  v => _command = Command.Delete },
                { "l|list", "return a list of roles\nUSAGE: role --list",
                  v => _command = Command.List },
                { "g|give", "add a user to a role\nUSAGE: role --give username rolename",
                  v => _command = Command.Give },
                { "t|take", "remove a user from a role\nUSAGE: role --take username rolename",
                  v => _command = Command.Take },
                { "u|users", "list all users in a role\nUSAGE: role --users rolename",
                  v => _command = Command.Users },
                { "r|roles", "list all roles for a user\nUSAGE: role --roles username",
                  v => _command = Command.Roles },
                { "h|help", "show this list of options\nUSAGE --help",
                  v => _command = null }
            };

            List <string> extras;

            try
            {
                extras = p.Parse(args);
            }
            catch (OptionException e)
            {
                sb.Append("role: ");
                sb.AppendLine(e.Message);
                sb.AppendLine("Try `role --help' for more information.");
                return(sb.ToString());
            }

            // perform the selected command
            if (_command == Command.Create)
            {
                if (extras.Count == 1)
                {
                    _provider.CreateRole(extras[0]);
                    sb.AppendLine("Role successfully created");
                }
                else
                {
                    sb.AppendLine("USAGE: role --create rolename");
                }
            }
            else if (_command == Command.Delete)
            {
                if (extras.Count == 1)
                {
                    try
                    {
                        var success = _provider.DeleteRole(extras[0], true);

                        if (success)
                        {
                            sb.AppendLine("Role successfully deleted");
                        }
                        else
                        {
                            sb.AppendFormat("Could not delete role: {0}", extras[0]);
                            sb.AppendLine();
                        }
                    }
                    catch (Exception ex)
                    {
                        sb.AppendFormat("Could not delete role: {0} - {1}", extras[0], ex.Message);
                        sb.AppendLine();
                    }
                }
                else
                {
                    sb.AppendLine("USAGE: role --delete rolename");
                }
            }
            else if (_command == Command.List)
            {
                if (extras.Count == 0)
                {
                    var roles = _provider.GetAllRoles();

                    if (roles.Count() > 0)
                    {
                        foreach (var role in roles)
                        {
                            sb.AppendLine(role);
                        }
                    }
                    else
                    {
                        sb.AppendLine("No roles found");
                    }
                }
                else
                {
                    sb.AppendLine("USAGE: role --list");
                }
            }
            else if (_command == Command.Give)
            {
                if (extras.Count == 2)
                {
                    _provider.AddUsersToRoles(new string[] { extras[0] }, new string[] { extras[1] });
                    sb.AppendFormat("Added {0} to {1}", extras[0], extras[1]);
                    sb.AppendLine();
                }
                else
                {
                    sb.AppendLine("USAGE: role --give username rolename");
                }
            }
            else if (_command == Command.Take)
            {
                if (extras.Count == 2)
                {
                    _provider.RemoveUsersFromRoles(new string[] { extras[0] }, new string[] { extras[1] });
                    sb.AppendFormat("Removed {0} from {1}", extras[0], extras[1]);
                    sb.AppendLine();
                }
                else
                {
                    sb.AppendLine("USAGE: role --take username rolename");
                }
            }
            else if (_command == Command.Users)
            {
                if (extras.Count == 1)
                {
                    var users = _provider.GetUsersInRole(extras[0]);

                    if (users.Count() > 0)
                    {
                        sb.AppendFormat("{0} users in {1}", users.Count(), extras[0]);
                        sb.AppendLine();

                        foreach (var u in users)
                        {
                            sb.AppendLine(u);
                        }
                    }
                    else
                    {
                        sb.AppendLine("No users in role");
                    }
                }
                else
                {
                    sb.AppendLine("USAGE: role --users rolename");
                }
            }
            else if (_command == Command.Roles)
            {
                if (extras.Count == 1)
                {
                    var roles = _provider.GetRolesForUser(extras[0]);

                    if (roles.Count() > 0)
                    {
                        sb.AppendFormat("{0} roles for {1}", roles.Count(), extras[0]);
                        sb.AppendLine();

                        foreach (var r in roles)
                        {
                            sb.AppendLine(r);
                        }
                    }
                    else
                    {
                        sb.AppendLine("No roles found for user");
                    }
                }
                else
                {
                    sb.AppendLine("USAGE: role --roles username");
                }
            }
            else
            {
                sb.AppendLine(ShowHelp(p));
            }

            return(sb.ToString());
        }
        /// <summary>
        /// Get Current UserID
        /// </summary>
        /// <param name="portalID">The portal ID.</param>
        /// <returns></returns>
        //public Guid GetCurrentUserID( int portalID ) {
        //    MembershipUser user = Membership.GetUser();
        //    return (Guid)user.ProviderUserKey;
        //}

        /// <summary>
        /// The GetPortalRoles method returns a list of all roles for the specified portal.
        /// </summary>
        /// <param name="portalAlias">The portal alias.</param>
        /// <returns>a <code>IList<RainbowRole></code> containing all role objects.
        /// </returns>
        public IList <RainbowRole> GetPortalRoles(string portalAlias)
        {
            return(RoleProvider.GetAllRoles(portalAlias));
        }