从 servlet 打开受密码保护的网站
该场景的预期用户将访问 servlet(例如 http://someip/myservlet)进而验证受密码保护的网站(例如mysite.com - 托管在 IIS 服务器上,启用 Windows 身份验证)隐式然后打开mysite.com – 这样:
- 目标用户将不会收到输入用户名和密码的提示。 密码,因为他将通过 servlet(托管在 Tomcat 等服务器上)
- 任何其他访问 链接文本< /a> 在不知道凭据的情况下将无法访问
要求是 (它必须打开该网站而不是获取内容,如 mysite.com< /a> 具有动态功能)
Java 中是否可能(HttpURLConnection)?
任何帮助表示赞赏。
谢谢。
The scenario is intended user will access the servlet (e.g http://someip/myservlet) which in turn authenticates a password protected website (e.g. mysite.com - which is hosted on IIS server with Use Windows authentication enabled) implicitly and then opens that mysite.com – so that:
- target users will not get prompt for username & password as he will go through the servlet(hosted on some server like tomcat)
- any other user accessing link text will not be able to access without knowing credentials
The requirement is
(it has to open that website not fetch the content as mysite.com has dynamic functionality in it)
Is it possible in Java (HttpURLConnection) ??
any help is appreciated.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为了确保我理解您的需求,这里有一个摘要:
您希望给定用户 A 连接到您的第一台服务器 Server1.domain1.com,该服务器将(从 java 服务器内部)连接到第二台服务器 server2.domain2.com(当前位于 IIS 下)。 然后,服务器 1 会将用户转发到服务器 2 的网页,挑战是避免任何身份验证弹出窗口。
根本问题是将server1 从server2 获得的身份验证票证从server1 传输到客户端浏览器,然后从客户端浏览器传输到server2。
这不是一个具体的java问题,而是一个全球性的WEB问题。 事实上,server2 接收到的用于识别客户端用户的唯一信息是在 http 流中,简而言之就是 IP 地址、URL 和 cookie。
如果 server1 和 server2 不是同一个域,则 Cookie 是一个死胡同(请参阅 RFC 2109 : http:// /www.ietf.org/rfc/rfc2109.txt),因为仅当 cookie 从同一域的服务器(相同或另一个)返回时,浏览器才会将 cookie 发送到给定域的服务器。
所以答案是一个两步过程:
乍一看,我没有看到其他简单的解决方案。
To be sure I understood your need, here is a summary :
you want a given user A to connect on your first server Server1.domain1.com, that would connect (from inside the java server) on a second server server2.domain2.com (currently under IIS). Then server1 would forward user to server2 web page, the challenge being avoiding any authentication popup.
The root problem is to transmit, from the server1 to the client browser, then from client browser to server2, the authentication ticket that server1 got from server2.
It is not specifically a java problem but more a global WEB problem. Indeed the only information received by server2 to identify client user is in the http flow, in short words the IP adress, the URL, and cookies.
Cookies is a dead end if server1 and server2 are not the same domain (see RFC 2109 : http://www.ietf.org/rfc/rfc2109.txt), as browser would send cookies to a server of a given domain only if the cookie was returned from a server (the same or another) of the SAME domain.
So the answer is a two step process :
At first sight I see no other simple solution.
HTTP 反向代理 似乎涵盖了您想要实现的功能。
这种代理将在另一个位置(例如 site2.domain2.com)“镜像”某些站点 site1.domain1.com
最常见的用例是 site1 不是公共的,反向代理将充当网关、负载均衡器、SSL 网关或类似的。
对于 Java 中的实现:我还推荐 Apache HTTP 客户端 库。 并且可以通过此客户端库使用 NTLM 身份验证。
It seems the functionality you like to implement is covered by HTTP reverse proxies.
This kind of proxy will "mirror" some site site1.domain1.com at another location like site2.domain2.com
Most common use-cases are that site1 is not pubic and the reverse proxy will act as a gateway, load balancer, SSL gateway or similar.
For implementation in Java: I also recommend the Apache HTTP client library. And it's possible to use NTLM authentication with this client lib.
如果您确实想要实现这种请求转发,那么内置的 HTTPURLConnection 可能还不够。 尝试一下 Apache HTTPClient 它有足够的自定义选项。 您还可以查找 TCP 转发解决方案或这篇文章。
The built in HTTPURLConnection might be not enough if you really want to implement this kind of request forwarding. Try the Apache HTTPClient which has ample of customization options. You could also look for TCP forward solutions or this post.