简体   繁体   English

tomcat webapp如何在没有spring安全性的情况下切换到https并返回http

[英]tomcat webapp How to switch to https and back to http without spring security

Using Tomcat 7.0.32, we have a login page, that by default, the user comes to through http. 使用Tomcat 7.0.32,我们有一个登录页面,默认情况下,用户通过http访问。 we immediately redirect the user to use https. 我们立即重定向用户以使用https。
Goal : After user enters the credentials, we want to redirect the user to the Home page using http. 目标:用户输入凭据后,我们希望使用http将用户重定向到主页。

I understand the security risks -- man in the middle, session hijacking, etc. 我理解安全风险 - 中间人,会话劫持等。

I can't use spring security -- it's too late in the game -- release is coming shortly and https performance sucks. 我不能使用Spring安全 - 在游戏中为时已晚 - 很快就会发布,https性能糟透了。

Also, our app has a "change password" usecase -- the user accesses "changepassword.jsp" from a menu in the home page, I guess I should redirect the user to "changepassword.jsp" using https. 此外,我们的应用程序有一个“更改密码”用例 - 用户从主页的菜单访问“changepassword.jsp”,我想我应该使用https将用户重定向到“changepassword.jsp”。 After password change is confirmed, then redirect user back again to homepage using http. 确认密码更改后,再使用http将用户重定向回主页。 Thoughts ? 想法?

How to go about doing it -- is there any sample code available ? 如何去做 - 是否有可用的示例代码?

UPDATE 1 : I've read about the issue from 更新1 :我已经从中了解了这个问题
1) http://tomcat.10.n6.nabble.com/Session-lost-when-switching-from-https-to-http-after-upgrade-to-Tomcat-6-td2105781.html 1) http://tomcat.10.n6.nabble.com/Session-lost-when-switching-from-https-to-http-after-upgrade-to-Tomcat-6-td2105781.html
2) http://tomcat.10.n6.nabble.com/how-to-auto-redirect-to-https-from-http-td2087325.html 2) http://tomcat.10.n6.nabble.com/how-to-auto-redirect-to-https-from-http-td2087325.html

Code from https://forums.oracle.com/forums/thread.jspa?threadID=1394970 (Cabir) 代码来自https://forums.oracle.com/forums/thread.jspa?threadID=1394970(Cabir

What gotchas should I expect ? 我应该期待什么?

You say "I know Spring Security can do it", but in fact Spring Security doesn't do anything special. 你说“我知道Spring Security可以做到”,但事实上Spring Security并没有做任何特别的事情。 It just performs a redirect to HTTPS, which you are doing yourself. 它只是执行重定向到HTTPS,您自己正在做。 If you create a session with a secure cookie, and then switch back to HTTP, you will lose the session. 如果使用安全cookie创建会话,然后切换回HTTP,则会丢失会话。 This is explained in the Spring Security FAQ . 这在Spring Security FAQ中有解释。 As it explains, if you create a session before you redirect to HTTPS, then the session cookie will not be flagged as secure and will be passed over both HTTP and HTTPS, maintaining the session throughout. 正如它解释的那样,如果您在重定向到HTTPS之前创建会话,那么会话cookie将不会被标记为安全,并且将通过HTTP和HTTPS传递,从而维护整个会话。

The only other option that I can think of would be using mod_headers or its equivalent to modify the Set-Cookie header and remove the Secure flag if it is present. 我能想到的唯一其他选项是使用mod_headers或其等价物修改Set-Cookie标头并删除Secure标志(如果存在)。 here's an example which does the opposite , adding the flag to all cookies. 这是一个相反的例子,将标志添加到所有cookie中。

As an aside, have you tried performance tuning your site with HTTPS ? 顺便说一下,您是否尝试使用HTTPS调整网站性能 You should really be using it throughout your app if there is any real value in your content and user accounts. 如果您的内容和用户帐户有任何实际价值,您应该在整个应用中使用它。

"Session hijacking" means different things in different contexts. “会话劫持”在不同的背景下意味着不同的东西。 You are considering a system where I can hijack a session in ten minutes with WireShark and no previous experience. 您正在考虑一个系统,我可以使用WireShark在十分钟内劫持一个会话,而且之前没有任何经验。 I just need to get the cookie that is flying unencrypted and copy it inside Chrome. 我只需要获取未加密的cookie并将其复制到Chrome中。 That seems like a too low barrier of entry. 这似乎是一个太低的进入门槛。

You should reconsider the performance hit of https, which will probably be a required part of http 2.0 (sorry, PDF). 您应该重新考虑https的性能影响,这可能是http 2.0的必需部分 (抱歉,PDF)。 From the document (pages 32-33): 从文件(第32-33页):

On our production frontend machines, SSL/TLS accounts for less than 1% of the CPU load, less than 10KB of memory per connection and less than 2% of network overhead - Adam Langley (Google) 在我们的生产前端机器上,SSL / TLS占CPU负载的不到1%,每个连接少于10KB的内存,不到2%的网络开销 - Adam Langley(谷歌)

I would spend ten minutes configuring SPDY in my server instead of avoiding https, if performance is the problem. 如果性能问题,我会花十分钟在我的服务器中配置SPDY,而不是避免使用https。

Is it possible to place an Apache HTTP Server in front of Tomcat? 是否可以将Apache HTTP Server放在Tomcat之前?

If you configure a Reverse Proxy , you can let Apache handle the SSL traffic. 如果配置反向代理 ,则可以让Apache处理SSL流量。

In this way, you can redirect requests for logon and change password pages to HTTPS. 通过这种方式,您可以将登录请求和更改密码页重定向到HTTPS。

Why dont You use Java Authentication and Authorization Service JAAS Using user credentials you can make LoginContext 为什么不使用Java身份验证和授权服务JAAS使用用户凭据可以创建LoginContext

LoginContext will login into server container and after that login you can easily get user session from HTTP request object. LoginContext将登录到服务器容器,登录后您可以轻松地从HTTP请求对象获取用户会话。 This way you can get user session whether its HTTP or HTTPS. 这样您就可以获得用户会话,无论是HTTP还是HTTPS。 On clicking changepassword link user should be directed to a secure URL and request object will give required information. 在单击changepassword链接时,应将用户定向到安全URL,并且请求对象将提供所需信息。

You can enable cookies in JAVA API 您可以在JAVA API中启用Cookie

CookieHandler.setDefault(new CookieManager());

or Cookie policy on it to accept all cookies. 或Cookie政策,以接受所有cookie。

CookieManager customCookieManager = new CookieManager(); customCookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(customCookieManager);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM