Configuring jetty to accept connections from only certain IP addresses

jettysolr

I am using the jetty that is shipped with Apache Solr to run Solr. I would like to configure jetty such that it only accepts connections from certain IP addresses. I know I can bind jetty to 127.0.0.1 to only accept connections from the localhost:

<Set name="host"><SystemProperty name="jetty.host" default="127.0.0.1" /></Set>

But how I do set it so that it can accept connections from certain non-localhost IP addresses as well?

Best Answer

You can use the IPAccessHandler that is in jetty 7, 8 and 9

http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/server/handler/IPAccessHandler.html

you would wire this up in the handler chain so that it is executed before anything else in the handler chains

[edit] also look at the jetty-ipaccess.xml file under $jetty.home/etc

http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/jetty-server/src/main/config/etc/jetty-ipaccess.xml