WCF 服务授权管理器设置 Thread.CurrentPrincipal
我有一个自定义 ServiceAuthorizationManager,我在其中重写 CheckAccess 并验证作为 URL 一部分的自定义身份验证令牌。验证后,我使用 GenericPrincipal 设置 Thread.CurrentPrincipal。但是当请求最终到达我的服务方法时,Thread.CurrentPrincipal 消失了,这不是我在身份验证管理器中设置的。 出了什么问题?
I have a custom ServiceAuthorizationManager where i override CheckAccess and validate a custom auth token that is part of the URL. After i validate, i set the Thread.CurrentPrincipal with a GenericPrincipal. But when the request finally reaches my service method, Thread.CurrentPrincipal is gone, it is not what i set in the auth manager.
What's going wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过在注册服务身份验证管理器的服务行为中设置principalPermissionMode =“None”来解决这个问题。这应该告诉 wcf 运行时不要将任何主体放入当前线程中。如果将其设置为“自定义”,它将覆盖您使用 GenericPrincipal 设置的任何主体。
I got around this by setting principalPermissionMode="None" in the service behavior where i register the service auth manager. This is supposed to tell the wcf runtime not to put any principal in the current thread. If you set it to "custom", it overwrites whatever principal you set using a GenericPrincipal.
如果您不希望使用内置机制进行授权,WCF 要求通过 IAuthorizationPolicy 识别当前主体,以便正确集成到 WCF 管道中。您需要指定“Custom”的PrincipalPermissionMode。
有关详细介绍,请参阅此文章:基于 WCF 的服务中的授权
If you do not wish to use the built-in mechanisms for authorization, WCF requires that the current principal be identified via an IAuthorizationPolicy to be properly integrated in the WCF pipeline. You will need to specify and PrincipalPermissionMode of 'Custom'.
For a detailed introduction see this article: Authorization In WCF-Based Services