需要一些方法只能在WCF Web服务的凭据 [英] Require credentials for some methods only in WCF web service

查看:99
本文介绍了需要一些方法只能在WCF Web服务的凭据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有不同的方法,其中一些需要进行认证(例如​​的ChangePassword,ChangeUserData)用户一UserAccountService和一些不(RegisterUser)

I have a UserAccountService with different methods, some of which require the user to be authenticated (e.g. ChangePassword, ChangeUserData) and some not (RegisterUser).

不过似乎我似乎无法得到它的工作,因此,只有一些方法需要身份验证。

However it seems I can't seem to get it to work, so that only some methods require authentication.

这需要身份验证的方法是用装饰

The methods that require authentication are decorated with

[PrincipalPermission(SecurityAction.Demand, Authenticated = true)]

在我的app.config我有一个绑定指定它使用的加密,并要求用户名凭据:

In my app.config I have a binding specified which uses encryption and requests UserName credentials:

    <binding name="authenticatedBinding">
      <security mode="TransportWithMessageCredential">
        <message clientCredentialType="UserName" />
      </security>
    </binding>

(我用basicHttpBinding的)

(I am using basicHttpBinding)

我也有配置的自定义身份验证提供者:

I also have a custom authentication provider configured:

      <serviceCredentials>
        <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="..." />
      </serviceCredentials>

使用这个配置我似乎无法来调用该服务的方法,而不需要经过验证。

With this configuration I can't seem to call any methods on the service without being authenticated.

如果我离开了安全配置,那么我可以调用不要求身份验证方法,但该消息凭证不再被运送。

If I leave out the security configuration, then I can call the methods that don't require authentication, but the message credentials are no longer being transported.

我如何必须配置我的服务,因此,它允许调用的所有方法,只需要用户名/密码时,需要的PrincipalPermission它被设置?

How do I have to configure my service, so that it allows all methods to be called and only requires the username/password to be set when the PrincipalPermission demands it?

我使用Silverlight为我的客户,如果这是重要的......

I am using Silverlight as my client, if that's important...

谢谢!

推荐答案

安全设置可以在终点级细粒,但不是合同中 - 所以你不能将安全&放大器;不安全的方法在,你想要的一种方式。我会建议

Security settings can be fine grained at end-point level but not within a contract - so you cannot combine secure & unsecure methods in a way that you desired. I will suggest that


    一个不安全的方法 -
  1. 您分两部分分手您的服务合同(接口)。其次将从无抵押部分继承和遗嘱包含需要固定的操作。

  2. 您服务的实现不需要改变(因为它应该实现了安全接口) - 所有你需要做的是揭露这个实现作为两个不同的终点两个不同的合同(在固定和另一个不安全的)。您需要锁定与任何安全配置,需要担保合同的终结点。

  3. 不幸的是,从客户的角度来看,你必须在身份验证边界,即直到用户通过验证后,就可以使用不安全的终点改用终点/ URL,但一次,认证,客户端可以使用任何端点。

这篇关于需要一些方法只能在WCF Web服务的凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