/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.jena.fuseki.authz;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.shiro.web.filter.authz.PortFilter;

/**
 * A Filter that can allow or deny access based on whether the
 * the host that sent the request is the loopback address (AKA localhost).
 * Use of the external IP address of the local machine does not permit access,
 * only the loopback interface is authorized.
 * Responds with HTTP 403 on any denied request.
 *
 * Example:
 * <pre>
 * [main]
 * localhost=org.apache.jena.fuseki.authz.LocalhostFilter
 * ...
 * [urls]
 * /LocalFilesForLocalPeople/** = localhost
 * </pre>
 * @see PortFilter
 */

public class LocalhostFilter extends AuthorizationFilter403 {

    private static final String message = "Access denied : only localhost access allowed";

    public LocalhostFilter() { super(message); }

    private static String LOCALHOST_IpV6 =  "0:0:0:0:0:0:0:1";
    private static String LOCALHOST_IpV4 =  "127.0.0.1";   // Strictly, 127.*.*.*

    @Override
    protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {
        String remoteAddr = request.getRemoteAddr();
        if ( LOCALHOST_IpV6.equals(remoteAddr) || LOCALHOST_IpV4.equals(remoteAddr) )
            return true;
        return false;
    }
}



@@ -840,16 +840,97 @@
 authz;%0A%0A
+import java.util.Arrays;%0Aimport java.util.Collection;%0Aimport java.util.HashSet;%0A%0A
 import j
@@ -1799,19 +1799,86 @@
 OST_IpV6
+_a
  = 
+%22%5B0:0:0:0:0:0:0:1%5D%22;%0A    private static String LOCALHOST_IpV6_b =
  %220:0:0:
@@ -1972,16 +1972,167 @@
 .*.*.*%0A%0A
+    private static final Collection%3CString%3E localhosts = new HashSet%3C%3E(%0A        Arrays.asList(LOCALHOST_IpV4, LOCALHOST_IpV6_a, LOCALHOST_IpV6_b));  %0A%0A
     @Ove
@@ -2329,131 +2329,59 @@
     
-if ( LOCALHOST_IpV6.equals(remoteAddr) %7C%7C LOCALHOST_IpV4.equals(remoteAddr) )%0A            return true;%0A        return false
+return localhosts.contains(request.getRemoteAddr())
 ;%0A  

Handle IPv6 localhost address for Jetty