How to disable certain HTTP methods (PUT, DELETE, TRACE and OPTIONS) in JBOSS7

本文介绍了三种禁用特定HTTP方法的方法:使用RewriteValve全局配置、通过web.xml中的安全约束进行WAR级别的限制以及利用Apache httpd的mod_rewrite模块。

Resolution

Option 1 -Using RewriteValve (can apply globally)

You can use RewriteValve to disable the http methods. Take a look atdocumentation http://docs.jboss.org/jbossweb/2.1.x/rewrite.html.You will need one RewriteCond directive and one RewriteRule.

In your RewriteCond directive you could specify all methods with use of the REQUEST_METHOD servervariable, for example:

RewriteCond %{REQUEST_METHOD} ^(PUT|DELETE|TRACE|OPTIONS)$ [NC]

then your RewriteRule can mark those as forbidden (it immediately sends back aHTTP response of 403 (FORBIDDEN)), for example:

RewriteRule .* - [F]

For EAP6:

RewriteValve can be configured asglobal valve in domain.xml or standalone.xml. You can add the <rewrite> tag to the <virtual-server> configuration of the web subsystem.

.. ..

<subsystem xmlns="urn:jboss:domain:web:1.1"default-virtual-server="default-host" native="false">

    <connector name="http" protocol="HTTP/1.1"scheme="http" socket-binding="http"/>

    <virtual-server name="default-host"enable-welcome-root="true">

        <rewritepattern=".*" substitution="-" flags="F">

           <condition test="%{REQUEST_METHOD}"pattern="^(PUT|DELETE|TRACE|OPTIONS)$" flags="NC" />

    </rewrite>

    </virtual-server>

</subsystem>

.. ..

Option 2 - web.xml Security constraints(per WAR)

This can be done by adding security constraints to theapplication's web.xml. For example:

.. ..

<security-constraint>

    <web-resource-collection>

       <web-resource-name>NoAccess</web-resource-name>

       <url-pattern>/*</url-pattern>

         <http-method>DELETE</http-method>

         <http-method>PUT</http-method>

         <http-method>OPTIONS</http-method>

         <http-method>TRACE</http-method>

         <http-method>POST</http-method>

    </web-resource-collection>

    <auth-constraint/>

</security-constraint>

.. ..

In the above example, access the following http requests DELETE, PUT, OPTIONS, POST aredisabled by default.

You can also restrict all methods other than explicitlyallowed ones by doing like:

.. ..

<security-constraint>

    <web-resource-collection>

       <web-resource-name>NoAccess</web-resource-name>

       <url-pattern>/*</url-pattern>   

    </web-resource-collection>   

    <auth-constraint/>

</security-constraint>

<security-constraint> 

    <web-resource-collection>    

        <web-resource-name>AllowedMethods</web-resource-name>    

        <url-pattern>/*</url-pattern>    

          <http-method>GET</http-method>

         <http-method>POST</http-method>

         <http-method>HEAD</http-method>

    </web-resource-collection>

</security-constraint>

.. ..

See the Java ServletSpecification and also The Java EE 5Tutorial - "Declaring Security Requirements in a DeploymentDescriptor" for more information.

Option 3 -Using Apache httpd mod_rewrite in front of JBoss

If you are fronting JBoss with Apache httpd, you can alsoapply the above rewrite rules in the httpd.conf.:

For example:

RewriteEngine On

 

RewriteCond %{REQUEST_METHOD} ^(PUT|DELETE|TRACE|OPTIONS)$ [NC]

RewriteRule .* - [F]

To verify theabove configuration:

You can use curl command to test if the configuration change iseffective: For example:

curl -v -XTRACE http://hostname:port/appContext

curl -v -XDELETE http://hostname:port/appContex

在Ubuntu系统中,禁用挂起功能可以通过多种方式实现,具体取决于用户希望在何种场景下禁用该功能。以下是几种常见的方法: ### 1. 禁用通过电源管理的自动挂起 Ubuntu 使用 `systemd` 来管理系统的电源状态,包括挂起(suspend)和休眠(hibernate)。可以通过修改 `logind.conf` 文件来禁用自动挂起功能。 编辑 `/etc/systemd/logind.conf` 文件: ```bash sudo nano /etc/systemd/logind.conf ``` 找到以下行并进行修改: ```ini HandleSuspendKey=ignore HandleLidSwitch=ignore ``` 保存文件后重启 `systemd-logind` 服务以应用更改: ```bash sudo systemctl restart systemd-logind ``` ### 2. 禁用通过图形界面的挂起选项 如果使用的是 GNOME 桌面环境,可以通过 GNOME 的设置工具来禁用挂起功能。安装 `dconf-editor` 工具并运行: ```bash sudo apt install dconf-editor dconf-editor ``` 导航到路径 `/org/gnome/settings-daemon/plugins/power/`,然后将 `sleep-inactive-ac-timeout` 和 `sleep-inactive-battery-timeout` 设置为 `0` 以禁用自动挂起。 ### 3. 完全移除挂起功能 如果希望完全禁用挂起功能,可以通过创建一个自定义的 `systemd` 服务来覆盖默认行为。创建一个新的服务文件: ```bash sudo nano /etc/systemd/system/disable-suspend.service ``` 添加以下内容: ```ini [Unit] Description=Disable Suspend [Service] Type=oneshot ExecStart=/bin/systemctl mask sleep.target [Install] WantedBy=multi-user.target ``` 启用并启动该服务: ```bash sudo systemctl enable disable-suspend.service sudo systemctl start disable-suspend.service ``` 此操作会阻止系统进入挂起状态,并且无法通过任何命令或快捷键触发挂起。 ### 4. 禁用通过内核参数 如果需要在系统启动时就完全禁用挂起功能,可以在 GRUB 配置中添加内核参数。编辑 `/etc/default/grub` 文件: ```bash sudo nano /etc/default/grub ``` 修改 `GRUB_CMDLINE_LINUX` 行以添加 `mem_sleep_default=deep` 参数: ```ini GRUB_CMDLINE_LINUX="... mem_sleep_default=deep" ``` 更新 GRUB 配置: ```bash sudo update-grub ``` 这种方法会直接影响系统的内存睡眠模式,从而限制挂起功能的行为。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值