gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 13:13:13 26 4
gpt4 key购买 nike

我们正在尝试创建一个只能由指定的 Windows 组访问的 WCF 服务。如何在服务器 web.config 和客户端配置中进行配置?

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

我四处搜索,然后我能找到的最好的例子都是这样的......

WCF Service, Windows Authentication

但这并没有解释如何将访问权限限制为仅特定的一个或多个组。

最佳答案

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

<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>

然后在服务代码中你可以请求窗口角色:

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

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

<behavior name="YourServiceBehavior">          
<serviceAuthorization principalPermissionMode="Custom">
<authorizationPolicies>
<add policyType="YourCustomAuthorizationPolicy"/>
</authorizationPolicies>
</serviceAuthorization>
</behavior>

并在代码中实现 IAuthorizationPolicy 接口(interface):

public class YourCustomAuthorizationPolicy : IAuthorizationPolicy
{
//you need to check msdn
}

关于没有 SSL 但具有 Windows 组身份验证的 WCF 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10593897/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com