34

我现在在一个谷歌应用引擎项目中。在我的应用程序中,我必须只允许 https 协议。而且我必须限制其他协议。它应该只允许 https。我在 web.xml 中添加了以下代码。

<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?

4

5 回答 5

64

可以将各个处理程序配置为在 WEB-INF 文件夹中的 app.yaml 文件中需要 HTTPS,如下所述:Java 应用程序配置使用 app.yaml - Google App Engine

您只需将这两个词添加到app.yaml文件中的相应url条目下:
secure: always

例如:

- url: .*
  script: main.app
  secure: always

然后,如果用户尝试使用 HTTP 访问 URL,她将被自动重定向到 HTTPS。很酷。

于 2011-06-11T13:07:48.627 回答
16

如果您想坚持使用“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

于 2014-10-15T23:41:20.683 回答
4

您使用的是自己的域吗?目前,GAE支持 *.appspot.com 域的 SSL 。一段时间以来,他们一直承诺为非 appspot 域提供 SSL 支持,我们都在等待这方面的消息。

于 2011-03-20T14:08:43.593 回答
1

这是给未来的人的!!!

  1. 在javaweb.xml中,在我的文件中添加下面的代码对我有用

    <security-constraint>
       <web-resource-collection>
          <web-resource-name>HTTPS redirect</web-resource-name>
          <url-pattern>/*</url-pattern>
       </web-resource-collection>
       <user-data-constraint>
          <transport-guarantee>CONFIDENTIAL</transport-guarantee>
       </user-data-constraint>
    </security-constraint>
    
  2. 对于其他项目,在文件secure: always中的所有 url 下添加app.yaml

于 2018-10-11T07:25:16.827 回答
0

将此添加到您的 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>
于 2017-05-03T11:36:27.573 回答