2011-11-21 31 views
5

我创建了一个使用Windows身份验证的WCF服务,并且希望对其进行设置,以便只有在用户位于Windows组中时才能访问它。我目前使用下面的属性中的代码来实现这一目标允许基于web.config中设置的组访问WCF

[PrincipalPermission(SecurityAction.Demand, Role = "Domain\MyGroup")] 

问题的,这是我必须做的每一种方法和编译,如果我想改变组。有没有办法让我可以设置可以在配置文件中访问的组和整个服务?

我试图在我的配置文件中的下列但是这似乎并没有工作

<security> 
    <authentication> 
     <windowsAuthentication authPersistSingleRequest="true" enabled="true"/> 
    </authentication> 
    <authorization> 
     <add accessType="Allow" roles="Domain\MyGroup" /> 
    </authorization> 
</security> 

回答

1

好吧我想通了。我有设置类似如下

<security> 
    <authentication> 
    <windowsAuthentication enabled="true" /> 
    </authentication> 
    <authorization> 
    <remove users="*" roles="" verbs="" /> 
    <remove users="?" roles="" verbs="" /> 
    <add accessType="Deny" users="?" /> 
    <add accessType="Allow" roles="Domain\MyGroup" /> 
    </authorization> 
</security> 

配置文件也必须设置

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 

而且在我的类,它实现合同WCF

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 

我想这意味着使用ASP林身份验证,而不是WCF,但我为我工作

+0

这是否强加任何显着的表现命中? – xr280xr

0

PrincipalPermission属性是从.NET代码访问安全性的功能,而不是与WCF。如果该服务托管在IIS中,则更灵活的方法如下MSDN post. WCF还支持不同的自定义身份验证机制as described here.

+0

你正在认证与授权混淆。 PrincipalPermissionAttribute与后者有关。虽然这个属性是CAS的一部分,但你并没有真正回答这个问题。 – xr280xr

相关问题