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: 104   Methods: 4
NCLOC: 59   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbstractAuthenticationToken.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;
 17   
 18    import org.acegisecurity.Authentication;
 19    import org.acegisecurity.userdetails.UserDetails;
 20   
 21   
 22    /**
 23    * Provides a <code>String</code> representation of the Authentication token.
 24    *
 25    * @author Ben Alex
 26    * @version $Id: AbstractAuthenticationToken.java,v 1.10 2005/11/29 13:10:09 benalex Exp $
 27    */
 28    public abstract class AbstractAuthenticationToken implements Authentication {
 29    //~ Methods ================================================================
 30   
 31    /**
 32    * Subclasses should override if they wish to provide additional details
 33    * about the authentication event.
 34    *
 35    * @return always <code>null</code>
 36    */
 37  5 public Object getDetails() {
 38  5 return null;
 39    }
 40   
 41  29 public String getName() {
 42  29 if (this.getPrincipal() instanceof UserDetails) {
 43  2 return ((UserDetails) this.getPrincipal()).getUsername();
 44    }
 45   
 46  27 return this.getPrincipal().toString();
 47    }
 48   
 49  51 public boolean equals(Object obj) {
 50  51 if (obj instanceof AbstractAuthenticationToken) {
 51  50 AbstractAuthenticationToken test = (AbstractAuthenticationToken) obj;
 52   
 53  50 if (!((this.getAuthorities() == null)
 54    && (test.getAuthorities() == null))) {
 55  45 if ((this.getAuthorities() == null)
 56    || (test.getAuthorities() == null)) {
 57  2 return false;
 58    }
 59   
 60  43 if (this.getAuthorities().length != test.getAuthorities().length) {
 61  2 return false;
 62    }
 63   
 64  41 for (int i = 0; i < this.getAuthorities().length; i++) {
 65  75 if (!this.getAuthorities()[i].equals(
 66    test.getAuthorities()[i])) {
 67  2 return false;
 68    }
 69    }
 70    }
 71   
 72  44 return (this.getPrincipal().equals(test.getPrincipal())
 73    && this.getCredentials().equals(test.getCredentials())
 74    && (this.isAuthenticated() == test.isAuthenticated()));
 75    }
 76   
 77  1 return false;
 78    }
 79   
 80  9 public String toString() {
 81  9 StringBuffer sb = new StringBuffer();
 82  9 sb.append(super.toString()).append(": ");
 83  9 sb.append("Username: ").append(this.getPrincipal()).append("; ");
 84  9 sb.append("Password: [PROTECTED]; ");
 85  9 sb.append("Authenticated: ").append(this.isAuthenticated()).append("; ");
 86  9 sb.append("Details: ").append(this.getDetails()).append("; ");
 87   
 88  9 if (this.getAuthorities() != null) {
 89  6 sb.append("Granted Authorities: ");
 90   
 91  6 for (int i = 0; i < this.getAuthorities().length; i++) {
 92  9 if (i > 0) {
 93  4 sb.append(", ");
 94    }
 95   
 96  9 sb.append(this.getAuthorities()[i].toString());
 97    }
 98    } else {
 99  3 sb.append("Not granted any authorities");
 100    }
 101   
 102  9 return sb.toString();
 103    }
 104    }