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: 124   Methods: 6
NCLOC: 62   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ChannelDecisionManagerImpl.java 100% 100% 100% 100%
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.securechannel;
 17   
 18    import org.acegisecurity.ConfigAttribute;
 19    import org.acegisecurity.ConfigAttributeDefinition;
 20    import org.acegisecurity.intercept.web.FilterInvocation;
 21   
 22    import org.springframework.beans.factory.InitializingBean;
 23   
 24    import java.io.IOException;
 25   
 26    import java.util.Iterator;
 27    import java.util.List;
 28   
 29    import javax.servlet.ServletException;
 30   
 31   
 32    /**
 33    * Implementation of {@link ChannelDecisionManager}.
 34    *
 35    * <p>
 36    * Iterates through each configured {@link ChannelProcessor}. If a
 37    * <code>ChannelProcessor</code> has any issue with the security of the
 38    * request, it should cause a redirect, exception or whatever other action is
 39    * appropriate for the <code>ChannelProcessor</code> implementation.
 40    * </p>
 41    *
 42    * <P>
 43    * Once any response is committed (ie a redirect is written to the response
 44    * object), the <code>ChannelDecisionManagerImpl</code> will not iterate
 45    * through any further <code>ChannelProcessor</code>s.
 46    * </p>
 47    *
 48    * @author Ben Alex
 49    * @version $Id: ChannelDecisionManagerImpl.java,v 1.4 2005/11/17 00:55:50 benalex Exp $
 50    */
 51    public class ChannelDecisionManagerImpl implements ChannelDecisionManager,
 52    InitializingBean {
 53    //~ Instance fields ========================================================
 54   
 55    private List channelProcessors;
 56   
 57    //~ Methods ================================================================
 58   
 59  7 public void setChannelProcessors(List newList) {
 60  7 checkIfValidList(newList);
 61   
 62  5 Iterator iter = newList.iterator();
 63   
 64  5 while (iter.hasNext()) {
 65  9 Object currentObject = null;
 66   
 67  9 try {
 68  9 currentObject = iter.next();
 69   
 70  9 ChannelProcessor attemptToCast = (ChannelProcessor) currentObject;
 71    } catch (ClassCastException cce) {
 72  1 throw new IllegalArgumentException("ChannelProcessor "
 73    + currentObject.getClass().getName()
 74    + " must implement ChannelProcessor");
 75    }
 76    }
 77   
 78  4 this.channelProcessors = newList;
 79    }
 80   
 81  2 public List getChannelProcessors() {
 82  2 return this.channelProcessors;
 83    }
 84   
 85  4 public void afterPropertiesSet() throws Exception {
 86  4 checkIfValidList(this.channelProcessors);
 87    }
 88   
 89  2 public void decide(FilterInvocation invocation,
 90    ConfigAttributeDefinition config) throws IOException, ServletException {
 91  2 Iterator iter = this.channelProcessors.iterator();
 92   
 93  2 while (iter.hasNext()) {
 94  3 ChannelProcessor processor = (ChannelProcessor) iter.next();
 95   
 96  3 processor.decide(invocation, config);
 97   
 98  3 if (invocation.getResponse().isCommitted()) {
 99  1 break;
 100    }
 101    }
 102    }
 103   
 104  3 public boolean supports(ConfigAttribute attribute) {
 105  3 Iterator iter = this.channelProcessors.iterator();
 106   
 107  3 while (iter.hasNext()) {
 108  5 ChannelProcessor processor = (ChannelProcessor) iter.next();
 109   
 110  5 if (processor.supports(attribute)) {
 111  2 return true;
 112    }
 113    }
 114   
 115  1 return false;
 116    }
 117   
 118  11 private void checkIfValidList(List listToCheck) {
 119  11 if ((listToCheck == null) || (listToCheck.size() == 0)) {
 120  3 throw new IllegalArgumentException(
 121    "A list of ChannelProcessors is required");
 122    }
 123    }
 124    }