[英]Custom Role Provider not triggering in webservice
<system.web>
<compilation debug="true"
targetFramework="4.0" />
<httpRuntime requestPathInvalidCharacters="" />
<authentication mode="Forms" />
<membership defaultProvider=">
<providers>
<clear />
<add name="ANSMP"
type="Test.Authentication.CustomMembershipProvider"
connectionStringName="DataConnection" />
</providers>
</membership>
<roleManager enabled="true"
defaultProvider="ANSRP">
<providers >
<clear />
<add connectionStringName="DataConnection"
applicationName="/"
name="ANSRP"
type="Test.Authentication.CustomRoleProvider" />
</providers>
</roleManager>
</system.web>
<system.serviceModel>
<behaviours>
<serviceBehaviors>
<behavior name="TestDataBehaviour">
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="MembershipProvider"
membershipProviderName="ANSMP"/>
</serviceCredentials>
<serviceMetadata httpGetEnabled="true"
httpsGetEnabled="true" />
<serviceAuthorization principalPermissionMode="UseAspNetRoles"
roleProviderName="ANSRP" />
<dataContractSerializer ignoreExtensionDataObject="true" />
<serviceDebug httpHelpPageBinding="webHttpBinding"
httpHelpPageBindingConfiguration=""
includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviour>
</behaviors>
</system.serviceModel>
假設我將自定義成員資格提供者和自定義角色提供者留空(Asin,所有方法均throw NotImplementedException
); 當我嘗試使用[PrinciplePermission(SecurityAction.Demand, Role = "Custom")]
或var b = Thread.CurrentPrincipal.IsInRole("Custom")]
檢查角色時,我會期望一個錯誤
但是,它只是一直返回, Access is denied
(在屬性上),並且在字段上為false
。
使用Membership.GetAllUsers()
實際上確實會給我一個NotImplementedError
..但是如何確保在使用PrincipalPermission Attribute時會觸發我的自定義角色提供程序和我的自定義成員資格提供程序?
編輯
我嘗試將, Test.Authentication
添加到成員資格提供程序以及角色提供程序的類型...
但是當前PrinciplePermission告訴我Request for principal permission failed
編輯2
檢查跟蹤日志時,發現以下內容:
The action that failed was:
Demand
The type of the first permission that failed was:
System.Security.Permissions.PrincipalPermission
The first permission that failed was:
<IPermission class="System.Security.Permissions.PrincipalPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1">
<Identity Authenticated="true"
Role="Customer"/>
</IPermission>
The demand was for:
<IPermission class="System.Security.Permissions.PrincipalPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1">
<Identity Authenticated="true"
Role="Customer"/>
</IPermission>
The assembly or AppDomain that failed was:
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
我也收到了一些Extension type not found
警告
<TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Warning">
<TraceIdentifier>http://msdn.microsoft.com/nl-NL/library/System.ServiceModel.ExtensionTypeNotFound.aspx</TraceIdentifier>
<Description>Extension type not found.</Description>
<AppDomain>/LM/W3SVC/1/ROOT/webapi3-6-130082517071825580</AppDomain>
<ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord">
<ExtensionName>pollingDuplexHttpBinding</ExtensionName>
<ExtensionType>System.ServiceModel.Configuration.PollingDuplexHttpBindingCollectionElement, System.ServiceModel.PollingDuplex, version=3.0.0.0, Culture=neutral</ExtensionType>
</ExtendedData>
</TraceRecord>
經過很多時間,我發現上面顯示的每個人都可以正常工作
在客戶端,當您創建服務引用時,將創建2個端點(在我們的示例中。我不知道這是否是標准的)。 一種是安全的,一種是..好,不是安全的。
為了使用令牌,我一直使用非安全令牌...但是為了使用成員資格提供者,角色提供者和用戶名密碼驗證,我需要使用安全端點!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.