首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >没有SSL但具有Windows组身份验证的WCF服务

没有SSL但具有Windows组身份验证的WCF服务
EN

Stack Overflow用户
提问于 2012-05-15 11:45:41
回答 2查看 2.1K关注 0票数 1

我们正在尝试创建仅可由指定的windows组访问的WCF服务。如何在服务器web.config和客户端配置中对其进行配置?

注意:我们希望能够在服务器web.config中控制允许访问的windows组,而不是在代码中。另外,我们根本不想要/不需要SSL。

我用谷歌搜索了一下,我能找到的最好的例子都是这样的……

WCF Service, Windows Authentication

但这并不能解释如何将访问权限限制到特定的一个或多个组。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-05-24 08:41:58

好的,这就是我们想出的解决方案。尽管它确实涉及到代码更改(添加AspNetCompatibilityRequirements属性),但我们现在可以在web.config文件中获得组/角色的配置,而不是硬编码。

要做到这一点有很多步骤……

1)在serviceHostingEnvironment元素中添加aspNetCompatibilityEnabled属性并设置为true,例如...

代码语言:javascript
复制
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />

这将告诉WCF服务在ASP.NET兼容模式下运行,并完全参与ASP.NET HTTP请求生命周期。有关详细信息,请参阅this MSDN article

2)在WCF代码中,按照上面的链接和在this MSDN article中指定的方式,将AspNetCompatibilityRequirements属性添加到服务类中。

代码语言:javascript
复制
<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)>

3)现在我们可以添加通常的ASP授权元素,以限制对指定组/用户的访问(如果没有上面的设置(1)和(2),这将被忽略)...

代码语言:javascript
复制
<system.web>
    <authorization>
        <allow roles="MYDOMAIN\WCFAuthenticatedUsers" /> <-- allows access to users in this group
        <deny users="*" /> <-- denies access to all other users
    </authorization>
</system.web>
票数 1
EN

Stack Overflow用户

发布于 2012-05-15 15:23:46

如果这是intranet应用程序,您可以使用netTcpBinding:

代码语言:javascript
复制
<services>
   <service name="YourService"
      behaviorConfiguration="YourServiceBehavior">
      <endpoint 
         binding="netTcpBinding"
         bindingConfiguration="SecureTransportWindows"
         contract="YourContract" />
   </service>
</services>

<bindings>
   <binding name="SecureTransportWindows">
      <security mode="Transport">
          <transport clientCredentialType="Windows" />
      </security>
   </binding>
</bindings>

<behaviors>
   <serviceBehaviors>
      <behavior name="YourServiceBehavior">          
          <serviceAuthorization principalPermissionMode="UseWindowsGroups" />
      </behavior>
   </serviceBehaviors>
</behaviours>

然后在服务代码中,你可以要求windows角色:

代码语言:javascript
复制
class YourService : YourContract
{
    [PrincipalPermission(SecurityAction.Demand, Role="MYDOMAIN\Administrators")]
    public string SecuredOperation(string name)
    {
       return "secured operation";
    }
}

如果您需要在config中设置它,那么您必须实现自定义授权:

代码语言:javascript
复制
<behavior name="YourServiceBehavior">          
   <serviceAuthorization principalPermissionMode="Custom">            
      <authorizationPolicies>
         <add policyType="YourCustomAuthorizationPolicy"/>
      </authorizationPolicies>          
   </serviceAuthorization>
</behavior>

并在代码中实现IAuthorizationPolicy接口:

代码语言:javascript
复制
public class YourCustomAuthorizationPolicy : IAuthorizationPolicy
{
   //you need to check msdn 
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10593897

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档