2012-01-24 47 views
1

使用独立身份验证WCF Web服务需要用户名和密码是否存在任何问题?我应该使用https还是其他一些最佳做法?独立身份验证wcf网络服务

此外,如果我想重置WCF Web服务用户的密码,我该如何防止任何形式的蛮力攻击?还是有围绕这种方法的最佳做法吗?我只是发送电子邮件/用户名来重置密码。

回答

1

这是一个明智的做法,如果你想你的外化服务的认证,对考试支持使用Windows Azure访问控制服务与另一个身份提供商进行身份联合,例如Active Directory联合身份验证服务甚至Facebook或Google。

这样做的另外一个好处是在未来支持备选身份验证方案比较容易,例如X.509证书。

您的需求似乎过于复杂,但您绝对应该考虑使用标准协议(如WS-Trust)来实施您的身份验证服务。在这种情况下,您的服务将是安全令牌服务(STS)以使用术语。这使用Windows Identity Foundation(WIF)得到了很好的支持,事实上Visual Studio的WIF工具包含一个STS样例来帮助您。

另外,还有一个由Dominic Baier创建的出色的现成开源STS,您可以下载,根据需要进行自定义(例如,使用您自己的用户名/密码存储区)。正如我说,你可以在这里

http://identityserver.codeplex.com/

下载这个,这也许比你需要更复杂的,但可能会在未来一个很好的投资。

+0

这实际上看起来很有趣。 –

+0

我最近被我自己的身份验证服务绊了一跤,然后经过几次迭代使它变得越来越复杂,我们终于重构了一个合适的STS--就像我们应该首先完成的那样; o) –

2

是的,你应该使用https。因为通过http进行身份验证同样容易受到未经身份验证的服务的攻击,所以任何人都可以通过线路嗅探纯文本。有一个在WCF一个很好的方法可以实现身份验证,使用UserNamePasswordValidator类..你可以创建服务器一些文本文件等都有用户名,密码可以通过发送电子邮件等变化..

public class MyCustomValidator: System.IdentityModel.Selectors.UserNamePasswordValidator 
{ 
    public override void Validate(string userName, string password) 
    { 
     if (null == userName || null == password) 
     { 
      throw new ArgumentNullException(); 
     } 

     else 
     { 
      bool isValid = UserRepository.ValidateUser(userName,password); //any db based checking 

      if(!isValid) 
      { 
       throw new SecurityTokenException("Unknown Username or Password"); 
      } 
     } 
    } 
} 

配置:

<system.serviceModel> 
     <bindings> 
     <wsHttpBinding> 
      <binding name="CustomAuthentication"> 
      <security mode="Message"> 
       <message clientCredentialType="UserName" /> 
      </security> 
      </binding> 
     </wsHttpBinding> 
     </bindings> 

     <behaviors> 
     <serviceBehaviors> 
      <behavior name="CustomValidator"> 
      <serviceCredentials> 
       <userNameAuthentication userNamePasswordValidationMode="Custom" 
       customUserNamePasswordValidatorType="MyAssembly.MyCustomValidator, MyAssembly"/> 
      </serviceCredentials> 
      </behavior> 
     </serviceBehaviors> 
     </behaviors>  

     <services> 
     <service name="MyService" behaviorConfiguration="CustomValidator"> 
      <endpoint address="" binding="wsHttpBinding" contract="IMyService" bindingConfiguration="CustomAuthentication" /> 
     </service> 
    </services> 
</system.serviceModel> 

,如果你要使用的验证没有HTTPS,你可以试试这个: WCF Authentication using basicHttpBinding and custom UserNamePasswordValidator