Address range support in ClientIpActivationStrategy - #172
Conversation
| ips.add(InetAddress.getByName(part)); | ||
| } | ||
| } catch (Exception e) { | ||
| log.warn("Ignoring illegal IP address or CIDR range " + part); |
There was a problem hiding this comment.
Not sure if this exception should be catched here. How would the togglz-console UI handle it?
There was a problem hiding this comment.
First you should catch UnknownHostException instead of Exception here.
And we should perhaps use the ParameterBuilder to create a validation rule for parameter values. The builder supports this using regular expressions. But you could also provider you own Parameter implementation which provides custom validation code. See ScriptEngineActivationStrategy for an example. This way we could catch invalid strategy parameters before they are saved.
| } | ||
|
|
||
| try { | ||
| if (ips.contains(InetAddress.getByName(request.getRemoteAddr()))) { |
There was a problem hiding this comment.
Does InetAddress.getByName() perform DNS lookups? If so, we should not use it because it will be a performance problem.
There was a problem hiding this comment.
Just checked the implementation. If the given address is an IPv4 or IPv6 address, no DNS lookup is done.
|
Thanks a lot for providing help with this. I added some comments to your code. |
|
I introduced a |
|
Awesome! Thanks a lot! I'll have a depper look at this ASAP. I'm currently packing my stuff for a two week trip. So it may take some time. Sorry about that. |
| if (cidrUtil.isInRange(remoteAddr)) { | ||
| return true; | ||
| } | ||
| } else if (InetAddress.getByName(remoteAddr).equals(InetAddress.getByName(part))) { |
There was a problem hiding this comment.
I think InetAddress.getByName(remoteAddr) should be moved out of the loop for performance...
|
Hey. Sorry for the delay. As I wrote earlier I'm currently on vacation and I promised my wife to not use the notebook too much. ;-) Your code looks great! I just added two comments. Thank you very much for your contribution. This is awesome! |
|
And BTW: The Parameter implementation looks great. This way the parameters will be validated correctly and there should never be an invalid IP / netmask, which is great! |
Just hold to this promise... ;-) I implemented your suggestions. |
|
Awesome! This looks great! Thank you so much. But it looks like there are test failures... Not sure why. Actually I don't think it is related to your changes. I'll have to check that... |
|
Ok, tests are green now. Seems like this was just a temporary failure. I just merged your changes. Thank you very much! 🍻 |
|
Nice! I'm looking forward to use this new feature... :-) |
|
I hope to find some time at the weekend to cut a release... |
|
Hey @ractive, I've a funny story to share. I just ran into weird test failures with the test you implemented on my notebook. Basically the failing test verified, that So the current code treats I "fixed" this like this: 1609f9b I'm not sure if I like that the code currently resolves hostnames. Does this make sense? |
|
Of course does the alphabet resolve Hm. This "abc/24" was a way to test the IllegalArgumentException that is thrown by the CIDRUtil. |
|
Awesome. Thanks. ;-) |
|
Back from holiday. I hope I can give it a shot this week... |
No description provided.