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: 153   Methods: 6
NCLOC: 82   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AclProviderManager.java 75% 86.5% 100% 84.1%
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.acl;
 17   
 18    import org.acegisecurity.Authentication;
 19   
 20    import org.apache.commons.logging.Log;
 21    import org.apache.commons.logging.LogFactory;
 22   
 23    import org.springframework.beans.factory.InitializingBean;
 24    import org.springframework.util.Assert;
 25   
 26    import java.util.Iterator;
 27    import java.util.List;
 28   
 29   
 30    /**
 31    * Iterates through a list of {@link AclProvider}s to locate the ACLs that
 32    * apply to a given domain object instance.
 33    *
 34    * <P>
 35    * If no compatible provider is found, it is assumed that no ACLs apply for the
 36    * specified domain object instance and <code>null</code> is returned.
 37    * </p>
 38    *
 39    * @author Ben Alex
 40    * @version $Id: AclProviderManager.java,v 1.4 2005/11/17 00:55:51 benalex Exp $
 41    */
 42    public class AclProviderManager implements AclManager, InitializingBean {
 43    //~ Static fields/initializers =============================================
 44   
 45    private static final Log logger = LogFactory.getLog(AclProviderManager.class);
 46   
 47    //~ Instance fields ========================================================
 48   
 49    private List providers;
 50   
 51    //~ Methods ================================================================
 52   
 53  4 public AclEntry[] getAcls(Object domainInstance) {
 54  4 Assert.notNull(domainInstance, "domainInstance is null - violating interface contract");
 55   
 56  3 Iterator iter = providers.iterator();
 57   
 58  3 while (iter.hasNext()) {
 59  3 AclProvider provider = (AclProvider) iter.next();
 60   
 61  3 if (provider.supports(domainInstance)) {
 62  1 if (logger.isDebugEnabled()) {
 63  0 logger.debug("ACL lookup using "
 64    + provider.getClass().getName());
 65    }
 66   
 67  1 return provider.getAcls(domainInstance);
 68    }
 69    }
 70   
 71  2 if (logger.isDebugEnabled()) {
 72  0 logger.debug("No AclProvider found for "
 73    + domainInstance.toString());
 74    }
 75   
 76  2 return null;
 77    }
 78   
 79  4 public AclEntry[] getAcls(Object domainInstance,
 80    Authentication authentication) {
 81  4 Assert.notNull(domainInstance, "domainInstance is null - violating interface contract");
 82  3 Assert.notNull(authentication, "authentication is null - violating interface contract");
 83   
 84  2 Iterator iter = providers.iterator();
 85   
 86  2 while (iter.hasNext()) {
 87  2 AclProvider provider = (AclProvider) iter.next();
 88   
 89  2 if (provider.supports(domainInstance)) {
 90  1 if (logger.isDebugEnabled()) {
 91  0 logger.debug("ACL lookup using "
 92    + provider.getClass().getName());
 93    }
 94   
 95  1 return provider.getAcls(domainInstance, authentication);
 96    } else {
 97  1 if (logger.isDebugEnabled()) {
 98  0 logger.debug("Provider " + provider.toString()
 99    + " does not support " + domainInstance);
 100    }
 101    }
 102    }
 103   
 104  1 if (logger.isDebugEnabled()) {
 105  0 logger.debug("No AclProvider found for "
 106    + domainInstance.toString());
 107    }
 108   
 109  1 return null;
 110    }
 111   
 112    /**
 113    * Sets the {@link AclProvider} objects to be used for ACL determinations.
 114    *
 115    * @param newList that should be used for ACL determinations
 116    *
 117    * @throws IllegalArgumentException if an invalid provider was included in
 118    * the list
 119    */
 120  7 public void setProviders(List newList) {
 121  7 checkIfValidList(newList);
 122   
 123  6 Iterator iter = newList.iterator();
 124   
 125  6 while (iter.hasNext()) {
 126  6 Object currentObject = null;
 127   
 128  6 try {
 129  6 currentObject = iter.next();
 130   
 131  6 AclProvider attemptToCast = (AclProvider) currentObject;
 132    } catch (ClassCastException cce) {
 133  1 throw new IllegalArgumentException("AclProvider "
 134    + currentObject.getClass().getName()
 135    + " must implement AclProvider");
 136    }
 137    }
 138   
 139  5 this.providers = newList;
 140    }
 141   
 142  1 public List getProviders() {
 143  1 return this.providers;
 144    }
 145   
 146  2 public void afterPropertiesSet() throws Exception {
 147  2 checkIfValidList(this.providers);
 148    }
 149   
 150  9 private void checkIfValidList(List listToCheck) {
 151  9 Assert.notEmpty(listToCheck, "A list of AclManagers is required");
 152    }
 153    }