public override void CreateRole(string roleName) { 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_Roles_CreateRole", connection.Connection); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandTimeout = this.CommandTimeout; SqlParameter parameter = new SqlParameter("@ReturnValue", SqlDbType.Int); parameter.Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add(parameter); cmd.Parameters.Add(this.CreateInputParam("@RoleName", SqlDbType.NVarChar, roleName)); cmd.ExecuteNonQuery(); switch (this.GetReturnValue(cmd)) { case 0: return; case 1: throw new ProviderException(Hidistro.Membership.ASPNETProvider.SR.GetString("The role '{0}' already exists.", roleName)); } throw new ProviderException(Hidistro.Membership.ASPNETProvider.SR.GetString("Stored procedure call failed.")); } finally { if (connection != null) { connection.Close(); connection = null; } } } catch { throw; } }
internal static void CheckArrayParameter(ref string[] param, bool checkForNull, bool checkIfEmpty, bool checkForCommas, int maxSize, string paramName) { if (param == null) { throw new ArgumentNullException(paramName); } if (param.Length < 1) { throw new ArgumentException(SR.GetString("The array parameter '{0}' should not be empty.", paramName), paramName); } Hashtable hashtable = new Hashtable(param.Length); for (int i = param.Length - 1; i >= 0; i--) { SecUtility.CheckParameter(ref param[i], checkForNull, checkIfEmpty, checkForCommas, maxSize, paramName + "[ " + i.ToString(CultureInfo.InvariantCulture) + " ]"); if (hashtable.Contains(param[i])) { throw new ArgumentException(SR.GetString("The array '{0}' should not contain duplicate values.", paramName), paramName); } hashtable.Add(param[i], param[i]); } }
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); }
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; } }
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); }
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); }