WCF サービスで UserNamePasswordValidator をオーバーライドしており、SQL データベースに対してユーザー名とパスワードを検証したいと考えています。接続文字列を PasswordValidator クラスに渡す方法はありますか? また、私のクラスはメインの WCF サービスとは別のものであることにも言及する必要がありました。
public class MyCustomUserNameValidator : UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
//TODO: how to pass in connection string??
connectionString = "Data Source=MyDataSource;Initial Catalog=MyCatalog;User ID=MyUserName;Password=MyPassword";
// connect to database and validate crendentials...
if (!valid)
{
throw new SecurityTokenException("Access Denied.");
}
}
}
構成セクション:
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="MyCompany.Services.Validation.MyCustomUserNameValidator, MyCompany.Services.Validation"/>
ありがとう。