开发者

Securing Spring web app by checking client's IP v4 address

In a Spring 3 based web app I am using a custom implementation of AbstractUserDetailsAuthenticationProvider to not only to check the username/password pair but also the IP address of the client. However, when I call within retrieveUser():

@Override
protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
    开发者_运维问答...
    String ipAddr = ((WebAuthenticationDetails)authentication.getDetails()).getRemoteAddress();
    ...
    User user = ...
    return user;
}

it returns 0:0:0:0:0:0:0:1%0. That will be the IP v6 address for localhost. How can I check now against a white list of IP v4 addresses if that method returns me a IP v6 address? Can I provide compatibility with IP v4 and v6 for the whitelist? Thank you for your insights!


If it is your local Tomcat, then try to invoke it not by http://localhost:8080/..., try to invoke it by http://127.0.0.1:8080/..


Late to the party but still relevant. Adding the following parameter to your startup script/run configuration will provide you with ipV4 addresses and not ipV6.

-Djava.net.preferIPv4Stack=true

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