tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier ...@ice-sa.com>
Subject Re: RemoteAddrValve syntax
Date Sun, 05 Apr 2009 18:33:09 GMT
Jonathan Mast wrote:
> How do I specify wildcards in the RemoteAddrValue declaration?
> 
> The Tomcat docs says it uses the java.util.regex package, so i wrote a test
> case like this:
> 
>         String patternStr = "192.168.*.*";
>         String searchStr = "192.168.1.2";
> 
>         Pattern p = Pattern.compile(patternStr);
>         Matcher m = p.matcher(searchStr);
>         System.out.println("Does " + patternStr);
>         System.out.println("Match " + searchStr);
>         boolean b = m.matches();
>         System.out.println("Result: " + b);
> 
> Which returns true, however when I placed patternStr into my server.xml file
> (following the conventions in the Tomcat docs of escaping the "." with \ ):
> <Valve className="org.apache.catalina.valves.RemoteAddrValve"
> allow="192\.168\.*\.*"/>

This is not a "Tomcat convention", it is how regular expressions work.
In a regular expression,
a "." means 'any character'
"\." mean 'the character "."'
the expression "\.*" means "a ".", 0 or n times"
The expression "192.168.1.2", as a regexp, matches "192.168.1.2", but 
also matches "192A168+1C2" and "19201689152" (and a lot more strings), 
since an unescaped "." matches any character.
The regexp "192.168.*.*" does  not make much sense, since the first ".*" 
will match anything that follows (or nothing), leaving nothing to match 
for the second ".*".

To match any address starting with "192.168.", use
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
  allow="192\.168\..*"/>
or (if you want to be really finicky about it)
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
  allow="192\.168\.\d{1,3}\.\d{1,3}"/>




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message