Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add meaningful toString/getIpAddress methods to org.springframework.security.web.util.matcher.IpAddressMatcher #16693

Open
transentia opened this issue Mar 3, 2025 · 1 comment
Labels
status: ideal-for-contribution An issue that we actively are looking for someone to help us with type: enhancement A general enhancement

Comments

@transentia
Copy link

Expected Behavior

It should be possible to determine the address that IpAddressMatcher was instantiated with. Via a getter or via toString.

Current Behavior

The best/only thing that one can get is:

org.springframework.security.web.util.matcher.IpAddressMatcher@4c18516

The class is final and cannot be overridden to supply these methods.
I guess this means that debugging would be a pain as well...

Looking at the code, it appears that the ipAddress parameter is not even retained after construction.

Context

I want to be able to read a list of matchers from an external config and then log the list once it has been created.

At the moment, I have to have use peek like this:

        // construct a whitelist for SecurityConfiguration and LumberjackUIAPI
        ipAddressMatcherWhitelist = CONF.values().stream()
                .filter(u -> u.getPort() != -1)  // ignore any entry that doesn't have a port
                .map(URI::getHost)
                .distinct()
                .map(StreamUtils.throwingFunctionWrapper(hostname -> InetAddress.getByName(hostname).getHostAddress()))
                // can't get value from IpAddressMatcher once constructed, so do logging here
                .peek(i -> log.info("Whitelisting server IP: {}", i))
                .map(IpAddressMatcher::new)
                .toList();

More cumbersome than I would like.

Less useful/informative than simply putting this after list creation:

log.info("Server whitelist: {}", ipAddressMatcherWhitelist);
@transentia transentia added status: waiting-for-triage An issue we've not yet triaged type: enhancement A general enhancement labels Mar 3, 2025
@jzheaux
Copy link
Contributor

jzheaux commented Mar 6, 2025

I think a toString() implementation that shows the IP address and its mask, for example 10.0.0.0/8, makes sense. Are you able to contribute a PR?

@jzheaux jzheaux added status: ideal-for-contribution An issue that we actively are looking for someone to help us with and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ideal-for-contribution An issue that we actively are looking for someone to help us with type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants