Restricting IP addresses for Jetty and Solr

前端 未结 2 1721
逝去的感伤
逝去的感伤 2020-12-03 14:36

I\'m setting up Solr using Jetty. I would like to restrict access to only a few IP addresses. It doesn\'t seem immediately obvious that this can be done using Jetty. Is it p

2条回答
  •  悲&欢浪女
    2020-12-03 14:54

    Solr 4.2.1 uses Jetty 8.1.8. Jetty 8 (as noted by jonas789) doesn't support .htaccess. Instead, it uses IPAccessHandler, which doesn't have great documentation available. I had to play with it quite a bit to get it work, so I'm posting an updated solution here.

    IPAccessHandler manages a blacklist and a whitelist, accepts arbitrary ranges of IPs, and supports attaching specific URI paths to each white/black -list entry. IPAccessHandler also subclasses HandlerWrapper, which turns out to be important.

    The solr app still lives in a WebAppContext (as in Lyndsay's solution), but a WebAppContext is now governed by a ContextHandler, which resides in a ContextHandlerCollection occupying the first handler slot in the server. To stop requests from the wrong IP from getting to the app, we need to wrap it inside an IPAccessHandler somewhere along that path. IPAccessHandler behaves oddly if it's in the wrong spot: I tried inserting it before the context handlers and it gave 403 Forbidden to the wrong machines, threw NullPointerException tantrums with no additional error messages, all sorts of nonsense. I finally got it to work by wrapping the ContextHandlerCollection itself, at the server level.

    Go to etc/jetty.xml and scroll to the handlers section. Then wrap the existing ContextHandlerCollection item as follows:

    
     
    
    
      
        
         
       
    
         
         
           
             xxx.xxx.xxx.xxx
           
           
             
             
           
         
         
    
       
           
             
           
           
             
           
         
        
      
    
    

    Resources:

    • http://comments.gmane.org/gmane.comp.java.jetty.support/6066
    • http://wiki.eclipse.org/Jetty#Configuration_Reference
    • http://wiki.eclipse.org/Jetty/Reference/jetty.xml_syntax
    • http://download.eclipse.org/jetty/stable-8/apidocs/org/eclipse/jetty/server/handler/IPAccessHandler.html

提交回复
热议问题