1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.jetspeed.profiler.rules.impl; 18 19 import org.apache.jetspeed.profiler.rules.RuleCriterion; 20 import org.apache.jetspeed.profiler.rules.RuleCriterionResolver; 21 import org.apache.jetspeed.request.RequestContext; 22 23 /*** 24 * IPCriterionResolver 25 * 26 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a> 27 * @author <a href="mailto:philip.donaghy@gmail.com">Philip Mark Donaghy</a> 28 * @version $Id: IPCriterionResolver.java 351839 2005-12-02 21:20:57Z taylor $ 29 */ 30 public class IPCriterionResolver extends StandardResolver implements 31 RuleCriterionResolver 32 { 33 34 /* 35 * (non-Javadoc) 36 * 37 * @see org.apache.jetspeed.profiler.rules.RuleCriterionResolver#resolve(org.apache.jetspeed.request.RequestContext, 38 * org.apache.jetspeed.profiler.rules.RuleCriterion) 39 */ 40 public String resolve(RequestContext context, RuleCriterion criterion) 41 { 42 // look for override 43 String value = super.resolve(context, criterion); 44 if (value != null) { return value.toLowerCase(); } 45 46 // Note IP addresses can vary depending on the client 47 // Konqueror 3.4.2 returns IPv6 e.g. 0:0:0:0:0:0:0:1 48 // Firefox 1.0.7 returns IPv4 e.g. 127.0.0.1 49 // This is the value used to resolve pages in the _ip directory 50 // TODO create an option to convert all IPv4 addresses to IPv6 51 return context.getRequest().getRemoteAddr(); 52 } 53 54 /* 55 * (non-Javadoc) 56 * 57 * @see org.apache.jetspeed.profiler.rules.RuleCriterionResolver#isControl() 58 */ 59 public boolean isControl(RuleCriterion criterion) 60 { 61 return true; 62 } 63 64 }