2
A
回答
2
利用現有的用戶Windows帳戶使用服務進行身份驗證
爲此,您應該將綁定配置的transport clientCredentialType
屬性設置爲Windows
。
<bindings>
<wsHttpBinding>
<binding>
<security mode="Message">
<transport clientCredentialType="Windows" />
</security>
</binding>
</wsHttpBinding>
</bindings>
允許添加從另一個項目服務引用的無需提供憑據
要做到這一點,創建一個mex
端點爲您服務端點。
<services>
<service name="Services.SampleService" behaviorConfiguration="wsDefaultBehavior">
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
限制,可以調用服務
這一個用戶是一個涉及多一點。我發現以每個用戶爲基礎確保服務的方式需要定製授權策略。執行授權的類必須實現IAuthorizationPolicy
接口。這是我的授權類的完整代碼:
namespace Services.SampleService.Authorization
{
/// <summary>
/// Handles the default authorization for access to the service
/// <para>Works in conjunction with the AuthorizedUsersDefault setting</para>
/// </summary>
public class DefaultAuthorization: IAuthorizationPolicy
{
string _Id;
public DefaultAuthorization()
{
this._Id = Guid.NewGuid().ToString();
}
public bool Evaluate(EvaluationContext evaluationContext, ref object state)
{
bool isAuthorized = false;
try
{
//get the identity of the authenticated user
IIdentity userIdentity = ((IIdentity)((System.Collections.Generic.List<System.Security.Principal.IIdentity>)evaluationContext.Properties["Identities"])[0]);
//verify that the user is authorized to access the service
isAuthorized = Properties.Settings.Default.AuthorizedUsersDefault.Contains(userIdentity.Name, StringComparison.OrdinalIgnoreCase);
if (isAuthorized)
{
//add the authorized identity to the current context
GenericPrincipal principal = new GenericPrincipal(userIdentity, null);
evaluationContext.Properties["Principal"] = principal;
}
}
catch (Exception e)
{
Logging.Log(Severity.Error, "There was an error authorizing a user", e);
isAuthorized = false;
}
return isAuthorized;
}
public ClaimSet Issuer
{
get { return ClaimSet.System; }
}
public string Id
{
get { return this._Id; }
}
}
}
「魔術師」在Evaluate
方法發生。在我的情況下,授權用戶列表維護在名爲AuthorizedUsersDefault
的Properties.Settings變量(類型ArrayOfString
)中。這樣,我可以維護用戶列表,而無需重新部署整個項目。
,然後用在每個服務的基礎上這一授權策略,設置在ServiceBehaviors
節點如下:
<behaviors>
<serviceBehaviors>
<behavior name="wsDefaultBehavior">
<serviceAuthorization principalPermissionMode="Custom">
<authorizationPolicies>
<add policyType="Services.SampleService.Authorization.DefaultAuthorization, MyAssemblyName" />
</authorizationPolicies>
</serviceAuthorization>
</behavior>
</serviceBehaviors>
</behaviors>
相關問題
- 1. 設置安全的SSL,WCF使用Windows身份驗證
- 2. wcf和安全,身份驗證和ssl
- 3. WCF - IIS Windows身份驗證
- 4. wcf和windows身份驗證
- 5. WCF Windows身份驗證
- 6. SQL Server Windows身份驗證安全
- 7. WCF - Windows身份驗證 - 安全設置需要匿名
- 8. WCF使用用戶名身份驗證和消息安全
- 9. 安全API身份驗證
- 10. 安全LDAP身份驗證
- 11. WCF身份驗證 - 驗證郵件安全性時出錯
- 12. WPF,使用ASP.Net身份驗證的WCF安全
- 13. 禁用Windows身份驗證WCF
- 14. 使用Windows身份驗證與TCP連接的WCF的安全性
- 15. WCF身份驗證
- 16. WCF身份驗證
- 17. WCF身份驗證
- 18. 使用Windows身份驗證安全單一視圖(MVC ASP.NET)?
- 19. wcf用戶身份驗證
- 20. 使用OmniAuth Facebook身份驗證路由的安全身份驗證
- 21. 帶WCF Windows身份驗證的ASP.NET
- 22. 瞭解WCF Windows身份驗證
- 23. Pockect PC WCF實現Windows身份驗證
- 24. WCF - 覆蓋Windows身份驗證
- 25. WCF服務Windows身份驗證
- 26. WCF Windows身份驗證,未通過
- 27. Silverlight和WCF與Windows身份驗證
- 28. WCF Windows身份驗證不WsHttpBinding的
- 29. WCF中的Windows身份驗證
- 30. .net 4.0 + WCF + WIndows身份驗證+ IIS