目前我有一項服務使用UserNamePasswordValidator
來驗證客戶端用戶。驗證代碼如下:WCF UserNamePasswordValidator是否需要檢查PrimaryIdentity.IsAuthenticated?
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?
}
}
任何幫助將不勝感激。