2011-11-21 34 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

相關問題