Exemple #1
0
 public static void AddUsersToRoles(string[] usernames, string[] roleNames)
 {
     EnsureEnabled();
     SecUtility.CheckArrayParameter(ref roleNames, true, true, true, 0, "roleNames");
     SecUtility.CheckArrayParameter(ref usernames, true, true, true, 0, "usernames");
     Provider.AddUsersToRoles(usernames, roleNames);
     try
     {
         RolePrincipal currentUser = GetCurrentUser() as RolePrincipal;
         if (((currentUser != null) && (currentUser.ProviderName == Provider.Name)) && currentUser.IsRoleListCached)
         {
             foreach (string str in usernames)
             {
                 if (System.Web.Util.StringUtil.EqualsIgnoreCase(currentUser.Identity.Name, str))
                 {
                     currentUser.SetDirty();
                     return;
                 }
             }
         }
     }
     catch
     {
     }
 }
Exemple #2
0
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////

        public override void RemoveUsersFromRoles(string[] userNames, string[] roleNames)
        {
            HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Medium, SR.API_not_supported_at_this_level);
            SecUtility.CheckArrayParameter(ref roleNames,
                                           true,
                                           true,
                                           true,
                                           0,
                                           "roleNames");

            SecUtility.CheckArrayParameter(ref userNames,
                                           true,
                                           true,
                                           true,
                                           0,
                                           "userNames");

            int index = 0;

            object[] args  = new object[2];
            object[] roles = new object[roleNames.Length];

            foreach (string rolename in roleNames)
            {
                roles[index++] = GetRole(rolename);
            }

            try {
                try {
                    foreach (object role in roles)
                    {
                        foreach (string username in userNames)
                        {
                            args[0] = username;
                            args[1] = null;
                            CallMethod(role, "DeleteMemberName", args);
                        }
                    }

                    foreach (object role in roles)
                    {
                        args[0] = 0;
                        args[1] = null;
                        CallMethod(role, "Submit", args);
                    }
                } finally {
                    foreach (object role in roles)
                    {
                        Marshal.FinalReleaseComObject(role);
                    }
                }
            } catch {
                throw;
            }
        }
Exemple #3
0
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////
        public static int DeleteProfiles(string[] usernames)
        {
            SecUtility.CheckArrayParameter(ref usernames,
                                           true,
                                           true,
                                           true,
                                           0,
                                           "usernames");


            return(Provider.DeleteProfiles(usernames));
        }
        public override void RemoveUsersFromRoles(string[] userNames, string[] roleNames)
        {
            HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Medium, "API_not_supported_at_this_level");
            SecUtility.CheckArrayParameter(ref roleNames, true, true, true, 0, "roleNames");
            SecUtility.CheckArrayParameter(ref userNames, true, true, true, 0, "userNames");
            int num = 0;

            object[] args      = new object[2];
            object[] objArray2 = new object[roleNames.Length];
            foreach (string str in roleNames)
            {
                objArray2[num++] = this.GetRole(str);
            }
            try
            {
                try
                {
                    foreach (object obj2 in objArray2)
                    {
                        foreach (string str2 in userNames)
                        {
                            args[0] = str2;
                            args[1] = null;
                            this.CallMethod(obj2, "DeleteMemberName", args);
                        }
                    }
                    foreach (object obj3 in objArray2)
                    {
                        args[0] = 0;
                        args[1] = null;
                        this.CallMethod(obj3, "Submit", args);
                    }
                }
                finally
                {
                    foreach (object obj4 in objArray2)
                    {
                        Marshal.FinalReleaseComObject(obj4);
                    }
                }
            }
            catch
            {
                throw;
            }
        }
