Skip to content

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

Closed
@transentia

Description

@transentia

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

Metadata

Metadata

Assignees

Labels

in: webAn issue in web modules (web, webmvc)status: duplicateA duplicate of another issuetype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions