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: 122   Methods: 8
NCLOC: 46   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbstractAdapterAuthenticationToken.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.adapters;
 17   
 18    import org.acegisecurity.GrantedAuthority;
 19    import org.acegisecurity.providers.AbstractAuthenticationToken;
 20   
 21   
 22    /**
 23    * Convenience superclass for {@link AuthByAdapter} implementations.
 24    *
 25    * @author Ben Alex
 26    * @version $Id: AbstractAdapterAuthenticationToken.java,v 1.5 2005/11/17 00:55:49 benalex Exp $
 27    */
 28    public abstract class AbstractAdapterAuthenticationToken
 29    extends AbstractAuthenticationToken implements AuthByAdapter {
 30    //~ Instance fields ========================================================
 31   
 32    private GrantedAuthority[] authorities;
 33    private int keyHash;
 34   
 35    //~ Constructors ===========================================================
 36   
 37  2 protected AbstractAdapterAuthenticationToken() {
 38  2 super();
 39    }
 40   
 41    /**
 42    * The only way an <code>AbstractAdapterAuthentication</code> should be
 43    * constructed.
 44    *
 45    * @param key the key that is hashed and made available via {@link
 46    * #getKeyHash()}
 47    * @param authorities the authorities granted to this principal
 48    */
 49  19 protected AbstractAdapterAuthenticationToken(String key,
 50    GrantedAuthority[] authorities) {
 51  19 super();
 52  19 this.keyHash = key.hashCode();
 53  19 this.authorities = authorities;
 54    }
 55   
 56    //~ Methods ================================================================
 57   
 58    /**
 59    * Setting is ignored. Always considered authenticated.
 60    *
 61    * @param ignored DOCUMENT ME!
 62    */
 63  1 public void setAuthenticated(boolean ignored) {
 64    // ignored
 65    }
 66   
 67    /**
 68    * Always returns <code>true</code>.
 69    *
 70    * @return DOCUMENT ME!
 71    */
 72  18 public boolean isAuthenticated() {
 73  18 return true;
 74    }
 75   
 76  120 public GrantedAuthority[] getAuthorities() {
 77  120 return authorities;
 78    }
 79   
 80  20 public int getKeyHash() {
 81  20 return this.keyHash;
 82    }
 83   
 84    /**
 85    * Iterates the granted authorities and indicates whether or not the
 86    * specified role is held.
 87    *
 88    * <p>
 89    * Comparison is based on the <code>String</code> returned by {@link
 90    * GrantedAuthority#getAuthority}.
 91    * </p>
 92    *
 93    * @param role the role being searched for in this object's granted
 94    * authorities list
 95    *
 96    * @return <code>true</code> if the granted authority is held, or
 97    * <code>false</code> otherwise
 98    */
 99  6 public boolean isUserInRole(String role) {
 100  6 for (int i = 0; i < this.authorities.length; i++) {
 101  11 if (role.equals(this.authorities[i].getAuthority())) {
 102  2 return true;
 103    }
 104    }
 105   
 106  4 return false;
 107    }
 108   
 109  13 public boolean equals(Object obj) {
 110  13 if (obj instanceof AbstractAdapterAuthenticationToken) {
 111  12 if (!super.equals(obj)) {
 112  4 return false;
 113    }
 114   
 115  8 AbstractAdapterAuthenticationToken test = (AbstractAdapterAuthenticationToken) obj;
 116   
 117  8 return (this.getKeyHash() == test.getKeyHash());
 118    }
 119   
 120  1 return false;
 121    }
 122    }