Exemple #5
0
        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            SecUtility.CheckArrayParameter(ref roleNames, true, true, true, 256, "roleNames");
            SecUtility.CheckArrayParameter(ref usernames, true, true, true, 256, "usernames");

            try
            {
                List <string> _usernames = usernames.ToList();
                List <string> _roleNames = roleNames.ToList();

                using (var session = new MongoSession(_connectionString))
                {
                    var users = (from u in session.Users
                                 where _usernames.Contains(u.UserName)
                                 select u).ToList();

                    var roles = (from r in session.Roles
                                 where _roleNames.Contains(r.RoleName)
                                 select r).ToList();

                    foreach (var userEntity in users)
                    {
                        if (userEntity.Roles.Any())
                        {
                            int oldCount     = userEntity.Roles.Count;
                            var matchedRoles = roles.Intersect(userEntity.Roles, new RoleComparer());

                            foreach (var matchedRole in matchedRoles)
                            {
                                userEntity.Roles.Remove(matchedRole);
                            }

                            if (oldCount != userEntity.Roles.Count)
                            {
                                session.Save(userEntity);
                            }
                        }
                    }
                }
            }
            catch
            {
                throw;
            }
        }
Exemple #6
0
 public static void RemoveUserFromRoles(string username, string[] roleNames)
 {
     EnsureEnabled();
     SecUtility.CheckParameter(ref username, true, true, true, 0, "username");
     SecUtility.CheckArrayParameter(ref roleNames, true, true, true, 0, "roleNames");
     Provider.RemoveUsersFromRoles(new string[] { username }, roleNames);
     try
     {
         RolePrincipal currentUser = GetCurrentUser() as RolePrincipal;
         if (((currentUser != null) && (currentUser.ProviderName == Provider.Name)) && (currentUser.IsRoleListCached && System.Web.Util.StringUtil.EqualsIgnoreCase(currentUser.Identity.Name, username)))
         {
             currentUser.SetDirty();
         }
     }
     catch
     {
     }
 }
Exemple #7
0
        public static void AssignPermissionsToRole(Guid roleId, params string[] permissionsArray)
        {
            SecUtility.CheckArrayParameter(ref permissionsArray, true, true, true, 256, "permissions");

            try
            {
                var role        = _session.Roles.FirstOrDefault(x => x.RoleId == roleId);
                var usersInRole = _session.Users.Where(x => x.Roles.Any(y => y.RoleId == roleId)).ToList();

                var permissions = (from p in _session.Permissions
                                   where permissionsArray.Contains(p.Name)
                                   select p).ToList();

                ProcessActionPermissionsToRole(permissions, role, usersInRole, (array, id) => { array.Add(id); return(array); });
            }
            catch
            {
                throw;
            }
        }
Exemple #8
0
        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            SecUtility.CheckArrayParameter(ref roleNames, true, true, true, 256, "roleNames");
            SecUtility.CheckArrayParameter(ref usernames, true, true, true, 256, "usernames");

            try
            {
                List <string> _usernames = usernames.ToList();
                List <string> _roleNames = roleNames.ToList();

                using (var session = new MongoSession(_connectionString))
                {
                    var users = (from u in session.Users
                                 where _usernames.Contains(u.UserName)
                                 select u).ToList();

                    var roles = (from r in session.Roles
                                 where _roleNames.Contains(r.RoleName)
                                 select r).ToList();

                    foreach (var userEntity in users)
                    {
                        if (userEntity.Roles.Any())
                        {
                            var newRoles = roles.Except(userEntity.Roles);
                            userEntity.Roles.AddRange(newRoles);
                        }
                        else
                        {
                            userEntity.Roles.AddRange(roles);
                        }

                        session.Save(userEntity);
                    }
                }
            }
            catch
            {
                throw;
            }
        }
Exemple #9
0
        static public void RemoveUsersFromRoles(string[] usernames, string [] roleNames)
        {
            EnsureEnabled();

            SecUtility.CheckArrayParameter(ref roleNames,
                                           true,
                                           true,
                                           true,
                                           0,
                                           "roleNames");

            SecUtility.CheckArrayParameter(ref usernames,
                                           true,
                                           true,
                                           true,
                                           0,
                                           "usernames");

            Provider.RemoveUsersFromRoles(usernames, roleNames);
            try
            {
                RolePrincipal user = GetCurrentUser() as RolePrincipal;
                if (user != null && user.ProviderName == Provider.Name && user.IsRoleListCached)
                {
                    foreach (string username in usernames)
                    {
                        if (StringUtil.EqualsIgnoreCase(user.Identity.Name, username))
                        {
                            user.SetDirty();
                            break;
                        }
                    }
                }
            }
            catch { }
        }
