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: 184   Methods: 13
NCLOC: 101   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CasAuthenticationToken.java 100% 100% 100% 100%
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.cas;
 17   
 18    import org.acegisecurity.GrantedAuthority;
 19    import org.acegisecurity.providers.AbstractAuthenticationToken;
 20    import org.acegisecurity.userdetails.UserDetails;
 21   
 22    import org.springframework.util.Assert;
 23   
 24    import java.io.Serializable;
 25   
 26    import java.util.List;
 27   
 28   
 29    /**
 30    * Represents a successful CAS <code>Authentication</code>.
 31    *
 32    * @author Ben Alex
 33    * @version $Id: CasAuthenticationToken.java,v 1.10 2005/11/29 13:10:07 benalex Exp $
 34    */
 35    public class CasAuthenticationToken extends AbstractAuthenticationToken
 36    implements Serializable {
 37    //~ Instance fields ========================================================
 38   
 39    private List proxyList;
 40    private Object credentials;
 41    private Object principal;
 42    private String proxyGrantingTicketIou;
 43    private UserDetails userDetails;
 44    private GrantedAuthority[] authorities;
 45    private boolean authenticated;
 46    private int keyHash;
 47   
 48    //~ Constructors ===========================================================
 49   
 50    /**
 51    * Constructor.
 52    *
 53    * @param key to identify if this object made by a given {@link
 54    * CasAuthenticationProvider}
 55    * @param principal the username from CAS (cannot be <code>null</code>)
 56    * @param credentials the service/proxy ticket ID from CAS (cannot be
 57    * <code>null</code>)
 58    * @param authorities the authorities granted to the user (from {@link
 59    * CasAuthoritiesPopulator}) (cannot be <code>null</code>)
 60    * @param userDetails the user details (from {@link
 61    * CasAuthoritiesPopulator}) (cannot be <code>null</code>)
 62    * @param proxyList the list of proxies from CAS (cannot be
 63    * <code>null</code>)
 64    * @param proxyGrantingTicketIou the PGT-IOU ID from CAS (cannot be
 65    * <code>null</code>, but may be an empty <code>String</code> if no
 66    * PGT-IOU ID was provided)
 67    *
 68    * @throws IllegalArgumentException if a <code>null</code> was passed
 69    */
 70  28 public CasAuthenticationToken(String key, Object principal,
 71    Object credentials, GrantedAuthority[] authorities,
 72    UserDetails userDetails, List proxyList, String proxyGrantingTicketIou) {
 73  28 if ((key == null) || ("".equals(key)) || (principal == null)
 74    || "".equals(principal) || (credentials == null)
 75    || "".equals(credentials) || (authorities == null)
 76    || (userDetails == null) || (proxyList == null)
 77    || (proxyGrantingTicketIou == null)) {
 78  7 throw new IllegalArgumentException(
 79    "Cannot pass null or empty values to constructor");
 80    }
 81   
 82  21 for (int i = 0; i < authorities.length; i++) {
 83  41 Assert.notNull(authorities[i],
 84    "Granted authority element " + i
 85    + " is null - GrantedAuthority[] cannot contain any null elements");
 86    }
 87   
 88  20 this.keyHash = key.hashCode();
 89  20 this.principal = principal;
 90  20 this.credentials = credentials;
 91  20 this.authorities = authorities;
 92  20 this.userDetails = userDetails;
 93  20 this.proxyList = proxyList;
 94  20 this.proxyGrantingTicketIou = proxyGrantingTicketIou;
 95  20 this.authenticated = true;
 96    }
 97   
 98  1 protected CasAuthenticationToken() {
 99  1 throw new IllegalArgumentException("Cannot use default constructor");
 100    }
 101   
 102    //~ Methods ================================================================
 103   
 104  1 public void setAuthenticated(boolean isAuthenticated) {
 105  1 this.authenticated = isAuthenticated;
 106    }
 107   
 108  16 public boolean isAuthenticated() {
 109  16 return this.authenticated;
 110    }
 111   
 112  102 public GrantedAuthority[] getAuthorities() {
 113  102 return this.authorities;
 114    }
 115   
 116  21 public Object getCredentials() {
 117  21 return this.credentials;
 118    }
 119   
 120  12 public int getKeyHash() {
 121  12 return this.keyHash;
 122    }
 123   
 124  20 public Object getPrincipal() {
 125  20 return this.principal;
 126    }
 127   
 128    /**
 129    * Obtains the proxy granting ticket IOU.
 130    *
 131    * @return the PGT IOU-ID or an empty <code>String</code> if no proxy
 132    * callback was requested when validating the service ticket
 133    */
 134  14 public String getProxyGrantingTicketIou() {
 135  14 return proxyGrantingTicketIou;
 136    }
 137   
 138  12 public List getProxyList() {
 139  12 return proxyList;
 140    }
 141   
 142  1 public UserDetails getUserDetails() {
 143  1 return userDetails;
 144    }
 145   
 146  8 public boolean equals(Object obj) {
 147  8 if (!super.equals(obj)) {
 148  1 return false;
 149    }
 150   
 151  7 if (obj instanceof CasAuthenticationToken) {
 152  6 CasAuthenticationToken test = (CasAuthenticationToken) obj;
 153   
 154    // proxyGrantingTicketIou is never null due to constructor
 155  6 if (!this.getProxyGrantingTicketIou().equals(test
 156    .getProxyGrantingTicketIou())) {
 157  1 return false;
 158    }
 159   
 160    // proxyList is never null due to constructor
 161  5 if (!this.getProxyList().equals(test.getProxyList())) {
 162  1 return false;
 163    }
 164   
 165  4 if (this.getKeyHash() != test.getKeyHash()) {
 166  1 return false;
 167    }
 168   
 169  3 return true;
 170    }
 171   
 172  1 return false;
 173    }
 174   
 175  1 public String toString() {
 176  1 StringBuffer sb = new StringBuffer();
 177  1 sb.append(super.toString());
 178  1 sb.append("; Credentials (Service/Proxy Ticket): " + this.credentials);
 179  1 sb.append("; Proxy-Granting Ticket IOU: " + this.proxyGrantingTicketIou);
 180  1 sb.append("; Proxy List: " + this.proxyList.toString());
 181   
 182  1 return sb.toString();
 183    }
 184    }