Coverage Report - org.acegisecurity.providers.cas.CasAuthenticationToken
 
Classes in this File Line Coverage Branch Coverage Complexity
CasAuthenticationToken
97% 
100% 
2.333
 
 1  
 /* Copyright 2004, 2005, 2006 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  
 
 20  
 import org.acegisecurity.providers.AbstractAuthenticationToken;
 21  
 
 22  
 import org.acegisecurity.userdetails.UserDetails;
 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 1784 2007-02-24 21:00:24Z luke_t $
 34  
  */
 35  
 public class CasAuthenticationToken extends AbstractAuthenticationToken implements Serializable {
 36  
     //~ Instance fields ================================================================================================
 37  
 
 38  
     private static final long serialVersionUID = 1L;
 39  
     private final List proxyList;
 40  
     private final Object credentials;
 41  
     private final Object principal;
 42  
     private final String proxyGrantingTicketIou;
 43  
     private final UserDetails userDetails;
 44  
     private final int keyHash;
 45  
 
 46  
     //~ Constructors ===================================================================================================
 47  
 
 48  
 /**
 49  
      * Constructor.
 50  
      *
 51  
      * @param key to identify if this object made by a given {@link
 52  
      *        CasAuthenticationProvider}
 53  
      * @param principal typically the UserDetails object (cannot  be <code>null</code>)
 54  
      * @param credentials the service/proxy ticket ID from CAS (cannot be
 55  
      *        <code>null</code>)
 56  
      * @param authorities the authorities granted to the user (from {@link
 57  
      *        CasAuthoritiesPopulator}) (cannot be <code>null</code>)
 58  
      * @param userDetails the user details (from {@link
 59  
      *        CasAuthoritiesPopulator}) (cannot be <code>null</code>)
 60  
      * @param proxyList the list of proxies from CAS (cannot be
 61  
      *        <code>null</code>)
 62  
      * @param proxyGrantingTicketIou the PGT-IOU ID from CAS (cannot be
 63  
      *        <code>null</code>, but may be an empty <code>String</code> if no
 64  
      *        PGT-IOU ID was provided)
 65  
      *
 66  
      * @throws IllegalArgumentException if a <code>null</code> was passed
 67  
      */
 68  
     public CasAuthenticationToken(final String key, final Object principal, final Object credentials,
 69  
         final GrantedAuthority[] authorities, final UserDetails userDetails, final List proxyList,
 70  
         final String proxyGrantingTicketIou) {
 71  29
         super(authorities);
 72  
 
 73  28
         if ((key == null) || ("".equals(key)) || (principal == null) || "".equals(principal) || (credentials == null)
 74  
             || "".equals(credentials) || (authorities == null) || (userDetails == null) || (proxyList == null)
 75  
             || (proxyGrantingTicketIou == null)) {
 76  7
             throw new IllegalArgumentException("Cannot pass null or empty values to constructor");
 77  
         }
 78  
 
 79  21
         this.keyHash = key.hashCode();
 80  21
         this.principal = principal;
 81  21
         this.credentials = credentials;
 82  21
         this.userDetails = userDetails;
 83  21
         this.proxyList = proxyList;
 84  21
         this.proxyGrantingTicketIou = proxyGrantingTicketIou;
 85  21
         setAuthenticated(true);
 86  21
     }
 87  
 
 88  
     //~ Methods ========================================================================================================
 89  
 
 90  
     public boolean equals(final Object obj) {
 91  8
         if (!super.equals(obj)) {
 92  2
             return false;
 93  
         }
 94  
 
 95  6
         if (obj instanceof CasAuthenticationToken) {
 96  6
             CasAuthenticationToken test = (CasAuthenticationToken) obj;
 97  
 
 98  
             // proxyGrantingTicketIou is never null due to constructor
 99  6
             if (!this.getProxyGrantingTicketIou().equals(test.getProxyGrantingTicketIou())) {
 100  1
                 return false;
 101  
             }
 102  
 
 103  
             // proxyList is never null due to constructor
 104  5
             if (!this.getProxyList().equals(test.getProxyList())) {
 105  1
                 return false;
 106  
             }
 107  
 
 108  4
             if (this.getKeyHash() != test.getKeyHash()) {
 109  1
                 return false;
 110  
             }
 111  
 
 112  3
             return true;
 113  
         }
 114  
 
 115  0
         return false;
 116  
     }
 117  
 
 118  
     public Object getCredentials() {
 119  23
         return this.credentials;
 120  
     }
 121  
 
 122  
     public int getKeyHash() {
 123  12
         return this.keyHash;
 124  
     }
 125  
 
 126  
     public Object getPrincipal() {
 127  22
         return this.principal;
 128  
     }
 129  
 
 130  
     /**
 131  
      * Obtains the proxy granting ticket IOU.
 132  
      *
 133  
      * @return the PGT IOU-ID or an empty <code>String</code> if no proxy callback was requested when validating the
 134  
      *         service ticket
 135  
      */
 136  
     public String getProxyGrantingTicketIou() {
 137  14
         return proxyGrantingTicketIou;
 138  
     }
 139  
 
 140  
     public List getProxyList() {
 141  12
         return proxyList;
 142  
     }
 143  
 
 144  
     public UserDetails getUserDetails() {
 145  1
         return userDetails;
 146  
     }
 147  
 
 148  
     public String toString() {
 149  1
         StringBuffer sb = new StringBuffer();
 150  1
         sb.append(super.toString());
 151  1
         sb.append("; Credentials (Service/Proxy Ticket): ").append(this.credentials);
 152  1
         sb.append("; Proxy-Granting Ticket IOU: ").append(this.proxyGrantingTicketIou);
 153  1
         sb.append("; Proxy List: ").append(this.proxyList);
 154  
 
 155  1
         return (sb.toString());
 156  
     }
 157  
 }