Exemple #10
0
        static public void AddUserToRoles(string username, string[] roleNames)
        {
            EnsureEnabled();

            SecUtility.CheckParameter(ref username, true, true, true, 0, "username");

            SecUtility.CheckArrayParameter(ref roleNames,
                                           true,
                                           true,
                                           true,
                                           0,
                                           "roleNames");

            Provider.AddUsersToRoles(new string [] { username }, roleNames);
            try
            {
                RolePrincipal user = GetCurrentUser() as RolePrincipal;
                if (user != null && user.ProviderName == Provider.Name && user.IsRoleListCached && StringUtil.EqualsIgnoreCase(user.Identity.Name, username))
                {
                    user.SetDirty();
                }
            }
            catch { }
        }
Exemple #11
0
        public static void RemovePermissionsFromRole(string roleName, params string[] permissionsArray)
        {
            SecUtility.CheckArrayParameter(ref permissionsArray, true, true, true, 256, "permissions");
            SecUtility.CheckParameter(ref roleName, true, false, true, 256, "roleName");

            try
            {
                List <string> _permissions = permissionsArray.ToList();

                var permissions = (from p in _session.Permissions
                                   where _permissions.Contains(p.Name)
                                   select p).ToList();

                var role        = _session.Roles.FirstOrDefault(x => x.RoleName == roleName);
                var usersInRole = _session.Users.Where(x => x.Roles.Any(y => y.RoleName == roleName)).ToList();


                ProcessActionPermissionsToRole(permissions, role, usersInRole, (array, id) => { array.Remove(id); return(array); });
            }
            catch
            {
                throw;
            }
        }
Exemple #12
0
        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            SecUtility.CheckArrayParameter(ref roleNames, true, true, true, 0x100, "roleNames");
            SecUtility.CheckArrayParameter(ref usernames, true, true, true, 0x100, "usernames");
            bool flag = false;

            try
            {
                SqlConnectionHolder connection = null;
                try
                {
                    connection = SqlConnectionHelper.GetConnection(this._sqlConnectionString, true);
                    this.CheckSchemaVersion(connection.Connection);
                    int length = usernames.Length;
                    while (length > 0)
                    {
                        string str = usernames[usernames.Length - length];
                        length--;
                        int index = usernames.Length - length;
                        while (index < usernames.Length)
                        {
                            if (((str.Length + usernames[index].Length) + 1) >= 0xfa0)
                            {
                                break;
                            }
                            str = str + "," + usernames[index];
                            length--;
                            index++;
                        }
                        int num3 = roleNames.Length;
                        while (num3 > 0)
                        {
                            string str2 = roleNames[roleNames.Length - num3];
                            num3--;
                            for (index = roleNames.Length - num3; index < roleNames.Length; index++)
                            {
                                if (((str2.Length + roleNames[index].Length) + 1) >= 0xfa0)
                                {
                                    break;
                                }
                                str2 = str2 + "," + roleNames[index];
                                num3--;
                            }
                            if (!flag && ((length > 0) || (num3 > 0)))
                            {
                                new SqlCommand("BEGIN TRANSACTION", connection.Connection).ExecuteNonQuery();
                                flag = true;
                            }
                            this.RemoveUsersFromRolesCore(connection.Connection, str, str2);
                        }
                    }
                    if (flag)
                    {
                        new SqlCommand("COMMIT TRANSACTION", connection.Connection).ExecuteNonQuery();
                        flag = false;
                    }
                }
                catch
                {
                    if (flag)
                    {
                        new SqlCommand("ROLLBACK TRANSACTION", connection.Connection).ExecuteNonQuery();
                        flag = false;
                    }
                    throw;
                }
                finally
                {
                    if (connection != null)
                    {
                        connection.Close();
                        connection = null;
                    }
                }
            }
            catch
            {
                throw;
            }
        }
Exemple #13
0
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            SecUtility.CheckArrayParameter(ref roleNames, true, true, true, 256, "roleNames");
            SecUtility.CheckArrayParameter(ref usernames, true, true, true, 256, "usernames");

            bool beginTranCalled = false;

            try {
                SqlConnectionHolder holder = null;
                try
                {
                    holder = SqlConnectionHelper.GetConnection(_sqlConnectionString, true);
                    CheckSchemaVersion(holder.Connection);
                    int numUsersRemaing = usernames.Length;
                    while (numUsersRemaing > 0)
                    {
                        int    iter;
                        string allUsers = usernames[usernames.Length - numUsersRemaing];
                        numUsersRemaing--;
                        for (iter = usernames.Length - numUsersRemaing; iter < usernames.Length; iter++)
                        {
                            if (allUsers.Length + usernames[iter].Length + 1 >= 4000)
                            {
                                break;
                            }
                            allUsers += "," + usernames[iter];
                            numUsersRemaing--;
                        }

                        int numRolesRemaining = roleNames.Length;
                        while (numRolesRemaining > 0)
                        {
                            string allRoles = roleNames[roleNames.Length - numRolesRemaining];
                            numRolesRemaining--;
                            for (iter = roleNames.Length - numRolesRemaining; iter < roleNames.Length; iter++)
                            {
                                if (allRoles.Length + roleNames[iter].Length + 1 >= 4000)
                                {
                                    break;
                                }
                                allRoles += "," + roleNames[iter];
                                numRolesRemaining--;
                            }

                            if (!beginTranCalled && (numUsersRemaing > 0 || numRolesRemaining > 0))
                            {
                                (new SqlCommand("BEGIN TRANSACTION", holder.Connection)).ExecuteNonQuery();
                                beginTranCalled = true;
                            }
                            RemoveUsersFromRolesCore(holder.Connection, allUsers, allRoles);
                        }
                    }
                    if (beginTranCalled)
                    {
                        (new SqlCommand("COMMIT TRANSACTION", holder.Connection)).ExecuteNonQuery();
                        beginTranCalled = false;
                    }
                } catch  {
                    if (beginTranCalled)
                    {
                        (new SqlCommand("ROLLBACK TRANSACTION", holder.Connection)).ExecuteNonQuery();
                        beginTranCalled = false;
                    }
                    throw;
                } finally {
                    if (holder != null)
                    {
                        holder.Close();
                        holder = null;
                    }
                }
            } catch {
                throw;
            }
        }
        /////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////////////////
        public override int DeleteProfiles(string[] usernames)
        {
            SecUtility.CheckArrayParameter(ref usernames,
                                           true,
                                           true,
                                           true,
                                           256,
                                           "usernames");

            int  numProfilesDeleted = 0;
            bool beginTranCalled    = false;

            try {
                SqlConnectionHolder holder = null;
                try
                {
                    holder = SqlConnectionHelper.GetConnection(_sqlConnectionString, true);
                    CheckSchemaVersion(holder.Connection);

                    SqlCommand cmd;

                    int numUsersRemaing = usernames.Length;
                    while (numUsersRemaing > 0)
                    {
                        string allUsers = usernames[usernames.Length - numUsersRemaing];
                        numUsersRemaing--;
                        for (int iter = usernames.Length - numUsersRemaing; iter < usernames.Length; iter++)
                        {
                            if (allUsers.Length + usernames[iter].Length + 1 >= 4000)
                            {
                                break;
                            }
                            allUsers += "," + usernames[iter];
                            numUsersRemaing--;
                        }

                        // We don't need to start a transaction if we can finish this in one sql command
                        if (!beginTranCalled && numUsersRemaing > 0)
                        {
                            cmd = new SqlCommand("BEGIN TRANSACTION", holder.Connection);
                            cmd.ExecuteNonQuery();
                            beginTranCalled = true;
                        }

                        cmd = new SqlCommand("dbo.aspnet_Profile_DeleteProfiles", holder.Connection);

                        cmd.CommandTimeout = CommandTimeout;
                        cmd.CommandType    = CommandType.StoredProcedure;
                        cmd.Parameters.Add(CreateInputParam("@ApplicationName", SqlDbType.NVarChar, ApplicationName));
                        cmd.Parameters.Add(CreateInputParam("@UserNames", SqlDbType.NVarChar, allUsers));
                        object o = cmd.ExecuteScalar();
                        if (o != null && o is int)
                        {
                            numProfilesDeleted += (int)o;
                        }
                    }

                    if (beginTranCalled)
                    {
                        cmd = new SqlCommand("COMMIT TRANSACTION", holder.Connection);
                        cmd.ExecuteNonQuery();
                        beginTranCalled = false;
                    }
                } catch  {
                    if (beginTranCalled)
                    {
                        SqlCommand cmd = new SqlCommand("ROLLBACK TRANSACTION", holder.Connection);
                        cmd.ExecuteNonQuery();
                        beginTranCalled = false;
                    }
                    throw;
                } finally {
                    if (holder != null)
                    {
                        holder.Close();
                        holder = null;
                    }
                }
            } catch {
                throw;
            }
            return(numProfilesDeleted);
        }
