【问题标题】:WCF Active Directory Authorization - PrincipalPermission -> access deniedWCF Active Directory 授权 - PrincipalPermission -> 拒绝访问
【发布时间】:2013-09-19 20:40:12
【问题描述】:

我尝试通过基于 AD 的登录系统来保护我的 WCF 服务。我创建了一个名为“TestUsers”的 AD 组。我的用户帐户是该组的成员。 WCF 服务托管在 IIS 中。

但我总是得到异常“SecurityAccessDeniedException”。

我的 WCF 服务如下所示:

Web.Config

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpEndpointBinding">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

IService1.cs(服务接口): 只有一种方法:

string GetWelcomeMessage();

Service1.svc.cs:

public class Service1 : IService1
    {
        [PrincipalPermission(SecurityAction.Demand, Role = @"mydomain\TestUsers")]
        public string GetWelcomeMessage()
        {
            return "hello world";
        }
    }

有什么想法吗???

任何帮助将不胜感激。

【问题讨论】:

    标签: c# wcf iis


    【解决方案1】:

    确保允许运行托管 IIS 的服务的帐户在 AD 中执行安全检查。

    也改变

    includeExceptionDetailInFaults="false"
    

    includeExceptionDetailInFaults="true"
    

    目前,这可能会帮助您分析问题。

    【讨论】:

    • 感谢您的回复弗洛里安。允许运行服务的帐户执行安全检查。我已将 includeExceptionDetailInFaults 更改为 true。但没有其他信息。
    • 删除属性后代码是否有效?您还可以通过删除属性并检查 ServiceSecurityContext.Current.WindowsIdentity 来验证您的绑定。
    • 当然,代码在没有“[PrincipalPermission(SecurityAction.Demand, Role = @"mydomain\TestUsers")]”的情况下也能工作。
    • 只是问:) ServiceSecurityContext.Current.WindowsIdentity 的价值是什么?
    • ;) 在消费应用程序中? ServiceSecurityContext.Current 为 NULL mhhhhhh
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-19
    • 2018-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-25
    相关资源
    最近更新 更多