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);

Comment From: jzheaux

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?

Comment From: wtigerhyunsu

I'd like to contribute to this issue. Would that be possible? if possible, please assign it to me !!

Comment From: wtigerhyunsu

@transentia Are you asking whether, when creating an object using new IpAddressMatcher, you want to be able to retrieve requiredAddress by calling IpAddressMatcher.getIpAddress() after registering it in IpAddressMatcher?

Do you just need a function inside IpAddressMatcher that returns the public requiredAddress?

Comment From: transentia

@wtigerhyunsu

At the time I opened this, I was just focussed on the toString.

I can definitely see the value of a getIpAddress method. also a getMask method, I guess.

And thank you for taking this on.

Comment From: wtigerhyunsu

@jzheaux Since this is my first comment, I didn't realize that I needed to mention someone to notify them. So I'm commenting again.

Would it be okay if I contributed to this issue?

Comment From: christopher-thumberger-whizus

@wtigerhyunsu jzheaux seems to rarely assigne issues. If it's something simple it's better to just do the issue and submit a PR than asking for assignment

Comment From: sjohnr

@christopher-thumberger-whizus it looks like @wtigerhyunsu was interested in contributing but you opened your own PR. It also looks like your PR doesn't quite match what was mentioned in this comment. For those reasons, I will assign this issue to @wtigerhyunsu so they can try their hand at opening a PR.