Exemple #15
0
        public override int DeleteProfiles(string[] usernames)
        {
            SecUtility.CheckArrayParameter(ref usernames, true, true, true, 0x100, "usernames");
            int  num  = 0;
            bool flag = false;

            try
            {
                SqlConnectionHolder connection = null;
                try
                {
                    try
                    {
                        connection = SqlConnectionHelper.GetConnection(this._sqlConnectionString, true);
                        this.CheckSchemaVersion(connection.Connection);
                        int length = usernames.Length;
                        while (length > 0)
                        {
                            SqlCommand command;
                            string     objValue = usernames[usernames.Length - length];
                            length--;
                            for (int i = usernames.Length - length; i < usernames.Length; i++)
                            {
                                if (((objValue.Length + usernames[i].Length) + 1) >= 0xfa0)
                                {
                                    break;
                                }
                                objValue = objValue + "," + usernames[i];
                                length--;
                            }
                            if (!flag && (length > 0))
                            {
                                command = new SqlCommand("BEGIN TRANSACTION", connection.Connection);
                                command.ExecuteNonQuery();
                                flag = true;
                            }
                            command = new SqlCommand("dbo.aspnet_Profile_DeleteProfiles", connection.Connection)
                            {
                                CommandTimeout = this.CommandTimeout,
                                CommandType    = CommandType.StoredProcedure
                            };
                            command.Parameters.Add(this.CreateInputParam("@ApplicationName", SqlDbType.NVarChar, this.ApplicationName));
                            command.Parameters.Add(this.CreateInputParam("@UserNames", SqlDbType.NVarChar, objValue));
                            object obj2 = command.ExecuteScalar();
                            if ((obj2 != null) && (obj2 is int))
                            {
                                num += (int)obj2;
                            }
                        }
                        if (flag)
                        {
                            new SqlCommand("COMMIT TRANSACTION", connection.Connection).ExecuteNonQuery();
                            flag = false;
                        }
                    }
                    catch
                    {
                        if (flag)
                        {
                            new SqlCommand("ROLLBACK TRANSACTION", connection.Connection).ExecuteNonQuery();
                            flag = false;
                        }
                        throw;
                    }
                    return(num);
                }
                finally
                {
                    if (connection != null)
                    {
                        connection.Close();
                        connection = null;
                    }
                }
            }
            catch
            {
                throw;
            }
            return(num);
        }