Coverage report

  %line %branch
org.apache.jetspeed.security.spi.impl.DefaultPasswordCredentialImpl
0% 
0% 

 1  
 /* 
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *     http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.jetspeed.security.spi.impl;
 18  
 
 19  
 import java.io.Serializable;
 20  
 import java.sql.Date;
 21  
 import java.sql.Timestamp;
 22  
 import java.util.Arrays;
 23  
 
 24  
 import org.apache.jetspeed.security.PasswordCredential;
 25  
 import org.apache.jetspeed.security.om.InternalCredential;
 26  
 
 27  
 /**
 28  
  * <p>
 29  
  * Default Password credential implementation. Provides the same mechanism as J2EE
 30  
  * <code>javax.resource.spi.security.PasswordCredential</code>.
 31  
  * </p>
 32  
  * 
 33  
  * <p>
 34  
  * Code borrowed from the Geronimo project.
 35  
  * </p>
 36  
  * 
 37  
  * @author <a href="mailto:dlestrat@apache.org">David Le Strat </a>
 38  
  */
 39  
 public class DefaultPasswordCredentialImpl implements PasswordCredential, Serializable
 40  
 {
 41  
 
 42  
     /** The default uid. */
 43  
     private static final long serialVersionUID = -4975305752376365096L;
 44  
 
 45  
     /** The user name. */
 46  
     private String userName;
 47  
 
 48  
     /** The password. */
 49  
     private char[] password;
 50  
 
 51  
     /** The update required state */
 52  
     private boolean updateRequired;
 53  
     
 54  
     /** The enabled state. */
 55  0
     private boolean enabled = true;
 56  
     
 57  
     /** The expired state. */
 58  
     private boolean expired;
 59  
     
 60  
     /** The expiration date. */
 61  
     private Date expirationDate;
 62  
     
 63  
     /** The previous authentication in date */
 64  
     private Timestamp previousAuthenticationDate;
 65  
     
 66  
     /** The last authentication in date */
 67  
     private Timestamp lastAuthenticationDate;
 68  
     
 69  
     /** The number of authentication failures */
 70  
     private int authenticationFailures;
 71  
 
 72  
     /**
 73  
      * @param userName
 74  
      * @param password
 75  
      */
 76  
     public DefaultPasswordCredentialImpl(String userName, char[] password)
 77  0
     {
 78  0
         this.userName = userName;
 79  0
         this.password = (char[]) password.clone();
 80  0
     }
 81  
     
 82  
     public DefaultPasswordCredentialImpl(String userName, InternalCredential credential)
 83  
     {
 84  0
         this(userName, credential.getValue().toCharArray());
 85  0
         this.updateRequired = credential.isUpdateRequired();
 86  0
         this.enabled = credential.isEnabled();
 87  0
         this.expired = credential.isExpired();
 88  0
         this.expirationDate = credential.getExpirationDate();
 89  0
         this.previousAuthenticationDate = credential.getPreviousAuthenticationDate();
 90  0
         this.lastAuthenticationDate = credential.getLastAuthenticationDate();
 91  0
         this.authenticationFailures = credential.getAuthenticationFailures();
 92  0
     }
 93  
     
 94  
     /**
 95  
      * @return The username.
 96  
      */
 97  
     public String getUserName()
 98  
     {
 99  0
         return userName;
 100  
     }
 101  
 
 102  
     /**
 103  
      * @return The password.
 104  
      */
 105  
     public char[] getPassword()
 106  
     {
 107  0
         return (char[]) password.clone();
 108  
     }
 109  
     
 110  
     
 111  
     /**
 112  
      * @see org.apache.jetspeed.security.PasswordCredential#isUpdateRequired()
 113  
      */
 114  
     public boolean isUpdateRequired()
 115  
     {
 116  0
         return updateRequired;
 117  
     }
 118  
 
 119  
     /**
 120  
      * @see org.apache.jetspeed.security.PasswordCredential#isEnabled()
 121  
      */
 122  
     public boolean isEnabled()
 123  
     {
 124  0
         return enabled;
 125  
     }
 126  
 
 127  
     /**
 128  
      * @see org.apache.jetspeed.security.PasswordCredential#isExpired()
 129  
      */
 130  
     public boolean isExpired()
 131  
     {
 132  0
         return expired;
 133  
     }
 134  
 
 135  
     /**
 136  
      * @see org.apache.jetspeed.security.PasswordCredential#getExpirationDate()
 137  
      */
 138  
     public Date getExpirationDate()
 139  
     {
 140  0
         return expirationDate;
 141  
     }
 142  
     
 143  
     /**
 144  
      * @see org.apache.jetspeed.security.PasswordCredential#getPreviousAuthenticationDate()
 145  
      */
 146  
     public Timestamp getPreviousAuthenticationDate()
 147  
     {
 148  0
         return previousAuthenticationDate;
 149  
     }
 150  
 
 151  
     /**
 152  
      * @see org.apache.jetspeed.security.PasswordCredential#getLastAuthenticationDate()
 153  
      */
 154  
     public Timestamp getLastAuthenticationDate()
 155  
     {
 156  0
         return lastAuthenticationDate;
 157  
     }
 158  
 
 159  
     /** 
 160  
      * @see org.apache.jetspeed.security.PasswordCredential#getAuthenticationFailures()
 161  
      */
 162  
     public int getAuthenticationFailures()
 163  
     {
 164  0
         return authenticationFailures;
 165  
     }
 166  
 
 167  
     /**
 168  
      * @see java.lang.Object#equals(java.lang.Object)
 169  
      */
 170  
     public boolean equals(Object o)
 171  
     {
 172  0
         if (this == o)
 173  0
             return true;
 174  0
         if (!(o instanceof DefaultPasswordCredentialImpl))
 175  0
             return false;
 176  
 
 177  0
         final DefaultPasswordCredentialImpl credential = (DefaultPasswordCredentialImpl) o;
 178  
 
 179  0
         if (!Arrays.equals(password, credential.password))
 180  0
             return false;
 181  0
         if (!userName.equals(credential.userName))
 182  0
             return false;
 183  
 
 184  0
         return true;
 185  
     }
 186  
 
 187  
     /**
 188  
      * @see java.lang.Object#hashCode()
 189  
      */
 190  
     public int hashCode()
 191  
     {
 192  0
         int result = userName.hashCode();
 193  0
         for (int i = 0; i < password.length; i++)
 194  
         {
 195  0
             result *= password[i];
 196  
         }
 197  0
         return result;
 198  
     }
 199  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.