Ejemplo n.º 1
0
        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            SecUtility.CheckParameter(ref roleName, true, true, true, 256, "roleName");
            SecUtility.CheckParameter(ref usernameToMatch, true, true, false, 256, "usernameToMatch");
            string[] result;
            try
            {
                SqlConnectionHolder sqlConnectionHolder = null;
                try
                {
                    sqlConnectionHolder = SqlConnectionHelper.GetConnection(this._sqlConnectionString, true);
                    SqlCommand       sqlCommand       = new SqlCommand("dbo.aspnet_UsersInRoles_FindUsersInRole", sqlConnectionHolder.Connection);
                    SqlDataReader    sqlDataReader    = null;
                    SqlParameter     sqlParameter     = new SqlParameter("@ReturnValue", SqlDbType.Int);
                    StringCollection stringCollection = new StringCollection();
                    sqlCommand.CommandType    = CommandType.StoredProcedure;
                    sqlCommand.CommandTimeout = this.CommandTimeout;
                    sqlParameter.Direction    = ParameterDirection.ReturnValue;
                    sqlCommand.Parameters.Add(sqlParameter);
                    sqlCommand.Parameters.Add(this.CreateInputParam("@RoleName", SqlDbType.NVarChar, roleName));
                    sqlCommand.Parameters.Add(this.CreateInputParam("@UserNameToMatch", SqlDbType.NVarChar, usernameToMatch));
                    try
                    {
                        sqlDataReader = sqlCommand.ExecuteReader(CommandBehavior.SequentialAccess);
                        while (sqlDataReader.Read())
                        {
                            stringCollection.Add(sqlDataReader.GetString(0));
                        }
                    }
                    catch
                    {
                        throw;
                    }
                    finally
                    {
                        if (sqlDataReader != null)
                        {
                            sqlDataReader.Close();
                        }
                    }
                    if (stringCollection.Count < 1)
                    {
                        switch (this.GetReturnValue(sqlCommand))
                        {
                        case 0:
                            result = new string[0];
                            break;

                        case 1:
                            throw new ProviderException(SR.GetString("The role '{0}' was not found.", roleName));

                        default:
                            throw new ProviderException(SR.GetString("Stored procedure call failed."));
                        }
                    }
                    else
                    {
                        string[] array = new string[stringCollection.Count];
                        stringCollection.CopyTo(array, 0);
                        result = array;
                    }
                }
                finally
                {
                    if (sqlConnectionHolder != null)
                    {
                        sqlConnectionHolder.Close();
                        sqlConnectionHolder = null;
                    }
                }
            }
            catch
            {
                throw;
            }
            return(result);
        }
Ejemplo n.º 2
0
        public override bool IsUserInRole(string username, string roleName)
        {
            SecUtility.CheckParameter(ref roleName, true, true, true, 256, "roleName");
            SecUtility.CheckParameter(ref username, true, false, true, 256, "username");
            if (username.Length < 1)
            {
                return(false);
            }
            bool result;

            try
            {
                SqlConnectionHolder sqlConnectionHolder = null;
                try
                {
                    sqlConnectionHolder = SqlConnectionHelper.GetConnection(this._sqlConnectionString, true);
                    SqlCommand sqlCommand = new SqlCommand("dbo.aspnet_UsersInRoles_IsUserInRole", sqlConnectionHolder.Connection);
                    sqlCommand.CommandType    = CommandType.StoredProcedure;
                    sqlCommand.CommandTimeout = this.CommandTimeout;
                    SqlParameter sqlParameter = new SqlParameter("@ReturnValue", SqlDbType.Int);
                    sqlParameter.Direction = ParameterDirection.ReturnValue;
                    sqlCommand.Parameters.Add(sqlParameter);
                    sqlCommand.Parameters.Add(this.CreateInputParam("@UserName", SqlDbType.NVarChar, username));
                    sqlCommand.Parameters.Add(this.CreateInputParam("@RoleName", SqlDbType.NVarChar, roleName));
                    sqlCommand.ExecuteNonQuery();
                    switch (this.GetReturnValue(sqlCommand))
                    {
                    case 0:
                        result = false;
                        break;

                    case 1:
                        result = true;
                        break;

                    case 2:
                        result = false;
                        break;

                    case 3:
                        result = false;
                        break;

                    default:
                        throw new ProviderException(SR.GetString("Stored procedure call failed."));
                    }
                }
                finally
                {
                    if (sqlConnectionHolder != null)
                    {
                        sqlConnectionHolder.Close();
                        sqlConnectionHolder = null;
                    }
                }
            }
            catch
            {
                throw;
            }
            return(result);
        }
Ejemplo n.º 3
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 flag = false;

            try
            {
                SqlConnectionHolder sqlConnectionHolder = null;
                try
                {
                    sqlConnectionHolder = SqlConnectionHelper.GetConnection(this._sqlConnectionString, true);
                    int i = usernames.Length;
                    while (i > 0)
                    {
                        string text = usernames[usernames.Length - i];
                        i--;
                        int num = usernames.Length - i;
                        while (num < usernames.Length && text.Length + usernames[num].Length + 1 < 4000)
                        {
                            text = text + "," + usernames[num];
                            i--;
                            num++;
                        }
                        int j = roleNames.Length;
                        while (j > 0)
                        {
                            string text2 = roleNames[roleNames.Length - j];
                            j--;
                            num = roleNames.Length - j;
                            while (num < roleNames.Length && text2.Length + roleNames[num].Length + 1 < 4000)
                            {
                                text2 = text2 + "," + roleNames[num];
                                j--;
                                num++;
                            }
                            if (!flag && (i > 0 || j > 0))
                            {
                                new SqlCommand("BEGIN TRANSACTION", sqlConnectionHolder.Connection).ExecuteNonQuery();
                                flag = true;
                            }
                            this.RemoveUsersFromRolesCore(sqlConnectionHolder.Connection, text, text2);
                        }
                    }
                    if (flag)
                    {
                        new SqlCommand("COMMIT TRANSACTION", sqlConnectionHolder.Connection).ExecuteNonQuery();
                        flag = false;
                    }
                }
                catch
                {
                    if (flag)
                    {
                        new SqlCommand("ROLLBACK TRANSACTION", sqlConnectionHolder.Connection).ExecuteNonQuery();
                        flag = false;
                    }
                    throw;
                }
                finally
                {
                    if (sqlConnectionHolder != null)
                    {
                        sqlConnectionHolder.Close();
                        sqlConnectionHolder = null;
                    }
                }
            }
            catch
            {
                throw;
            }
        }