<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Add a global valve in AS7 (7.2.x)
</h3>
<span style="margin-bottom: 10px;">
    modified by <a href="https://community.jboss.org/people/jfclere">Jean-Frederic Clere</a> in <i>JBoss Web Development</i> - <a href="https://community.jboss.org/docs/DOC-47954">View the full document</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>The global valve feature has been added by pull request #3326.</p><p>To use it you need to put the valve class(es) in a jar and the jar in a module, tell do that with an example:</p><p>Let's use the Tomcat <code>RemoteAddrValve.</code></p><p>In tomcat you would have something like in server.xml</p><p><code>&lt;Valve className="org.apache.catalina.valves.RemoteAddrValve" deny="127.*"/&gt;</code></p><p>In AS7 in standalone.xml in the web subsystem:</p><table><tbody><tr><td style=";"><br/></td><td style=";">&lt;valve name="myvalve" module="mymodule" class-name="org.apache.catalina.valves.RemoteAddrValve"&gt;</td></tr><tr><td style=";"><br/></td><td style=";">&lt;param param-name="deny" param-value="127.*"/&gt;</td></tr><tr><td style=";"><br/></td><td style=";">&lt;/valve&gt;</td></tr></tbody></table><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Or via the jboss-cli:</p><p>./valve=myvalve:add(class-name=<code>org.apache.catalina.valves.RemoteAddrValve</code>,module=mymodule,enabled=false)</p><p> ./valve=myvalve:add-param(param-name=deny,param-value=127.*)</p><p>./valve=myvalve:write-attribute(name=enabled, value=true)</p><p>/:reload</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The class needs to be in a jar.</p><p>Compile the RemoteAddrValve.java from the jbossweb sources or extract it from jbossweb.jar.</p><p>then create the jar:</p><p>jar cvf myjar.jar org/apache/catalina/valves/RemoteAddrValve.class</p><p>then create the module:</p><p>mkdir modules/mymodule</p><p>mkdir modules/mymodule/main</p><p>mv myjar.jar modules/mymodule/main</p><p>add create the modules/mymodule/main/module.xml with the content:</p><p>&lt;module xmlns="urn:jboss:module:1.1" name="mymodule"&gt;</p><p>&#160;&#160;&#160; &lt;properties&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;property name="jboss.api" value="private"/&gt;</p><p>&#160;&#160;&#160; &lt;/properties&gt;</p><p>&#160;&#160;&#160; &lt;resources&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;resource-root path="myjar.jar"/&gt;</p><p>&#160;&#160;&#160; &lt;/resources&gt;</p><p>&#160;&#160;&#160; &lt;dependencies&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;module name="sun.jdk"/&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;module name="javax.servlet.api"/&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;module name="org.jboss.as.web"/&gt;</p><p>&#160;&#160;&#160; &lt;/dependencies&gt;</p><p>&lt;/module&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>To test the valve start AS7 on 0.0.0.0 (bin/standalone.sh -b 0.0.0.0) and use curl:</p><p><span>curl -v </span><a class="jive-link-external-small" href="http://localhost:8080/" target="_blank">http://localhost:8080/</a></p><p>* About to connect() to localhost port 8080 (#0)</p><p>*&#160;&#160; Trying 127.0.0.1...</p><p>* connected</p><p>* Connected to localhost (127.0.0.1) port 8080 (#0)</p><p>&gt; GET / HTTP/1.1</p><p>&gt; User-Agent: curl/7.24.0 (i686-redhat-linux-gnu) libcurl/7.24.0 NSS/3.13.5.0 zlib/1.2.5 libidn/1.24 libssh2/1.4.1</p><p>&gt; Host: localhost:8080</p><p>&gt; Accept: */*</p><p>&gt; </p><p>&lt; HTTP/1.1 403 Forbidden</p><p>&lt; Server: Apache-Coyote/1.1</p><p>&lt; Transfer-Encoding: chunked</p><p>&lt; Date: Mon, 26 Nov 2012 10:57:17 GMT</p><p>&lt; </p><p>* Connection #0 to host localhost left intact</p><p>* Closing connection #0</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>using curl and the hostname should give the normal AS7 page, if not try from a another box:</p><p><span>[jfclere@neo6 ~]$ curl -v </span><a class="jive-link-external-small" href="http://jfcpc:8080/" target="_blank">http://jfcpc:8080/</a></p><p>* About to connect() to jfcpc port 8080 (#0)</p><p>*&#160;&#160; Trying 10.33.144.3... connected</p><p>* Connected to jfcpc (10.33.144.3) port 8080 (#0)</p><p>&gt; GET / HTTP/1.1</p><p>&gt; User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.12.6.2 zlib/1.2.3 libidn/1.9 libssh2/1.2.4</p><p>&gt; Host: jfcpc:8080</p><p>&gt; Accept: */*</p><p>&gt; </p><p>&lt; HTTP/1.1 200 OK</p><p>&lt; Server: Apache-Coyote/1.1</p><p>&lt; Accept-Ranges: bytes</p><p>&lt; ETag: W/"2432-1353665779000"</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Comment by <a href="https://community.jboss.org/docs/DOC-47954">going to Community</a></p>

        <p style="margin: 0;">Create a new document in JBoss Web Development at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=102&containerType=14&container=2112">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>