示例#1
0
        internal static SqlConnectionHolder GetConnection(string connectionString, bool revertImpersonation)
        {
            connectionString.ToUpperInvariant();

            SqlConnectionHolder holder = new SqlConnectionHolder(connectionString);

            bool flag = true;

            try
            {

                holder.Open(null, revertImpersonation);

                flag = false;

            }
            finally
            {
                if (flag)
                {
                    holder.Close();
                    holder = null;
                }
            }

            return holder;
        }
示例#2
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);
                    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;
            }
        }
示例#3
0
        public override string[] GetUsersInRole(string roleName)
        {
            string[] strArray2;
            SecUtility.CheckParameter(ref roleName, true, true, true, 0x100, "roleName");
            try
            {
                SqlConnectionHolder connection = null;
                try
                {
                    connection = SqlConnectionHelper.GetConnection(this._sqlConnectionString, true);
                    SqlCommand       cmd       = new SqlCommand("dbo.aspnet_UsersInRoles_GetUsersInRoles", connection.Connection);
                    SqlDataReader    reader    = null;
                    SqlParameter     parameter = new SqlParameter("@ReturnValue", SqlDbType.Int);
                    StringCollection strings   = new StringCollection();
                    cmd.CommandType     = CommandType.StoredProcedure;
                    cmd.CommandTimeout  = this.CommandTimeout;
                    parameter.Direction = ParameterDirection.ReturnValue;
                    cmd.Parameters.Add(parameter);
                    cmd.Parameters.Add(this.CreateInputParam("@RoleName", SqlDbType.NVarChar, roleName));
                    try
                    {
                        reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
                        while (reader.Read())
                        {
                            strings.Add(reader.GetString(0));
                        }
                    }
                    catch
                    {
                        throw;
                    }
                    finally
                    {
                        if (reader != null)
                        {
                            reader.Close();
                        }
                    }
                    if (strings.Count < 1)
                    {
                        switch (this.GetReturnValue(cmd))
                        {
                        case 0:
                            return(new string[0]);

                        case 1:
                            throw new ProviderException(Hidistro.Membership.ASPNETProvider.SR.GetString("The role '{0}' was not found.", roleName));
                        }
                        throw new ProviderException(Hidistro.Membership.ASPNETProvider.SR.GetString("Stored procedure call failed."));
                    }
                    string[] array = new string[strings.Count];
                    strings.CopyTo(array, 0);
                    strArray2 = array;
                }
                finally
                {
                    if (connection != null)
                    {
                        connection.Close();
                        connection = null;
                    }
                }
            }
            catch
            {
                throw;
            }
            return(strArray2);
        }
示例#4
0
        public override string[] GetRolesForUser(string username)
        {
            SecUtility.CheckParameter(ref username, true, false, true, 256, "username");
            if (username.Length < 1)
            {
                return(new string[0]);
            }
            try
            {
                SqlConnectionHolder connection = null;
                try
                {
                    connection = SqlConnectionHelper.GetConnection(_sqlConnectionString, true);
                    SqlCommand   cmd       = new SqlCommand("dbo.aspnet_UsersInRoles_GetRolesForUser", connection.Connection);
                    SqlParameter parameter = new SqlParameter("@ReturnValue", SqlDbType.Int);

                    StringCollection strings = new StringCollection();
                    cmd.CommandType     = CommandType.StoredProcedure;
                    cmd.CommandTimeout  = CommandTimeout;
                    parameter.Direction = ParameterDirection.ReturnValue;
                    cmd.Parameters.Add(parameter);
                    cmd.Parameters.Add(CreateInputParam("@UserName", SqlDbType.NVarChar, username));

                    using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
                    {
                        while (null != reader && reader.Read())
                        {
                            strings.Add(reader.GetString(0));
                        }
                    }

                    if (strings.Count > 0)
                    {
                        string[] array = new string[strings.Count];
                        strings.CopyTo(array, 0);
                        return(array);
                    }
                    switch (GetReturnValue(cmd))
                    {
                    case 0:
                    {
                        return(new string[0]);
                    }

                    case 1:
                    {
                        return(new string[0]);
                    }
                    }
                    throw new ProviderException(Hidistro.Membership.ASPNETProvider.SR.GetString("Stored procedure call failed."));
                }
                finally
                {
                    if (connection != null)
                    {
                        connection.Close();
                        connection = null;
                    }
                }
            }
            catch
            {
                throw;
            }
        }
示例#5
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);
        }
示例#6
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);
        }
示例#7
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;
            }
        }