https只在谷歌应用引擎
问题描述:
我现在在谷歌应用引擎项目。在我的应用程序中,我只需要允许https协议。我必须限制其他协议。它应该只允许https。我在web.xml中添加了下面的代码。https只在谷歌应用引擎
<security-constraint>
<web-resource-collection>
<web-resource-name>Protected Area</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
但部署后它可以在协议(http和https)上工作。如何限制http?
答
可以将各个处理程序配置为在WEB-INF文件夹中的app.yaml文件中要求HTTPS,如此处所述:Java Application Configuration Using app.yaml - Google App Engine。
你只需要这两个词的适当url
条目下添加到您的app.yaml
文件:secure: always
例如:
- url: .*
script: main.app
secure: always
如果用户试图用HTTP访问URL然后她将被自动重定向到HTTPS。很酷。
答
如果您想坚持使用“web.xml”而不是使用“app.yaml”选项(它将在部署时覆盖您的web.xml & appengine-web.xml文件),则可以添加:
<security-constraint>
<web-resource-collection>
<web-resource-name>everything</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
参考: https://cloud.google.com/appengine/docs/java/config/webxml#Security_and_Authentication
答
添加到您的web.xml文件
<security-constraint>
<web-resource-collection>
<web-resource-name>all</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
你测试你部署到应用程序的相同版本?您是否尝试删除“”? –
2011-03-20 13:59:53
我正在测试我部署的相同版本。我没有通过删除网络资源名称进行测试。让我试试现在。谢谢。 – DonX 2011-03-20 14:07:23