仅在Google应用引擎中使用https

Don*_*onX 31 https google-app-engine maven-gae-plugin

我现在正在使用谷歌应用引擎项目.在我的应用程序中,我必须只允许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>
Run Code Online (Sandbox Code Playgroud)

但是在部署之后,它同时适用于协议(http和https).如何限制http?

zen*_*bor 54

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

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

例如:

- url: .*
  script: main.app
  secure: always
Run Code Online (Sandbox Code Playgroud)

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


小智 14

如果您想坚持使用"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>
Run Code Online (Sandbox Code Playgroud)

参考:https: //cloud.google.com/appengine/docs/java/config/webxml#Security_and_Authentication


YKS*_*YKS 4

您使用自己的域名吗?目前,GAE支持 *.appspot.com 域的 SSL 。他们承诺对非 appspot 域提供 SSL 支持已经有一段时间了,我们都在等待这方面的消息。

  • 现在支持自定义域的 SSL https://support.google.com/a/answer/2644334?hl=en (4认同)