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: 141   Methods: 9
NCLOC: 76   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbstractAccessDecisionManager.java 100% 93.1% 88.9% 94%
coverage coverage
 1    /* Copyright 2004, 2005 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.vote;
 17   
 18    import java.util.Iterator;
 19    import java.util.List;
 20   
 21    import org.acegisecurity.AccessDecisionManager;
 22    import org.acegisecurity.AcegiMessageSource;
 23    import org.acegisecurity.ConfigAttribute;
 24    import org.springframework.beans.factory.InitializingBean;
 25    import org.springframework.context.MessageSource;
 26    import org.springframework.context.MessageSourceAware;
 27    import org.springframework.context.support.MessageSourceAccessor;
 28    import org.springframework.util.Assert;
 29   
 30   
 31    /**
 32    * Abstract implementation of {@link AccessDecisionManager}.
 33    *
 34    * <p>
 35    * Handles configuration of a bean context defined list of {@link
 36    * AccessDecisionVoter}s and the access control behaviour if all voters
 37    * abstain from voting (defaults to deny access).
 38    * </p>
 39    */
 40    public abstract class AbstractAccessDecisionManager
 41    implements AccessDecisionManager, InitializingBean, MessageSourceAware {
 42    //~ Instance fields ========================================================
 43   
 44    private List decisionVoters;
 45    protected MessageSourceAccessor messages = AcegiMessageSource.getAccessor();
 46    private boolean allowIfAllAbstainDecisions = false;
 47   
 48    //~ Methods ================================================================
 49   
 50  1 public void afterPropertiesSet() throws Exception {
 51  1 checkIfValidList(this.decisionVoters);
 52  0 Assert.notNull(this.messages, "A message source must be set");
 53    }
 54   
 55  27 private void checkIfValidList(List listToCheck) {
 56  27 if ((listToCheck == null) || (listToCheck.size() == 0)) {
 57  3 throw new IllegalArgumentException(
 58    "A list of AccessDecisionVoters is required");
 59    }
 60    }
 61   
 62  24 public List getDecisionVoters() {
 63  24 return this.decisionVoters;
 64    }
 65   
 66  14 public boolean isAllowIfAllAbstainDecisions() {
 67  14 return allowIfAllAbstainDecisions;
 68    }
 69   
 70  4 public void setAllowIfAllAbstainDecisions(
 71    boolean allowIfAllAbstainDecisions) {
 72  4 this.allowIfAllAbstainDecisions = allowIfAllAbstainDecisions;
 73    }
 74   
 75  26 public void setDecisionVoters(List newList) {
 76  26 checkIfValidList(newList);
 77   
 78  24 Iterator iter = newList.iterator();
 79   
 80  24 while (iter.hasNext()) {
 81  68 Object currentObject = null;
 82   
 83  68 try {
 84  68 currentObject = iter.next();
 85   
 86  68 AccessDecisionVoter attemptToCast = (AccessDecisionVoter) currentObject;
 87    } catch (ClassCastException cce) {
 88  1 throw new IllegalArgumentException("AccessDecisionVoter "
 89    + currentObject.getClass().getName()
 90    + " must implement AccessDecisionVoter");
 91    }
 92    }
 93   
 94  23 this.decisionVoters = newList;
 95    }
 96   
 97  0 public void setMessageSource(MessageSource messageSource) {
 98  0 this.messages = new MessageSourceAccessor(messageSource);
 99    }
 100   
 101  2 public boolean supports(ConfigAttribute attribute) {
 102  2 Iterator iter = this.decisionVoters.iterator();
 103   
 104  2 while (iter.hasNext()) {
 105  4 AccessDecisionVoter voter = (AccessDecisionVoter) iter.next();
 106   
 107  4 if (voter.supports(attribute)) {
 108  1 return true;
 109    }
 110    }
 111   
 112  1 return false;
 113    }
 114   
 115    /**
 116    * Iterates through all <code>AccessDecisionVoter</code>s and ensures each
 117    * can support the presented class.
 118    *
 119    * <p>
 120    * If one or more voters cannot support the presented class,
 121    * <code>false</code> is returned.
 122    * </p>
 123    *
 124    * @param clazz DOCUMENT ME!
 125    *
 126    * @return DOCUMENT ME!
 127    */
 128  2 public boolean supports(Class clazz) {
 129  2 Iterator iter = this.decisionVoters.iterator();
 130   
 131  2 while (iter.hasNext()) {
 132  4 AccessDecisionVoter voter = (AccessDecisionVoter) iter.next();
 133   
 134  4 if (!voter.supports(clazz)) {
 135  1 return false;
 136    }
 137    }
 138   
 139  1 return true;
 140    }
 141    }