Clover coverage report - Acegi Security System for Spring - 1.0.0-RC1
Coverage timestamp: Mon Dec 5 2005 09:05:15 EST
file stats: LOC: 139   Methods: 1
NCLOC: 68   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
FilterInvocationDefinitionSourceEditor.java 83.3% 88.9% 100% 87.3%
coverage coverage
 1    /* Copyright 2004 Acegi Technology Pty Limited
 2    *
 3    * Licensed under the Apache License, Version 2.0 (the "License");
 4    * you may not use this file except in compliance with the License.
 5    * You may obtain a copy of the License at
 6    *
 7    * http://www.apache.org/licenses/LICENSE-2.0
 8    *
 9    * Unless required by applicable law or agreed to in writing, software
 10    * distributed under the License is distributed on an "AS IS" BASIS,
 11    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12    * See the License for the specific language governing permissions and
 13    * limitations under the License.
 14    */
 15   
 16    package org.acegisecurity.intercept.web;
 17   
 18    import org.acegisecurity.ConfigAttributeDefinition;
 19    import org.acegisecurity.ConfigAttributeEditor;
 20   
 21    import org.apache.commons.logging.Log;
 22    import org.apache.commons.logging.LogFactory;
 23   
 24    import org.springframework.util.StringUtils;
 25   
 26    import java.beans.PropertyEditorSupport;
 27   
 28    import java.io.BufferedReader;
 29    import java.io.IOException;
 30    import java.io.StringReader;
 31   
 32   
 33    /**
 34    * Property editor to assist with the setup of a {@link
 35    * FilterInvocationDefinitionSource}.
 36    *
 37    * <p>
 38    * The class creates and populates a {@link
 39    * RegExpBasedFilterInvocationDefinitionMap} or {@link
 40    * PathBasedFilterInvocationDefinitionMap} (depending on the type of patterns
 41    * presented).
 42    * </p>
 43    *
 44    * <P>
 45    * By default the class treats presented patterns as regular expressions. If
 46    * the keyword <code>PATTERN_TYPE_APACHE_ANT</code> is present (case
 47    * sensitive), patterns will be treated as Apache Ant paths rather than
 48    * regular expressions.
 49    * </p>
 50    *
 51    * @author Ben Alex
 52    * @version $Id: FilterInvocationDefinitionSourceEditor.java,v 1.3 2005/11/17 00:55:50 benalex Exp $
 53    */
 54    public class FilterInvocationDefinitionSourceEditor
 55    extends PropertyEditorSupport {
 56    //~ Static fields/initializers =============================================
 57   
 58    private static final Log logger = LogFactory.getLog(FilterInvocationDefinitionSourceEditor.class);
 59   
 60    //~ Methods ================================================================
 61   
 62  33 public void setAsText(String s) throws IllegalArgumentException {
 63  33 FilterInvocationDefinitionMap source = new RegExpBasedFilterInvocationDefinitionMap();
 64   
 65  33 if ((s == null) || "".equals(s)) {
 66    // Leave target object empty
 67    } else {
 68    // Check if we need to override the default definition map
 69  31 if (s.lastIndexOf("PATTERN_TYPE_APACHE_ANT") != -1) {
 70  20 source = new PathBasedFilterInvocationDefinitionMap();
 71   
 72  20 if (logger.isDebugEnabled()) {
 73  0 logger.debug(("Detected PATTERN_TYPE_APACHE_ANT directive; using Apache Ant style path expressions"));
 74    }
 75    }
 76   
 77  31 BufferedReader br = new BufferedReader(new StringReader(s));
 78  31 int counter = 0;
 79  31 String line;
 80   
 81  31 while (true) {
 82  146 counter++;
 83   
 84  146 try {
 85  146 line = br.readLine();
 86    } catch (IOException ioe) {
 87  0 throw new IllegalArgumentException(ioe.getMessage());
 88    }
 89   
 90  146 if (line == null) {
 91  30 break;
 92    }
 93   
 94  116 line = line.trim();
 95   
 96  116 if (logger.isDebugEnabled()) {
 97  0 logger.debug("Line " + counter + ": " + line);
 98    }
 99   
 100  116 if (line.startsWith("//")) {
 101  2 continue;
 102    }
 103   
 104  114 if (line.equals("CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON")) {
 105  12 if (logger.isDebugEnabled()) {
 106  0 logger.debug("Line " + counter
 107    + ": Instructing mapper to convert URLs to lowercase before comparison");
 108    }
 109   
 110  12 source.setConvertUrlToLowercaseBeforeComparison(true);
 111   
 112  12 continue;
 113    }
 114   
 115  102 if (line.lastIndexOf('=') == -1) {
 116  45 continue;
 117    }
 118   
 119    // Tokenize the line into its name/value tokens
 120  57 String[] nameValue = StringUtils.delimitedListToStringArray(line,
 121    "=");
 122  57 String name = nameValue[0];
 123  57 String value = nameValue[1];
 124   
 125    // Convert value to series of security configuration attributes
 126  57 ConfigAttributeEditor configAttribEd = new ConfigAttributeEditor();
 127  57 configAttribEd.setAsText(value);
 128   
 129  57 ConfigAttributeDefinition attr = (ConfigAttributeDefinition) configAttribEd
 130    .getValue();
 131   
 132    // Register the regular expression and its attribute
 133  57 source.addSecureUrl(name, attr);
 134    }
 135    }
 136   
 137  32 setValue(source);
 138    }
 139    }