Coverage Report - org.acegisecurity.providers.rememberme.RememberMeAuthenticationToken
 
Classes in this File Line Coverage Branch Coverage Complexity
RememberMeAuthenticationToken
94% 
100% 
2.6
 
 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.rememberme;
 17  
 
 18  
 import java.io.Serializable;
 19  
 
 20  
 import org.acegisecurity.GrantedAuthority;
 21  
 import org.acegisecurity.providers.AbstractAuthenticationToken;
 22  
 
 23  
 
 24  
 /**
 25  
  * Represents a remembered <code>Authentication</code>.<p>A remembered <code>Authentication</code> must provide a
 26  
  * fully valid <code>Authentication</code>, including the <code>GrantedAuthority</code>[]s that apply.</p>
 27  
  *
 28  
  * @author Ben Alex
 29  
  * @version $Id: RememberMeAuthenticationToken.java 1784 2007-02-24 21:00:24Z luke_t $
 30  
  */
 31  
 public class RememberMeAuthenticationToken extends AbstractAuthenticationToken implements Serializable {
 32  
     //~ Instance fields ================================================================================================
 33  
 
 34  
     private static final long serialVersionUID = 1L;
 35  
     private Object principal;
 36  
     private int keyHash;
 37  
 
 38  
     //~ Constructors ===================================================================================================
 39  
 
 40  
     /**
 41  
      * Constructor.
 42  
      *
 43  
      * @param key to identify if this object made by an authorised client
 44  
      * @param principal the principal (typically a <code>UserDetails</code>)
 45  
      * @param authorities the authorities granted to the principal
 46  
      *
 47  
      * @throws IllegalArgumentException if a <code>null</code> was passed
 48  
      */
 49  
     public RememberMeAuthenticationToken(String key, Object principal, GrantedAuthority[] authorities) {
 50  19
         super(authorities);
 51  
 
 52  18
         if ((key == null) || ("".equals(key)) || (principal == null) || "".equals(principal)) {
 53  2
             throw new IllegalArgumentException("Cannot pass null or empty values to constructor");
 54  
         }
 55  
 
 56  16
         this.keyHash = key.hashCode();
 57  16
         this.principal = principal;
 58  16
         setAuthenticated(true);
 59  16
     }
 60  
 
 61  
     //~ Methods ========================================================================================================
 62  
 
 63  
     public boolean equals(Object obj) {
 64  5
         if (!super.equals(obj)) {
 65  2
             return false;
 66  
         }
 67  
 
 68  3
         if (obj instanceof RememberMeAuthenticationToken) {
 69  3
             RememberMeAuthenticationToken test = (RememberMeAuthenticationToken) obj;
 70  
 
 71  3
             if (this.getKeyHash() != test.getKeyHash()) {
 72  1
                 return false;
 73  
             }
 74  
 
 75  2
             return true;
 76  
         }
 77  
 
 78  0
         return false;
 79  
     }
 80  
 
 81  
     /**
 82  
      * Always returns an empty <code>String</code>
 83  
      *
 84  
      * @return an empty String
 85  
      */
 86  
     public Object getCredentials() {
 87  8
         return "";
 88  
     }
 89  
 
 90  
     public int getKeyHash() {
 91  9
         return this.keyHash;
 92  
     }
 93  
 
 94  
     public Object getPrincipal() {
 95  11
         return this.principal;
 96  
     }
 97  
 }