You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2021/02/23 15:08:25 UTC
Subclassing RemoteCIDRFilter in an application
All,
A bunch of clients at $work are suddenly asking if they can restrict
their users to certain IP "addresses" when logging-in. Should be easy
with a Filter or similar, right?
Tomcat has both RemoteCIRDFilter and RemoteIPFilter: why re-invent the
wheel?
Looking at RemoteCIDRFilter (which is much more flexible than
RemoteIPFilter), I can see these methods:
public void setDeny(String deny);
public String getDeny();
public void setAllow(String allow);
public String getAllow();
At first, I thought "maybe I can simply subclass and override
getAllow()" but the class's code references its own member directly:
private boolean isAllowed(final String property) {
[...]
for (final NetMask nm : allow) {
if (nm.matches(addr)) {
return true;
}
}
[...]
}
The isAllowed() method itself is private and therefore not overridable.
For the sake of argument, I could change that code to:
for (final NetMask nm : getAllowNetMasks()) {
if (nm.matches(addr)) {
return true;
}
}
... and introduce a new method which returns that member, then override
it in my subclass.
Since this control needs to be implemented as a per-user setting, the
existing "allow" and "deny" members would be ignored.
Other than a trivial waste of memory (and the dependence upon
Tomcat-specific code), can anyone think of a reason not to simply make
these changes and subclass the Filter in my own application?
-chris
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Subclassing RemoteCIDRFilter in an application
Posted by Christopher Schultz <ch...@christopherschultz.net>.
All,
On 2/23/21 10:08, Christopher Schultz wrote:
> Tomcat has both RemoteCIDRFilter and RemoteIPFilter: why re-invent the
> wheel?
>
> Looking at RemoteCIDRFilter (which is much more flexible than
> RemoteIPFilter), I can see these methods:
Oops, I meant RemoteAddressFilter, here, of course
-chris
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org