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