tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier ...@ice-sa.com>
Subject Re: Denying IPs using the Valve command in context.xml
Date Tue, 04 Oct 2011 21:48:01 GMT
Christopher Schultz wrote:
...

> 
>> And, it seems that the Pattern class, and its own .matches()
>> method, does work in the way that a non-exclusively-java programmer
>> would expect, anchors and all.
> 
> Does it?
> 

Yes, because if one defines e.g. a Pattern "^abcdef" and uses it via
yesno = Pattern.matches("^abcdef",input);
it will actually match the pattern at the beginning of the string only, which is what one

would expect.  Thus

Pattern.matches("^abc","abcdef");

would return true, while this :

Pattern.compile("^abc").matcher("abcdef").matches()

would return false (according to what I read in the documentation of Matcher.matches()).
Not so ?

> 
>> So my question is : which of Matcher or Pattern is really used in
>> the Valve's code ?
> 
> You could read the code :)
> 

Do you mean to say that trying to configure Tomcat according to the online documentation,

with the purpose of using it as a servlet container, is reserved exclusively for java 
programmers ?
;-)

...

I guess that what I have trouble understanding here, is how the Java regex library can go

about allowing to create a Pattern like "^abc", and then using it in a Matcher.matches() 
method, completely ignoring the anchors which it accepted in the Pattern and silently 
inserting its own.

Unless apparently, if you first call
Matcher.useAnchoringBounds(true)

/then/ it would respect the anchors in the Pattern.
Or ?

I must admit that I cannot really be sure of my interpretation of the useAnchoringBounds 
method :

quote :

public Matcher useAnchoringBounds(boolean b)

     Sets the anchoring of region bounds for this matcher.

     Invoking this method with an argument of true will set this matcher to use anchoring

bounds. If the boolean argument is false, then non-anchoring bounds will be used.

     Using anchoring bounds, the boundaries of this matcher's region match anchors such as

^ and $.

     Without anchoring bounds, the boundaries of this matcher's region will not match 
anchors such as ^ and $.

     By default, a matcher uses anchoring region boundaries.

unquote

The above would seem to indicate that by default, anchors like ^ and $ (in the Pattern ?)

are being respected.
But then, how come they are not, in the allow/deny of the Valve ?
Does the Valve code itself strip any provided anchors, and "force" ^ and $ around the 
expression provided in the allow/deny attributes ?



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


Mime
View raw message