Google Cloud Endpoints - apiKeyRequired 在端点有尾部斜杠时不起作用
Google Cloud Endpoints - apiKeyRequired not working when endpoint has trailing slash
我在 Google Cloud Endpoints Frameworks for App Engine (Java) 中有一个端点。端点被限制为需要像这样的 API 密钥:
@ApiMethod(name = "echo", path = "echo", apiKeyRequired = AnnotationBoolean.TRUE, httpMethod = ApiMethod.HttpMethod.GET)
这是有效的。但是,如果我在进行调用时添加尾部斜杠,则端点 returns 数据没有 api 密钥要求。
我试图在 api 定义中全局限制 api 访问,如下所示:
@Api(
name = "myapi",
version = "v1",
apiKeyRequired = AnnotationBoolean.TRUE,
但这似乎不起作用。我已经重新生成了 openapi.json 并重新部署了 openapi.js 和 App Engine 应用程序,如果端点有尾部斜线,则它仍然可以访问,但并非没有。
有谁知道如何防止这种情况发生?非常感谢任何见解。
我无法在 Google 个端点内解决这个问题,所以我利用 tuckey 的 urlrewrite 删除过滤器中的尾部斜杠
web.xml
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>confPath</param-name>
<param-value>/WEB-INF/urlrewrite.xml</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/_ah/api/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
urlrewrite.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.1//EN" "http://www.tuckey.org/res/dtds/urlrewrite3.1.dtd">
<urlrewrite>
<rule match-type="regex">
<note>Remove trailing slash</note>
<from>^(.*)/$</from>
<to type="redirect"></to>
</rule>
</urlrewrite>
更多信息:
http://www.tuckey.org/urlrewrite/manual/4.0/index.html
注意:到目前为止,它还没有正确重定向。我将继续努力,并将 post 更新,但现在至少我得到了带有尾部斜杠的版本的 404,而不是没有 api 键的响应数据,这满足我目前的安全需求
我在 Google Cloud Endpoints Frameworks for App Engine (Java) 中有一个端点。端点被限制为需要像这样的 API 密钥:
@ApiMethod(name = "echo", path = "echo", apiKeyRequired = AnnotationBoolean.TRUE, httpMethod = ApiMethod.HttpMethod.GET)
这是有效的。但是,如果我在进行调用时添加尾部斜杠,则端点 returns 数据没有 api 密钥要求。
我试图在 api 定义中全局限制 api 访问,如下所示:
@Api(
name = "myapi",
version = "v1",
apiKeyRequired = AnnotationBoolean.TRUE,
但这似乎不起作用。我已经重新生成了 openapi.json 并重新部署了 openapi.js 和 App Engine 应用程序,如果端点有尾部斜线,则它仍然可以访问,但并非没有。
有谁知道如何防止这种情况发生?非常感谢任何见解。
我无法在 Google 个端点内解决这个问题,所以我利用 tuckey 的 urlrewrite 删除过滤器中的尾部斜杠
web.xml
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>confPath</param-name>
<param-value>/WEB-INF/urlrewrite.xml</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/_ah/api/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
urlrewrite.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.1//EN" "http://www.tuckey.org/res/dtds/urlrewrite3.1.dtd">
<urlrewrite>
<rule match-type="regex">
<note>Remove trailing slash</note>
<from>^(.*)/$</from>
<to type="redirect"></to>
</rule>
</urlrewrite>
更多信息:
http://www.tuckey.org/urlrewrite/manual/4.0/index.html
注意:到目前为止,它还没有正确重定向。我将继续努力,并将 post 更新,但现在至少我得到了带有尾部斜杠的版本的 404,而不是没有 api 键的响应数据,这满足我目前的安全需求