HTTPS 和 RETEasy

发布于 2024-11-17 17:01:34 字数 100 浏览 2 评论 0原文

RESTEasy 配置(使用 2.*)或 jax-rs 中是否有一种方法不允许 http 访问任何基于 REST 的 Web 服务?我只想为 https 下的 Web 服务端点提供服务。

Is there a way within the RESTEasy configuration (using 2.*) or jax-rs to not allow http access to any REST based web services? I want to only serve the web service end points under https.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

樱娆 2024-11-24 17:01:34

在 tomcat 中,它是按端口完成的。似乎需要 3 个步骤来进行设置。

1) 创建密钥库文件。我使用 java 生成此命令如下

Keytool –genkey –alias presto  –keypass prestoAdmin  –keystore presto.bin –storepass prestoAdmin

将 presto.bin 文件复制到 tomcat 的 webapps 目录

2) 为 tomcat 设置 server.xml

<Connector port=”PORT_TO_BE_SCURED”  maxThreads="200"
scheme="https" secure="true" SSLEnabled="true"
keystoreFile../webapps/presto.bin " keystorePass="prestoAdmin"
clientAuth="false" sslProtocol="TLS"/>

3) 配置 Web 服务以使用安全连接。将以下内容添加到 web.xml

<security-constraint>
<web-resource-collection>
<web-resource-name>securedapp</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>

我从 http://tomcat 中提取此内容。 apache.org/tomcat-6.0-doc/ssl-howto.html

In tomcat its done in on a per port basis. There looks to be 3 steps to setting this up.

1) Creating the KeyStore file. I used java to gen this command is as follows

Keytool –genkey –alias presto  –keypass prestoAdmin  –keystore presto.bin –storepass prestoAdmin

Copy the presto.bin file into the webapps dir of tomcat

2) Setting up server.xml for tomcat

<Connector port=”PORT_TO_BE_SCURED”  maxThreads="200"
scheme="https" secure="true" SSLEnabled="true"
keystoreFile../webapps/presto.bin " keystorePass="prestoAdmin"
clientAuth="false" sslProtocol="TLS"/>

3) Configuring the web service to use the secured connection. Add the following to web.xml

<security-constraint>
<web-resource-collection>
<web-resource-name>securedapp</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>

I pulled this from http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html

浅笑轻吟梦一曲 2024-11-24 17:01:34

我是这样做的:

HttpServletRequest httpServletRequest =
    ResteasyProviderFactory.getContextData(HttpServletRequest.class);
HttpServletResponse httpServletResponse =
    ResteasyProviderFactory.getContextData(HttpServletResponse.class);

if (!httpServletRequest.isSecure())
{
    try
    {
        httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "Use HTTPS");
    }
    catch (IOException e)
    {
        throw new WebApplicationException(e);
    }
}

这是纯粹的 RESTEasy 解决方案,您可以在处理请求之前将此代码放置在任何位置。

我使用了 tapestry-resteasy 集成,并使用 挂毯服务顾问

Here's how I did this:

HttpServletRequest httpServletRequest =
    ResteasyProviderFactory.getContextData(HttpServletRequest.class);
HttpServletResponse httpServletResponse =
    ResteasyProviderFactory.getContextData(HttpServletResponse.class);

if (!httpServletRequest.isSecure())
{
    try
    {
        httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "Use HTTPS");
    }
    catch (IOException e)
    {
        throw new WebApplicationException(e);
    }
}

This is pure-RESTEasy solution and you can place this code anywhere before handling request.

I used tapestry-resteasy integration and implemented this using tapestry service advisors.

动听の歌 2024-11-24 17:01:34

我认为这个配置不应该在 RESTEasy 端,而应该在 servlet 容器或 Web 服务器上。

例如,如果您运行 Tomcat,请在 server.xml 中从 8080 端口删除连接器,并为 8443 端口定义一个连接器。所以Tomcat将不再接受http流量。

I believe that this configuration should not be at RESTEasy side, but rather at servlet container or web server.

For example if you run Tomcat, in server.xml remove connector from 8080 port and define one for 8443 port. So Tomcat won't accept the http traffic anymore.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文