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