Currently I have a service that uses a UserNamePasswordValidator
to authenticate the client user. The code for the validation goes as follows:
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.");
}
As you can see, the code will always throw an exception when something is wrong.
Now for the question - Is there any reason I should check whether ServiceSecurityContext.Current.PrimaryIdentity.IsAuthenticated
is true inside my OperationContract
functions? For example,
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?
}
}
Any help would be greatly appreciated.