cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Flynn <pfl...@ucc.ie>
Subject Re: Restricting access by IP address
Date Tue, 15 Sep 2009 09:30:15 GMT
Thomas Markus wrote:
> try a generic RegexMatcher (all untested :) )

I solved it temporarily by simply passing the IP address into the XSLT 
stylesheet and doing the substringing there: that also let me output a 
suitably-formatted eror message for off-siters. Thanks for your help.

///Peter

> in your sitemap add this to components with your pattern:
> <map:matchers default="wildcard">
> <map:matcher name="regular" src="test.RegexMatcher">
>     <pattern>^192\.168\.\d+\.\d+</pattern>
> </map:matcher>
> </map:matchers>
> 
> and in your pipeline:
> 
> <map:match pattern="{request:remoteAddr}" type="regular">
>     <!-- matched content, access regex groups  with {0} or {1} ... -->
> </map:match>
> <!-- unmatched content -->
> 
> 
> package test;
> 
> import java.util.HashMap;
> import java.util.Map;
> import java.util.regex.Pattern;
> 
> import org.apache.avalon.framework.configuration.Configurable;
> import org.apache.avalon.framework.configuration.Configuration;
> import org.apache.avalon.framework.configuration.ConfigurationException;
> import org.apache.avalon.framework.logger.AbstractLogEnabled;
> import org.apache.avalon.framework.parameters.Parameters;
> import org.apache.avalon.framework.thread.ThreadSafe;
> import org.apache.cocoon.matching.Matcher;
> import org.apache.cocoon.sitemap.PatternException;
> 
> public class RegexMatcher extends AbstractLogEnabled implements Matcher,
> Configurable, ThreadSafe {
> 
>     private Pattern    regexpattern;
> 
>     public void configure(Configuration configuration) throws
> ConfigurationException {
>         regexpattern =
> Pattern.compile(configuration.getChild("pattern").getValue().trim());
>     }
> 
>     public Map match(String pattern, Map objectModel, Parameters
> parameters) throws PatternException {
>         java.util.regex.Matcher m = regexpattern.matcher(pattern);
>         if (m.matches()) {
>             HashMap<String, String> h = new HashMap<String, String>();
>             for (int i = 0, j = m.groupCount(); i <= j; i++)
>                 h.put(String.valueOf(i), m.group(i));
>             return h;
>         }
>         return null;
>     }
> 
> }
> 
> 
> Peter Flynn schrieb:
>> Peter Flynn wrote:
>>> Thomas Markus wrote:
>>>> hi,
>>>>
>>>> look at http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#access
>>>>
>>>> or use a matcher/selector in your sitemap
>>>>
>>>> <map:select type="parameter">
>>>>     <map:parameter name="parameter-selector-test"
>>>> value="{request:remoteAddr}" />
>>>>     <map:when test="127.0.0.1">
>>>>         <!-- actions for this ip -->
>>>>     </map:when>
>>>>     <map:otherwise>
>>>>         <!--  -->
>>>>     </map:otherwise>
>>>> </map:select>
>>> That look like the right approach...except I can't find any
>>> documentation at
>>> http://cocoon.apache.org/2.2/core-modules/core/2.2/840_1_1.html on
>>> the syntax of the test attribute.
>> I found some under the entry for Parameter Selector but it appears
>> that the test will only perform a plain equality. Is there a way to
>> perform a substring operation; when testing an IP address for access
>> permission I want to allow all xxx.yyy.*.* and prohibit everything else.
>>
>> ///Peter
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>> For additional commands, e-mail: users-help@cocoon.apache.org
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message