Passing HttpContext.Current.User.Identity to WCF

a 夏天 提交于 2019-12-05 07:34:47

I can't really answer directly to your question but hopefully will help you find the definite answer.

You have 2 service layers, and seems your requirement is to share Authentication identity among all layers.

So, in principle, you'd need (at least) the same Authentication mechanisms or algorithms or techniques to achieve this. But at this point you are not using the same (and you noticed when you saw a FormsIdentity and a WindowsIdentity there).

Facts:

  • You will need the same Authentication mechanism.
  • Whatever mechanism you use, needs to support that 3rd hop you want to make (meaning you can use a user's identity with a 3rd service without actually having the credentials to re-authenticate).

Problems:

  • If you continue to use Forms authentication, then you'll need to reauthenticate with your WCF service (and of course provide Identity credentials, this may help). This I find hard to do unless you keep the password the User used to authenticate him/herself which is generally a bad idea.
  • If you continue to use Windows Authentication for you site, then you'll have a problem if the user is logging in from the Intranet. Funny thing with Kerberos (Active Directory uses Kerberos) is that it let's the user access remote resources without reauthenticating... but this User Identity Token is only good for 1 hop. While your WCF and MVC services are on the same server, it'll work but if you eventually take your WCF service away... that's a 3rd box boundary... a 3rd hop, and the Kerberos ticket will not be good enough.

So... being unaware of your requirements, I would first suggest you:

  • Forget about Authentication on your WCF layer
  • Make your WCF service access private (work your Networking skills... firewalls et al). I'd start by having WCF run on a separate IIS Web Site that doesn't listen to port 80 (or 443) and make sure Firewall blocks access to your new WCF port from IPs outside your LAN (or even better, outside your white list (localhost for now)).
  • Specify the user identity as a parameter of every WCF call. Or if you are feeling wild, explore ways of specifying a user identity thru SOAP headers (if your WCF uses SOAP). A custom header should do just fine as well. You will trust then your Web Site to correctly challenge and authenticate users before granting them access to your WCF services.

I've seen this running many times by now. Not having authentication on a private service is a good performance deal, but you need to take precautions cause in general, most of the IT attacks come from the internal LAN.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!