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: 125   Methods: 9
NCLOC: 64   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AnonymousAuthenticationToken.java 90% 95.7% 100% 95.2%
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.providers.anonymous;
 17   
 18    import org.acegisecurity.GrantedAuthority;
 19    import org.acegisecurity.providers.AbstractAuthenticationToken;
 20   
 21    import org.springframework.util.Assert;
 22   
 23    import java.io.Serializable;
 24   
 25   
 26    /**
 27    * Represents an anonymous <code>Authentication</code>.
 28    *
 29    * @author Ben Alex
 30    * @version $Id: AnonymousAuthenticationToken.java,v 1.4 2005/11/17 00:55:50 benalex Exp $
 31    */
 32    public class AnonymousAuthenticationToken extends AbstractAuthenticationToken
 33    implements Serializable {
 34    //~ Instance fields ========================================================
 35   
 36    private Object principal;
 37    private GrantedAuthority[] authorities;
 38    private boolean authenticated;
 39    private int keyHash;
 40   
 41    //~ Constructors ===========================================================
 42   
 43    /**
 44    * Constructor.
 45    *
 46    * @param key to identify if this object made by an authorised client
 47    * @param principal the principal (typically a <code>UserDetails</code>)
 48    * @param authorities the authorities granted to the principal
 49    *
 50    * @throws IllegalArgumentException if a <code>null</code> was passed
 51    */
 52  24 public AnonymousAuthenticationToken(String key, Object principal,
 53    GrantedAuthority[] authorities) {
 54  24 if ((key == null) || ("".equals(key)) || (principal == null)
 55    || "".equals(principal) || (authorities == null)
 56    || (authorities.length == 0)) {
 57  4 throw new IllegalArgumentException(
 58    "Cannot pass null or empty values to constructor");
 59    }
 60   
 61  20 for (int i = 0; i < authorities.length; i++) {
 62  31 Assert.notNull(authorities[i],
 63    "Granted authority element " + i
 64    + " is null - GrantedAuthority[] cannot contain any null elements");
 65    }
 66   
 67  19 this.keyHash = key.hashCode();
 68  19 this.principal = principal;
 69  19 this.authorities = authorities;
 70  19 this.authenticated = true;
 71    }
 72   
 73  1 protected AnonymousAuthenticationToken() {
 74  1 throw new IllegalArgumentException("Cannot use default constructor");
 75    }
 76   
 77    //~ Methods ================================================================
 78   
 79  1 public void setAuthenticated(boolean isAuthenticated) {
 80  1 this.authenticated = isAuthenticated;
 81    }
 82   
 83  11 public boolean isAuthenticated() {
 84  11 return this.authenticated;
 85    }
 86   
 87  68 public GrantedAuthority[] getAuthorities() {
 88  68 return this.authorities;
 89    }
 90   
 91    /**
 92    * Always returns an empty <code>String</code>
 93    *
 94    * @return an empty String
 95    */
 96  10 public Object getCredentials() {
 97  10 return "";
 98    }
 99   
 100  11 public int getKeyHash() {
 101  11 return this.keyHash;
 102    }
 103   
 104  13 public Object getPrincipal() {
 105  13 return this.principal;
 106    }
 107   
 108  6 public boolean equals(Object obj) {
 109  6 if (!super.equals(obj)) {
 110  2 return false;
 111    }
 112   
 113  4 if (obj instanceof AnonymousAuthenticationToken) {
 114  4 AnonymousAuthenticationToken test = (AnonymousAuthenticationToken) obj;
 115   
 116  4 if (this.getKeyHash() != test.getKeyHash()) {
 117  1 return false;
 118    }
 119   
 120  3 return true;
 121    }
 122   
 123  0 return false;
 124    }
 125    }