wcf usernamepasswordvalidatorは、PrimaryIdentity.isauthenticatedをチェックする必要がありますか?
-
27-09-2019 - |
質問
現在、aを使用するサービスがあります UserNamePasswordValidator
クライアントユーザーを認証するには。検証のコードは次のとおりです。
public override void Validate(String userName, String password)
{
if (userName == null) || (password == null)
throw new FaultException("Username and/or password not specified.");
if (userName != "test") && (password != "tset")
throw new FaultException("Invalid username and/or password.");
}
ご覧のとおり、コードは何かが間違っている場合、常に例外をスローします。
さて、質問のために - 理由はありますか? ServiceSecurityContext.Current.PrimaryIdentity.IsAuthenticated
私の中は真実です OperationContract
関数?例えば、
public interface IMyService
{
[OperationContract]
void myOpContract();
}
public class MyService : IMyService
{
public void myOpContract()
{
// Do I really need this conditional statement?
if (ServiceSecurityContext.Current.PrimaryIdentity.IsAuthenticated)
// Proceed as expected
else
// Fail?
}
}
どんな助けも大歓迎です。
解決
この記事のいくつかのコメントから - Silverlight 3:カスタムユーザー名 /パスワード認証メカニズムでWCFサービスを保護する さまざまなテストから - if ([...]PrimaryIdentity.IsAuthenticated)
セクションは必要ありません。内部に障害を投げます UserNamePasswordValidator
セキュリティ交渉を中止するトリックはありますか。
ただし、著者を代表して優れたアイデアの1つは、 if ([...]PrimaryIdentity.IsAuthenticated)
条件付きステートメントは、将来、セキュリティなしで新しいバインディング(接続タイプ)が追加されている場合に役立ちます。
所属していません StackOverflow