Glassfish 只允许 GET 和 POST 方法
Glassfish allow only GET and POST methods
部署 ear 后,我需要在 glassfish 4.1.1 中隐藏我们应用程序的方法,因此在 web.xml 我添加了以下内容:
<security-constraint>
<display-name>Constraint1</display-name>
<web-resource-collection>
<web-resource-name>https</web-resource-name>
<description/>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<user-data-constraint>
<description/>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
所以当我用 curl 检查时:
curl -i -X OPTIONS --insecure https://address
我得到以下信息:
Allow: GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS
您所做的并没有禁用未列出的方法(例如 PUT、DELETE),而是在使用这些方法时强制进行身份验证。如果您不想支持特定的 HTTP 方法,您可以构建一个不支持该特定方法的 Web 应用程序。
例如,如果您部署的应用程序将某个 REST 端点公开给 GET 和 POST,而不是 PUT,那么如果有人尝试使用 PUT 访问它,他们很可能已经获得了某种方法不支持的错误。您还可以更进一步,实际为 PUT 定义该端点,但随后抛出异常、return 自定义错误消息等。
阅读 here 了解更多信息。
部署 ear 后,我需要在 glassfish 4.1.1 中隐藏我们应用程序的方法,因此在 web.xml 我添加了以下内容:
<security-constraint>
<display-name>Constraint1</display-name>
<web-resource-collection>
<web-resource-name>https</web-resource-name>
<description/>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<user-data-constraint>
<description/>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
所以当我用 curl 检查时:
curl -i -X OPTIONS --insecure https://address
我得到以下信息:
Allow: GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS
您所做的并没有禁用未列出的方法(例如 PUT、DELETE),而是在使用这些方法时强制进行身份验证。如果您不想支持特定的 HTTP 方法,您可以构建一个不支持该特定方法的 Web 应用程序。
例如,如果您部署的应用程序将某个 REST 端点公开给 GET 和 POST,而不是 PUT,那么如果有人尝试使用 PUT 访问它,他们很可能已经获得了某种方法不支持的错误。您还可以更进一步,实际为 PUT 定义该端点,但随后抛出异常、return 自定义错误消息等。
阅读 here 了解更多信息。